﻿/**
    This object is used in the criteria panel on both the property search and search results page.
*/
function SearchHelper(locationID, lifestylesID, typeForSaleID, typeForRentID, amenitiesID, priceID, propertyTypeID, propertyStyleID, bedsID, bathsID, propertyCountID, viewResultsID)
{    
    /*------------------------- MEMBERS BEGIN  ***/
    var LocationID       = locationID;
    var LifestylesID     = lifestylesID;
    var TypeForSaleID    = typeForSaleID;
    var TypeForRentID    = typeForRentID;
    var AmenitiesID      = amenitiesID;
    var PriceID          = priceID;
    var PropertyTypeID   = propertyTypeID;
    var PropertyStyleID  = propertyStyleID;
    var BedsID           = bedsID;    
    var BathsID          = bathsID;
    var PropertyCountID  = propertyCountID;
    var ViewResultsID    = viewResultsID;
    var CurrencyID;
    var divCurrentCriteriaPanel;
    var tdLocation;
    var tdLifestyle;
    var tdAmenities;
    var divPrice;
    var divType;
    var divStyle;
    var tdPriceTypeAndStyle;
    var divBeds;
    var divBaths;
    var tdBedsBaths;
    var DisableCriteriaPanel;
    
    var LifestylesDimVals; // this array will hold the endeca Dimensio IDs for the list of lifestyles
    var AmenitiesDimVals; // this array will hold the endeca Dimensio IDs for the list of amenities
    var ForRentDimVal;
    var ForSaleDimVal;
    var AsyncHandlerOperation;
    var CurrencyExchangeRate;
    var PriceRangeForSale;
    var PriceRangeForRent;
    var TextNoMatches = 'There are no properties in the system the match the selected criteria.\nPlease further refine your search and click on this link again.';
    var TextNoMinimum = 'No Minimum';
    var TextNoMaximum = 'No Maximum';
    var TextLoading = 'Loading';
    var that = this;

    var DefaultPropertySearchUrl;
 
    function Initialize() {
        this.Location       = jQuery('#' + LocationID);
        this.Lifestyle      = jQuery('#' + LifestylesID);
        this.TypeForSale    = jQuery('#' + TypeForSaleID);
        this.TypeForRent    = jQuery('#' + TypeForRentID);
        this.Amenities      = jQuery('#' + AmenitiesID);
        this.Price          = jQuery('#' + PriceID);
        this.PropertyType   = jQuery('#' + PropertyTypeID);
        this.PropertyStyle  = jQuery('#' + PropertyStyleID);
        this.Beds           = jQuery('#' + BedsID);
        this.Baths          = jQuery('#' + BathsID);
        this.PropertyCount  = jQuery('#' + PropertyCountID);
        this.ViewResults    = jQuery('#' + ViewResultsID);
        this.Currency       = jQuery('#' + CurrencyID);
        jQuery('#' + LocationID + ',#' + TypeForSaleID + ',#' + TypeForRentID + ',#' + PropertyStyleID + ',#' + BedsID + ',#' + BathsID).change(function() { that.UpdateCount(); });
        jQuery('#' + LifestylesID + ',#' + AmenitiesID + ',#' + PropertyTypeID).click(function(event) { that.UpdateCount(); });
        this.Price.bind('slidechange', function(event, ui) { that.UpdateCount(); return true; });
    }
    
    this.PriceSlide = function(event, ui) {
		var  user_val1=ui.values[0]; 
			var  user_val2=ui.values[1]; 
				jQuery("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
				jQuery("#price_min").val(ui.values[0]);
				jQuery("#price_max").val(ui.values[1]);
				  var str=$("search_form").serialize();
				jQuery("#products").load('ajaxSlider.php?'+str+'&minValue='+ui.values[0]+'&maxValue='+ui.values[1],'',function(){});
        isForRent = jQuery("#prop_type_rent").is(":checked");
	   if(isForRent) {
		   whichRange = that.PriceRangeForRent;
		  // show_count_ajax_properties();
		   } else {
			whichRange =   that.PriceRangeForSale;
		   }
	    var startValue = ui.values[0] == 0 ? that.TextNoMinimum : whichRange[ui.values[0]].format;

        var endValue = whichRange[ui.values[1]].value == -1 ? that.TextNoMaximum : whichRange[ui.values[1]].format;
		jQuery("#price_min").val(whichRange[ui.values[0]].value);
		jQuery("#price_max").val(whichRange[ui.values[1]].value);

        jQuery("#amount").val(startValue + ' - ' + endValue);
		jQuery("#products").load('ajaxSlider.php?'+str+'&minValue='+whichRange[ui.values[0]].value+'&maxValue='+whichRange[ui.values[1]].value,'',function(data){ });
    }

   
    /*------------------------- PUBLIC METHODS END  ***/    
}

// Variables 
	var opened = true;
	var num = 0;
	var prevText = "";
	var searchCounter = 0;
	var locationSearchTimer;
	

// On Document Ready 
jQuery(document).ready(function() {
    opened = true;
});

