/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){

});
function Login2(form,datos, url, divloading, home){
    var vacios = 0;
    var obligatorios = $("#forml .obligl");  // Podr?a ser tambi?n $("div.testc")
    obligatorios.each( function(i) { // i va desde 0 hasta divs.length-1
	if($(this).val()=="e-mail"|| $(this).val()=="contraseña") { 
                vacios = 1;
                alert("Introducir Usuario y contrasena");
                return false;
	}
        if($(this).val()==""){
                vacios = 1;
                alert("Introducir Usuario y contrasena");
                return false;
             } 
        
   });

   if(vacios == 1){ 
   	return false;
   } else {
    //alert(datos+'\n'+url+'\n'+divloading);
    var info;
    info=$("#"+form).serialize();
    //alert(info);
    if(datos!='')  info=datos+'&'+info;
    $.ajax({
        type: "POST",
        url: url,
        data: info,
        async: false,
        cache:false,
        success: function(texto){
            //alert(texto);
            if(texto>0){
            	$("#"+divloading).removeClass("img_loading");
            	$("#"+divloading).hide();
            	location.href=home;
            } else{ 
                $("#contrasena_login").val("");
                alert("No existe usuario");
    		return false;
            }
        }
    });   
    return false;
   }
}


function Login(form,datos, url, divloading, home){
    var vacios = 0;
    var obligatorios = $(".obliglogin");  // Podr?a ser tambi?n $("div.testc")
    obligatorios.each( function(i) { // i va desde 0 hasta divs.length-1
        if($(this).val()==""){
                vacios = 1;
                alert("Introducir Usuario y contrasena");
                return false;
             } 
        
   });

   if(vacios == 1){ 
   	return false;
   } else {
    //alert(datos+'\n'+url+'\n'+divloading);
    var info;
    info=$("#"+form).serialize();
    //alert(info);
    if(datos!='')  info=datos+'&'+info;
    $.ajax({
        type: "POST",
        url: url,
        data: info,
        async: false,
        cache:false,
        success: function(texto){
            //alert(texto);
            if(texto>0){
            $("#"+divloading).removeClass("img_loading");
            $("#"+divloading).hide();
            location.href=home;
            } else{ 
                $("#contrasena_login").val("");
                alert("No existe usuario");
            }
        }
    });   
   }
}

function cerrarSesion(home){
    
    $.ajax({
        
        type: "POST",
        url:"/opcionesLogin.php",
        data: "opcion=cerrar",
        async: false,
        cache:false,
        success: function(msg){
            
            if(msg==0){
                        
            alert("Sesion cerrada satisfactoriamente");
            location.href=home;
            
            }
            else alert("No es posible cerrar la sesion");
                
            
        }
    });
    
}

function validarEmail(datos, url){
    
   // alert(datos+'\n'+url+'\n');
    
    $.ajax({
        
        type: "POST",
        url:url,
        data: datos,
        async: false,
        cache:false,
        success: function(msg){
            
            if(msg>0){
            }
            else alert("Usuario o Clave incorrectos");
                
            
        }
    });
    
}


function accionAjax(datos, url,asinc,divloading,div){


     $.ajax({
        beforeSend: function(){

          $(divloading).addClass("img_loading");
          
        },
        type: "POST",
        url:url,
        data: datos,
        async: asinc,
        cache:false,
        success: function(msg){
            
            
            $(divloading).removeClass("img_loading");
            $(divloading).hide();

            $(div).html(msg);
            
            
                
            
        }
    });
    
}

function formAjax(form, datos, url, div, divloading){
    
    
    var info;
    info=$(form).serialize();
    //alert(info);
    if(datos!='')  info=datos+'&'+info;
    $.ajax({
        type: "POST",
        url: url,
        data: info,
        async: false,
        cache:false,
        success: function(texto){
            //alert(texto);
            if(texto>0){
            $(divloading).removeClass("img_loading");
            $(divloading).hide();
            $(div).html(msg);
            }
            else alert("No existe usuario");
            
            
            
        }
  })      

}

