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(',', '');
            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(',', '');
            //if(pricemax == 0){pricemax = 9999999999}
            if(pricemax.toString().toLowerCase().indexOf('million') > -1) {pricemax = pricemax.substring(0,1) + "000000";}
        }
        if (debug) { alert(pricemin + ':' + pricemax); }

        // Property Type
        var pt = '';
        var atleastonechecked = false;
        if (gE("results_All-Properties") != null) { if (gE("results_All-Properties").checked == true) { pt += 'All-'; atleastonechecked=true;} }
        if (gE("results_Single-family") != null)  { if (gE("results_Single-family").checked == true) { pt += 'Single Family-'; atleastonechecked=true;} }
        if (gE("results_Condo") != null)          { if (gE("results_Condo").checked == true) { pt += 'Condo-'; atleastonechecked=true;} }
        if (gE("results_Townhouse") != null)      { if (gE("results_Townhouse").checked == true) { pt += 'Townhouse-'; atleastonechecked=true;} }
        if (gE("results_Multi-family") != null)   { if (gE("results_Multi-family").checked == true) { pt += 'Multi Family-'; atleastonechecked=true;} }
        if (gE("results_Land") != null)           { if (gE("results_Land").checked == true) { pt += 'Land-'; atleastonechecked=true;} }
        if (gE("results_Other") != null)          { if (gE("results_Other").checked == true) { pt += 'Other-'; atleastonechecked=true;} }
        if (atleastonechecked == false)
        {
            if (gE("results_All-Properties") != null) {gE("results_All-Properties").checked = true;pt += 'All-';}
        }
        // 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) {
            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

        var query = pricemin + "^" + pricemax + "^" + pt + "^" + beds + "^" + baths + "^" + sqftStart + "^" + sqftEnd + "^" + yearStart + "^" + yearEnd + "^" + saletype + "^" + jsQueryString + "^" + oh + "^" + vt;
        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
                    this; // the options for this ajax request
                    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';
}

