﻿/**
    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 $shelper = jQuery.noConflict();	
			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=$shelper("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);
		
		
		var var_name = $shelper("input[@name=\'type\']:checked").val();
		
		  var key= document.search_form.keywords.value ;
		//var total_zoin=""
		var total_properties=""
		var location_total =""
		var rooms_total=""
		var rooms_empls=""
		var rooms = ""
		var method = ""
		var features=""
		var features_empls=""
		var features_total=""
		var bathrooms= "";
	   var bedrooms= "" ;
	   var floorsize= "";
	   var lotsize= "";
	   var glarea= "";
			   
		
		/*var zoin = document.search_form['zoning[]'];
		if(zoin.length != '')
		{
			 for(var i=0; i < zoin.length; i++){
			  if(zoin[i].checked)
			  {
					total_zoin +=zoin[i].value+",";	
			  }	
			}
			var zoing=total_zoin;
		}*/
		
		var properties_empls = document.search_form['properties[]'];
		if(properties_empls.length != '')
		{
			 for(var i=0; i < properties_empls.length; i++){
			 if(properties_empls[i].checked)
			 {
					total_properties +=properties_empls[i].value+",";
			  }
			}
			var property=total_properties;
		}
		var location_empls = document.search_form['location[]'];
		if(location_empls.length != '')
		{
			 for(var i=0; i < location_empls.length; i++){
			 if(location_empls[i].checked)
			 {
					 location_total +=location_empls[i].value+",";
			 }
			}
	    	var location=location_total;
		}
		
		if(document.search_form.advance_type.value != '')
		{
			
			method = "2";
			
			var rooms_empls = document.search_form['rooms[]'];
			if(rooms_empls.length != '')
			{
				 for(var i=0; i < rooms_empls.length; i++){
				 if(rooms_empls[i].checked)
				 {
						 rooms_total +=rooms_empls[i].value+",";
				 }
				}
				var rooms=rooms_total;
				
			}
			
			var features_empls = document.search_form['features[]'];
			if(features_empls.length != '')
			{
				 for(var i=0; i < features_empls.length; i++){
				 if(features_empls[i].checked)
				 {
						 features_total +=features_empls[i].value+",";
				 }
				}
				var features=features_total;
				
			}
			   var bathrooms= document.search_form.bathrooms.value ;
			   var bedrooms= document.search_form.bedrooms.value ;
			   var floorsize= document.search_form.floorsize.value ;
			   var lotsize= document.search_form.lotsize.value ;
			   var glarea= document.search_form.glarea.value ;
			
			var theUL  = document.getElementById('products');
			theUL.innerHTML = '<div class="search-loading"></div>';   
			   
		}
		else
		 {
			 var theUL  = document.getElementById('products');
			theUL.innerHTML = '';   
			 
		}
		//alert(rooms);
		
		
		
		//url = 'minValue='+whichRange[ui.values[0]].value+'&maxValue='+whichRange[ui.values[1]].value+'&type='+var_name+'&keywords='+key+'&zoing='+zoing+'&property='+property+'&location='+location+'&method='+method+'&rooms='+rooms+'&features='+features;
		url = 'minValue='+whichRange[ui.values[0]].value+'&maxValue='+whichRange[ui.values[1]].value+'&type='+var_name+'&keywords='+key+'&property='+property+'&location='+location+'&method='+method+'&rooms='+rooms+'&features='+features;
		
		if(bathrooms)
		{
			url +=	'&bathrooms='+bathrooms;
		}
		if(bedrooms)
		{
			url += '&bedrooms='+bedrooms;
		}
		
		if(floorsize)
		{
			url += '&floorsize='+floorsize ;	
		}
		if(lotsize)
		{
			url += '&lotsize='+lotsize ;	
		}
		
		if(glarea)
		{
			url += '&glarea='+glarea ;	
		}
	    
		jQuery("#amount").val(startValue + ' - ' + endValue);
		
		
		jQuery("#products").load('ajaxSlider.php?'+url,function(){
		});
	
		//jQuery("#products").load('ajaxSlider.php?'+str+'&minValue='+whichRange[ui.values[0]].value+'&maxValue='+whichRange[ui.values[1]].value+'&type='+var_name,'',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;
});


