function RFQuery(LeftNavBusy) {
    
    //alert('leftnavbusy='+LeftNavBusy);

    if(LeftNavBusy == 'false'){
        var debug = false;

        if (debug) { alert('in requery'); }
        
        loading(true);
        //gE('waiting').style.display = 'block';
        
        // Type of Sale 
        var saletype = "All";
        if (gE("selected_sale_type") != null) {
            saletype = gE("selected_sale_type").value;
        }
        //alert('saletype:'+ saletype); 
        // Price
        var pricemin = 0;
        if (gE("selected_price_min") != null) {
            pricemin = gE("selected_price_min").innerHTML; pricemin =  pricemin.replace(',', '').replace('$', '');
            $("#results_searchpricelistmin li").removeClass("selected");
            $("#results_searchpricelistmin li[id='" + pricemin + "']").addClass("selected");    
            if(pricemin.toString().toLowerCase().indexOf('million') > -1) {pricemin = pricemin.substring(0,1) + "000000";}
        }
        var pricemax = 9999999999;
        if (gE("selected_price_max") != null) {
            pricemax = gE("selected_price_max").innerHTML; pricemax = pricemax.replace(',', '').replace('$', '');
            $("#results_searchpricelistmax li").removeClass("selected");
            $("#results_searchpricelistmax li[id='" + pricemax + "']").addClass("selected");    
            if(pricemax.toString().toLowerCase().indexOf('million') > -1) {pricemax = pricemax.substring(0,1) + "000000";}
        }
        if (debug) { alert(pricemin + ':' + pricemax); }

        // Property Type
        var pt = '';
        var ptLabel = '';
        
        var atleastonechecked = false;
        if (gE("results_All-Properties") != null)           { if (gE("results_All-Properties").checked == true) { pt += 'All-'; ptLabel += 'All Property Types, '; atleastonechecked=true;} }
        if (gE("results_Single-family") != null)            { if (gE("results_Single-family").checked == true) { pt += 'Single Family-'; ptLabel += 'Single Family, '; atleastonechecked=true;} }
        if (gE("results_Condo") != null)                    { if (gE("results_Condo").checked == true) { pt += 'Condo-'; ptLabel += 'Condo, '; atleastonechecked=true;} }
        if (gE("results_Townhouse") != null)                { if (gE("results_Townhouse").checked == true) { pt += 'Townhouse-'; ptLabel += 'Townhouse, '; atleastonechecked=true;} }
        if (gE("results_Multi-family") != null)             { if (gE("results_Multi-family").checked == true) { pt += 'Multi Family-'; ptLabel += 'Multi Family, '; atleastonechecked=true;} }
        if (gE("results_Land") != null)                     { if (gE("results_Land").checked == true) { pt += 'Land-'; ptLabel += 'Land, '; atleastonechecked=true;} }
        if (gE("results_Other") != null)                    { if (gE("results_Other").checked == true) { pt += 'Other-'; ptLabel += 'Other, '; atleastonechecked=true;} }
        if (gE("results_55-Community") != null)             { if (gE("results_55-Community").checked == true) { pt += '55-Community-'; ptLabel += '55+ Community, '; atleastonechecked=true;} }
        if (gE("results_Apartment") != null)                { if (gE("results_Apartment").checked == true) { pt += 'Apartment-'; ptLabel += 'Apartment, '; atleastonechecked=true;} }
        if (gE("results_Duplex") != null)                   { if (gE("results_Duplex").checked == true) { pt += 'Duplex-'; ptLabel += 'Duplex, '; atleastonechecked=true;} }
        if (gE("results_Loft") != null)                     { if (gE("results_Loft").checked == true) { pt += 'Loft-'; ptLabel += 'Loft, '; atleastonechecked=true;} }
        if (gE("results_New-Construction") != null)         { if (gE("results_New-Construction").checked == true) { pt += 'New-Construction-'; ptLabel += 'New Construction, '; atleastonechecked=true;} }
        if (atleastonechecked == false)
        {
            $("#results_search_propertytype").html("All Property Types");
            
            pt += 'All-';
        }
        else 
        {
            $("#results_search_propertytype").html(ptLabel.substr(0, ptLabel.length - 2));
        }
        
        // Amenities
        var at = '';
        var atLabel = '';
        
        var atleastoneamenitychecked = false;
        if (gE("results_a-c") != null)                      { if (gE("results_a-c").checked == true) { at += 'A-C-'; atLabel += 'A / C, '; atleastoneamenitychecked=true;} }
        if (gE("results_fireplace") != null)                { if (gE("results_fireplace").checked == true) { at += 'Fireplace-'; atLabel += 'Fireplace, '; atleastoneamenitychecked=true;} }
        if (gE("results_garage") != null)                   { if (gE("results_garage").checked == true) { at += 'Garage-'; atLabel += 'Garage, '; atleastoneamenitychecked=true;} }
        if (gE("results_golf-course") != null)              { if (gE("results_golf-course").checked == true) { at += 'Golf-Course-'; atLabel += 'Golf Course, '; atleastoneamenitychecked=true;} }
        if (gE("results_patio-deck") != null)               { if (gE("results_patio-deck").checked == true) { at += 'Patio-Deck-'; atLabel += 'Patio / Deck, '; atleastoneamenitychecked=true;} }
        if (gE("results_pool") != null)                     { if (gE("results_pool").checked == true) { at += 'Pool-'; atLabel += 'Pool, '; atleastoneamenitychecked=true;} }
        if (gE("results_retirement") != null)               { if (gE("results_retirement").checked == true) { at += 'Retirement-'; atLabel += 'Retirement, '; atleastoneamenitychecked=true;} }
        if (gE("results_waterfront") != null)               { if (gE("results_waterfront").checked == true) { at += 'Waterfront-'; atLabel += 'Waterfront, '; atleastoneamenitychecked=true;} }
        if (gE("results_central-air-conditioning") != null) { if (gE("results_central-air-conditioning").checked == true) { at += 'Central-Air-Conditioning-'; atLabel += 'Central Air Conditioning, '; atleastoneamenitychecked=true;} }
        if (gE("results_dishwasher") != null)               { if (gE("results_dishwasher").checked == true) { at += 'Dishwasher-'; atLabel += 'Dishwasher, '; atleastoneamenitychecked=true;} }
        if (gE("results_doorman") != null)                  { if (gE("results_doorman").checked == true) { at += 'Doorman-'; atLabel += 'Doorman, '; atleastoneamenitychecked=true;} }
        if (gE("results_washer-dryer-hookups") != null)     { if (gE("results_washer-dryer-hookups").checked == true) { at += 'Washer-Dryer-Hookups-'; atLabel += 'Washer Dryer Hookups, '; atleastoneamenitychecked=true;} }
        if (gE("results_washer-dryer-in-bldg") != null)     { if (gE("results_washer-dryer-in-bldg").checked == true) { at += 'Washer-Dryer-In-Building-'; atLabel += 'Washer Dryer in Building, '; atleastoneamenitychecked=true;} }
        if (gE("results_washer-dryer-in-unit") != null)     { if (gE("results_washer-dryer-in-unit").checked == true) { at += 'Washer-Dryer-In-Unit-'; atLabel += 'Washer Dryer in Unit, '; atleastoneamenitychecked=true;} }
        if (gE("results_waterfront-beach") != null)         { if (gE("results_waterfront-beach").checked == true) { at += 'Waterfront-Beach-'; atLabel += 'Waterfront Beach, '; atleastoneamenitychecked=true;} }
        if (gE("results_waterfront-river") != null)         { if (gE("results_waterfront-river").checked == true) { at += 'Waterfront-River-'; atLabel += 'Waterfront River, '; atleastoneamenitychecked=true;} }
        if (gE("results_waterfront-lake") != null)          { if (gE("results_waterfront-lake").checked == true) { at += 'Waterfront-Lake-'; atLabel += 'Waterfront Lake, '; atleastoneamenitychecked=true;} }
        if (gE("results_waterfront-bay") != null)           { if (gE("results_waterfront-bay").checked == true) { at += 'Waterfront-Bay-'; atLabel += 'Waterfront Bay, '; atleastoneamenitychecked=true;} }
        if (gE("results_mountain-view") != null)            { if (gE("results_mountain-view").checked == true) { at += 'Mountain-View-'; atLabel += 'Mountain View, '; atleastoneamenitychecked=true;} }
        if (gE("results_yard") != null)                     { if (gE("results_yard").checked == true) { at += 'Yard-'; atLabel += 'Yard, '; atleastoneamenitychecked=true;} }
        if (gE("results_senior-community") != null)         { if (gE("results_senior-community").checked == true) { at += 'Senior-Community-'; atLabel += 'Senior Community, '; atleastoneamenitychecked=true;} }
        if (atleastoneamenitychecked == false)
        {
            $("#results_search_amenities").html("No Preference");
            at += 'All-';
        }
        else 
        {
            $("#results_search_amenities").html(atLabel.substr(0, atLabel.length - 2));
        }

        // Open Houses
        var oh = '';
        if (gE("results_All-Dates") != null) { if (gE("results_All-Dates").checked == true) { oh += 'All-';} }
        if (gE("results_Today") != null) { if (gE("results_Today").checked == true) { oh += 'Today-'; } }
        if (gE("results_Tomorrow") != null) { if (gE("results_Tomorrow").checked == true) { oh += 'Tomorrow-';} }
        if (gE("results_This-weekend") != null) { if (gE("results_This-weekend").checked == true) { oh += 'This weekend-'; } }
        if (gE("results_Next-weekend") != null) { if (gE("results_Next-weekend").checked == true) { oh += 'Next weekend-'; } }
        if (gE("ohstart") != null) {if (gE("ohstart").value != "") { oh += 'OHStart=' + gE("ohstart").value; } }
        if (gE("ohend") != null) {if (gE("ohend").value != "") { oh += 'OHEnd=' + gE("ohend").value; }  }
        //alert('oh:' + oh);
        
        //Condition For No Open Houses.
        if (gE("openhouse_count") != null)
            {
                if ( trim(gE("openhouse_count").innerHTML).toString().toLowerCase() == "there are no open houses scheduled within the current results set" )
                {
                    oh += "OHStart=OHEnd=";
                }
            }
        //alert('oh:' + oh);    
        //Virtual Tour
        var vt = ""
        if (gE("results_With_virtualtours") != null) {if(gE("results_With_virtualtours").checked == true) {vt+= "Virtual-Tours"}}
        
        //Beds/Baths
        var beds = 'any';
        if (gE("results_search_bedrooms") != null) {
//            alert(gE("results_search_bedrooms").firstChild.innerHTML);
//            $("#bedrooms_drop_div li").removeClass("selected");
//            //$("#bedrooms_drop_div li[id='" + pricemin + "']").addClass("selected");    
            beds = gE("results_search_bedrooms").firstChild.innerHTML;
        }
        var baths = 'any'
        if (gE("results_search_bathrooms") != null) {
            baths = gE("results_search_bathrooms").firstChild.innerHTML;
        }

        if (debug) { alert(baths + ':' + beds); }
        
        //Square Feet
        var sqftStart = 0;
        if (gE("sqft_floor") != null) {
            sqftStart = gE("sqft_floor").innerHTML;
        }
        var sqftEnd = 5000;
        if (gE("sqft_ceiling") != null) {
            sqftEnd = gE("sqft_ceiling").innerHTML;
        }

        if (debug) { alert(sqftStart + ':' + sqftEnd); }
        
	    //BuiltYear
        var yearStart = 0;
        if (gE('age_floor') != null) {
            yearStart = gE('age_floor').innerHTML;
        }
        var yearEnd = 9999;
        if (gE('age_ceiling') != null) {
            yearEnd = gE('age_ceiling').innerHTML;
        }

        //OpenHouse
        // dcb todo start - do i need to copy the builtyear stuff above?
        var OHStart = 0;
        if (gE('ohstart') != null) {
            OHStart = gE('ohstart').innerHTML;
        }
        var OHEnd = 9999;
        if (gE('ohend') != null) {
            OHEnd = gE('ohend').innerHTML;
        }

        if (debug) { alert(OHStart + ':' + OHEnd); }
        /// dcb todo end

        //Pet Policies
        var pp = "";
        if (gE("results_pets-no-preference") != null) { if (gE("results_pets-no-preference").checked == true) { pp += 'No-Preference'; } }
        if (gE("results_pets-cats") != null)  { if (gE("results_pets-cats").checked == true) { pp += 'Cats-'; } }
        if (gE("results_pets-small-dogs") != null)          { if (gE("results_pets-small-dogs").checked == true) { pp += 'Small-Dogs-'; } }
        if (gE("results_pets-large-dogs") != null)          { if (gE("results_pets-large-dogs").checked == true) { pp += 'Large-Dogs-'; } }
        if (gE("results_pets-other") != null)      { if (gE("results_pets-other").checked == true) { pp += 'Other-'; } }

        var query = pricemin + "^" + pricemax + "^" + pt + "^" + beds + "^" + baths + "^" + sqftStart + "^" + sqftEnd + "^" + yearStart + "^" + yearEnd + "^" + saletype + "^" + jsQueryString + "^" + oh + "^" + vt + "^" + SEOSection + "^" + at + "^" + pp;
        var strURL = WebRoot + "controls/ajaxcalls/ResultsQuery.aspx?query=" + escape(query);

        if (debug) { alert(strURL); }
        try {
            $.ajax({
                url: strURL,
                type: 'GET',
                dataType: 'text',
                success: function(data) {
                    if (debug) { alert("Data Loaded: " + data); }
                    RefinementQuery(data);
                    if (debug) { alert("done with RefinementQuery(data)"); }
                    paginationWidth();
                    loading(false);
                    toogle_map_view(false);
                    SetWindowLocation();
                    repositionAd();
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    // typically only one of textStatus or errorThrown 
                    // will have info
                // the options for this ajax request
                    this; 
                    if (debug) { alert('error this:' + this + '\n XMLHttpRequest:' + XMLHttpRequest + '\ntextStatus:' + textStatus); }
                }
            });
        }
        catch (e) {
            alert('error:' + e);
        }
    }
      
}

function LoseSpan(str) {

    str = trim(str);
    var s = str.indexOf(">");
    str = str.substring(s + 1, str.length);
    str = str.replace("</span>", "");
    return str;
    
}

function SetWindowLocation()
{
    //Sets the location of the page to top. 
    window.scroll(0,0);
}


function OpenHouseinSelectionBox()
{
    var openhousefound = false;
    var all_li = new Array();
    all_li = getElemsByClass('li','selected_li');
    for (var i = 0; i < all_li.length; i++)
    {
         var childnode = all_li[i].getAttribute('id');
         if(childnode.match('open_house_'))
         {
            openhousefound = true;            
            break;
         }         
    }
    return openhousefound;
}

function ClearCustomDateRange() {
    gE("ohstart").value = "";
    gE("ohend").value = "";
    gE("CustomDateRange").checked = 'false';
}



























