var options;

function fetchoptions(SearchState, SearchType)
{
   document.HFS.elements['City[]'].length = 0;
   document.HFS.elements['City[]'].disabled = false;
   var loadtxt = "Loading...Please Wait";
   var myNewOption = new Option(loadtxt, "0");
   document.HFS.elements['City[]'].options[0] = myNewOption;
   url = '/apps/hfs5/ajax-cities.php?SearchState=' + SearchState + '&SearchType=' + SearchType;
   getDataReturnXml(url, getoptions);
}

function getoptions(xml)
{
  options = xml.getElementsByTagName("city");
  listoptions(options);
}

function listoptions ()
{
   var loopIndex;
   var selectControl = document.HFS.elements['City[]'];

   for (loopIndex = 0; loopIndex < options.length; loopIndex++ )
   {
      // John Jimenez - 4/11/2007
      // The "value" attrib of the Option was not being set, thus causing Internet Explorer
      // to not properly execute the AJAX.
      // The fix only required that we also set the "value" attrib.
      selectControl.options[loopIndex] = new 
         Option(options[loopIndex].firstChild.data,options[loopIndex].firstChild.data);
   }
}
   
function fetchoptions2(type)
{
   document.HFS.elements['SearchState'].length = 0;
   document.HFS.elements['SearchState'].disabled = false;
   document.HFS.elements['City'].length = 0;
   document.HFS.elements['City'].disabled = true;
   document.HFS.elements['house_type'].length = 0;
   document.HFS.elements['house_type'].disabled = true;
   var loadtxt = "Loading...Please Wait";
   var myNewOption = new Option(loadtxt, "0");
   document.HFS.elements['SearchState'].options[0] = myNewOption;
   url = '/apps/hfs5/ajax-states.php?SearchType=' + type;
   getDataReturnXml(url, getoptions2);
}

function getoptions2(xml)
{
  options = xml.getElementsByTagName("state");
  listoptions2(options);
}

function listoptions2 ()
{
   var loopIndex;
   var selectControl = document.HFS.elements['SearchState'];

   for (loopIndex = 0; loopIndex < options.length; loopIndex++ )
   {
      // John Jimenez - 4/11/2007
      // The "value" attrib of the Option was not being set, thus causing Internet Explorer
      // to not properly execute the AJAX.
      // The fix only required that we also set the "value" attrib.
      selectControl.options[loopIndex] = new 
         Option(options[loopIndex].firstChild.data,options[loopIndex].firstChild.data);
   }
}

   





function fetchoptions3(cities)
{
   document.HFS.elements['house_type'].length = 0;
   document.HFS.elements['house_type'].disabled = false;
   var loadtxt = "Loading...Please Wait";
   var myNewOption = new Option(loadtxt, "0");
   document.HFS.elements['house_type'].options[0] = myNewOption;
   url = '/apps/hfs5/ajax-hometypes.php?SearchType=' + document.HFS.search_type.options[document.HFS.search_type.selectedIndex].value
	   + '&Cities=' + cities + '&SearchState=' + document.HFS.SearchState.options[document.HFS.SearchState.selectedIndex].value;

   getDataReturnXml(url, getoptions3);
}

function getoptions3(xml)
{
  options = xml.getElementsByTagName("type");
  listoptions3(options);
}

function listoptions3 ()
{
   var loopIndex;
   var selectControl = document.HFS.elements['house_type'];

   for (loopIndex = 0; loopIndex < options.length; loopIndex++ )
   {
      // John Jimenez - 4/11/2007
      // The "value" attrib of the Option was not being set. To avoid any
      // issues going forward, we added the "value" attrib here as well.
      selectControl.options[loopIndex] = new 
         Option(options[loopIndex].firstChild.data,options[loopIndex].firstChild.data);
   }
}










function UpdateHomeTypes()
{

   var selectedArray = new Array();
   var selObj = document.getElementById('City');
   var i;
   var count = 0;
   for (i=0; i<selObj.options.length; i++) {
      if (selObj.options[i].selected) {
         selectedArray[count] = selObj.options[i].value;
         count++;
       }
   }
   fetchoptions3(selectedArray);   
 
}