function appendOptionLast(elSel, num, value)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = num;
  elOptNew.value = value
 

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// stores the reference to the XMLHttpRequest object
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 process_property(location, number, budget, property)
{
	
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "property.php?number=" + number + "&location="+location+"&budget="+budget+"&property="+property, true);  
    
    //alert("property.php?number=" + number + "&location="+location+"&budget="+budget+"&property="+property);
    
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handle_property;
    // make the server request
    xmlHttp.send(null);
  }
}



function handle_property() 
{
	


  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
  	
  	
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      xmlRoot = xmlResponse.documentElement;
      
      idArr = xmlRoot.getElementsByTagName("id");
      nameArr = xmlRoot.getElementsByTagName("name");
      
      
      // get the text message, which is in the first child of
      // the the document element
      // helloMessage = xmlDocumentElement.firstChild.data;
   
      var el =  document.getElementById("quality");
      
      el.disabled = false;
      
      removeAllOptions(el);
      appendOptionLast(el, " -- Please Select -- ", 0);
      
      
      for (i= 0;i < idArr.length;i++) {
      	id = idArr.item(i).firstChild.data;
      	name = nameArr.item(i).firstChild.data;
      	
      	appendOptionLast(el, name, id);
      }
      
      
      
      
      
    
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}





// make asynchronous HTTP request using the XMLHttpRequest object 
function process_budget(location, number, budget)
{
	
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "budget.php?number=" + number + "&location="+location+"&budget="+budget, true); 
    
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handle_budget;
    // make the server request
    xmlHttp.send(null);
  }
}



function handle_budget() 
{
	


  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      xmlRoot = xmlResponse.documentElement;
      
      idArr = xmlRoot.getElementsByTagName("id");
      nameArr = xmlRoot.getElementsByTagName("name");
      
      
      // get the text message, which is in the first child of
      // the the document element
      // helloMessage = xmlDocumentElement.firstChild.data;
   
      var el =  document.getElementById("property");
      
      el.disabled = false;
      
      removeAllOptions(el);
      appendOptionLast(el, " -- Please Select -- ", 0);
      
      
      for (i= 0;i < idArr.length;i++) {
      	id = idArr.item(i).firstChild.data;
      	name = nameArr.item(i).firstChild.data;
      	
      	appendOptionLast(el, name, id);
      }
      
      
      
      
      // update the client display using the data received from the server
    // document.getElementById("number").innerHTML = '<option value=0>' + helloMessage + '</option>';
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}




// make asynchronous HTTP request using the XMLHttpRequest object 
function process_number(location, number)
{

  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "number.php?number=" + number + "&location="+location, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handle_number;
    // make the server request
    xmlHttp.send(null);
  }
}



function handle_number() 
{
	


  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      xmlDocumentElement = xmlResponse.documentElement;
      // get the text message, which is in the first child of
      // the the document element
      helloMessage = xmlDocumentElement.firstChild.data;
   
      
      var el =  document.getElementById("budget");
      
      el.disabled = false;
      
      removeAllOptions(el);
      appendOptionLast(el, " -- Please Select -- ", 0);
      
      min = helloMessage;
      
      if (helloMessage <= 900) appendOptionLast(el, "under 900", 900);
      if (helloMessage <= 1200) appendOptionLast(el, "under 1200", 1200);
      if (helloMessage <= 1500) appendOptionLast(el, "under 1500", 1500);
      if (helloMessage <= 2000) appendOptionLast(el, "under 2000", 2000);
      if (helloMessage <= 2500) appendOptionLast(el, "under 2500", 2500);
      if (helloMessage <= 3000) appendOptionLast(el, "under 3000", 3000);
      if (helloMessage <= 3500) appendOptionLast(el, "under 3500", 3500);
      appendOptionLast(el, "over 3500", "o3500");
      appendOptionLast(el, "over 4000", "o4000");
      
      
      // update the client display using the data received from the server
    // document.getElementById("number").innerHTML = '<option value=0>' + helloMessage + '</option>';
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}




// make asynchronous HTTP request using the XMLHttpRequest object 
function process_location(value)
{
	
	
	
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "location.php?id=" + value, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handle_location;
    // make the server request
    xmlHttp.send(null);
  }
}

// executed automatically when a message is received from the server
function handle_location() 
{
	
	
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      xmlDocumentElement = xmlResponse.documentElement;
      // get the text message, which is in the first child of
      // the the document element
      helloMessage = xmlDocumentElement.firstChild.data;
    
      var el =  document.getElementById("numero");

      el.disabled = false;
      
      removeAllOptions(el);
      appendOptionLast(el, " -- Please Select -- ", 0);
      for (i = 1;i <= helloMessage;i++) {
      	appendOptionLast(el, i,i)
      }
      // update the client display using the data received from the server
    // document.getElementById("number").innerHTML = '<option value=0>' + helloMessage + '</option>';
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}