var url = "/globals/coldfusion/GetSourcesFromZipCode.cfm"; // The server-side script
var zipInterval;
var enteredZip = "";

function zip_httpReturnResults(obj) {
	resultObj = eval(obj);
	sourceOpt['DISPLAY'] = resultObj;
	sourceList = "DISPLAY";
	popluateDropDownList(sourceField,sourceList);
}
function popluateDropDownList(selObj,objItem) {
	addOptgroup(selObj,objItem);
	objectDisplay(secondaryForm,form_disp_prop);
	objectDisplay(selObj,obj_disp_prop);
	objectEnable(selObj,false);
	document.getElementById(selObj).focus();
	//objectDisplay(loadingDiv,'none');
}

var isWorking = false;
function updateZipcode(paramStr) {
	if (paramStr != "") {
		objectDisplay(sourceField,'none');
		objectEnable(sourceField,true);
		//objectDisplay(loadingDiv,'block');
		isWorking = false;
		paramStr = "param=" + paramStr;
		sendHttpRequest(paramStr,'zip_httpReturnResults');
		clearInterval(zipInterval);
		}
	}
function checkZipcode() {
	zipVal = document.getElementById(zipField).value;
	
	if (zipVal != enteredZip) {
		if (validateZip(zipVal)) {//if (zipVal.length == 5 && isNaN(zipVal) == false) {
			removeOptgroup(sourceField);
			updateZipcode(zipVal);
			}
		if (zipVal.length < 5) {
			objectDisplay(secondaryForm,'none');
			objectDisplay(sourceField,'none');
			objectEnable(sourceField,true);
			}
		}
		
	enteredZip = document.getElementById(zipField).value;
	}
function objectDisplay(objName,disp) {
	if (document.getElementById(objName)) {
		document.getElementById(objName).style.display = disp;
		}
	}
	
function objectEnable(objName,bool) {
if (document.getElementById(objName)) {
	document.getElementById(objName).disabled = bool;
	}
}

function setZipInterval() {
zipInterval = window.setInterval("checkZipcode()",1000);
}

function resetZipInterval() {
if (zipInterval) {
	clearInterval(zipInterval);
	}
}