//validate email id
function checkUser( formObj ){
	xmlHttp = GetXmlHttpObject();
	
	if(xmlHttp == null) { 
		alert("Browser does not support HTTP Request");
		return;
	}
	
	emailId = formObj.chkemail.value;
	password = formObj.chkpassword.value;
	url = "index.php?page=checkUser&chkemail="+emailId+"&chkpassword="+password
	url = url
	xmlHttp.onreadystatechange = stateChanged
	xmlHttp.open("get",url,true)
	xmlHttp.send(null)	
	return false;
}

// Checking browser compatabile
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

// State Changed 
function stateChanged() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{ 
		var response = xmlHttp.responseText
		if(response == "false"){
			document.getElementById("message").innerHTML = "Incorrect email-id / password.";
		}
		else{
			getSessionValue();
			closeMessage();
			alert("Now , you can short-list your properties.");
			//document.propList.focus();
			//propShortlist("document.propList");
			//document.propList.submit();
		}	
	}
	else{	
		//document.getElementById("message").innerHTML = "Loading.....";
	} 
}



function getSessionValue(){
	xmlHttpSession = GetXmlHttpObject();
	
	if( xmlHttpSession == null) { 
		alert("Browser does not support HTTP Request");
		return;
	}
	
	url = "index.php?page=getSession"
	url = url
	xmlHttpSession.onreadystatechange = stateChangedSession
	xmlHttpSession.open("get",url,true)
	xmlHttpSession.send(null)	
}

// State Changed 
function stateChangedSession() 
{ 
	if ( xmlHttpSession.readyState == 4 || xmlHttpSession.readyState == "complete")
	{ 
		sessionData = xmlHttpSession.responseText;
		sessionDataArr = sessionData.split("^^");
		name = sessionDataArr[1];
		if(name == ""){
			document.getElementById("welcomeDiv").innerHTML = "Welcome Guest";					
		}
		else{
			document.getElementById("welcomeDiv").innerHTML = "Welcome "+name+" <a href='#'> Myaccount </a>";
			}
	}
}
