var xmlHttp

function GetXmlHttpObject() {
  var xmlHttp=null;
  try {
   // Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
  }
  catch(e) {
   //Internet Explorer
   try {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e) {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
  }
  return xmlHttp;
}

function populateCity(state) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
   alert ("Browser does not support HTTP Request")
   return
  }
  var url = "http://www.blibber.com/secure/register.php?action=getCities&State="+document.getElementById('CompanyState').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('CompanyCity').innerHTML=xmlHttp.responseText
    }
  }
}

function checkCompany(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your browser does not support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkCompany&Company="+document.getElementById('CompanyName').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkCompany').innerHTML=xmlHttp.responseText
    }
  }
}

function checkEmail(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your browser does not support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkEmail&Email="+document.getElementById('ContactEmail').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkEmail').innerHTML=xmlHttp.responseText
    }
  }
}

function checkContactName(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your Browser Does Not Support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkContactName&ContactName="+document.getElementById('ContactName').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkContactName').innerHTML=xmlHttp.responseText
    }
  }
}
function checkContactPhone(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your Browser Does Not Support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkContactPhone&CompanyContactPhone="+document.getElementById('CompanyContactPhone').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkContactPhone').innerHTML=xmlHttp.responseText
    }
  }
}
function checkCompanyAddressLine1(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your Browser Does Not Support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkCompanyAddressLine1&CompanyAddressLine1="+document.getElementById('CompanyAddressLine1').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkCompanyAddressLine1').innerHTML=xmlHttp.responseText
    }
  }
}
function checkCompanyCity(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your Browser Does Not Support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkCompanyCity&CompanyCity="+document.getElementById('CompanyCity').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkCompanyCity').innerHTML=xmlHttp.responseText
    }
  }
}
function checkCompanyState(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your Browser Does Not Support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkCompanyState&CompanyState="+document.getElementById('CompanyState').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkCompanyState').innerHTML=xmlHttp.responseText
    }
  }
}
function checkCompanyZipCode(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Your Browser Does Not Support AJAX")
    return
  }
  var url = "http://www.blibber.com/secure/register.php?action=checkZipCode&CompanyZipCode="+document.getElementById('CompanyZipCode').value;
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      document.getElementById('checkCompanyZipCode').innerHTML=xmlHttp.responseText
    }
  }
}
function submitRegistration(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Browser does not support AJAX")
    return
  }
  var ContactName = document.forms["registerCompany"].elements["ContactName"].value;
  var ContactEmail = document.forms["registerCompany"].elements["ContactEmail"].value;
  var CompanyName = document.forms["registerCompany"].elements["CompanyName"].value;
  var CompanyAddressLine1 = document.forms["registerCompany"].elements["CompanyAddressLine1"].value;
  var CompanyAddressLine2 = document.forms["registerCompany"].elements["CompanyAddressLine2"].value;
  var CompanyContactPhone = document.forms["registerCompany"].elements["CompanyContactPhone"].value;
  var CompanyCity = document.forms["registerCompany"].elements["CompanyCity"].value;
  var CompanyState = document.forms["registerCompany"].elements["CompanyState"].value;
  var CompanyZipCode = document.forms["registerCompany"].elements["CompanyZipCode"].value;
  var CompanyExtension = document.forms["registerCompany"].elements["CompanyExtension"].value;
  var url="http://www.blibber.com/secure/register.php?action=doRegister";
  var params = "&ContactName="+ContactName+"&ContactEmail="+ContactEmail+"&CompanyName="+CompanyName+"&CompanyAddressLine1="+CompanyAddressLine1+"&CompanyAddressLine2="+CompanyAddressLine2+"&CompanyContactPhone="+CompanyContactPhone;
  params = params+"&CompanyCity="+CompanyCity+"&CompanyState="+CompanyState+"&CompanyZipCode="+CompanyZipCode+"&CompanyExtension="+CompanyExtension;
  xmlHttp.open("POST",url,true);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.onreadystatechange = function() {
	  if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  		document.getElementById('registerMessage').innerHTML=xmlHttp.responseText
	  }
  }
  xmlHttp.send(params);
}
function doLogin(str) {
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null) {
    alert("Browser does not support AJAX")
    return
  }
  var Email = document.forms["login"].elements["Email"].value;
  var Password = document.forms["login"].elements["Password"].value;
  var url="http://www.blibber.com/secure/login.php?action=doLogin";
  var params = "&Email="+Email+"&Password="+Password;
  if(Email && Password) {
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.onreadystatechange = function() {
  	  if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  	    if(xmlHttp.responseText == "239u249824") {
  	      window.location = "http://www.blibber.com/client/"
  	    } else {
    		  document.getElementById('loginMessage').innerHTML=xmlHttp.responseText
        }
  	  }
    }
  xmlHttp.send(params);
  } else {
      document.getElementById('loginMessage').innerHTML="Please provide login credentials"
  }
}
