	var xmlhttpLogin;
	var xmlDoc;
	var Parameter = "";
	
	function CaptureEventLogin(evt)
	{
			evt = (evt) ? evt : event;
			var charCode = (evt.which) ? evt.which : evt.keyCode;
			//If Press Enter the begin Search
			if(charCode==13)
				CheckLogin();
	}
	
	function CheckLogin()
	{
		revealModalregister('modalPage', 'sCompanyList');
		//Set Parameter
		Parameter = "txtUserName=" + document.getElementById("txtUserName").value + "&txtPassword=" + document.getElementById("txtPassword").value;
		//Request Check Login
		RequestPageCheckLogin('checklogin.php', Parameter);
	}
	
	function ClearLogin()
	{
		document.getElementById("txtUserName").value = "";
		document.getElementById("txtPassword").value = "";
	}
	
	function RequestPageCheckLogin(url, parameter)
	{
		xmlhttpLogin=null;
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			xmlhttpLogin=new XMLHttpRequest();
		}
		// code for IE
		else if (window.ActiveXObject)
		{
			xmlhttpLogin=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if (xmlhttpLogin!=null)
		{
			  xmlhttpLogin.open("POST", url, true);
			  
			  xmlhttpLogin.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			  xmlhttpLogin.setRequestHeader("Content-length", parameter.length);
			  xmlhttpLogin.setRequestHeader("Connection", "close");
			  
			  xmlhttpLogin.onreadystatechange=StateChangeCheckLogin;
			  xmlhttpLogin.send(parameter);
		}
		else
		{
			alert("Your browser does not support XMLHTTP.");
		}
	}
	
	function StateChangeCheckLogin()
	{				
		//readyState, 0 = uninitialized
		//		1 = loading
		//		2 = loaded
		//		3 = interactive
		//		4 = complete
		
		//Completed Request
		if (xmlhttpLogin.readyState==4)
		  {
			// Status value just 404 and 200, 404 = "Not Found" & 200 = "Ok"
			if (xmlhttpLogin.status==200)
			{				
				//Get Response from next page
				var resp = xmlhttpLogin.responseText;	// response
				
				var RespArray = resp.split("#");
				
				
				//user exist on database and redirect to CompanyList.php
				if(RespArray[0] == "true")
				{
					//~ alert("true");
					//Administrator
					if(RespArray[1] == "1")
						window.location = "companylist.php";
					else{

						if(RespArray[3] == "1")
						window.location = "viewprofile.php?cid=" + RespArray[2];
						else
							window.location = "api_sample/api_sample.php";
					}
				}
				else
				{
					//~ alert("false");
					document.getElementById("sError").innerHTML = "User does not exist";
					//Hide Modal Background
					hideModal('modalPage')
				}
				
			}
			else
			{
				//Hide Modal Background
				hideModal('modalPage')
				alert("Problem retrieving data");
			}
		  }
	}