var activeForm = null;

function showZipError(rform, flw){
//debug('Showing...');

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 mnUrl = '/for-sale/GetValidZip.action?zc='+rzip;
zipAJX = new Ajax();
zipAJX.rForm = rform;
zipAJX.flw = flw;
zipAJX.followup = function(){
isValid = eval("("+zipAJX.pb[0]+")");
zipAJX.flw(zipAJX.rForm, isValid);
};
zipAJX.start("GET", mnUrl);
}
} else {flw(rform, true );}

}

function testFollow(isValid){
//debug(isValid);
}

function miniFollow(rform, isValid){
//debug('MiniFollow:'+isValid);
if(!isValid){
//alert("The ZIP Code You've Entered is Not Valid.");
} 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){
debug("updateCity");
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);

}

//----------------------------------------------------------------------------------------------------------------------//

function updateCityHP(){
// debug("updateCity");
var citySelect = document.getElementById("chooseCitySelect");

var cityValue = getSelectValue(citySelect);

cityValue = cityValue.split("|")[0];

if(cityValue.length > 0){

document.getElementById("miniZip").zip.value = cityValue;

//swapCityList(2);

}

 setNationalRadius(citySelect);

}
