var activeForm = null;
var zipErrorText = "The Zip Code You've Entered is Not Valid.";

function showZipError(rform, flw){
document.getElementById("chooseCitySelect").selectedIndex = 0;
dimIE6FormElements(false);
window.scrollTo(0,0);
var errWindow = document.getElementById("zipError");
var errWindowForm = document.getElementById("miniZip");
errWindowForm.pform = rform;
activeForm = rform;
errWindowForm.pformfollow = flw;
errWindowForm.zip.value = rform.zc.value;
errWindow.style.display = "block";
document.miniZip.zip.focus();
}
function zipErrorHide(){
hideZipError();
}
function hideZipError(){
setNationalRadius(null);
dimIE6FormElements(true);
document.getElementById("zipError").style.display = "none";
}

function postProcessZip(){
document.getElementById("zc").value = document.getElementById("minizip").value;
}

function checkZipFirst(rform, flw, rzip){
if(!isDealer && !isMicrosite){
//alert('checking zip first...');
if(quickForm){storeAndGo("", rform);}
if(rzip.length < 5){flw(rform, false);} else {

var isValid = false;
var url = '/for-sale/GetValidZip.action';
dojo.io.bind({
url: url,

content: {
zc: rzip
},

handler: function(type, data, evt){
//debug(data);
isValid = eval("("+data+")");

flw(rform, isValid);
}
});
}
} else {flw(rform, true );}

}

function testFollow(isValid){
debug(isValid);
}

function miniFollow(rform, isValid){
debug('MiniFollow:'+isValid);
if(!isValid){
alert(zipErrorText);
} else {
rform.pform.zc.value = rform.zip.value;
debug(rform.pformfollow);
rform.pformfollow(rform.pform);
hideZipError();
}
}


function dimIE6FormElements(show){

var visSet = "hidden";
if(show){visSet = "visible";}
for(i=0;i<ie6dimlist.length;i++){

if(document.getElementById(ie6dimlist[i])){
document.getElementById(ie6dimlist[i]).style.visibility = visSet;
}
}
}

function setNationalRadius(citySelect){
if(activeForm.rd.selectedIndex){
var rRadius = activeForm.rd;
if(citySelect != null && citySelect.selectedIndex == 1){debug("All..."+activeForm.name);lastRealRadius = getSelectValue(rRadius);rRadius.selectedIndex = (rRadius.options.length-1);}
else {
debug("in else:"+rRadius);
if(lastRealRadius != null){prePopSelect(rRadius, lastRealRadius);}
}
} else if(activeForm.name == "newForm" && buyIndex && citySelect != null && citySelect.selectedIndex == 1){activeForm.rd.value = "100000"}
 else if(activeForm.name == "newForm" && buyIndex && citySelect != null && citySelect.selectedIndex != 1 && lastRealRadius != null){activeForm.rd.value = lastRealRadius}
}

function updateCity(rForm){
var citySelect = document.getElementById("chooseCitySelect");
var cityValue = getSelectValue(citySelect);
cityValue = cityValue.split("|")[0];
if(cityValue.length > 0){
document.getElementById("zc").value = cityValue;
//swapCityList(2);
}
setNationalRadius(citySelect);
}