var DEBUG = 0;
function ConstructURL(add) {
  if (!add) {
    return '/quotecomp?type=earthquake&street=' + escape(document.getElementById('street').value) + '&add=1';
  }
  else if (add > 1) {
    return '/quotecomp?type=earthquake&street=' + escape(document.getElementById('street').value) + '&stronly=1';
  }
  return '/quotecomp?type=earthquake&street=' + escape(document.getElementById('street').value);
}
function getResults() {
  parse_page(ConstructURL('2')); // get city, quickly
  parse_page(ConstructURL('1')); //address
  parse_page(ConstructURL()); // other data
}
function parse_page(url) {
  if (!url) {
    return;
  }
  var xmlhttp = false;
  var use_msie = 0;
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.overrideMimeType('text/plain');
  }
  else if (window.ActiveXObject) {
    use_msie = 1;
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open('GET', url, true);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
       var LocObj = eval("(" + xmlhttp.responseText + ")");
       for (field in LocObj) {
         try {
		if (!document.getElementById(field).value)
		  document.getElementById(field).value = LocObj[field];
	 } catch(error) {
	     try{
		if (document.getElementById("unittype").selectedIndex <= 0) 
		   document.getElementById(field).selectedIndex = LocObj[field];
	        } catch(e) {}
         }
       }
    }
  };
  xmlhttp.send(null);
}



