var xmlHttp;

function AjaxCallbackFunction()
{
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response  = xmlHttp.responseXML;
			query_type = response.getElementsByTagName('query_type')[0].firstChild.data;
			res = response.getElementsByTagName('answer')[0].firstChild.data;
    	    document.getElementById('answer').innerHTML = res;
			res2 = response.getElementsByTagName('answer2')[0].firstChild.data;
    	    document.getElementById('answer2').innerHTML = res2;
			res3 = response.getElementsByTagName('answer3')[0].firstChild.data;
    	    document.getElementById('answer3').innerHTML = res3;
			res4 = response.getElementsByTagName('answer4')[0].firstChild.data;
    	    document.getElementById('answer4').innerHTML = res4;
			res5 = response.getElementsByTagName('answer5')[0].firstChild.data;
    	    document.getElementById('answer5').innerHTML = res5;
		}
		else {
		}
	}
}

function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {            
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
} 

function SendAjaxRequest(url) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp) {
		xmlHttp.onreadystatechange = AjaxCallbackFunction;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}           

function SubmitQueryRequest() {
    var param = document.f.param.value;            
    var param2 = document.f.param2.value;            
    var param3 = document.f.param3.value;            
    var param4 = document.f.param4.value;            
    var param51 = document.f.param51.value;            
    var param52 = document.f.param52.value;            
    SendAjaxRequest('services/zipcode/zipcode.php?query_type=find_city' + 
        '&param=' + param + 
        '&param2=' + param2  + 
        '&param3=' + param3 + 
        '&param4=' + param4 + 
        '&param51=' + param51 + 
        '&param52=' + param52 + 
        '&rand=' + Math.random());
}

