//window.onload = initAll;

/* xhr is an XMLHttpRequest object. Created outside of all functions so that it is globally available. */
var xhr = false;

function makePOSTRequest(url, parameters)
{
  // Mozilla, Safari,...
  if (window.XMLHttpRequest)
  { 
	 xhr = new XMLHttpRequest();
	 if (xhr.overrideMimeType)
	 {
		// set type accordingly to anticipated content type
		xhr.overrideMimeType('text/html');
	 }
  }
  // IE
  else if (window.ActiveXObject)
  { 
	 try
	 {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch (e)
	 {
		try
		{
		   xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {}
	 }
  }
  
  if (!xhr)
  {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  xhr.onreadystatechange = showContents;
  xhr.open('POST', url, true);
  xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhr.setRequestHeader("Content-length", parameters.length);
  xhr.setRequestHeader("Connection", "close");
  xhr.send(parameters);
}

function get(obj)
{
	var FirstName = document.getElementById("FirstName").value;
	var LastName = document.getElementById("LastName").value;
	var Email = document.getElementById("Email").value;
	var Phone = document.getElementById("Phone").value;
	var City = document.getElementById("City").value;
	var SubscribeCheckBox = document.getElementById("SubscribeCheckBox").value;
	
	var blnHTML = document.getElementById("blnHTML").value;
	var company_id = document.getElementById("company_id").value;
	
  	var poststr = "FirstName=" + encodeURI(FirstName) + "&LastName=" + encodeURI(LastName) + "&Email=" + encodeURI(Email) + "&Phone=" + encodeURI(Phone) + "&City=" + encodeURI(City) + "&SubscribeCheckBox=" + SubscribeCheckBox + "&blnHTML=" + blnHTML + "&company_id=" + company_id;
	
	makePOSTRequest('search-request.asp', poststr);
}

function showContents()
{
	// ready state 4 = complete; object has finished initializing
	if (xhr.readyState == 4)
	{
		// status code 200 means everything is fine
		if (xhr.status == 200)
		{
			var outMsg = xhr.responseText;
		}
		else
		{
			var outMsg = "There was a problem with the request " + xhr.status;
		}
		document.getElementById("UpdateArea").innerHTML = outMsg;
		
		// if no errors and form submits successfully hide form.
		if (outMsg == '<p class="thankyou"><strong>Thank You!</strong><br /><br />Your Message Has Been Sent Successfully.</p>')
		{
			setTimeout("hideForm()", 2000);
		}
	}
}

// changes style on form to hide it from view.
function hideForm()
{
	document.getElementById("UnlockSearchForm").style.display="none"
}