// 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) {
            eval('var rtn = ' + xmlHttp.responseText);

            if (rtn.city.length > 0 && fldCity.value.length == 0) {
                fldCity.value = rtn.city;
            }

            if (rtn.state.length > 0 && fldState.selectedIndex != 1) {
                for (var i = 0; i < fldState.options.length; i++) {
                    if (fldState.options[i].value == rtn.state) {
                        fldState.selectedIndex = i;
                        break;
                    }
                }
                if (i == fldState.options.length) { fldState.selectedIndex = 0 };
            }
        }
    }
}
