var xmlhttp

function validateuser(str)
{

document.getElementById("txtHint").innerHTML="Processing........";  //Display wait message.
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="/inc/validateuser.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function validatepass(str)
{

//processing message
//document.getElementById("txtHint").innerHTML="Processing........";   //Display wait message.
// We need to store the username if the username was found.

if (document.getElementById("txtHint").innerHTML=="User found.")
{
	var usr=document.getElementById("txtusername");
	setcookie('user',usr.value,7);
}

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

var url="/inc/validatepass.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function validateboth()
{

//Verify password field.

if (document.getElementById("txtpassword").value==""){
	document.getElementById("txtHint").innerHTML="Password cannot be blank!"
}
else
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="/inc/validateboth.php";
var txtusername=document.getElementById("txtusername").value;
var txtpassword=document.getElementById("txtpassword").value;
url=url+"?txtusername="+txtusername+ "&txtpassword=" + txtpassword;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}  //End of field validation.

}

function gotodtr(usr){
	//Call script to determine user and direct.
	
	var location=("http://retirementresort.ca/inc/determine.php?q=" + usr);
	this.location.href = location;
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  document.getElementById("Wait").style.visibility="hidden";  //Show wait image. 
  //Check for message.
		if (document.getElementById("txtHint").innerHTML=="Password found.")
		{
			//Call function to call script to determine the user.
			gotodtr(document.getElementById("txtusername").value);  
		}
		else {
			document.getElementById("lblwait").innerHTML="";
		}

  }

if (xmlhttp.readyState==1)
  {
		document.getElementById("Wait").style.visibility="visible";    
		document.getElementById("Wait").src="../Images/ajax-loader.gif";    
		document.getElementById("lblwait").innerHTML="Processing.....";
  }

}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


