/* ***************************************
 *	Name		:		lib.js 
 * 	Date		:		2007/11/03
 * 	Autor		:		Nono Martinez <nonomartinez@gmail.com>
 *	package		:		rima
 * 	Description	:		Ajax rima lib for rima.js.
 *	Depends		:		jquery.js, rima.js
 */ 

rimaLive = function (ev,el,callback){
	$(el).live(ev, function(){ 
		eval(callback);
	});
}

rimaLoad = function (div,url){
	$(div).load(url);
}

rimaGo = function (div,url,pars) {
	$(div).load(url + pars);
}

rimaLink = function(div, url, pars, method, params ){
	$(document).ready( function(){
		
		if(method == undefined) method = 'get';
		
		$.ajax({
		   type: method,
		   url: url,
		   dataType:'html',
		   async:true,
		   data: pars,
		   
		   beforeSend: function(xhr) {

				if(params != undefined && params.beforeSend != undefined){
			    	eval(params.beforeSend);
				
			    }
		   },
		   
		   success: function(data){
		   		
				$(div).html(data);
		
				if(params != undefined && params.success != undefined){
					eval(params.success);
				}
		   },
		   
		   error: function (XMLHttpRequest, textStatus, errorThrown) {
			  if(params != undefined && params.error != undefined){
			  	eval(params.error);
			  }
		   },
		   
		   complete: function (XMLHttpRequest, textStatus) {
			  if(params != undefined && params.complete != undefined){
				  eval(params.complete);
			  }
		   }
		});
	});
}

rimaSubmit = function (frm, div, url, pars, method, params) {
		
		$(document).ready(function(){
		 if(pars == null || pars == undefined) pars == '';
		 if(method == undefined) method = 'POST';
		 
		if($(frm).valid()){
			$(frm).submit(function() {
				$.ajax({
				      type: method,
				      url: url + "?" + pars,
				      data: $(frm).formSerialize(),
				      success: function(data){

								$("#content").html(data);
							},
					  error: function(data){
					  		},
					  complete: function(){
					  		}
					  
				});
				return false;
			});
		}
	});
		
}

rimaDrop = function (div, modulo, pars){
	$(document).ready(function(){
	  if (confirm('Esta seguro de que desea borrar el registro?')){
		var url = 'modulos/' + modulo + '/borrar.php';
		$.ajax({
		   type: 'get',
		   url: url,
		   dataType:'html',
		   contentType: 'application/x-www-form-urlencoded',
		   data: pars,
		   async: true,
		   
		   beforeSend: function(xhr) {
		   },
		   
		   success: function(datos){
				$('div#content').html(datos);
		   }
		});
	  }
	});
}


rimaTranslate = function(el,lang) {
    $(el).translate(lang);
}


rimaSwitchStyle = function(t) {
    var ss = $("link[@rel$=stylesheet]");
    ss.each(function(i) {
        this.disabled = true;
        if (this.title && this.title == t) {
            this.disabled = false;
        } 
    });
}


