
//========================================================
//  CheckText
//  Ensures that when the user first clicks the sales
//  search, the default text is removed
//========================================================
function CheckText(ele)
{
    if (trim(ele.value) == DefaultSalesSearchText)
    {
        ele.value = ""; 
    }
}

//========================================================
//  FoeSearch - used for clicking search examples 
//  below Sales Search Text input
//========================================================
function FoeSearch(string)
{
    var theForm = document.forms["searchform"]; //document.searchform;
        theForm.txtSearch.value = string;
}

//========================================================
//  FoeContentSearch - used for clicking search examples 
//  below Content Search Text input
//========================================================
function FoeContentSearch(string)
{
    var theForm = document.forms["searchform"]; //document.searchform;
        theForm.txtContentSearch.value = string;
}

//========================================================
//   ArticleSearch - called from keyword links
//========================================================
function ArticleSearch(term)
{
    var theForm = document.forms["searchform"]; //document.searchform;
    DoSearchContentSmall1(term);


//    if (theForm.txtContentSearch)
//    {
       // theForm.txtContentSearch.value = term;
        //DoSearchContentSmall(theForm);
//    }
}
//=======================================================
function ContentKeyDown(e, ele, CurrentSearchForm)
{
    if(CurrentSearchForm == undefined || CurrentSearchForm == null)
    {
        SearchForm = document.forms["searchform"];
    }
    else
    {
        SearchForm = CurrentSearchForm;
    }
    
    if (gE("oops_wrapper").style.display == "block")
    {
        return false;
    }
    var val = ele.value;
    if (window.event)
    {
        keynum = e.keyCode;
    }
    else if(e.which)
    {
        keynum = e.which;
    }
    switch(keynum)
    {
        case 13: // enter key
            DoSearchContentSmall(SearchForm);
            break;  
        default:    
            return true;
            break;
    }
}

function DoSearchContentSmall1(theForm)
{

    var term = theForm;
    if (trim(term).length < 3)
    {
        var strURL = String.format("{0}Controls/AjaxCalls/GetTop10ArticleSearches.aspx", WebRoot);
                                
        $AJAX.GetForDelegate(function(AjaxResponse) 
        {    
            OOps(String.format("<p class='top'>Please enter a term or phrase into the search field.</p><p class='b'>Top Searches: </p>{0}" ,AjaxResponse));
        }, strURL);
        
    }
    else
    {
        //OmReportLocation(this,'Article and Videos','Search box');
          
        var strURL = String.format("{0}Controls/AjaxCalls/ContentSearchBar.aspx?N=0&Ntk=ArticleSearch&Ntt={1}&sid={2}", 
                                WebRoot,
                                escape(term),
                                sid);
                                
        $AJAX.GetForDelegate(function(AjaxResponse) { eval(AjaxResponse); }, strURL);
    }
}


//=======================================================

//========================================================
//   DoSearchContentSmall
//========================================================
function DoSearchContentSmall(theForm)
{
    var term = theForm.txtContentSearch.value;
    if (trim(term).length < 3)
    {
        var strURL = String.format("{0}Controls/AjaxCalls/GetTop10ArticleSearches.aspx", WebRoot);
                                
        $AJAX.GetForDelegate(function(AjaxResponse) 
        { 
           
            OOps(String.format("<p class='top'>Please enter a term or phrase into the search field.</p><p class='b'>Top Searches: </p>{0}" ,AjaxResponse));
        }, strURL);
        
    }
    else
    {
        //OmReportLocation(this,'Article and Videos','Search box');
        var strURL = String.format("{0}Controls/AjaxCalls/ContentSearchBar.aspx?N=0&Ntk=ArticleSearch&Ntt={1}&sid={2}", 
                                WebRoot,
                                escape(theForm.txtContentSearch.value),
                                sid);
                                
        $AJAX.GetForDelegate(function(AjaxResponse) { eval(AjaxResponse); }, strURL);
    }
}

//========================================================
//   DoSearchWebID
//========================================================
function DoSearchWebID(theForm)
{    
    var SearchType = "sale";
    var NavQuery = new Array();
        NavQuery.push(saleID);
    var QueryString = "N=" + NavQuery.join("+");

    var txtSearch = theForm.txtIDSearch.value;
    if (txtSearch == "" || txtSearch == "Enter ID")
    {
        WebOOps("Please enter a Web ID into the mobile search field.");
        return false;
    }
    else
    {
        txtSearch = txtSearch.replace(' ','');
        QueryString += String.format("&Ntt={0}&Ntk=IdMLS&Ntx=mode matchall",txtSearch);
        //----------------- AJAX CAll 
        var strURL = WebRoot + "Controls/AjaxCalls/SearchBar.aspx?SearchType=" + SearchType +  "&txtIDSearch=" + txtSearch  + "&" + QueryString;
    }    
    var ResponseDelegate = function(AjaxResponse)
    {
        if (AjaxResponse.indexOf("var doEval = true;") > -1) // flag indicating we should evaluate the response
        {
            eval(AjaxResponse);
        }
        else
        {
            gE("searchformresult").innerHTML = AjaxResponse;
        }
    };
  
    
    //-----------------
    $AJAX.GetForDelegate(ResponseDelegate, strURL);
    //window.location.href = strURL; // for testing
    //-----------------}
}
//========================================================
//   DoSearchSalesSmall
//========================================================
function DoSearchSalesSmall(theForm)
{   
    var SearchType = "sale";
    var beds = "0";
    var pnum1 = 0;
    var pnum2 = 99000000;
    var txtSearch = "";
    var qrystr = "";
    var qryPrice = "";
    var els = theForm.elements;   
        txtSearch = trim(theForm.txtSearch.value);
    
    var sb  = theForm.sb.value; // Passed for Search Bar State ... 
    var NavQuery = new Array();
        NavQuery.push(saleID);
        
        CloseSuggest();
   
    if (theForm.EndecaId.value.length > 0)
    {
        NavQuery.push(theForm.EndecaId.value);
    }
    
    var QueryString = "N=" + NavQuery.join("+");
   
    txtSearch = trim(txtSearch);
    
    if (txtSearch == "" || txtSearch == "City and State, Zip Code or Web Id")
    {
        OOps("<p class='top'>Please enter a city/state or a zip code into the search field.  We recommend that you follow the following format:</p><ul><li>City, State (e.g. <a href=\"javascript:FoeSearch('San Francisco, CA');\">San Francisco, CA</a>)</li><li>Zip Code (e.g.  <a href=\"javascript:FoeSearch('89148');\">89148</a>)</li></ul>");
        //gE("oops_wrapper").style.display = "block";
        return false;
    }
    
    var RegExZip = txtSearch.replace(/[0-9]{5}/,'');
	if (RegExZip == '') 
	{
	   txtSearch = txtSearch.replace(' ','');
       QueryString += String.format("&Ntt={0}&Ntk=AddrZip&Ntx=mode matchall",txtSearch);          
    }
    else
    {
        var IsWebId = txtSearch.replace(/[0-9]{7,10}/,'');
	    if (IsWebId == '') 
	    {
	       txtSearch = txtSearch.replace(' ','');
	       QueryString += String.format("&Ntt={0}&Ntk=IdMLS&Ntx=mode matchall",txtSearch);
	    }
    }
    
    //----------------- AJAX CAll 
    var strURL = WebRoot + "Controls/AjaxCalls/SearchBar.aspx?submit=true&SearchType=" + SearchType + "&sid=" + sid + "&txtSearch=" + txtSearch + "&sb=" + sb + "&" + QueryString + qryPrice;
    
    //document.body.innerHTML = strURL;
    //return;
    
    //==================================================
    //  Response delegate handles conditions, if there are zero results, or if there are more than one result.
    //  If One Result :     redirect to results
    //  If More Than one :  Display dropdown with selection
    //  If zero :           display Zero Results
    //==================================================
 
    var ResponseDelegate = function(AjaxResponse)
    {
        if (AjaxResponse.indexOf("var doEval = true;") > -1) // flag indicating we should evaluate the response
        {
            eval(AjaxResponse);
             if (AjaxResponse.indexOf("var webIdOops = true;") > -1) // flag indicating we should evaluate the response
                {
               //gE("oopsID").className ="oopsWebId clearfix";
                }
        }
        else
        {
            gE("searchformresult").innerHTML = AjaxResponse;
        }
    };
  
    
    //-----------------
    $AJAX.GetForDelegate(ResponseDelegate, strURL);
    //window.location.href = strURL; // for testing
    //-----------------
}

//========================================================
//   DoSearchSalesSmall
//========================================================
function DoSearchForRegion(theForm)
{   
   
    var SearchType = "sale";
    var beds = "0";
    var pnum1 = 0;
    var pnum2 = 99000000;
    var txtSearch = "";
    var qrystr = "";
    var qryPrice = "";
    var els = theForm.elements;   
        txtSearch = trim(theForm.txtSearch.value);
    
    var sb  = theForm.sb.value; // Passed for Search Bar State ... 
    var NavQuery = new Array();
        NavQuery.push(saleID);
        
        CloseSuggest();
   
    if (theForm.EndecaId.value.length > 0)
    {
        NavQuery.push(theForm.EndecaId.value);
    }
    
    var QueryString = "N=" + NavQuery.join("+");
   
    txtSearch = trim(txtSearch);
    
    if (txtSearch == "" || txtSearch == "City and State, Zip Code or Web Id")
    {
        OOps("<p class='top'>Please enter a city/state or a zip code into the search field.  We recommend that you follow the following format:</p><ul><li>City, State (e.g. <a href=\"javascript:FoeSearch('San Francisco, CA');\">San Francisco, CA</a>)</li><li>Zip Code (e.g.  <a href=\"javascript:FoeSearch('89148');\">89148</a>)</li></ul>");
        //gE("oops_wrapper").style.display = "block";
        return false;
    }
    
    var RegExZip = txtSearch.replace(/[0-9]{5}/,'');
	if (RegExZip == '') 
	{
	   txtSearch = txtSearch.replace(' ','');
       QueryString += String.format("&Ntt={0}&Ntk=AddrZip&Ntx=mode matchall",txtSearch);          
    }
    
    //----------------- AJAX CAll 
    var strURL = WebRoot + "Controls/AjaxCalls/GetCityStateZip.aspx?SearchType=" + SearchType + "&txtSearch=" + txtSearch + "&sb=" + sb + "&" + QueryString + qryPrice;
    
    var ResponseDelegate = function(AjaxResponse)
    {
        if (AjaxResponse.indexOf("var doEval = true;") > -1) // flag indicating we should evaluate the response
        {
            eval(AjaxResponse);
        }
        else
        {
            gE("searchformresult").innerHTML = AjaxResponse;
        }
    };
  
    
    //-----------------
    $AJAX.GetForDelegate(ResponseDelegate, strURL);
    //window.location.href = strURL; // for testing
    //-----------------
}

function HGTVSearch(Searchterm)
{ 
   var Search=Searchterm.split("="); 
   var txtSearch=Search[1].replace(/\+/g, ' ');       
   txtSearch=txtSearch.replace('%2c',','); 
  if (txtSearch == "" || txtSearch == "City and State, Zip Code of Web Id")
    {        
        OOps("<p class='top'>Please enter a city/state or a zip code into the search field.  We recommend that you follow the following format:</p><ul><li>City, State (e.g. <a href=\"javascript:FoeSearch('San Francisco, CA');\">San Francisco, CA</a>)</li><li>Zip Code (e.g.  <a href=\"javascript:FoeSearch('89148');\">89148</a>)</li></ul>");
        
         return false;
    }
    var QueryString="";
   
    
    var strURL = WebRoot + "Controls/AjaxCalls/SearchBar.aspx?sid=" + sid + "&txtSearch=" + txtSearch ;
    var ResponseDelegate = function(AjaxResponse)
    {
        if (AjaxResponse.indexOf("var doEval = true;") > -1) // flag indicating we should evaluate the response
        {
            eval(AjaxResponse);
        }
        else
        {
            gE("searchformresult").innerHTML = AjaxResponse;
        }
    };
  
    
    //-----------------
    $AJAX.GetForDelegate(ResponseDelegate, strURL);
}

//========================================================
//   DoSearchSalesExpanded
//========================================================
function DoSearchSalesExpanded(theForm)
{    
    var SearchType = "sale";
    var beds = "0";
    var pnum1 = 0;
    var pnum2 = 99000000;
    var txtSearch = "";
    var qrystr = "";
    var qryPrice = "";
    var els = theForm.elements;   
        txtSearch = trim(theForm.txtSearch.value);
    
    var sb  = theForm.sb.value; // Passed for Search Bar State ... 
    var NavQuery = new Array();
        NavQuery.push(saleID);
        
        CloseSuggest();
    var isRefinementsSelected = false;
   
    if (theForm.EndecaId.value.length > 0)
    {
        NavQuery.push(theForm.EndecaId.value);
    }
    

    var bedslist = theForm.search_bedrooms;
    if (bedslist.selectedIndex > 0)
    {
        NavQuery.push(bedslist[bedslist.selectedIndex].value);
        isRefinementsSelected = true;
    } 

    var bathslist = theForm.search_bathrooms.options;
    if (bathslist.selectedIndex > 0)
    {
        NavQuery.push(bathslist[bathslist.selectedIndex].value);
        isRefinementsSelected = true;
    } 

    var ptypelist = theForm.search_propertytype.options;
    if (ptypelist.selectedIndex > 0)
    {
        NavQuery.push(ptypelist[ptypelist.selectedIndex].value);
        isRefinementsSelected = true;
    } 

    var QueryString = "N=" + NavQuery.join("+");
   

    var minPrice = theForm.search_pricemin.options;
    var maxPrice = theForm.search_pricemax.options;
    if ((minPrice.selectedIndex > 0) || (maxPrice.selectedIndex > 0))
    {   
        if((minPrice.selectedIndex > maxPrice.selectedIndex) && (maxPrice.selectedIndex != 0))
        {
             OOps("<p id='price_error'>The minimum price must be less than the maximum price</p>");
             return false;
        }
        else
        {
            qryPrice = String.format("&Nf=Price_Sales|BTWN+{0}+{1}", 
                                minPrice[minPrice.selectedIndex].value, 
                                maxPrice[maxPrice.selectedIndex].value);    
            isRefinementsSelected = true;
        }
    }
    else
    {
        qryPrice = "";
    }
    
    txtSearch = trim(txtSearch);
    
    if (txtSearch == "" || txtSearch == "City and State, Zip Code or Web Id")
    {
       OOps("<p class='top'>Please enter a city/state or a zip code into the search field.  We recommend that you follow the following format:</p><ul><li>City, State (e.g. <a href=\"javascript:FoeSearch('San Francisco, CA');\">San Francisco, CA</a>)</li><li>Zip Code (e.g.  <a href=\"javascript:FoeSearch('89148');\">89148</a>)</li></ul>");
       // gE("oops_wrapper").style.display = "block";
       return false;
    }
    
    var RegExZip = txtSearch.replace(/[0-9]{5}/,'');
	if (RegExZip == '') 
	{
	   txtSearch = txtSearch.replace(' ','');
	   if(isRefinementsSelected == true)
	    {
           QueryString += String.format("&Ntt={0}&Ntk=AddrZip&Ntx=mode matchall",txtSearch);
	    }
	    else
	    {
           QueryString += String.format("&Ntt={0}&Ntk=ZipRId&Ntx=mode matchall",txtSearch);       
        }   
    }
    else
    {
        var IsWebId = txtSearch.replace(/[0-9]{7,10}/,'');
	    if (IsWebId == '') 
	    {
	       txtSearch = txtSearch.replace(' ','');
	       QueryString += String.format("&Ntt={0}&Ntk=IdMLS&Ntx=mode matchall",txtSearch);
	    }
    }
//    //var RegExZip = new RegExp("[ABCEGHJKLMNPRSTVXY]\\d[A-Z]\\s?\\d[A-Z]\\d", "i");
//    var RegExZip = new RegExp(/[0-9]{5}/);
//    
//    if (RegExZip.exec(txtSearch) != null) // the regex matched a zip code
//    {
//        txtSearch = txtSearch.replace(' ','');
//        QueryString += String.format("&Ntt={0}&Ntk=AddrZip&Ntx=mode matchall",txtSearch);
//    }
    
    //----------------- AJAX CAll 
    var strURL = WebRoot + "Controls/AjaxCalls/SearchBar.aspx?SearchType=" + SearchType + "&txtSearch=" + txtSearch + "&sid=" + sid + "&sb=" + sb + "&" + QueryString + qryPrice;
    
    //document.body.innerHTML = strURL;
    //return;
    
    //==================================================
    //  Response delegate handles conditions, if there are zero results, or if there are more than one result.
    //  If One Result :     redirect to results
    //  If More Than one :  Display dropdown with selection
    //  If zero :           display Zero Results
    //==================================================
    
    var ResponseDelegate = function(AjaxResponse)
    {
        if (AjaxResponse.indexOf("var doEval = true;") > -1) // flag indicating we should evaluate the response
        {
            eval(AjaxResponse);
             if (AjaxResponse.indexOf("var webIdOops = true;") > -1) // flag indicating we should evaluate the response
                {
              // gE("oopsID").className ="oopsWebId clearfix";
                }
        }
        else
        {
            gE("searchformresult").innerHTML = AjaxResponse;
        }
    };
  
    
    //-----------------
    $AJAX.GetForDelegate(ResponseDelegate, strURL);
    //window.location.href = strURL; // for testing
    //-----------------
}



//========================================================
//   DoSearchSalesExpandedHome
//========================================================
function DoSearchSalesExpandedHome(theForm)
{  
    var PriceMinLIs = gE("searchpricelistmin").getElementsByTagName("li");
    var PriceMinSelectedIndex = parseInt(gE("search_pricemin").getElementsByTagName("span")[0].id);
    
    //PriceMinLIs[PriceMinSelectedIndex].id
    var PriceMaxLIs = gE("searchpricelistmax").getElementsByTagName("li");
    var PriceMaxSelectedIndex = parseInt(gE("search_pricemax").getElementsByTagName("span")[0].id);
     
    var BedLIs = gE("searchbeds").getElementsByTagName("li");
    var BedSelectedIndex = parseInt(gE("search_bedrooms").getElementsByTagName("span")[0].id);
  
    var BathLIs = gE("searchbaths").getElementsByTagName("li");
    var BathSelectedIndex = parseInt(gE("search_bathrooms").getElementsByTagName("span")[0].id);
    
    var PropertyTypeLIs = gE("searchpropertytypes").getElementsByTagName("li"); 
    var PropertyTypeSelectedIndex = parseInt(gE("search_propertytype").getElementsByTagName("span")[0].id);
   
    var SalesTypeLIs = gE("searchnarrow").getElementsByTagName("li");
    var SalesTypeSelectedIndex = parseInt(gE("search_narrow").getElementsByTagName("span")[0].id);
 
    var SearchType = "sale";
    var beds = "0";
    var pnum1 = 0;
    var pnum2 = 99000000;
    var txtSearch = "";
    var qrystr = "";
    var qryPrice = "";
    var els = theForm.elements;   
        txtSearch = trim(theForm.txtSearch.value);
    
    var sb  = theForm.sb.value; // Passed for Search Bar State ... 
    var NavQuery = new Array();
        NavQuery.push(saleID);
        
        CloseSuggest();
    var isRefinementsSelected = false;
    
    if (theForm.EndecaId.value.length > 0)
    {
        NavQuery.push(theForm.EndecaId.value);
    }
    
    if(BedSelectedIndex != 0)//initial value
    {
         NavQuery.push(BedLIs[BedSelectedIndex].id);
         isRefinementsSelected = true;
    }

    if (BathSelectedIndex != 0)//initial value
    {
        NavQuery.push(BathLIs[BathSelectedIndex].id);
        isRefinementsSelected = true;
    } 
    
    if (PropertyTypeSelectedIndex != 0)
    {
        NavQuery.push(PropertyTypeLIs[PropertyTypeSelectedIndex].id);
        isRefinementsSelected = true;
    }

    if (SalesTypeSelectedIndex != 0)
    {
        NavQuery.push(SalesTypeLIs[SalesTypeSelectedIndex].id);
        isRefinementsSelected = true;
    }

    // added for New Homes
    if (SalesTypeSelectedIndex == 2)
    {
        NavQuery.push(newHomesID);
    }

    // added for Open Houses
    if (SalesTypeSelectedIndex == 3) {
        NavQuery.push(openHousesID);
    }
     
    var QueryString = "N=" + NavQuery.join("+");

    if((PriceMinSelectedIndex > 0)||(PriceMaxSelectedIndex > 0))
    {
            if((PriceMinSelectedIndex > PriceMaxSelectedIndex)&& (PriceMaxSelectedIndex !=0))
        {
            OOps("<p id='price_error'>The minimum price must be less than the maximum price</p>");
            return false;
        }
        else
        {
        qryPrice = String.format("&Nf=Price_Sales|BTWN+{0}+{1}", 
                             PriceMinLIs[PriceMinSelectedIndex].id, 
                             PriceMaxLIs[PriceMaxSelectedIndex].id);    
        
         isRefinementsSelected = true;
        }
    }
    
    txtSearch = trim(txtSearch);
    
    if (txtSearch == "" || txtSearch == "City and State, Zip Code or Web Id")
    {
        OOps("<p class='top'>Please enter a city/state or a zip code into the search field.  We recommend that you follow the following format:</p><ul><li>City, State (e.g. <a href=\"javascript:FoeSearch('San Francisco, CA');\">San Francisco, CA</a>)</li><li>Zip Code (e.g.  <a href=\"javascript:FoeSearch('89148');\">89148</a>)</li></ul>");
     // gE("oops_wrapper").style.display = "block";
      return false;
    }
    var RegExZip = txtSearch.replace(/[0-9]{5}/,'');
	if (RegExZip == '') 
	{
//	    txtSearch = txtSearch.replace(' ','');
//	    if(isRefinementsSelected == true)
//	    {
//                if (theForm.foreclosures_only.checked)
//                {
//                    QueryString += String.format("&Ntt={0}||F&Ntk=AddrZip||CodeListingType&Ntx=mode matchall",txtSearch);
//                }
//                else
//                {
//                    QueryString += String.format("&Ntt={0}&Ntk=AddrZip&Ntx=mode matchall",txtSearch);
//                }
//	    }
//	    else
//	    {
	      if (SalesTypeSelectedIndex == 1)
          {
             QueryString += String.format("&Ntt={0}||F&Ntk=AddrZip||CodeListingType&Ntx=mode matchall",txtSearch);
          }
          else
          {
             QueryString += String.format("&Ntt={0}&Ntk=AddrZip&Ntx=mode matchall",txtSearch);
          }
//       }
    }
    else
    {
        var IsWebId = txtSearch.replace(/[0-9]{7,10}/,'');
	    if (IsWebId == '') 
	    {
	       txtSearch = txtSearch.replace(' ','');
	       QueryString += String.format("&Ntt={0}&Ntk=IdMLS&Ntx=mode matchall",txtSearch);
	    }
        else
        {
            if (SalesTypeSelectedIndex == 1)
            {
                QueryString += "&Ntt=F&Ntk=CodeListingType&Ntx=mode matchall";
            }
        }
    }
    //----------------- AJAX CAll 
    var strURL = WebRoot + "Controls/AjaxCalls/SearchBar.aspx?submit=true&SearchType=" + SearchType + "&txtSearch=" + txtSearch + "&sid=" + sid + "&sb=" + sb + "&" + QueryString + qryPrice;
    
    //document.body.innerHTML = strURL;
    //alert(strURL);
    //return;
    
    //==================================================
    //  Response delegate handles conditions, if there are zero results, or if there are more than one result.
    //  If One Result :     redirect to results
    //  If More Than one :  Display dropdown with selection
    //  If zero :           display Zero Results
    //==================================================
    
    var ResponseDelegate = function(AjaxResponse)
    {
        if (AjaxResponse.indexOf("var doEval = true;") > -1) // flag indicating we should evaluate the response
        {
            //   alert(AjaxResponse);
            if (AjaxResponse.indexOf("location.href") > -1) // if successfull .
            {
//                var Page = "Home"; //called from the home page
//                if (location.href.toLowerCase().indexOf("for_sale") > -1 || location.href.toLowerCase().indexOf("city-guide") > -1) // chk the page name
//                {
//                 Page = "Other"; 
//                }    
//                OmReportLocation(this,'Homes for Sale - ' + Page ,'Search box');
            }
            eval(AjaxResponse);
            if (AjaxResponse.indexOf("var webIdOops = true;") > -1) // flag indicating we should evaluate the response
                {
               //gE("oopsID").className ="oopsWebId clearfix";
                }
        }
        else
        {
           gE("searchformresult").innerHTML = AjaxResponse;
        }
        

    };
  
    
    //-----------------
    $AJAX.GetForDelegate(ResponseDelegate, strURL);
    //window.location.href = strURL; // for testing
    //-----------------
}

//function getArrayIDs(objLIs)
//{
//    var arrReturn = new Array();
//    
//    if(objLIs == null)
//    {
//        return null;
//    }
//    
//    for(int i=0; i< objLIs.length; i++)
//    {
//        arrReturn[arrReturn.length] = objLIs[i].id;
//    }
//    return arrReturn;
//    
//}
//========================================================
//   SwitchSearch
//========================================================
function SwitchSearch(type, state, Query)
{
    if (Query == undefined)
    {
        Query = "";
    }
    var UGen = new UrlGen(Query);
    
    if (state == undefined)
    {
        state = "small";
    }
    
    var AfterLoad = function(){void(null);}; // to be defined where needed, called after new search is loaded
    
    switch(type)
    {
        case "content":
            UGen.RemoveParam("sb");
            UGen.AddParam("sb", "2");
            var strURL = WebRoot + "Controls/AjaxCalls/GetSearchBar.aspx?" + UGen.ToString();
            BarStatus.value = BevtQueue; // Reset "search In" selector
            gE("search_list_backOpen").style.display = "none";
            break;
        case "contentHome":
            UGen.RemoveParam("sb");
            UGen.AddParam("sb", "3");
            var strURL = WebRoot + "Controls/AjaxCalls/GetSearchBar.aspx?" + UGen.ToString();
               gE("prop_search_content").style.background="url(../../images/search-n_art_hp_bkg.jpg) no-repeat";
                 gE("global_header").style.background="url(../../images/hp-n_header_art_bg.jpg) no-repeat top";
             break;
        case "salesHome":
            switch(state)
            {
                case "small":
                    UGen.RemoveParam("sb");
                    UGen.AddParam("sb", "4");
                    var strURL = WebRoot + "Controls/AjaxCalls/GetSearchBar.aspx?" + UGen.ToString();
                    break;
                default:
                    UGen.RemoveParam("sb");
                    UGen.AddParam("sb", "5");
                    var strURL = WebRoot + "Controls/AjaxCalls/GetSearchBar.aspx?" + UGen.ToString();
                       gE("prop_search_content").style.background="url(../../images/search-n_prop_hp_bkg.jpg) no-repeat";
                         gE("global_header").style.background="url(../../images/hp-n_header_prop_bg.jpg) no-repeat top";
                    break;
            }
            break;
        default:
            switch(state)
            {
                case "small":
                    UGen.RemoveParam("sb");
                    UGen.AddParam("sb", "1");
                    var strURL = WebRoot + "Controls/AjaxCalls/GetSearchBar.aspx?" + UGen.ToString();
                    BarStatus.value = BevtQueue; // Reset "search In" selector
                    gE("search_list_backOpen").style.display = "none";
                    break;
                default:
                    UGen.RemoveParam("sb");
                    UGen.AddParam("sb", "0");
                    var strURL = WebRoot + "Controls/AjaxCalls/GetSearchBar.aspx?" + UGen.ToString();
                  gE("search_list_backOpen").style.display = "none";
                    AfterLoad = function()
                    {
                        window.setTimeout(function()
                        {
                            gE("txtSearch").focus();
                        },100);
                    };
                    break;
            }
            break;
    }
    //document.body.innerHTML = strURL;
    //$AJAX.GetToObject(gE("searchbardiv"), strURL);
    $AJAX.GetForDelegate(function(AjaxResponse)
    {
        gE("searchbardiv").innerHTML = AjaxResponse;
        AfterLoad();
    }, strURL);
}


//========================================================
//  GetC - Can be used for multinational search
//  See LivingChoices
//========================================================
function GetC()
{
    //var CVal = gE("CVal");
    //return CVal.options[CVal.options.selectedIndex].value;
    return 200; // USA
}

if(document.body)
{
document.body.onclick = function(){CloseSuggest();OOpsClose();};
}

// Suggest id to distinguish among different search boxes.
var SearchForm = document.forms["searchform"];
var SuggestId = "suggest";
//========================================================
//  SuggestDown
//  Used for Suggest functionality
//========================================================
function SuggestDown(e, ele, CurrentSearchForm, CurrentSuggestId)
{
    if(CurrentSearchForm == undefined || CurrentSearchForm == null)
    {
        SearchForm = document.forms["searchform"];
    }
    else
    {
        SearchForm = CurrentSearchForm;
    }
    if(CurrentSuggestId == undefined || CurrentSuggestId == null)
    {
        SuggestId = "suggest";
    }
    else
    {
        SuggestId = CurrentSuggestId;
    }
    
    if (gE("oops_wrapper").style.display == "block")
    {
        return false;
    }
    var val = ele.value;
    if (window.event)
    {
        keynum = e.keyCode;
    }
    else if(e.which)
    {
        keynum = e.which;
    }
    switch(keynum)
    {
        case 13: // enter key
            if (gE(SuggestId).style.display == "block")
            {
                if (CurrentSuggestIndex() > -1)
                {
                    //var content = gE("ila" + CurrentSuggestIndex()).innerHTML.replace(/<[^>]+>/g,"").replace(/\s\/\s/g,"/");
                    //AddSuggest(content.toUpperCase());
                    //var content = gE("ila" + CurrentSuggestIndex()).innerHTML.replace(/<[^>]+>/g,"").replace(/\s\/\s/g,"/");
                    AddSuggest(CurrentSuggestIndex());
                    StopProcessingEvents(e);
                    return false;
                 }
            }
            if(SuggestId.toLowerCase() != 'suggest')
            {
                DoSearchForRegion(SearchForm);
            }
            else
            {
                if (SearchBarType == "0")
                {
                    DoSearchSalesExpandedHome(ele.form);
                }
                else
                {
                    DoSearchSalesSmall(ele.form);
                }
            }
            break;   
            /*
            else
            {
                CloseSuggest();
                
            }*/
             
        case 27: // escape
            CloseSuggest();
            ele.value = val;
            return false;
            break;
        default:    
            return true;
            break;
    }
}

//========================================================
//  SuggestUp
//  Used for Suggest functionality
//========================================================
function SuggestUp(e, ele)
{
    if (gE("oops_wrapper").style.display == "block")
    {
        return false;
    }
    var val = ele.value;
    if (window.event)
    {
        keynum = e.keyCode;
    }
    else if(e.which)
    {
        keynum = e.which;
    }
    switch(keynum)
    {
        case 13: // enter key
            if (gE(SuggestId).style.display == "block")
            {
                CloseSuggest();
                StopProcessingEvents(e);
                return false;
            }
            return true;
            break;
        case 27: // escape
            CloseSuggest();
            ele.value = val;
            return false;
            break;
        case 40:
            SuggestSelect(CurrentSuggestIndex()+1);
            break;    
        case 36:
        case 37:
        case 38:
        case 39:
            SuggestSelect(CurrentSuggestIndex()-1);
            break;    
        default:    
            if (trim(ele.value).length > 1)
            {
                //CloseSuggest();
                ele.value = ReplacePotentiallyDangerous(ele);
                var Query = String.format("{0}Controls/AjaxCalls/Suggest.aspx?C={1}&term={2}", WebRoot, GetC(), trim(ele.value));
                $AJAX.GetForDelegate(ShowSuggest, Query);
            }
            else
            {
                CloseSuggest();
            }
            break;
    }
}
//========================================================
//  Removes dangerous characters(<,>,etc.)
//========================================================
function ReplacePotentiallyDangerous(ele)
{
	var re = /[^a-z0-9\s-,()\/\:'\&]/gi;
	return ele.value.replace(re, '');
}
//========================================================
//  Stops processing Events
//========================================================
function StopProcessingEvents(e)
{
    if (e && e.preventDefault) 
    {
        e.preventDefault();
    }
    else if (window.event && window.event.returnValue)
    {
        window.eventReturnValue = false;
    }
}


//========================================================
//  CurrentSuggestIndex
//  Used for Suggest functionality
//========================================================
function CurrentSuggestIndex()
{
    var LIS = gE(SuggestId).getElementsByTagName("div");
    var T = -1;
    for(var x=0;x<LIS.length;x++)
    {
        if (LIS[x].className == 'hot')
        {
            T = x;
            break;
        }
    }
    return T;
}

//========================================================
//  ScrollToItem
//  Used for Suggest functionality
//========================================================
function ScrollToItem(elepos)
{
    var eleE = gE('ila' + elepos);
    var eleS = gE(SuggestId);
    var Etop = eleE.offsetTop;
    var Stop = eleS.scrollTop;
    
    if (Etop < gE(SuggestId).scrollTop)
    {
        gE(SuggestId).scrollTop = Etop;
    }
    else if ((Etop + eleE.offsetHeight) > (Stop + eleS.offsetHeight))
    {
        gE(SuggestId).scrollTop = Etop - eleS.offsetHeight + eleE.offsetHeight;
    }
}

//========================================================
//  SuggestSelect
//  Used for Suggest functionality
//========================================================
function SuggestSelect(num)
{
    var LIS = gE(SuggestId).getElementsByTagName("div");
    var item = null;
    
    for(var x=0;x<LIS.length;x++)
    {
        if (x==num)
        {
            LIS[x].className = 'hot';
            item = x;
        }
        else
        {
            LIS[x].className = 'non';
        }
    }
    if (item==null)
    {
        if (num > LIS.length-1)
        {
            item = LIS.length-1;
            LIS[item].className = 'hot';
        }
        else
        {
            item = 0;
        }
    }

    if (item > 0)
    {
        ScrollToItem(item);
    }
}

//========================================================
//  ShowSuggest
//  Used for Suggest functionality
//========================================================
function ShowSuggest(AjaxResponse)
{
    if (trim(AjaxResponse).length > 0)
    {
        if (gE(SuggestId).style.display != "block")
        {
            gE(SuggestId).style.display = "block";
        }
        OOpsClose();
        ToggleSelects("hidden");
        gE(SuggestId).innerHTML = AjaxResponse;
    }
    else
    {
        CloseSuggest();
    }
}

//========================================================
//  ToggleSelects
//  Used for Suggest functionality
//========================================================
function ToggleSelects(visibility)
{
    var Sel = document.getElementsByTagName("select");
    for (var x=0; x<Sel.length; x++)
    {
        Sel[x].style.visibility = visibility;
    }
}

//========================================================
//  CloseSuggest
//  Used for Suggest functionality
//========================================================
function CloseSuggest()
{
    gE(SuggestId).style.display = "none";
    ToggleSelects("visible");
    
}

//========================================================
//  AddSuggest
//  Used for Suggest functionality
//========================================================
function AddSuggest(index)
{
    var CityName = gE("ila" + index).innerHTML.replace(/<[^>]+>/g,"").replace(/\s\/\s/g,"/");
    var EndecaId = gE("ila" + index).getAttribute('name');
        SearchForm.txtSearch.value = CityName.toUpperCase();
        SearchForm.EndecaId.value = EndecaId;
        //CloseSuggest();
}
 
//========================================================
//  OOps
//========================================================
function OOps(strMessage, strClassName)
{
    window.setTimeout(function()
    {
        if (strClassName == undefined)
        {
            strClassName = "oops_wrapper clearfix";
        }
        if (BarStatus.value != BevtQueue)
        {
            gE("txtSearch").blur(); // cause the sales search bar to close
            window.setTimeout(function()
            {
                OOps(strMessage, strClassName); // recall oops after it's closed
            },300);
            return;
        }
        //alert(strMessage);
    //    window.setTimeout(function()
    //    {
            CloseSuggest();
            ToggleSelects("hidden");
            gE("oops_wrapper").style.display = "block";
            gE("oops_wrapper").className = strClassName;
            gE("oops_text").innerHTML = strMessage;
    //    },10);
    },300);
}

//========================================================
//  OOps
//========================================================
function WebOOps(strMessage, strClassName)
{
    window.setTimeout(function()
    {
        if (strClassName == undefined)
        {
            strClassName = "oops_wrapper";
        }
        //alert(strMessage);
    //    window.setTimeout(function()
    //    {
            CloseSuggest();
            ToggleSelects("hidden");
            gE("weboops_wrapper").style.display = "block";
            gE("weboops_wrapper").className = strClassName;
            gE("weboops_text").innerHTML = strMessage;
    //    },10);
    },300);
}

function OOpsClose()
{
    if (gE(SuggestId).style.display == "none")
    {
        ToggleSelects("visible");
    }
    gE("oops_wrapper").style.display = "none";
}

function WebOopsClose()
{
    gE("weboops_wrapper").style.display = "none";
}
//========================================================
//  SwitchSearchType(strStatus)
//  Controls the toggle dropdown between "property" and 
//  "content" search
//  If no value is passed for strStatus, the options
//  toggle.
//========================================================
function SwitchSearchType(strStatus)
{
    window.setTimeout(function()
    {
        if (strStatus == undefined)
        {
            if (gE("search_type_list").style.display != 'block')
            {
                strStatus = "open";
            }
            else
            {
                strStatus = "close";
            }
        }
        
        //window.location.href += "#" + strStatus;
        if (strStatus == "open")
        {
            if (BarStatus.value != BevtQueue) // search bar is open
            {
                gE("txtSearch").blur(); // cause the sales search bar to close
                window.setTimeout(function()
                {
                    SwitchSearchType(strStatus); // recall SwitchSearchType after it's closed
                },300);
                return;
            }
            gE("search_type_list").style.display = 'block';
            gE("search_list_backOpen").style.display = 'block';
            //  Next line For Debugging
            //  gE("search_list_backOpen").style.backgroundColor = '#fff';
            
            var G = new GetWindowBunds();
            gE("search_list_backOpen").style.left = "1px";
            gE("search_list_backOpen").style.top = "1px";
            gE("search_list_backOpen").style.width = (G.VisibleWidth - 20) + "px";
            gE("search_list_backOpen").style.height = (G.PageHeight - 20) + "px";
            //window.location.href += "#open";
            //BevtStasis('STOpen');
        }
        else
        {
            gE("search_type_list").style.display = "none";
            gE("search_list_backOpen").style.display = "none";
            //window.location.href += "#closed";
    //        if (BarStatus.value != BevtQueue)
    //        {
    //            gE("txtSearch").focus();
    //            //window.location.href += "#focused";
    //        }
        }
    },300);
}

//========================================================
//  Bevt(e) 
//  Property SEarch Bar Close Events
//  Manages the opened state of the nav bar
//  if clicked outside any form element, and that element
//  loses focus, close the bar
//  only called from Property Search, Expanded
//========================================================
var BevtQueue = "clicked off"; // constant value to determine if it's time to close bar
function Bevt(e)
{
    var IE7 = (navigator.appVersion.indexOf("MSIE 7.") == -1) ? false : true;
    var IE6 = (navigator.appVersion.indexOf("MSIE 6.") == -1) ? false : true;
    
	var theTarget;
	if (!e || IE7 || IE6) 
	{ 
		e = window.event; 
		e.cancelBubble = true;
	}
	else
	{
	    e.stopPropagation();  
	}
	if (e.target) 
	{ 
		theTarget = e.target; 
	}
	else if (e.srcElement) 
	{ 
		theTarget = e.srcElement; 
	}
	if (theTarget.nodeType == 3) // defeat Safari bug
	{
		theTarget = theTarget.parentNode;
	}
	
	//alert("type:" + e.type);
	switch(e.type)
	{
		case "focus":
			BarStatus.value = "event: " + e.type + "\nTarget ID: " + theTarget.id;
			break;
			// **TEMPORARILY COMMENTED OUT TO MAKE RESKINNING SEARCH BAR EASIER
		case "blur":
			BarStatus.value = BevtQueue;
			window.clearTimeout(BarStatus.timeout);
			BarStatus.timeout = window.setTimeout(function()
			{
				if (BarStatus.value == BevtQueue) // status value has not changed
				{
					if (PageCache != null)
					{
					    // PageCache defined in /results.aspx
					    SwitchSearch('sales', 'small', PageCache.QueryString);
					}
					else
					{
					    // DefaultQueryString defined in /Controls/SearchBar/Global.ascx
					    SwitchSearch('sales', 'small', DefaultQueryString); 
					}
				}
			},200);
			break;
	}
	//gE("NavStatus").value = BarStatus.value; 
}

var BarStatus = new BevtValue(BevtQueue);

function BevtValue(Bevt)
{
	this.value = Bevt;
	this.timeout = window.setTimeout(function(){void(null);},1); // moot timeout to load variable
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  used when a value needs to be set for BarStatus so the nav 
//  won't close. Called when the user clicks the "switch search
//  type" toggle, and the Expanded Sales SEarch is open.
//  Called with a SetTimeout so it fires AFTER the last onBlur()
//  event is called.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function BevtStasis(val)
{
    window.setTimeout(function()
    {
        BarStatus.value = val; 
    },100);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//used to open and close the divs replacing the dropdowns on the 
//homepage expanded search
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function BedDrop()
{
    if (gE("bed_drop").style.display != 'block')
    {
        strStatus = "open";
    }
    else
    {
        strStatus = "close";
    }

    if (strStatus == "open")
    {
        gE("bed_drop").style.display = 'block';
        gE("bed_drop_backOpen").style.display = 'block';
        gE("min_drop").style.display = 'none';
        gE("min_drop_backOpen").style.display = 'none';
        gE("max_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("bath_drop").style.display = 'none';
        gE("bath_drop_backOpen").style.display = 'none';
        gE("type_drop").style.display = 'none';
        gE("type_drop_backOpen").style.display = 'none';
        gE("narrow_drop").style.display = 'none';
        gE("narrow_drop_backOpen").style.display = 'none';
        var G = new GetWindowBunds();
        var width = G.VisibleWidth - 50;
        var left = 944- width;
        gE("bed_drop_backOpen").style.left = (left/2)+ 10 +"px";
        gE("bed_drop_backOpen").style.top = "1px";
        gE("bed_drop_backOpen").style.width = (G.VisibleWidth - 20) + "px";
        gE("bed_drop_backOpen").style.height = (G.VisibleHeight - 20) + "px";
    }
    else
    {
        gE("bed_drop").style.display = 'none';
        gE("bed_drop_backOpen").style.display = 'none';
        gE("search_bedrooms").style.background = 'url(../../images/bed_bkg.gif)';
        gE("txtSearch").focus(); // Keeps nav open
    }
}
function closeBedDrop()
{
    gE("bed_drop").style.display ="none";
    gE("bed_drop_backOpen").style.display ="none";
    gE("search_bedrooms").className ="";
    gE("txtSearch").focus(); // Keeps nav open
} 

function BathDrop() 
{
    if (gE("bath_drop").style.display != 'block')
    {
        strStatus = "open";
    }
    else
    {
        strStatus = "close";
    }

    if (strStatus == "open")
    {
        gE("bath_drop").style.display = 'block';
        gE("bath_drop_backOpen").style.display = 'block';
        gE("min_drop").style.display = 'none';
        gE("min_drop_backOpen").style.display = 'none';
        gE("max_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("bed_drop").style.display = 'none';
        gE("bed_drop_backOpen").style.display = 'none';
        gE("type_drop").style.display = 'none';
        gE("type_drop_backOpen").style.display = 'none';
        gE("narrow_drop").style.display = 'none';
        gE("narrow_drop_backOpen").style.display = 'none';
        var G = new GetWindowBunds();
        var width = G.VisibleWidth - 50;
        var left = 944- width;
        gE("bath_drop_backOpen").style.left = (left/2)+ 10 +"px";
        gE("bath_drop_backOpen").style.top = "1px";
        gE("bath_drop_backOpen").style.width = (G.VisibleWidth - 30) + "px";
        gE("bath_drop_backOpen").style.height = (G.VisibleHeight - 30) + "px";
    }
    else
    {
        gE("bath_drop").style.display = 'none';
        gE("bath_drop_backOpen").style.display = 'none';
        gE("search_bathrooms").style.background = 'url(../../images/bath_bkg.gif)';
        gE("txtSearch").focus(); // Keeps nav open
    }
}
function closeBathDrop()
{
    gE("bath_drop").style.display ="none";
    gE("bath_drop_backOpen").style.display ="none";
    gE("search_bathrooms").className ="";
    gE("txtSearch").focus(); // Keeps nav open
} 
function TypeDrop() 
{
    if (gE("type_drop").style.display != 'block')
    {
        strStatus = "open";
    }
    else
    {
        strStatus = "close";
    }

    if (strStatus == "open")
    {
        gE("type_drop").style.display = 'block';
        gE("type_drop_backOpen").style.display = 'block';
        gE("min_drop").style.display = 'none';
        gE("min_drop_backOpen").style.display = 'none';
        gE("max_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("bath_drop").style.display = 'none';
        gE("bath_drop_backOpen").style.display = 'none';
        gE("bed_drop").style.display = 'none';
        gE("bed_drop_backOpen").style.display = 'none';
        gE("narrow_drop").style.display = 'none';
        gE("narrow_drop_backOpen").style.display = 'none';
        var G = new GetWindowBunds();
        var width = G.VisibleWidth - 50;
        var left = 944- width;
        gE("type_drop_backOpen").style.left = (left/2)+ 10 +"px";
        gE("type_drop_backOpen").style.top = "1px";
        gE("type_drop_backOpen").style.width = (G.VisibleWidth - 30) + "px";
        gE("type_drop_backOpen").style.height = (G.VisibleHeight - 30) + "px";
    }
    else
    {
        gE("type_drop").style.display = 'none';
        gE("type_drop_backOpen").style.display = 'none';
        gE("search_propertytype").style.background = 'url(../../images/type_bkg.gif)';
        gE("txtSearch").focus(); // Keeps nav open
    }
}
function closeTypeDrop()
{
    gE("type_drop").style.display ="none";
    gE("type_drop_backOpen").style.display ="none";
    gE("search_propertytype").className ="";
    gE("txtSearch").focus(); // Keeps nav open
}

function NarrowDrop() 
{
    if (gE("narrow_drop").style.display != 'block')
    {
        strStatus = "open";
    }
    else
    {
        strStatus = "close";
    }

        
    if (strStatus == "open")
    {
        gE("narrow_drop").style.display = 'block';
        gE("narrow_drop_backOpen").style.display = 'block';
        gE("min_drop").style.display = 'none';
        gE("min_drop_backOpen").style.display = 'none';
        gE("max_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("bath_drop").style.display = 'none';
        gE("bath_drop_backOpen").style.display = 'none';
        gE("bed_drop").style.display = 'none';
        gE("bed_drop_backOpen").style.display = 'none';
        gE("type_drop").style.display = 'none';
        gE("type_drop_backOpen").style.display = 'none';
        var G = new GetWindowBunds();
        var width = G.VisibleWidth - 50;
        var left = 944- width;
        gE("narrow_drop_backOpen").style.left = (left/2)+ 10 +"px";
        gE("narrow_drop_backOpen").style.top = "1px";
        gE("narrow_drop_backOpen").style.width = (G.VisibleWidth - 30) + "px";
        gE("narrow_drop_backOpen").style.height = (G.VisibleHeight - 30) + "px";
    }
    else
    {
        gE("narrow_drop").style.display = 'none';
        gE("narrow_drop_backOpen").style.display = 'none';
        gE("search_narrow").style.background = 'url(../../images/narrow_bkg.gif)';
        gE("txtSearch").focus(); // Keeps nav open
    }
}
function closeNarrowDrop()
{
    gE("narrow_drop").style.display ="none";
    gE("narrow_drop_backOpen").style.display ="none";
    gE("search_narrow").className ="";
    gE("txtSearch").focus(); // Keeps nav open
} 

function MinDrop() 
{

    if (gE("min_drop").style.display != 'block')
    {
        strStatus = "open";
    }
    else
    {
        strStatus = "close";
    }

    if (strStatus == "open")
    {
        
        gE("min_drop").style.display = 'block';
        gE("min_drop_backOpen").style.display = 'block';
        gE("bed_drop").style.display = 'none';
        gE("bed_drop_backOpen").style.display = 'none';
        gE("max_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("bath_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("type_drop").style.display = 'none';
        gE("type_drop_backOpen").style.display = 'none';
        gE("narrow_drop").style.display = 'none';
        gE("narrow_drop_backOpen").style.display = 'none';
        var G = new GetWindowBunds();
        var width = G.VisibleWidth - 50;
        var left = 944- width;
        gE("min_drop_backOpen").style.left = (left/2)+ 10 +"px";
        gE("min_drop_backOpen").style.top = "1px";
        gE("min_drop_backOpen").style.width = (G.VisibleWidth - 30) + "px";
        gE("min_drop_backOpen").style.height = (G.VisibleHeight - 30) + "px";
    }
    else
    {
        gE("min_drop").style.display = 'none';
        gE("min_drop_backOpen").style.display = 'none';
        gE("search_pricemin").style.background = 'url(../../images/price_min_bkg.gif)';
        gE("txtSearch").focus(); // Keeps nav open
    }
}

function closeMinDrop()
{
    gE("min_drop").style.display ="none";
    gE("min_drop_backOpen").style.display ="none";
    gE("search_pricemin").className ="";
    gE("txtSearch").focus(); // Keeps nav open
} 

function MaxDrop() 
{
    if (gE("max_drop").style.display != 'block')
    {
        strStatus = "open";
    }
    else
    {
        strStatus = "close";
    }
    
    if (strStatus == "open")
    {
        gE("max_drop").style.display = 'block';
        gE("max_drop_backOpen").style.display = 'block';
        gE("min_drop").style.display = 'none';
        gE("min_drop_backOpen").style.display = 'none';
        gE("bed_drop").style.display = 'none';
        gE("bed_drop_backOpen").style.display = 'none';
        gE("bath_drop").style.display = 'none';
        gE("bath_drop_backOpen").style.display = 'none';
        gE("type_drop").style.display = 'none';
        gE("type_drop_backOpen").style.display = 'none';
        gE("narrow_drop").style.display = 'none';
        gE("narrow_drop_backOpen").style.display = 'none';
        var G = new GetWindowBunds();
        var width = G.VisibleWidth - 50;
        var left = 944- width;
        gE("max_drop_backOpen").style.left = (left/2)+ 10 +"px";
        gE("max_drop_backOpen").style.top = "1px";
        gE("max_drop_backOpen").style.width = (G.VisibleWidth - 30) + "px";
        gE("max_drop_backOpen").style.height = (G.VisibleHeight - 30) + "px";
    }
    else
    {
        gE("max_drop").style.display = 'none';
        gE("max_drop_backOpen").style.display = 'none';
        gE("search_pricemax").style.background = 'url(../../images/price_max_bkg.gif)';
        gE("txtSearch").focus(); // Keeps nav open
    }
}

function closeMaxDrop()
{
    gE("max_drop").style.display ="none";
    gE("max_drop_backOpen").style.display ="none";
    gE("search_pricemax").className ="";
    gE("txtSearch").focus(); // Keeps nav open
} 


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//used to close the divs replacing the dropdowns on the 
//homepage expanded search and pass selected criteria to 
//search bar
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function SelectMinPriceHP(id, selectedIndex)
{
    gE("search_pricemin").innerHTML = "<span id='"+selectedIndex+"' >" + id+ "</span>";
    gE("min_drop").style.display = "none";
    gE("min_drop_backOpen").style.display = 'none';
    gE("search_pricemin").style.background = 'url(../../images/price_min_bkg.gif)'; 
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectMaxPriceHP(id,selectedIndex)
{
    gE("search_pricemax").innerHTML = "<span  id='"+selectedIndex+"'>" + id + "</span>";
    gE("max_drop").style.display = "none";
    gE("max_drop_backOpen").style.display = 'none';
    gE("search_pricemax").style.background = 'url(../../images/price_max_bkg.gif)';
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectMinPrice(e, id, selectedIndex)
{
    gE("search_pricemin").innerHTML = "<span id='"+selectedIndex+"' >" + id + "</span>";
    gE("min_drop").style.display = "none";
    gE("min_drop_backOpen").style.display = 'none';
    gE("search_pricemin").style.background = 'url(../../images/price_min_bkg.gif)'; 
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectMaxPrice(e, id,selectedIndex)
{
    gE("search_pricemax").innerHTML = "<span  id='"+selectedIndex+"'>" + id + "</span>";
    gE("max_drop").style.display = "none";
    gE("max_drop_backOpen").style.display = 'none';
    gE("search_pricemax").style.background = 'url(../../images/price_max_bkg.gif)';
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectBed(id, selectedIndex)
{
    gE("search_bedrooms").innerHTML = "<span id='"+selectedIndex+"'>" + id + "</span>";
    gE("bed_drop").style.display = "none";
    gE("bed_drop_backOpen").style.display = 'none';
    gE("search_bedrooms").style.background = 'url(../../images/bed_bkg.gif)';
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectBath(id, selectedIndex)
{
    gE("search_bathrooms").innerHTML = "<span id='"+selectedIndex+"'>" + id + "</span>";
    gE("bath_drop").style.display = "none";
    gE("bath_drop_backOpen").style.display = 'none';
    gE("search_bathrooms").style.background = 'url(../../images/bath_bkg.gif)';
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectType(id, selectedIndex)
{
    gE("search_propertytype").innerHTML = "<span id='"+selectedIndex+"'>" + id + "</span>";
    gE("type_drop").style.display = "none";
    gE("type_drop_backOpen").style.display = 'none';
    gE("search_propertytype").style.background = 'url(../../images/type_bkg.gif)';
    gE("txtSearch").focus(); // Keeps nav open
}

function SelectSalesType(id, selectedIndex)
{
    gE("search_narrow").innerHTML = "<span id='"+selectedIndex+"'>" + id + "</span>";
    gE("narrow_drop").style.display = "none";
    gE("narrow_drop_backOpen").style.display = 'none';
    gE("search_narrow").style.background = 'url(../../images/narrow_bkg.gif)';
    gE("txtSearch").focus(); // Keeps nav open
}

function PriceMinHover() {
gE("search_pricemin").style.background = 'url(/images/price_min_bkg.gif) no-repeat 0 -37px';
}
function PriceMinOut() {
gE("search_pricemin").style.background = 'url(/images/price_min_bkg.gif) no-repeat 0 0';

}

function PriceMaxHover() {

gE("search_pricemax").style.background = 'url(/images/price_max_bkg.gif) 0 -37px';
}
function PriceMaxOut() {
  gE("search_pricemax").style.background = 'url(/images/price_max_bkg.gif)';
}
function BedHover() {

gE("search_bedrooms").style.background = 'url(/images/bed_bkg.gif) 0 -37px';
}
function BedOut() {
  gE("search_bedrooms").style.background = 'url(/images/bed_bkg.gif)';
}

function BathHover() {
gE("search_bathrooms").style.background = 'url(/images/bath_bkg.gif) 0 -37px';
}
function BathOut() {
gE("search_bathrooms").style.background = 'url(/images/bath_bkg.gif)';
}

function TypeHover() {
gE("search_propertytype").style.background = 'url(/images/type_bkg.gif) 0 -37px';
}
function TypeOut() {
  gE("search_propertytype").style.background = 'url(/images/type_bkg.gif)';
}

function NarrowHover() {
gE("search_narrow").style.background = 'url(/images/narrow_bkg.gif) 0 -37px';
}
function NarrowOut() {
  gE("search_narrow").style.background = 'url(/images/narrow_bkg.gif)';
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//opens and closes the Web ID explanation popup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function openWebID() {
  gE("webID-exp").style.display = "block";
  gE("webid_backClose").style.display = "block";
}

function closeWebID() {
  gE("webID-exp").style.display = "none";
  gE("webid_backClose").style.display = "none";
}


function showWhite() {
gE("priceminLI").style.background ="FFFFFF";
}
