 jQuery.fn._blank = function() {



	function clickHandler(e) {

		// si el usuario ha utilizado una tecla de control

		// no hacemos nada

		if (e.ctrlKey || e.shiftKey || e.metaKey)

			return;



		// abrimos la ventana

		var w = window.open(this.href, '_blank');

		if (w && !w.closed) {

			// si efectivamente hemos logrado abrirla

			// la ponemos en foco

			w.focus();

			// y cancelamos el comportamiento por defecto

			// del enlace

			e.preventDefault();

		}

	}



	this

		.filter('a[@href]') // que no se nos cuele algo que no sea un enlace

		.bind('click', clickHandler);



	return this; // permitimos concatenabilidad



}





function trim(cadena)

{

 

	for(i=0; i<cadena.length;i++ )

	{

		if(cadena.charAt(i)==" ")

			cadena=cadena.substring(i+1, cadena.length);

		else

			break;

	}



	for(i=cadena.length-1; i>=0; i--)

	{

	 

		if(cadena.substr(i,i)==" ")

		  {

			cadena=cadena.substring(0,i);

	 

		  }

		else

			break;

	}

	

	return cadena;

}

function DoBuscaUsuario() {

 var usr=jQuery("#CTLMTOID_USUARIO").val();

 var parametros = {nombre:usr};

  

  var urlServer = "buscauser.php" 

   jQuery.ajax({type: "POST", 

		 url: urlServer,

				   data: parametros,

				   dataType: "json",

				   async:false,

				   success: function(data) 

	                {

                     recogeUser( data);

					}         

                  });

}

function DoSalvaUsuario() {

    

      var estado;

      jQuery(':selected').each(function(i, selected){

	    estado=jQuery(this).text();

      });

	  estado=estado.substr(0,1);



  var parametros = {

  ID_USUARIO:jQuery("#CTLMTOID_USUARIO").val(),

  PASSWORD:jQuery("#CTLMTOPASSWORD").val(),

  ESTADO :estado,

  NOMBRE_USUARIO:jQuery("#CTLMTONOMBRE_USUARIO").val(),

  FECHA_NAC:jQuery("#CTLMTOFECHA_NAC").val(),

  CORREO_ELECTRONICO:jQuery("#CTLMTOCORREO_ELECTRONICO").val(),

  TELMOVIL:jQuery("#CTLMTOTELMOVIL").val(),

  TELOFI:jQuery("#CTLMTOTELOFI").val(),

  TELCASA:jQuery("#CTLMTOTELCASA").val(),

  PAIS_USUARIO:jQuery("#CTLMTOPAIS_USUARIO").val()  

  };

  

  var urlServer = "salvauser.php" 

   jQuery.ajax({type: "POST", 

		 url: urlServer,

				   data: parametros,

				   dataType: "TXT",

				   async:false,

				   success: function(data) 

	                {

                     recogesalvaUser( data);

					}         

                  });

}





function ChecaSecurity(ses,usuario) {

 

var parametros = { session:ses,usuario:usuario};

  

  var urlServer = "../login/checasecurity.php" 

   jQuery.ajax({type: "POST", 

		 url: urlServer,

				   //data: parametros,

				   dataType: "TXT",

				   async:false,

				   success: function(data) 

	                {

                     recogeInfos2( data);

					}         

                  });

}

function recogeInfos2(valorretornado){ 

   

   if (valorretornado.indexOf("OK")>=0)

    {

	

	}

   else	

   {

     alert("no esta logueado");

   //document.location.href="../index.php";

    alert(" esta logueado");

   var load = window.open('../index.php','','scrollbars=no,menubar=no,height=700,width=800,resizable=yes,toolbar=no,location=no,status=no');



  return true;

   }

    

}



function regresaprincipal() {

 document.location.href="../index.php"

 return true;

}

function DoLogin() {

 var usr=jQuery("#user").val();

 var pwd=jQuery("#password").val();

 var ses=jQuery("#session").val();

   

 var parametros = {nombre:usr, pass: pwd, session:ses};

  

  var urlServer = "ingresa.php" 

   jQuery.ajax({type: "POST", 

		 url: urlServer,

				   data: parametros,

				   dataType: "json",

				   async:true,

				   error: function (xhr, desc, exceptionobj) {

                                   alert(xhr.responseText);

                     },

				   

				   success: function(data) 

	                {

                     recogeInfos( data,usr);

					}         

                  });

}

   function recogeInfos(valorretornado,nombre){

    

   if (valorretornado["valor"]==1)

    {

	 

	  var ses=jQuery("#session").val();

	  var oldWin = window.parent.location.href="../admin/administracion.php";
 
	  return true;



	} 

   else	

   

       alert("fallo tu login"+valorretornado["valor"]);

   }



  function recogeNada(valorretornado){

   }

function recogeUser(valorretornado){

   try 

      {         

	  $("#CTLMTONOMBRE_USUARIO").val("");

	  $("#CTLMTOFECHA_NAC").val("");

	  $("#CTLMTOCORREO_ELECTRONICO").val("");

	  $("#CTLMTOTELMOVIL").val("");

	  $("#CTLMTOTELOFI").val("");

	  $("#CTLMTOTELCASA").val("");

	  $("#CTLMTOPAIS_USUARIO").val("");

	  $("#CTLMTOESTADO").val("");

	  

      $("#CTLMTONOMBRE_USUARIO").val(valorretornado["NOMBRE_USUARIO"]);

	  $("#CTLMTOFECHA_NAC").val(valorretornado["FECHA_NAC"]);

	  $("#CTLMTOCORREO_ELECTRONICO").val(valorretornado["CORREO_ELECTRONICO"]);

	  $("#CTLMTOTELMOVIL").val(valorretornado["TELMOVIL"]);

	  $("#CTLMTOTELOFI").val(valorretornado["TELOFI"]);

	  $("#CTLMTOTELCASA").val(valorretornado["TELCASA"]);

	  $("#CTLMTOPAIS_USUARIO").val(valorretornado["CODIGO_PAIS"]);

	  $("#CTLMTOESTADO").val(valorretornado["ESTADO"]);

	}  

     catch(err) 

     {

     

     }       

    	

}

function limpiauser(){

   try 

      {  

      $("#CTLMTOID_USUARIO").val("");	  

	  $("#CTLMTONOMBRE_USUARIO").val("");

	  $("#CTLMTOFECHA_NAC").val("");

	  $("#CTLMTOCORREO_ELECTRONICO").val("");

	  $("#CTLMTOTELMOVIL").val("");

	  $("#CTLMTOTELOFI").val("");

	  $("#CTLMTOTELCASA").val("");

	  $("#CTLMTOPAIS_USUARIO").val("");

	  $("#CTLMTOESTADO").val("");

	}  

     catch(err) 

     {

     

     }       

    	

}

function recogesalvaUser(valorretornado){

   if (valorretornado.indexOf("OK")>=0)

        showDialog('Success', "Proceso Correcto",'success',3);

    

   else

   alert("Se Presento un Error "+valorretornado);

}

 

function regreso(){ 

  document.location.href="../index.php";

  return true;

} 

 

 