var xmlhttp=false;

 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function handleStateChange()
{        
    if (xmlhttp.readyState == 3)
    {
        alert(xmlhttp.responseText);
    }
}

function ajax_call() {

	document.getElementById("cordinates").innerHTML = "Please wait...";
	xmlhttp.open("GET","ajax/ajaxWork.php?city="+document.getElementById('city').value+"&state="+document.getElementById('state').value+"&address="+document.getElementById('address').value,true);
	xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState);
		if (xmlhttp.readyState==4) {
			if(xmlhttp.responseText=="error0") {
				document.getElementById("cordinates").innerHTML = "Please input a accurate address above.";
				document.getElementById("txtCordinates").value = "";
			}
			else {
				document.getElementById("cordinates").innerHTML = xmlhttp.responseText;
				document.getElementById("txtCordinates").value = xmlhttp.responseText;
				
				fcb("(" + xmlhttp.responseText + ")");
			}
		}
	}
	xmlhttp.send(null)
	
	return false;
}

function getProvince(country_id,site_url) {
	
	modelvar = document.getElementById('province');
	
	if (country_id == '') {
		modelvar.options.length = 1;
		document.getElementById('city').options.length = 1;
	}
	else {
		xmlhttp.open("GET",site_url + "/ajax.php?country_id="+country_id+"&call=getp",true);
		xmlhttp.onreadystatechange=function() {
			
			if (xmlhttp.readyState==4) {
						
				eval(xmlhttp.responseText);	
								
				modelIndex = 0;
				modelvar.options.length = 1;
				document.getElementById('city').options.length = 1;
				modelvar.options[modelIndex] =   new Option ('...', '');
					
				for (modelIndex=0; modelIndex < ids.length; modelIndex++) {
					modelvar.options[modelIndex+1] =   new Option (pnames[modelIndex],ids[modelIndex]);
				}
				
			}
		}
		
		xmlhttp.send(null)
	}
	
}

function getCity(province_id,site_url) {
	modelvar = document.getElementById('city');
	
	if (province_id == '') {
		modelvar.options.length = 1;
	}
	else {
		xmlhttp.open("GET",site_url + "/ajax.php?province_id="+province_id+"&call=getc",true);
		xmlhttp.onreadystatechange=function() {
			
			if (xmlhttp.readyState==4) {
						
				eval(xmlhttp.responseText);	
				
				
				modelIndex = 0;
				modelvar.options.length = 0;
				modelvar.options[modelIndex] =   new Option ('...', '');
					
				for (modelIndex=0; modelIndex < ids.length; modelIndex++) {
					modelvar.options[modelIndex+1] =   new Option (cnames[modelIndex],ids[modelIndex]);
				}
				
			}
		}
		
		xmlhttp.send(null)
	}

}
