var PropertySearchPanel = function() {

	var min = '0';
	var max = '0';
	var domain = 'sale';
	var saleSelectValues = new Array(10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 125000, 150000, 175000, 200000, 225000, 300000, 350000, 350000, 400000, 450000, 500000, 600000, 700000, 800000, 900000, 1000000, 1250000, 1500000, 1750000, 2000000, 2250000, 2500000, 2750000, 3000000);
	var rentSelectValues = new Array(100, 150, 200, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 6000, 7000, 8000, 9000, 10000);

	return {
		bootstrap : function(event) {
			if ($('propertyforsaleorrent')) {
				$('propertyforsaleorrent').innerHTML = '<input type="radio" name="domain" value="sale" checked="checked" id="domainsale" /><span>For sale</span><br /><input type="radio" name="domain" value="rent" id="domainrent" /><span>For rent</span>';
			}
			$('domainsale').observe('change', PropertySearchPanel.changeForm);
			$('domainrent').observe('change', PropertySearchPanel.changeForm);
			
			if (domain == 'rent') {
				PropertySearchPanel.populateMinimumMaximum('rent');
			}

			Utility.selectValue($('propertysearchmin'), min);
			Utility.selectValue($('propertysearchmax'), max);
			
			if (domain) {
				$('domainsale').checked = (domain == 'sale');
				$('domainrent').checked = (domain == 'rent');
			}
		},
		
		changeForm : function(event) {
			if ($('domainsale').checked) {
				PropertySearchPanel.populateMinimumMaximum('sale');	
			} else if ($('domainrent').checked) {
				PropertySearchPanel.populateMinimumMaximum('rent');
			}
		},
		
		populateMinimumMaximum : function(type) {
			Utility.clearSelectBox($('propertysearchmin'));			
			Utility.clearSelectBox($('propertysearchmax'));

			Utility.addOption($('propertysearchmin'), 'Any', '');
			Utility.addOption($('propertysearchmax'), 'Any', '');
			
			if (type == 'sale')
				selectValues = saleSelectValues;
			else
				selectValues = rentSelectValues;
			
			selectValues.each(function(item) {
				Utility.addOption($('propertysearchmin'), Utility.addCommas(item), item);
				Utility.addOption($('propertysearchmax'), Utility.addCommas(item), item);
			});
		},
		
		setMinimum : function(val) {
			min  = val;
		},
		
		setMaximum : function(val) {
			max = val;
		},		
	
		setDomain : function(val) {
			domain = val;
		}		
	}
}();