

function sending_form_html(php, parametros, salida){
    send_data(php, parametros, salida, "html");
}

// ************* ENVIA UN FORMULARIO **********************
function sending_form_json(php, parametros, salida){
    send_data(php, parametros, salida, "json");
}

function send_data(php, parametros, salida, formato){
    if(parametros.length>0){
        $.ajax({         
             dataType: formato,
             cache:false,
             data:parametros + "&control=" + control,
             type:"post",
             url:php,
             success:function(data){
                   if(salida!="") window[salida](data);
    	     }
    	});
    }
}


function validar_vacio(texto){
    if(jQuery.trim($("#" + texto).val())==""){
        $("#" + texto).addClass("ui-state-error");
        return false;
    }else{
        $("#" + texto).removeClass("ui-state-error");
        return true;
    }
}


function validar_email(email){
    if(validar_vacio($("#" + email).val())){
       if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#" + email).val())) {
          $("#" + email).removeClass("ui-state-error");
          return true;
       }else{
          $("#" + email).addClass("ui-state-error");
          return false;
       }
    }else return false;
}









function validar_formulario_vacio(id_form){
    var salida = true;
    $("#" + id_form +" select").each(function(){
             if($(this).val().length == 0){
                $(this).addClass("error");
                salida = false;
             }else $(this).removeClass("error");
    });
    
    $("#" + id_form +" input").each(function(){
        if(jQuery.trim($(this).val())=="") {
                $(this).addClass("error");
                salida = false;
             }else $(this).removeClass("error");
    });
    
    return salida;
}



//************ LIMPIA LOS DATOS ANTES DE ENVIAR *********************************************
function prepare_send(id_form){
   
        var salida = "";
        var andpersand = "";
        var valor = "";
        
        $("#" + id_form +" select").each(function(){
             if($(this).val()!=""){ 
                salida = salida + andpersand + $(this).attr("name") + "=" + $(this).val();
                andpersand = "&"; 
             }
        });
        
        $("#" + id_form +" input").each(function(){
            if($(this).attr("type")=="checkbox"){
                if($(this).attr("checked") == true) {
                    salida = salida + andpersand + $(this).attr("name") + "=" + $(this).val();
                    andpersand = "&";
                }
            }else{
                if($(this).val()!=""){
                     if((strpos($(this).val(),"&") === false) ) valor = $(this).val();
                     else valor = str_replace("&","%26",$(this).val());
                     
                     salida = salida + andpersand + $(this).attr("name") + "=" + valor;
                     andpersand = "&";
                }
            }
        });
        
        salida = salida + andpersand + "control=" + $("#control_sesion").val();
        
    
    return salida;
}
// ****************************************************************************************

// ********** reemplaza string por otro ***************************************************
function str_replace(busca, repla, orig){
	str 	= new String(orig);

	rExp	= "/"+busca+"/g";
	rExp	= eval(rExp);
	newS	= String(repla);

	str = new String(str.replace(rExp, newS));

	return str;
}
// ****************************************************************************************
// ********* posicion de un string dentro de otro *****************************************
function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}
// ****************************************************************************************
