// JavaScript Document

var xmlHttp = createXmlHttpRequestObject(); 
// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function dologin(){
     var loginform = '<table cellspacing="0" cellpadding="0" border="0"><tr><td align="right" style="color: #000000; font-size: 14px; font-weight: bold;">Login:</td><td width="5"></td><td align="left"><input type="text" id="loginid" name="loginid" /></td><td width="15"></td><td align="right" style="color: #000000; font-size: 14px; font-weight: bold;">Password:</td><td width="5"></td><td align="left"><input type="password" id="pword" name="pword" /></td><td width="10"></td><td align="center"><input type="button" name="Login" value="Login" onclick="processlogin();"></td></tr></table>';
     document.getElementById("dlogin").innerHTML = loginform; 
}

function processlogin(){
     var login = "";
     var pssword = "";
     
     if (document.getElementById('loginid') == null){
          login = "";
     }else{
          login = document.getElementById('loginid').value;
     }
     
     if (document.getElementById('pword') == null){
          pssword = "";
     
     }else{
          pssword = document.getElementById('pword').value
     }
     
     if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open("GET", "../dealer/includes/checklogin.php?login=" + login + "&password=" + pssword, true); 
		xmlHttp.onreadystatechange = loginresponse;
		xmlHttp.send(null);
	}
}

function loginresponse(){
	if (xmlHttp.readyState == 4){
    	if (xmlHttp.status == 200){
			response = xmlHttp.responseText;
			document.getElementById("dlogin").innerHTML = response;
		} 
		else 
		{
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}