﻿// JScript File
// Http variable declaration...
function getReqXMLHTTPObj()
{
 var a = null;
 try{a = new ActiveXObject("Msxml2.XMLHTTP")}
 catch(b)
 {
  try{a = new ActiveXObject("Microsoft.XMLHTTP")}
  catch(c){a=null;}
 }
 if(!a && typeof XMLHttpRequest!="undefined")
 {
  a = new XMLHttpRequest();
 } 
 return a;
}
var req;

// Ajax function..
function AjaxCall(url, onCallback) 
{
 
 req = getReqXMLHTTPObj();
    req.onreadystatechange = onCallback;
    var rnd = Math.floor(Math.random()*100000)
    url = url + "&rnd=" + rnd;
    req.open("GET", url, true);
    req.send(null);
}

// Mail validation...For English.
function ChkEmail(mail)
{
		var str=mail;
		if (!str=="")
		{
			if (str.indexOf("@",1) == -1)
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
			if (str.indexOf("@",1)== 0)
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
			if (str.indexOf(".")== 0)
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
			if (str.indexOf(".",1) == -1)
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
		
			// extra validation
			var posat=str.indexOf("@");
			var posdot=str.indexOf(".");
			var rposdot=str.lastIndexOf(".");
			if(rposdot==posdot)
			if((posdot < posat) || (posdot-posat < 3))
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
			if(str.charAt(str.length-1)==".")
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
			if(str.charAt(str.length-1)=="@")
			{
				alert("That is not a valid Email Address. Please enter again!");
				return false;
			}
			var j=0;
			for( var i=0;i<str.length;i++)
			{
				if(str.charAt(i) == "@")
				j++;
			}
			if(j > 1)
			{
			alert("That is not a valid Email Address. Please enter again!");
			return false;
			}			
			//}
		}
		return true;
}

//Mail Validation.... For Spanish

function ChkEmailSp(mail)
{
		var str=mail;
		if (!str=="")
		{
			if (str.indexOf("@",1) == -1)
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
			if (str.indexOf("@",1)== 0)
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
			if (str.indexOf(".")== 0)
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
			if (str.indexOf(".",1) == -1)
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
		
			// extra validation
			var posat=str.indexOf("@");
			var posdot=str.indexOf(".");
			var rposdot=str.lastIndexOf(".");
			if(rposdot==posdot)
			if((posdot < posat) || (posdot-posat < 3))
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
			if(str.charAt(str.length-1)==".")
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
			if(str.charAt(str.length-1)=="@")
			{
				alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
				return false;
			}
			var j=0;
			for( var i=0;i<str.length;i++)
			{
				if(str.charAt(i) == "@")
				j++;
			}
			if(j > 1)
			{
			alert("Esta no es una dirección de correo electrónico valida. Por favor, introduzca de nuevo!");
			return false;
			}			
			//}
		}
		return true;
}


function trim(str) 
{ 
    return str.replace(/^\s+|\s+$/g,''); 
}

// Forgot Password form Validation..Fro English..
function ForgetValidation()
{
    document.getElementById('idmessage1').innerHTML = "";
    YourEmail=trim(document.getElementById('textfield').value);
	if(YourEmail=="")
	{
		alert("Please Enter Your Email Address!");
		return false;
	}
	if(!ChkEmail(YourEmail))
	{
		return false;
	}
	  document.getElementById('idmessage1').innerHTML ="Don't Close The Window. Please Wait...";

	forgetPassword();
	//return true;
}

// Forgot Password form Validation..Fro Spanish..
function ForgetValidationSp()
{
    document.getElementById('idmessage1').innerHTML = "";
    YourEmail=trim(document.getElementById('textfield').value);
	if(YourEmail=="")
	{
		alert("Por favor, introduzca la dirección de correo electrónico!");
		return false;
	}
	if(!ChkEmailSp(YourEmail))
	{
		return false;
	}
	forgetPassword();
	//return true;
}

// Call ajax function..
function forgetPassword()
{
  document.getElementById('idmessage1').style.display = 'inline';
  var email = document.getElementById('textfield').value;
  qs="forget-password.aspx?email="+email;
//  alert(qs);
  AjaxCall(qs, forget_password);
}

// Return function...
function forget_password()
{
  if (req.readyState == "4") 
  {
       //alert("text");
       text=req.responseText;
       document.getElementById('idmessage1').style.display = 'inline';
       document.getElementById('idmessage1').innerHTML = text;
   }
   //alert(req.readyState);

}
