// Purpose: Contractor Search AJAX client side code
// Author:  JTankersley, 2009/06/08
// Notes:   Based on W3Schools PHP/AJAX template

var xmlhttpCounty;
var xmlhttpType;

function getCounty()
{
// alert('county');
var inState = document.getElementById('selState').value;
if (inState.length==0) { inState = 'WI'; }
xmlhttpCounty=GetXmlHttpObject();
if (xmlhttpCounty==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
// Clear dropdowns
document.getElementById("divCounty").innerHTML= "<select name='selCounty' id='selCounty' style='HEIGHT: 22px; WIDTH: 268px'></select>";
document.getElementById("divType").innerHTML= "<select name='selType' id='selType' style='HEIGHT: 22px; WIDTH: 268px'></select>";  
  
var url="/ajax/getcounty.php";
url=url+"?state="+inState;
url=url+"&sid="+Math.random();
xmlhttpCounty.onreadystatechange=setCounty;
xmlhttpCounty.open("GET",url,true);
xmlhttpCounty.send(null);
}


function setCounty()
{
if (xmlhttpCounty.readyState==4)
  {
  document.getElementById("divCounty").innerHTML= xmlhttpCounty.responseText;  // 'hello' + Math.random(); 
  getType();
  }
}


function getType()
{
// alert('type');
var inState = document.getElementById('selState').value;
var inCounty = document.getElementById('selCounty').value;
if (inState.length==0) { inState = 'WI'; }
if (inCounty.length==0) { inCounty = 'Adams'; }
xmlhttpType=GetXmlHttpObject();
if (xmlhttpType==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
  
// Clear dropdowns
document.getElementById("divType").innerHTML= "<select name='selType' id='selType' style='HEIGHT: 22px; WIDTH: 268px'></select>";  
  
var url="/ajax/gettype.php";
url=url+"?state="+inState;
url=url+"&county="+inCounty;
url=url+"&sid="+Math.random();
xmlhttpType.onreadystatechange=setType;
xmlhttpType.open("GET",url,true);
xmlhttpType.send(null);
}


function setType()
{
if (xmlhttpType.readyState==4)
  {
  document.getElementById("divType").innerHTML=xmlhttpType.responseText;
  }
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}