function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function init()
{
  MM_preloadImages('imgs/navg_off_1.jpg', 'imgs/navg_1_on.jpg', 'imgs/navg_off_2.jpg', 'imgs/navg_2_on.jpg', 'imgs/navg_off_3.jpg', 'imgs/navg_3_on.jpg', 'imgs/navg_off_4.jpg', 'imgs/navg_4_on.jpg', 'imgs/navg_off_5.jpg', 'imgs/navg_5_on.jpg', 'imgs/navg_off_6.jpg', 'imgs/navg_6_on.jpg', 'imgs/spec-02-on.jpg' );

}



    function setDefaultClick(p_src, p_default) {
        if (p_src.value == p_default) {
            p_src.value = "";
        }
    }
    function setDefaultBlur(p_src, p_default) {
        if (p_src.value == "") {
            p_src.value = p_default;
        }
    }
    function updatePropertyType(p_obj) {
        var frm = p_obj.form;
        for (var i = 0; i < p_obj.options.length; i++ ) {
            var field = p_obj.options[i].value;
            if (field != "") frm[field].value = (i == p_obj.selectedIndex) ? "Y" : "";
        }
    }
    function quickSearch(frm) {
        if (frm.temp_address && frm.temp_address.value != "Address") frm.address.value = frm.temp_address.value;
        if (frm.temp_zip_code && frm.temp_zip_code.value != "Zip") frm.zip_code.value = frm.temp_zip_code.value;
        if (frm.temp_property_id && frm.temp_property_id.value != "MLS Number") frm.property_id.value = frm.temp_property_id.value;
        frm.submit();
    }
    function quickSearch2() {
        var frm = document.forms.searchForm;
        if (frm.address.value == "Address") frm.address.value = "";
        frm.submit();
    }

    // this is set to yes after all the variables have been loaded
    city_county_loaded = "no";
    city_page_load_first_run = "Y";
    county_page_load_first_run = "Y";
    useall = true;
    allfactor = 1;
    
    // when all the variables have been loaded via the external js file the city_county_loaded variable will be set to yes.
    // then we can move on
    function checkDataLoad(){
        if (city_county_loaded == "no"){
            setTimeout ("checkDataLoad();", 250);
        }else{
            updateCounties();
            updateCities();
        }
    }
    // checks the current state (if one is defined) and populates the list of counties in the select box
    function updateCounties(){
        f = document.searchForm;
        
        // blank the select box
        RemoveAll(f.county);
//        RemoveAll(f.chosencities);
//        f.city.value = '';
        // if we need to, add the 'all' option
        if (useall){
            AddToSelect(f.county,"- County -","");
        }
        // loop over the array of states, adding them to the dropdown
        for (x=0; x<counties.length; x++){
            // a little test to make sure only the right counties show up if a state is chosen
            use_this_county = 1;
            
                chosen_state = f.state.options[f.state.selectedIndex].value;
                if(states[x] != chosen_state){
                    use_this_county = 0;
                }
            
            // if the state matches, or if there is no state, add it to the select
            if(use_this_county == 1){        
                AddToSelect(f.county,counties[x],counties[x]);
                //Set the Default County to selected if one is present
                 if (f.DefaultCounty.value.toLowerCase() == counties[x].toLowerCase())
                  {
                    SelectOption(f.county, counties[x], true);
                  }
            }
        }
        // select the first one
        if(f.DefaultCounty.value == "")
         {
          f.county.selectedIndex=0;
         }

        if (county_page_load_first_run == "Y"){
            county_page_load_first_run = "N";
            
            if ("" != ''){
                SelectOption(f.county, "", "");
            }else if ("" != ''){
                SelectOption(f.county, "", "");
            }
            
        }else{
            // populate the city list
            //RemoveAll(f.chosencities);
            updateCities();
        }
    }
    // this function accepts a county name and returns the index of that county
    // from within the js array that contains the city data
    function getCountyIndex(countyname){
        chosen_state = f.state.options[f.state.selectedIndex].value;
        for (x=0; x<counties.length; x++){
            if(counties[x] == countyname && states[x] == chosen_state){
                return(x);
            }
        }
    }
    // update the city dropdown according to chosen county or 'all' for a given state
    function updateCities(){
        // blank the dropdown
        RemoveAll(f.citylist);
        f.city.value = "";
        AddToSelect(f.citylist, "- City -", "");
        // get the county array index
        countySelectIndex = f.county.selectedIndex - allfactor;
        // less than zero if they chose 'all'
        if (countySelectIndex < 0){
            // now we choose which index points to the chosen state
            chosen_state = f.state.options[f.state.selectedIndex].value;
            chosen_state_index = listfind(state_list, chosen_state, ",");
            // loop over the state/city array and build the list
            if(chosen_state_index > 0){
                for (x=0; x<all_array[chosen_state_index].length; x++){
                    AddToSelect(f.citylist, all_array[chosen_state_index][x], all_array[chosen_state_index][x]);

                }
            }else{
                // this will only happen if the admin puts a state in the list for a given market and there happen
                // to be no cities in the db that match.  this will be VERY rare, if ever.
                alert("No Cities in this state")
            }
        }else{
            // pull back the index for the chosen county
            countyIndex = getCountyIndex(f.county.options[f.county.selectedIndex].value)
            
            // loop over the county/city array and add to city select
            for (x=0; x<cities[countyIndex].length; x++){
                AddToSelect(f.citylist, cities[countyIndex][x], cities[countyIndex][x]);
            }
        }
    }
    var f;

    function listfind(thelist, thevalue, delim){
        if (! delim){
            delim = ",";
        }
        l = listlen(thelist, delim);
        listpos = -1;
        
        for (var x = 1; x < l; x++){
            listelement = listgetat(thelist,x,delim);
            if (listelement == thevalue){
                listpos = x;
                break;
            }
        }
        return listpos;
    }
    
    window.onload=checkDataLoad;