// JScript source code

var xmlHttp

function sendMail(str)
{
	if (str.length==0)
	{ 
		//document.getElementById("showStatusDiv").innerHTML="";
		return;
	}
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	 
	var url="Email_SendForgottenPwd.asp";
	url=url+"?email="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function setNewPWD(str){
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	 
	var url="ChangePassword.asp";
	url=url+"?pwd="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=checkStatusOnChangePwd;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function checkStatusOnChangePwd(){
	if (xmlHttp.readyState==4)
	{ 
		var servResponse = 	xmlHttp.responseText;
		document.getElementById("statusDiv").innerHTML = '';				
		if(servResponse == "SUCCESS"){ //on SUCCESS
			alert("Your password has been changed successfully.");			
		}
		else{ // error - not matched validateion or problem with executing query
			alert(servResponse);						
		}
				
	}else{
		document.getElementById("statusDiv").innerHTML = '<img src="images/ajax-loader.gif"><br />';
	}
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var servResponse = 	xmlHttp.responseText;
				
		if(servResponse == "SUCCESS"){ //on SUCCESS
			document.getElementById("showStatusDiv").innerHTML="";
			alert("Your password has been sent to your email account.");
			showHide_ForgtnPwdDiv(); // hide DIV with forgotten password
		}
		else{ // on error - there is no such mail in the database or problem with sending mail
			document.getElementById("showStatusDiv").innerHTML = servResponse;		
		}
		
	}else{
		document.getElementById("showStatusDiv").innerHTML = '<img src="images/ajax-loader.gif">';
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}

