// JavaScript Document
var xmlHttp;

function zipLookup(fuseroot, zip, fldCity, fldState) {	
	if (trim(zip).length != 5 || !checkChars(zip, "0123456789")) return false;
	
	if (window.ActiveXObject)
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		xmlHttp = new XMLHttpRequest();

	if (xmlHttp != null) {
		xmlHttp.onreadystatechange = function(){processZipChange(fldCity, fldState)};
		xmlHttp.open("GET", fuseroot + '/includes/lookup/ziplookup.cfm?zip=' + zip, true);
		xmlHttp.send(null);
	} else {
//		alert('Your browser does not support XMLHTTP.');
	}
}   
   
function processZipChange(fldCity, fldState) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseXML;
			var cylist = response.getElementsByTagName('city');
			var stlist = response.getElementsByTagName('state');

			var cy = cylist[0].firstChild.nodeValue;
			var st = stlist[0].firstChild.nodeValue;

			if (cy.length > 0 && fldCity != '')
				fldCity.value = cy;
			if (st.length > 0 && fldState != '') {
				for (var i = 0; i < fldState.options.length; i++) {
					if (fldState.options[i].value == st) {
						fldState.selectedIndex = i;
						break;
					}
				}
				if (i == fldState.options.length) fldState.selectedIndex = 0;
			}
		} else {
//			alert('There was a problem retrieving the XML data:\n' + xmlHttp.statusText);
		}
	}
}