(function (){
    var yuiDom = YAHOO.util.Dom;

    var yuiEvent = YAHOO.util.Event;

    var SearchFormHandler = (function () {
        var searchForm = null;
        var localeCode = "en";
        var searchType = "standard";
        var standardTrigger =  null;
        var standardFormToggler = null;
        var pinYinTrigger = null;
        var pinYinFormToggler = null;
        var dateInputs = null;
        var standardInputs = null;
        var pinYinInputs = null;
        var loadingText = "Loading...";
        var cityText = "City";
        var self = {
            initialize: function(params) {
                localeCode = params.localeCode || localeCode;
                localeCode = localeCode.split("_")[0];
                loadingText = params.loadingText || loadingText;
                cityText = params.cityText || cityText;
                searchForm = yuiDom.get("searchForm");
                yuiEvent.addListener("closeErrorIcon","click",function() {
                    yuiDom.removeClass(searchForm, "errorMessageBox");
                    var shownErrors = yuiDom.getElementsByClassName ( "topError" , "li" , yuiDom.get("errorBlock") , function(element){
                        yuiDom.setStyle(element, "display", "none");
                    });
                });
                yuiEvent.addListener("searchForm","submit",SW.local.SearchFormHandler.validateForm, yuiDom.get("searchForm"));
                dateInputs = { 
                    arrivalDate: yuiDom.get("fnb_arrivalDate"),
                    departureDate: yuiDom.get("fnb_departureDate")
                }

                if(localeCode == "zh" || localeCode == "ja") {
                    standardInputs = {
                        city: yuiDom.get("fnb_citySelect"),
                        state: yuiDom.get("fnb_stateSelect"),
                        country: yuiDom.get("fnb_countrySelect")
                    }
                    yuiEvent.addListener(standardInputs.country,"change",self.checkState, {countrySelect: standardInputs.country, stateSelect: standardInputs.state});
                    yuiEvent.addListener(standardInputs.state,"change",self.getCities);

                    if(localeCode == "zh") {
                        pinYinInputs = {
                            city :yuiDom.get("cityField"),
                            state: yuiDom.get("fnb_pinYinStateSelect"),
                            country: yuiDom.get("fnb_pinYinCountrySelect")
                        }

                        yuiEvent.addListener(pinYinInputs.country, "change", self.checkState, {countrySelect: pinYinInputs.country, stateSelect: pinYinInputs.state});
                        yuiEvent.addListener(pinYinInputs.state, "change", self.updateCountry);
                        standardTrigger = yuiDom.get("standardTrigger");
                        pinYinTrigger = yuiDom.get("pinYinTrigger");
                        standardFormToggler = SW.widget.displayToggler({
                            element:yuiDom.get("fnb_standardFormContainer"),
                            showTriggers: pinYinTrigger,
                            showDuration:.3,
                            hideDuration:.3,
                            showAttributes: {
                                height: {from: 0, to: 60}
                            },
                            hideAttributes: {
                                height: {from: 60, to: 0 }
                            },
                            showOnStart: function (config) {
                                yuiDom.setStyle(config.element, "height", 0);
                                yuiDom.setStyle(config.showTriggers, "display", "none");
                                yuiDom.setStyle(standardTrigger, "display", "block");
                                searchType = "standard";
                                pinYinFormToggler.hide();
                            }
                        });
                        pinYinFormToggler = SW.widget.displayToggler({
                            element:yuiDom.get("fnb_pinYinFormContainer"),
                            showTriggers: standardTrigger,
                            showDuration:.3,
                            hideDuration:.3,
                            showAttributes: {
                                height: {from: 0, to: 60},
                                top: {from: 60, to: 0}
                            },
                            hideAttributes: {
                                height: {from: 60, to: 0 },
                                top: {from: 0, to: 60}
                            },
                            showOnStart: function (config) {
                                yuiDom.setStyle(config.element, "height", 0);
                                yuiDom.setStyle(config.showTriggers, "display", "none");
                                yuiDom.setStyle(pinYinTrigger, "display", "block");
                                searchType = "pinYin";
                                standardFormToggler.hide();
                            }
                        });
                        if(standardInputs.state.value != "") {
                            standardInputs.state.disabled = false;
                            self.getCities();
                        }

                        
                        pinYinFormToggler.hide();
                        standardFormToggler.show();
                    }
                }
            },
            getCities: function () {
                standardInputs.city.disabled = true;
                yuiConnect.asyncRequest("GET", "/dp/en_US/common/search/get_cities.jsp?country="
                    + standardInputs.country.value
                    + "&state="
                    + (standardInputs.state.selectedIndex > 0 ? standardInputs.state.value : ""),
                    {
                        success: self.populateSelect
                    }
                );
                standardInputs.city.options[0].text = loadingText;
            },
            populateSelect: function (xhr) {
                var selectOptions = xhr.responseXML.getElementsByTagName("city");

                standardInputs.city.options.length = 1;
                standardInputs.city.selectedIndex = 0;
                standardInputs.city.options[0].text = cityText;
                if (selectOptions.length > 0) {
                    standardInputs.city.disabled = false;
                    for (var i = 0; i < selectOptions.length; i++) {
                        var selected = false;
                        standardInputs.city.options[standardInputs.city.options.length] = new Option(selectOptions[i].firstChild.nodeValue, selectOptions[i].getAttribute("en"), selected);
                    }
                }
            },
            updateCountry: function () {
                var c = false;
                if(isIn(pinYinInputs.state.value,us_states)) {
                    c = "US";
                } else if(isIn(pinYinInputs.state.value,ca_prov)) {
                    c = "CA";
                } else if(isIn(pinYinInputs.state.value,misc)) {
                    c = "US";
                }
                if (c != false) {
                    setDropDown(c,pinYinInputs.country);
                }

            },
            checkState: function(e, params) {
                if(params.countrySelect.value == "US" || params.countrySelect.value == "CA") {
                    params.stateSelect.disabled = false;
                }
                else {
                    params.stateSelect.selectedIndex = 1;
                    params.stateSelect.value = "";
                    params.stateSelect.disabled = true;
                    self.getCities();
                }
            },
            validateForm: function (e,searchForm) {
                yuiDom.getElementsByClassName("error", "label", "searchFormArea", function(label) {
                    yuiDom.removeClass(label, "error");
                });
                var errors = false;
                if(localeCode != "ja" && localeCode != "zh") {
/*
                    if(yuiDom.get("cityField").value == "" ||
                       yuiDom.get("fnb_stateSelect").value == "" ||
                       yuiDom.get("fnb_countrySelect").value == "") {
                       yuiDom.setStyle("searchCriteriaRequiredError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
*/
                    if(yuiDom.get("fnb_countrySelect").value == "" && yuiDom.get("cityField").value == "") {
                        yuiDom.addClass("cityLabel", "error");
                        yuiDom.setStyle("searchCriteriaRequiredError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
                    if(yuiDom.get("fnb_countrySelect").value == "") {
                        yuiDom.addClass("cityLabel", "error");
                        yuiDom.setStyle("countryRequiredForCitySearchError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
                    if((yuiDom.get("fnb_countrySelect").value == "US" && yuiDom.get("fnb_stateSelect").value  == "")) {
                        yuiDom.addClass("cityLabel", "error");
                        yuiDom.setStyle("toGeneralUSSearchError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
                }
                else {
                    // japanese and chinese locale
                    if(localeCode == "ja" || searchType == "standard") {
                        if(standardInputs.country.value == "" && standardInputs.city.value == "") {
                            yuiDom.addClass("cityLabel", "error");
                            yuiDom.setStyle("countryRequiredForCitySearchError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                        if(standardInputs.country.value == "") {
                            yuiDom.addClass("cityLabel", "error");
                            yuiDom.setStyle("countryRequiredForCitySearchError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                        if((standardInputs.country.value == "US" && standardInputs.state.value == "" && standardInputs.city.value == "")) {
                            yuiDom.addClass("cityLabel", "error");
                            yuiDom.setStyle("toGeneralUSSearchError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                    }
                    else if(localeCode == "zh" && searchType == "pinYin"){
                        if(pinYinInputs.country.value == "") {
                            yuiDom.addClass("cityLabel", "error");
                            yuiDom.setStyle("countryRequiredForCitySearchError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                        if(pinYinInputs.country.value != "" && (pinYinInputs.state.value == "" && pinYinInputs.city.value == "")) {
                            yuiDom.addClass("cityLabel", "error");
                            yuiDom.setStyle("searchCriteriaRequiredError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }

                    }
                }

                if ((dateInputs.arrivalDate.value != "" && dateInputs.departureDate.value != "") && (dateInputs.arrivalDate.value != dateFormatString || dateInputs.departureDate.value != dateFormatString)) {
                    var checkIn = new validDate(dateInputs.arrivalDate);
                    var checkOut = new validDate(dateInputs.departureDate);
                    var datesDelta = checkIn.diffDate(checkOut.d);
                    if (!(checkIn.valid) && (!checkOut.valid)) {
                        yuiDom.addClass("arrivalDateLabel", "error");
                        yuiDom.addClass("departureDateLabel", "error");
                        yuiDom.setStyle("ciAnddepartureDatesInvalidError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
                    else if (!checkIn.valid) {
                        yuiDom.addClass("arrivalDateLabel", "error");
                        yuiDom.setStyle("arrivalDateInvalidError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
                    else if (!checkOut.valid) {
                        yuiDom.addClass("departureDateLabel", "error");
                        yuiDom.setStyle("departureDateInvalidError", "display", "block");
                        return SearchFormHandler.returnError(e, true);
                    }
                    else if ((checkIn.valid) & (checkOut.valid)) {
                        var datesDelta = checkIn.diffDate(checkOut.d);
                        var nowDelta = checkIn.diffDate(new Date());
                        if (nowDelta > 0) {

                        }
                        else if (nowDelta < -561) {
                            yuiDom.addClass("arrivalDateLabel", "error");
                            yuiDom.addClass("departureDateLabel", "error");
                            yuiDom.setStyle("bookToFarInFutureError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                        else if (datesDelta < 0) {
                            yuiDom.addClass("arrivalDateLabel", "error");
                            yuiDom.addClass("departureDateLabel", "error");
                            yuiDom.setStyle("departureBeforeArrivalError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                        else if (datesDelta > 30) {
                            yuiDom.addClass("arrivalDateLabel", "error");
                            yuiDom.addClass("departureDateLabel", "error");
                            yuiDom.setStyle("maximumLengthStayExceededError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                        else if (datesDelta < 1) {
                            yuiDom.addClass("arrivalDateLabel", "error");
                            yuiDom.addClass("departureDateLabel", "error");
                            yuiDom.setStyle("arrivalEqualsDepartureError", "display", "block");
                            return SearchFormHandler.returnError(e, true);
                        }
                    }
                }
            },
            returnError: function(e, hasError) {
                var errors = hasError;
                if(!errors && localeCode == "zh") {
                    if(searchType == "pinYin") {
                        standardInputs.city.disabled = true;
                        standardInputs.state.disabled = true;
                        standardInputs.country.disabled = true;
                    }
                    else {
                        pinYinInputs.city.disabled = true;
                        pinYinInputs.state.disabled = true;
                        pinYinInputs.country.disabled = true;
                    }
                }
                if(errors) {
                    yuiEvent.preventDefault(e);
                    yuiDom.addClass(searchForm, "errorMessageBox");
                }
                return !errors;

            }
        }

        return self;
    })();
    YAHOO.namespace("SW.local.SearchFormHandler");
    SW.local.SearchFormHandler = SearchFormHandler;
})();


var stateProvinceAutoSet = true;
var countryAutoSet = true;
var searchForm = new WebForm();

function searchForm_onSubmit() {
	//city_onBlur();
	searchForm.resetErrors();
	dateStatus = checkDates();

	if (document.searchForm.searchType.value != "favorite") {
		checkLocationFields();
		searchForm.collapseErrors("multipleError");
	} else if (document.searchForm.searchType.value == "favorite") {
		checkFavoriteSearch(dateStatus);
		searchForm.collapseErrors("datesAndPropertyRquiredError");
	}

	if (searchForm.hasErrors()) {
		searchForm.showErrors();
		return false;
	} else {
		return true;
	}
}
function checkFavoriteSearch(dateStatus) {
	if (document.searchForm.favoritePropertyID.value < 1) {
		searchForm.addError("~favoritePropertyNotSelectedError", "favoriteHotelLabel");
	}
	if (dateStatus == "DATES_NOT_SET") {
		searchForm.addError("~datesAreRequiredError","arrivalDateLabel","departureDateLabel");
	}
}
function checkLocationFields() {
	locationStatus = getLocationStatus();
	zipCodeStatus = getZipCodeStatus();

	if (document.searchForm.address != null) {
		isAddressSearch = (document.searchForm.searchType.value == "address")
		addressEntered = (document.searchForm.address.value != "")
	} else {
		isAddressSearch = false;
		addressEntered = false;
	}

	if (!isAddressSearch) {
		if (locationStatus == "INCOMPLETE") { // the location fields don't exist in the form
			return;
		}
		if (locationStatus =="BLANK") {
			searchForm.addError("~searchCriteriaRequiredError","cityLabel", "stateProvinceError", "countryError" );
			return;
		}
		if (locationStatus == "CITY_ONLY") {
			searchForm.addError("~countryRequiredForCitySearchError", "countryError" );
            return;
		}
		if (locationStatus == "INVALID_US_SEARCH") {
			searchForm.addError("~toGeneralUSSearchError","stateProvinceError" );
			return;
		}
	} else {
		if (zipCodeStatus == "INVALID") {
			searchForm.addError("~invalidZipCodeError","zipLabel");
			return;
		}
		if (zipCodeStatus == "VALID") {
			return;
		}
		if ((locationStatus =="INVALID_US_SEARCH") && (!addressEntered)) {
			searchForm.addError("~searchCriteriaRequiredError","cityLabel", "stateProvinceError", "zipLabel", "addressLabel" );
			return;
		}
		if (addressEntered) {
			if ((document.searchForm.city.value =="") && (document.searchForm.stateProvince.value == "")) {
				searchForm.addError("~searchCriteriaRequiredError","cityLabel", "stateProvinceError");
				return;
			} else if(locationStatus=="STATE_SEARCH") {
				searchForm.addError("~searchCriteriaRequiredError","cityLabel");
				return;
			} else if(locationStatus=="INVALID_US_SEARCH") {
				searchForm.addError("~searchCriteriaRequiredError","stateProvinceError");
				return;
			}
		}

	}
}
function getLocationStatus() {
	if (document.searchForm.city != null) {cityEmpty = (document.searchForm.city.value =="");} else {cityEmpty = false;}
	if (document.searchForm.stateProvince != null){stateProvinceEmpty = (document.searchForm.stateProvince.value == "");} else {stateProvinceEmpty = false;}
	if (document.searchForm.country != null){
		countryEmpty = (document.searchForm.country.value=="");
		countryUS = (document.searchForm.country.value=="US");
	} else {
		countryEmpty = false;
		countryUS = false;
	}

	if ((document.searchForm.city != null && !cityEmpty) && (document.searchForm.stateProvince != null && !stateProvinceEmpty) && (document.searchForm.country != null && !countryEmpty)) { return "COMPLETE_SEARCH"; }
	if ((document.searchForm.stateProvince != null && !stateProvinceEmpty) && (document.searchForm.country != null && !countryEmpty)) { return "STATE_SEARCH"; }
	if ((document.searchForm.city != null && !cityEmpty) && (document.searchForm.country != null && !countryUS) && (!countryEmpty)) { return "NON_US_CITY_SEARCH"; }
	if ((document.searchForm.country != null && !countryEmpty) && (!countryUS) ) { return "NON_US_COUNTRY_SEARCH"; }
	if ((document.searchForm.stateProvince != null && stateProvinceEmpty) && (document.searchForm.country != null && countryUS) ){ return "INVALID_US_SEARCH"; }
	if ((document.searchForm.city != null && !cityEmpty) && (document.searchForm.stateProvince != null && stateProvinceEmpty) && (document.searchForm.country != null && countryEmpty)) { return "CITY_ONLY"; }
	if ((document.searchForm.city != null && cityEmpty) && (document.searchForm.stateProvince != null && stateProvinceEmpty) && (document.searchForm.country != null && countryEmpty)) { return "BLANK"; }
	return "INCOMPLETE";
}
function getZipCodeStatus() {
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if(f.zipCode != null && f.zipCode.value == ''){
		return "BLANK";
	} else if(f.zipCode != null && !objRegExp.test(f.zipCode.value)){
		return "INVALID";
	} else {
		return "VALID"
	}
}

function checkDates() {
	if ((document.searchForm.arrivalDate.value == dateFormatString) && (document.searchForm.departureDate.value == dateFormatString)) {
		return "DATES_NOT_SET";
	}

	var checkIn = new validDate(document.searchForm.arrivalDate);
	var checkOut = new validDate(document.searchForm.departureDate);

	if (!(checkIn.valid) && (!checkOut.valid) ) {
		searchForm.addError("~ciAnddepartureDatesInvalidError", "arrivalDateLabel","departureDateLabel")
	} else if (!checkIn.valid ) {
		searchForm.addError("~arrivalDateInvalidError","arrivalDateLabel")
	} else if (!checkOut.valid ) {
		searchForm.addError("~departureDateInvalidError","departureDateLabel")
	} else 	if ( (checkIn.valid) & (checkOut.valid)  ) {
		var datesDelta = checkIn.diffDate( checkOut.d);
		var nowDelta = checkIn.diffDate(new Date());
		if (nowDelta > 0 ) {
			searchForm.addError("~checkInEarlierThanTodayError","arrivalDateLabel");
		} else if (nowDelta < -561) {
			searchForm.addError("~bookToFarInFutureError","arrivalDateLabel");
			searchForm.addError()
		} else if (datesDelta < 0) {
			searchForm.addError("~departureBeforeArrivalError","departureDateLabel");
		} else if (datesDelta > 31) {
			searchForm.addError("~maximumLengthStayExceededError", "arrivalDateLabel","departureDateLabel");
		} else if (datesDelta < 1) {
			searchForm.addError("~arrivalEqualsDepartureError", "arrivalDateLabel","departureDateLabel");
		}
	}
	return "";
}



function city_onFocus() {
	document.searchForm.city.value = "";
	if (stateProvinceAutoSet) { f.stateProvince.selectedIndex = 0; }
	if (countryAutoSet) { f.country.selectedIndex = 0; }
}

function city_onBlur() {
	a = isIn(document.searchForm.city.value.toLowerCase(),topCities)
	if (a != false) {
		setDropDown(a[1],document.searchForm.stateProvince);
		setDropDown(a[2],document.searchForm.country);
		country_onChange();
		stateProvinceAutoSet = true;
		countryAutoSet = true;
	}
}

function stateProvince_onChange() {
	c = false;
	if(isIn(document.searchForm.stateProvince.value,us_states)) {
		c = "US";
	} else if(isIn(document.searchForm.stateProvince.value,ca_prov)) {
		c = "CA";
	} else if(isIn(document.searchForm.stateProvince.value,misc)) {
		c = "US";
	}
	if (c != false) {
		setDropDown(c,document.searchForm.country);
	}
	country_onChange();
	stateProvinceAutoSet = false;
}
function country_onChange() {
	var f = document.searchForm; 
    if (f.searchType.value=="address") {
		setDropDown("US",document.searchForm.country);
	}
	if ((f.country[f.country.selectedIndex].value != "US") && (f.country[f.country.selectedIndex].value != "CA")) {
		setDropDown("",document.searchForm.stateProvince);
	}
	if (f.country[f.country.selectedIndex].value == "US") {
		f.rateRange.disabled = false;
	} else {
		f.rateRange.disabled = true;
		f.rateRange.selectedIndex = 0;
	}
	stateProvinceAutoSet = false;
	countryAutoSet = false;
}
function rateRange_onChange() {
	var f = document.searchForm;
	if (f.country[f.country.selectedIndex].value == "US") {
		f.rateRange.disabled = false;
	} else {
		f.rateRange.disabled = true;
		f.rateRange.selectedIndex = 0;
	}
}

function setDropDown(v,dd) {
	for (i = 0; i < dd.options.length - 1; i++ ) {
		if ( dd.options[i].value == v ) {
			dd.selectedIndex = i;
			return true
		}
	}
	return false;
}

function isIn(elt, list){
	for(var i=0; i < list.length; i++){
		var tempArray = list[i].split(":")
		if( tempArray[0] == elt ){
			return tempArray;
		}
	}
	return false;
}

function searchTab_onClick(searchAction, isLoggedIn) {
	searchForm.resetErrors();
	document.searchForm.searchAction.value = searchAction;
	var t = (searchAction == 'findRooms')
	document.getElementById('rightSearchTab').className = t ? "faded" : "selected";
	document.getElementById('leftSearchTab').className = t ? "selected" : "faded";
	document.getElementById('roomInfo').style.display= t ? "" : "none";

	document.getElementById('redeemLoggedOut').style.display = (!isLoggedIn && (!t)) ? "block" : "none";
	document.getElementById('standardForm').style.display = (! (!isLoggedIn && (!t))) ? "block" : "none";
}

function arrivalDate_onFocus() {
	var checkIn = new validDate(document.searchForm.arrivalDate);
	if (  !checkIn.valid ) { document.searchForm.arrivalDate.value="";}
}

function arrivalDate_onBlur() {
	var checkIn = new validDate(document.searchForm.arrivalDate);
	if ( checkIn.valid ) {
		checkIn.setField();
		var checkOut = validDate(document.searchForm.departureDate);
		if (checkOut.valid ) { before = (checkIn.diffDate(checkOut.d) <= 0);}
		if ( (! (checkOut.valid)) || before) {
			checkOut.setD(checkIn.d);
			checkOut.nextDay();
			checkOut.setField();
		}
	} else {document.searchForm.arrivalDate.value=dateFormatString;}
}
function departureDate_onFocus() {
	var checkOut = new validDate(document.searchForm.departureDate);
	if (  !checkOut.valid ) { document.searchForm.departureDate.value="";}
}
function departureDate_onBlur() {
	var checkOut = new validDate(document.searchForm.departureDate);
	if ( checkOut.valid ) { checkOut.setField(); } else {document.searchForm.departureDate.value=dateFormatString;}
}

function favorites_onBlur() {
}

function favorites_onClick(id, t) {
	document.searchForm.favoritePropertyID.value = id;
	var nodes = document.getElementById('favoriteHotels').getElementsByTagName('A');
	for( var x = 0; x < nodes.length ; x++ ) {
		nodes[x].className="";
	}
	t.className="selectedFavorite";
	document.searchForm.arrivalDate.focus();
}

function searchType_onClick(searchType) {
	searchForm.resetErrors();
	document.searchForm.searchType.value = searchType;
	document.getElementById('cityToggle').className = (searchType == "city") ? "toggleHREFSelected" : "toggleHREF";
	document.getElementById('addressToggle').className = (searchType == "address") ? "toggleHREFSelected" : "toggleHREF";
	document.getElementById('favoritesToggle').className = (searchType == "favorite") ? "toggleHREFSelected" : "toggleHREF";
	var byF = (searchType == "favorite")
	document.getElementById('byLocationBlock').style.display = byF ? "none" : "block";
	document.getElementById('byFavoriteBlock').style.display = byF ? "block" : "none";
	if (!byF) {
		var t = (searchType == "city");
		document.getElementById('byLocationBlock').style.display = "none";
		document.getElementById('addressBlock').style.display= t ? "none" : "block";
		document.getElementById('city').style.width= t ? "200px" : "60px";
		document.getElementById('zipCode').style.display= t ? "none" : "block";
		if (!t) {document.searchForm.country.selectedIndex = 1;}
		document.getElementById('byLocationBlock').style.display = "block";
		rateRange_onChange();
	} else {
		f.rateRange.disabled = true;
		f.rateRange.selectedIndex = 0;
	}
}
function advancedSearch_onClick() {
	document.searchForm.searchAction.value = "advanced";
	if (document.searchForm.sendRedirect.value != null){
		document.searchForm.sendRedirect.value = "true";
	}
	f.submit();
}

function tab_onClick(tabName) {
	searchForm.resetErrors();

	if (tabName.value =="address") {
		searchType="address";
		f.searchType.value = "address"
		switchDisplay("addressFieldBlock","show");
		switchDisplay("zipFieldBlock","show");
	} else {
		searchType="city";
		f.searchType.value = "city"
		switchDisplay("addressFieldBlock");
		switchDisplay("zipFieldBlock");
	}
}

