// JavaScript Document
function createObject()
{
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	request_type = new XMLHttpRequest();
	}
	return request_type;
}

var http = createObject();
function login()
{
	var Un = encodeURI(document.getElementById('username').value);
	var Pwd = encodeURI(document.getElementById('password').value);
	http.open('get', "Login_Check.cfm?un=" + Un +"&pwd=" + Pwd,true);
	http.onreadystatechange = loginReply;
	http.send(null);
}
function loginReply()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		document.getElementById('hdnValue').value = response;
		var txtvalue = document.getElementById('hdnValue').value;
		var trimvalued = trim(txtvalue);
		//alert(trimvalued);	
			//document.getElementById('username').value = trimvalued;
    	if(trimvalued == "valid")
		{

			//document.frmhme.action = "Login_Session.cfm";
document.frmhme.action = "corp/login/index.cfm?action=login";
 			document.frmhme.submit();
		}
		else if(trimvalued == "UN_Invalid")
		{
			var previousInnerHTML = new String();
       		previousInnerHTML = "Invalid login information !!";
			document.getElementById('div1').innerHTML = previousInnerHTML;
			document.getElementById('password').value="";
		}
		else if(trimvalued == "Apartment")
		{
			window.location='Apartment.cfm';
		}
		else if(trimvalued == "dbError")
		{			
			var previousInnerHTML = new String();        	  
       		previousInnerHTML = "Server Error";
			document.getElementById('div1').innerHTML = previousInnerHTML;
			document.getElementById('username').value="";
			document.getElementById('password').value="";
		}
		else
		{			
			var previousInnerHTML = new String();    
       		previousInnerHTML = "Invalid login information !!";
			document.getElementById('div1').innerHTML = previousInnerHTML;
			document.getElementById('username').value="";
			document.getElementById('password').value="";
		}
	}

}
 function trim(stringToTrim)
 {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
 }
