function PullDownRequest(postcode) {
	var postdata = "";
	postdata += "postcode="+postcode;
	
	document.getElementById("PostCodeKey").innerHTML = "Loading Suburb Data . . . Please Wait";
	document.getElementById("PostCodeKey").style.display = "";
	
	AJAX_HTTP_Post("postcode.asp",postdata,"PullDownResponse","Could Not Auto-fill Suburb Data. Please type the suburb.")
}

function PullDownResponse(txt) {
	document.getElementById("PostCodeKey").innerHTML = txt;
	document.getElementById("PostCodeKey").style.display = "";
	$("select[name='fld_PostCodeKey']").change(
		function() {
			$("#txtSuburbDisplay").val($("#txtSuburb").val());
		}
	);
	
	/*if (setkey == 1) {
		for(index = 0; index < document.frmApplicationStep1.fld_PostCodeKey.length; index++) {
			if (document.frmApplicationStep1.fld_PostCodeKey[index].value == "<%=l_PostCodeKey%>") {
				document.frmApplicationStep1.fld_PostCodeKey.selectedIndex = index;
			}
		}
		setkey = 0;
	}*/
}

function SuburbChange() {
	document.frmApplicationStep1.fld_PostCodeKey.selectedIndex = 0;
}

function CheckPostCode(pc) {
	if (pc.length == 4) {
		PullDownRequest(pc);
	} else {
		$("#txtSuburb").val("");
		$("#txtSuburbDisplay").val("");
		document.getElementById("PostCodeKey").innerHTML = "<input type=hidden name=\"fld_PostCodeKey\" value=\"\">";
	}
}

function PostCodeChange() {
	selct = document.frmApplicationStep1.fld_PostCodeKey.selectedIndex;
	if (selct == 0) {
		document.frmApplicationStep1.txtSuburb.value = "";
	} else {
		document.frmApplicationStep1.txtSuburb.value = document.frmApplicationStep1.fld_PostCodeKey.options[selct].text;
	}
}

function AJAX_HTTP_Post(url, parameters, callback_function, error_msg) { 
	// Create http_request object
	var http_request = false; 
	if (window.XMLHttpRequest) { // Mozilla, Safari,... 
		http_request = new XMLHttpRequest(); 
		if (http_request.overrideMimeType) { 
			http_request.overrideMimeType('text/xml'); 
		} 
	} else if (window.ActiveXObject) { // IE 
		try { 	
			http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
           try { 
               http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
           } catch (e) {} 
        } 
    } 

	if (!http_request) { 
       alert(error_msg+'\n(Code: NO XMLHTTP SUPPORT)'); 
       return false; 
   	} 
   	
	// Set the state of the http_request object	
	http_request.onreadystatechange = function() { 
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
               eval(callback_function + '(http_request.responseText)'); 
           } else { 
               alert(error_msg+'\n(Code: ' + http_request.status + ')'); 
           } 
       } 
   } 
   http_request.open('POST', url, true);
   http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http_request.setRequestHeader("Content-length", parameters.length);
   http_request.setRequestHeader("Connection", "close");
   http_request.send(parameters);
}
