HomeSearch = {
	IDX_URL_Root : "http://idx.diversesolutions.com/search/482/68", //example: http://idx.diversesolutions.com/search/12/4
	URL_Root : "Combined_Home_Search.htm#", // CHANGE THIS IF THE PATH TO YOUR IFRAME PAGE IS DIFFERENT for example, if your frame page is http://www.mysite.com/idxsearch.php fill in: idxsearch.php? for URL_Root
	
	Search : function(showAdvanced){
		//price_min, price_max, bed_min, bath_min, city, sqft_min, property_types, features, communities, mls_numbers, zipcode
		var price_min = document.getElementById('price_min');
		var price_max = document.getElementById('price_max');
		var bed_min = document.getElementById('bed_min');
		var bath_min = document.getElementById('bath_min');
		var city = document.getElementById('city');
		var sqft_min = document.getElementById('sqft_min');
		var sqft_max = document.getElementById('sqft_max');
		var lot_min = document.getElementById('lot_min');
		var lot_max = document.getElementById('lot_max');
		var yearbuilt_min = document.getElementById('yearbuilt_min');
		var yearbuilt_max = document.getElementById('yearbuilt_max');
		var property_types = document.getElementById('property_types');
		var features = document.getElementById('features');
		var communities = document.getElementById('communities');
		var tracts = document.getElementById('tracts');
		var schools = document.getElementById('schools');
		var mls_numbers = document.getElementById('mls_numbers');
		var zipcode = document.getElementById('zipcode');
		var foreclosurestatus = document.getElementById('foreclosurestatus');
		var dayslisted_min = document.getElementById('dayslisted_min');
		var dayslisted_max = document.getElementById('dayslisted_max');
		var pricedrop_percent = document.getElementById('pricedrop_percent');
		var pricedrop_days = document.getElementById('pricedrop_days');
		
		var PropertyTypes = "";
		var URLType = "";
		var CitiesList = "";
		var FeaturesList = "";
		//http://idx.diversesolutions.com/search/482/68/mlsnumber/T2338356#MinYearBuilt=1920&MaxYearBuilt=1940&PropertyTypes=560&PerformSearch&MaxLatitude=29.386961521657504&MaxLongitude=-80.66162109375&MinLatitude=28.18098087972553&MinLongitude=-82.42218017578125&
		
		//Both = Foreclosures=3
		//Pre = 2
		//Bank = 1
		
		for(var i=0;i<city.options.length;i++){
			if(city.options[i].selected){
				if(city.options[i].value == "area"){
					for(var j=i+1;j<city.options.length;j++){
						if(city.options[j].value == "area")
							j = city.options.length;
						else
							CitiesList += encodeURIComponent(city.options[j].value) + ",";
					}
				} else {
						CitiesList += encodeURIComponent(city.options[i].value) + ",";
				}
			}
		}
		if(CitiesList.length > 0) CitiesList = CitiesList.substring(0, CitiesList.length - 1);
		
		for(var i=0;i<features.options.length;i++){
			if(features.options[i].selected)
				FeaturesList += features.options[i].value + ",";
		}
		if(FeaturesList.length > 0) FeaturesList = FeaturesList.substring(0, FeaturesList.length - 1);
		
		var queryString = 
			(property_types == null || property_types.value == "" ? "" : "&PropertyTypes=" + property_types.value ) + 
			(FeaturesList == null || FeaturesList == "" ? "" : "&Features=" + FeaturesList ) + 
			(mls_numbers == null || mls_numbers.value == "" ? "" : "&MlsNumbers=" + mls_numbers.value ) + 
			(price_min == null || price_min.value == "" ? "" : "&MinPrice=" + price_min.value ) + 
			(price_max == null || price_max.value == "" ? "" : "&MaxPrice=" + price_max.value ) + 
			(sqft_min == null || sqft_min.value == "0" || sqft_min.value == "" ? "" : "&MinImprovedSqFt=" + encodeURIComponent(sqft_min.value)) + 
			(sqft_max == null || sqft_max.value == "0" || sqft_max.value == "" ? "" : "&MaxImprovedSqFt=" + encodeURIComponent(sqft_max.value)) + 
			(lot_min == null || lot_min.value == "0" || lot_min.value == "" ? "" : "&MinLotSqFt=" + encodeURIComponent(lot_min.value)) + 
			(lot_max == null || lot_max.value == "0" || lot_max.value == "" ? "" : "&MaxLotSqFt=" + encodeURIComponent(lot_max.value)) + 
			(bed_min == null || bed_min.value == "0" || bed_min.value == "" ? "" : "&MinBeds=" + bed_min.value ) + 
			(bath_min == null || bath_min.value == "0" || bath_min.value == "" ? "" : "&MinBaths=" + bath_min.value ) + 
			(yearbuilt_min == null || yearbuilt_min.value == "0" || yearbuilt_min.value == "" ? "" : "&MinYearBuilt=" + yearbuilt_min.value ) + 
			(yearbuilt_max == null || yearbuilt_max.value == "0" || yearbuilt_max.value == "" ? "" : "&MaxYearBuilt=" + yearbuilt_max.value ) + 
			(dayslisted_min == null || dayslisted_min.value == "0" || dayslisted_min.value == "" ? "" : "&MinDaysOnMarket=" + dayslisted_min.value ) + 
			(dayslisted_max == null || dayslisted_max.value == "0" || dayslisted_max.value == "" ? "" : "&MaxDaysOnMarket=" + dayslisted_max.value ) + 
			(pricedrop_percent == null || pricedrop_percent.value == "0" || pricedrop_percent.value == "" ? "" : "&PriceDropPercent=" + pricedrop_percent.value ) + 
			(pricedrop_days == null || pricedrop_days.value == "0" || pricedrop_days.value == "" ? "" : "&PriceDropDays=" + pricedrop_days.value ) + 
			(foreclosurestatus == null || foreclosurestatus.value == "0" || foreclosurestatus.value == "" ? "" : "&Foreclosures=" + foreclosurestatus.value ) + 
			(CitiesList == null || CitiesList == "" ? "" : "&Cities=" + CitiesList) + 
			(zipcode == null || zipcode.value == "" ? "" : "&ZipCodes=" + encodeURIComponent(zipcode.value)) + 
			(tracts == null || tracts.value == "" ? "" : "&Tracts=" + encodeURIComponent(tracts.value)) + 
			(schools == null || schools.value == "" ? "" : "&Schools=" + encodeURIComponent(schools.value)) + 
			(communities == null || communities.value == "" ? "" : "&Communities=" + encodeURIComponent(communities.value));
			
		
		FinalUrl = "";
		if (typeof showAdvanced != 'undefined' && showAdvanced) {
			FinalUrl = "/" + this.URL_Root + '&ShowAdvanced'; //queryString = queryString + '&ShowAdvanced';
		} else {
			FinalUrl = "/" + this.URL_Root + queryString + "&PerformSearch&";
		}

		if(typeof window.navigate != "undefined"){
			window.navigate(FinalUrl);
		} else {
			location.href = FinalUrl;
		}
	},
	
	Advanced : function(){
		var AdvancedCriteria = document.getElementById('AdvancedCriteria');
		
		AdvancedCriteria.style.display = "block";
	},
	
	BuildSearchFrame : function(frame){
		var iFrame = document.getElementById(frame);
	
		if(iFrame){
			var hash = "";
			
			if(location.search != ""){
				hash = location.search;
				
				if(hash.substring(0,1) == "?") hash = hash.substring(1);
				if(hash.substring(0,1) == "&") hash = hash.substring(1);
				hash = "#" + hash;
			} else if(location.hash != ""){
				hash = location.hash;
			}
			
			iFrame.src = this.IDX_URL_Root +  hash;
		}
	}
}