// JavaScript Document
function cambiaCaptcha ()
    {
	    var imgCaptcha = document.getElementById("imgCaptcha");
		imgCaptcha.src = 'generaCaptcha.php?s='+Math.random();
		return false;		
	}
function createRequestObject()
{
	try
	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
	}
	return xmlhttp;
}
var http = createRequestObject();
function validaCaptcha()
   {
	    var captcha_txt = document.getElementById('captha_txt').value;	
	    var url = 'validaCaptcha.php?captha_txt=' + captcha_txt;
		http.open('GET', url, true);
		http.onreadystatechange = resultado;
		http.send(null);
   }   
function resultado()
{
	if(http.readyState == 4)
	{
		var res = http.responseText;				
		if(res == true)
		{
			document.getElementById('captha_txt').style.border = '1px solid #49c24f';
			document.getElementById('captha_txt').style.background = '#bcffbf';
		}
		if(res == false)
		{
			document.getElementById('captha_txt').style.border = '1px solid #c24949';
			document.getElementById('captha_txt').style.background = '#ffbcbc';
		}
	}
}
function validarDatos ()
    {
	}
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  var encontrada = 0;
  var valor;
  for (var i=0;i<vars.length;i++) 
	    {
			var pair = vars[i].split("=");
			if (pair[0] == variable) 
			{
			  valor =  pair[1];
			  encontrada = 1;
    		}
  		} 
   if (encontrada == 1)
      {
	    return valor
	  }
   else
      {
        return undefined;
	  }
	  
}	
$(document).ready(function() 
	   {
		   var error = getQueryVariable("mal");   
		   if (error == 1)
		     {
				 if ($('#lang').val() == 1 )
				   {
					   //es
					   $('#mensaje').html("Este correo electr&oacute;nico no est&aacute; registrado.");
				   }
				 if ($('#lang').val() == 2 )
				   {
					   //en
					   $('#mensaje').html("The email address is not registered on the data base.");					   
				   }
				 if ($('#lang').val() == 3 )
				   {
					   //po
					   $('#mensaje').html("Este e-mail não existe na nossa base de dados.");					   
				   }				   
			 }	
		   if (error == 2)
		     {
				 if ($('#lang').val() == 1 )
				   {
					   //es
					   $('#mensaje').html("Este correo electr&oacute;nico no est&aacute; activo.");
				   }
				 if ($('#lang').val() == 2 )
				   {
					   //en
					   $('#mensaje').html("The email address is not active.");					   
				   }
				 if ($('#lang').val() == 3 )
				   {
					   //po
					   $('#mensaje').html("Este e-mail não existe na nossa base de dados.");					   
				   }				   
			 }				 
   			$('#correoe').focus();	
			$('#passForm').validate(
				{
					 rules: 
					   {
						  correoe: 
							{
							   required: true,
							   email: true
							},
						  captha_txt: 
							{
								required: true,						
								remote: "validaCaptcha.php"
							}
						}, //end rules
					 messages: 
					   {
						  correoe: 
							{
								required: "",
								email: ""
							},
						  captha_txt: 
							{
								required: "",
								remote: jQuery.format("")
							}
						},
					 /*errorPlacement: function(error, element) 
						{ 
						   if ( element.is(":radio") || element.is(":checkbox")) 
							  {
								 error.appendTo( element.parent()); 
							  }
						   else
							  {
								 error.insertAfter(element.next());
							  } 
						}*/
		errorLabelContainer: "#mensaje",
		showErrors: function(errorMap, errorList) 
		   {

		      $("#mensaje").html("Por favor escribe tu correo y la clave de confirmación correctamente.");
			  this.defaultShowErrors();
		   }//this.numberOfInvalids()						
			  }); // end validate			 
	   });//document.ready




