	
	//=========================================================================
	// SmartLead - Zip Code Finder
	//=========================================================================

function RequestZipCodesAPI(sRequestCode)
{
	var bValidZipCode = (IsValidZipCode(window.document.getElementById('txt' + sRequestCode + 'ZipCode').value, false).ReturnCode == 0);
	var bValidCityState = (IsEmpty(window.document.getElementById('txt' + sRequestCode + 'City').value).ReturnCode == 0 && window.document.getElementById('cbo' + sRequestCode + 'State').selectedIndex > 0);
	if (bValidZipCode || bValidCityState) {
	    if (bValidZipCode) 
	    {
	        var url = "zip_finder.asp?get=zip&zip=" + window.document.getElementById('txt' + sRequestCode + 'ZipCode').value + "&d=" + new Date().getTime();
	        $.get(url, function(data) {
	            var city = $(data).find("City:eq(0)").text();
	            var state = $(data).find("State:eq(0)").text();
	            var hUserError;

	            //Clear the error messages and the marked fields.
	            ResetErrorDisplay();
	            if (city != "" && state != "") {
	                document.getElementById('txt' + sRequestCode + 'City').value = city;
	                document.getElementById('cbo' + sRequestCode + 'State').value = state;
	            }
	            else {
	                hUserError = new UserError('txt' + sRequestCode + 'ZipCode', 'The zip code you entered was not found.', sRequestCode == 'From' ? 3 : 4, 2);
	                hUserError.DisplayError();
	            }
	        }, "xml");
	    }
	    else {
	        // first we get the long/lat
	        var url = "zip_finder.asp?get=ll&city=" + window.document.getElementById('txt' + sRequestCode + 'City').value + "&state=" + window.document.getElementById('cbo' + sRequestCode + 'State').value + "&d=" + new Date().getTime();
	        $.get(url, function(data) {
	            var latitude = $(data).find("Latitude:eq(0)").text();
	            var longitude = $(data).find("Longitude:eq(0)").text();
	            var url = "zip_finder.asp?get=zip_ll&lat=" + latitude + "&long=" + longitude;
	            $.get(url, function(data2) {
	                var zip = $(data2).find("PostalCodeNumber:eq(0)").text();
	                document.getElementById('txt' + sRequestCode + 'ZipCode').value = zip;
	            }, "xml");
	        }, "xml");
	    }
	}
	else 
	{
		alert('In order to find a zip code enter a city name, select a state and then click the Find button.\nIf you want to validate your zip code enter it and click the find button.');
	}
}
	function RequestZipCodes(sRequestCode) 
	{
	var bValidZipCode = (IsValidZipCode(window.document.getElementById('txt' + sRequestCode + 'ZipCode').value, false).ReturnCode == 0);
	var bValidCityState = (IsEmpty(window.document.getElementById('txt' + sRequestCode + 'City').value).ReturnCode == 0 && window.document.getElementById('cbo' + sRequestCode + 'State').selectedIndex > 0);		
	var theform = 
		(document.getElementById('fraGetZipCode').document == null) ?
			document.getElementById('fraGetZipCode').contentDocument.getElementById('frmGetZipCode') :
			document.frames['fraGetZipCode'].document.getElementById('frmGetZipCode');

		if (bValidZipCode || bValidCityState) {
			theform.txtRequestCode.value = sRequestCode; 

			if (bValidZipCode) {
				theform.txtZipCode.value = window.document.getElementById('txt' + sRequestCode + 'ZipCode').value;
				theform.txtCity.value = '';
				theform.txtStateCode.value = '';
			}
			else {
				theform.txtZipCode.value = '';
				theform.txtCity.value = window.document.getElementById('txt' + sRequestCode + 'City').value;
				theform.txtStateCode.value = window.document.getElementById('cbo' + sRequestCode + 'State').value;
			}
					
			theform.submit();
		}
		else 
			alert('In order to find a zip code enter a city name, select a state and then click the Find button.\nIf you want to validate your zip code enter it and click the find button.');
	}


	
	function ReceiveZipCodes(sRequestCode, iResultCount) 
	{
	var hUserError;
	
		//Clear the error messages and the marked fields.
		ResetErrorDisplay(); 

		if (iResultCount > 0) {
			SelectZipCode(0, sRequestCode);
			window.document.getElementById('cmd' + sRequestCode + 'ZipList').disabled = !(iResultCount > 1);
		}
		else {
			hUserError =  new UserError('txt' + sRequestCode + 'ZipCode', 'The zip code you entered was not found.', sRequestCode=='From'?3:4, 2);
			hUserError.DisplayError();
			}  
	}



	//function DisplayZipHelp() 
	//{
	//var iLeftPos = event.srcElement.id=='HelpFromZip'?0:300;
	//
	//	window.winPopupHelpZip.style.left = event.clientX + window.document.body.scrollLeft - iLeftPos;
	//	window.winPopupHelpZip.style.top =  event.clientY + window.document.body.scrollTop - 145;
	//	window.winPopupHelpZip.style.display = 'inline';
	//}



	function ShowZipList(e) 
	{
	var src;
		if (e.srcElement) src = e.srcElement;
		else if (e.target) src = e.target;	
	var iLeftPos = src.id=='cmdFromZipList'?0:300;
 	var thedoc = 
		(document.getElementById('fraGetZipCode').document == null) ?
			document.getElementById('fraGetZipCode').contentDocument :
			document.frames['fraGetZipCode'].document;

		document.getElementById('ZipListBlock').innerHTML = thedoc.getElementById('ZipListBlock').innerHTML;
		document.getElementById('txtRequest').value = src.name.indexOf('From')>0?'From':'To';
			
		document.getElementById('winPopupZipList').style.left = e.clientX + window.document.body.scrollLeft - iLeftPos;
		document.getElementById('winPopupZipList').style.top =  e.clientY + window.document.body.scrollTop - 145;
		document.getElementById('winPopupZipList').style.display = 'inline';
	}



	function GetCityState() 
	{
	var src;
		if (e.srcElement) src = e.srcElement;
		else if (e.target) src = e.target;
			
	var sRequestCode = src.name.indexOf('From')>0?'From':'To';
	var theform = 
		(document.getElementById('fraGetZipCode').document == null) ?
			document.getElementById('fraGetZipCode').contentDocument.getElementById('frmGetZipCode') :
			frames['fraGetZipCode'].document.getElementById('frmGetZipCode');
	
		if (IsValidZipCode(src.value, false).ReturnCode == 0) {
			theform.txtRequestCode.value = sRequestCode; 
			theform.txtZipCode.value = window.document.getElementById('txt' + sRequestCode + 'ZipCode').value;
			theform.submit();
		}
	}


	
	function SelectZipCode(iIndex, sRequestCode) 
	{
	var thedoc = 
		(document.getElementById('fraGetZipCode').document == null) ?
			document.getElementById('fraGetZipCode').contentDocument :
			document.frames['fraGetZipCode'].document;
			
	var sValue = thedoc.getElementById('lstZipCodes').options[iIndex].text;
			
		document.getElementById('winPopupZipList').style.display = 'none'; 	

		document.getElementById('txt' + sRequestCode + 'ZipCode').value = sValue.slice(0,5);
		document.getElementById('txt' + sRequestCode + 'City').value = sValue.slice(8, sValue.length - 4);
		document.getElementById('cbo' + sRequestCode + 'State').value = sValue.slice(sValue.length - 2);
	}

