function search(e) {
	for (i = 0; i < document.hs.SubSelect1.length; i++) {
		if (document.hs.SubSelect1.options[i].value.substr(0,e.value.length) == e.value.toUpperCase()) {
			document.hs.SubSelect1.options[i].selected = true;
			break;
		}
	}
}
function submitForm() {
   for (i = 0; i < document.hs.elements["Sub[]"].length; i++) {
   	document.hs.elements["Sub[]"].options[i].selected = true;
   }
}

function addOption(theSel, theText, theValue) {
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex) { 
  var selLength = theSel.length;
  if(selLength>0) {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo) {
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  var i;
  var j;
  for(i=selLength-1; i>=0; i--) {
    if(theSelFrom.options[i].selected) {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
      j = i - 1;
     }
  }
  
  for(i=selectedCount-1; i>=0; i--) {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  theSelFrom.options[j].selected = true;
}

function mapSearch() {
	$(document).ready(function() {
	if ($("input#hidden").val() == 'L') window.location = '?Renting/Property-Search';
	else window.location = '?Buying/Property-Search';
	});
}


$(document).ready(function() {
	$("input#buy").click(function() {
		var prices = new Array('100K','150K','200K','250K','300K','350K','400K','450K','500K','550K','600K','650K','700K','750K','800K','850K','900K','1.0M','1.1M','1.2M','1.3M','1.4M','1.5M','1.6M','1.7M','1.8M','1.9M','2.0M','2.25M','2.5M','2.75M','3.0M','3.25M','3.5M','3.75M','4.0M');
		options = '<option value="0">Minimum</option>';
   		for (i = 0; i < prices.length; i++) options += '<option value="' + prices[i] + '">' + prices[i] + '</option>';
   		$("select#min").html(options);
		options = '<option value="0">Maximum</option>';
   		for (i = 0; i < prices.length; i++) options += '<option value="' + prices[i] + '">' + prices[i] + '</option>';
   		$("select#max").html(options);
   		$("tr.leasing").hide();
   		$("tr.buying").show();
   	});
	$("input#rent").click(function() {
		var rents = new Array('100 p/w','150 p/w','200 p/w','250 p/w','300 p/w','350 p/w','400 p/w','450 p/w','500 p/w','550 p/w','600 p/w','700 p/w','800 p/w','900 p/w','1000 p/w','1200 p/w','1500 p/w');
		options = '<option value="0">Minimum</option>';
   		for (i = 0; i < rents.length; i++) options += '<option value="' + rents[i] + '">' + rents[i] + '</option>';
   		$("select#min").html(options);
		options = '<option value="0">Maximum</option>';
   		for (i = 0; i < rents.length; i++) options += '<option value="' + rents[i] + '">' + rents[i] + '</option>';
   		$("select#max").html(options);
   		$("tr.leasing").show();
   		$("tr.buying").hide();
    });
 });

 $(document).ready(function() {
   $("li.buying").click(function() {
		var prices = new Array('100K','150K','200K','250K','300K','350K','400K','450K','500K','550K','600K','650K','700K','750K','800K','850K','900K','1.0M','1.1M','1.2M','1.3M','1.4M','1.5M','1.6M','1.7M','1.8M','1.9M','2.0M','2.25M','2.5M','2.75M','3.0M','3.25M','3.5M','3.75M','4.0M');
		options = '<option value="0">Minimum</option>';
   		for (i = 0; i < prices.length; i++) options += '<option value="' + prices[i] + '">' + prices[i] + '</option>';
   		$("select#min").html(options);
		options = '<option value="0">Maximum</option>';
   		for (i = 0; i < prices.length; i++) options += '<option value="' + prices[i] + '">' + prices[i] + '</option>';
   		$("select#max").html(options);
		$("li.renting a").removeClass("selected");
		$("li.buying a").addClass("selected");
		$("input#hidden").val("S");
		$(".hol").hide();		
		$(".fur").hide();		
		$(".lan").show();	
   });
   $("li.renting").click(function() {
		var rents = new Array('100 p/w','150 p/w','200 p/w','250 p/w','300 p/w','350 p/w','400 p/w','450 p/w','500 p/w','550 p/w','600 p/w','700 p/w','800 p/w','900 p/w','1000 p/w','1200 p/w','1500 p/w');
		options = '<option value="0">Minimum</option>';
   		for (i = 0; i < rents.length; i++) options += '<option value="' + rents[i] + '">' + rents[i] + '</option>';
   		$("select#min").html(options);
		options = '<option value="0">Maximum</option>';
   		for (i = 0; i < rents.length; i++) options += '<option value="' + rents[i] + '">' + rents[i] + '</option>';
   		$("select#max").html(options);
		$("li.buying a").removeClass("selected");
		$("li.renting a").addClass("selected");
		$("input#hidden").val("L");	
		$(".hol").show();
		$(".fur").show();
		$(".lan").hide();		
   });
 });
