function searchPriceCriteria() 
{
	var saleCheck    = document.getElementById('Search_Sale');
	var rentalCheck  = document.getElementById('Search_Rental');
	var rentalShortCheck  = document.getElementById('Search_Rental_Short');
	var priceFromObj = document.getElementById('priceFrom');
	var priceToObj   = document.getElementById('priceTo');
	
	var rentalShortPrices = new Array();
	rentalShortPrices[1] = 'R100';
	rentalShortPrices[2] = 'R200';
	rentalShortPrices[3] = 'R300';
	rentalShortPrices[4] = 'R400';
	rentalShortPrices[5] = 'R500';
	rentalShortPrices[6] = 'R600';
	rentalShortPrices[7] = 'R800';
	rentalShortPrices[8] = 'R1,000';
	rentalShortPrices[8] = 'R2,000';
	rentalShortPrices[8] = 'R4,000';
	rentalShortPrices[8] = 'R6,000';
	rentalShortPrices[8] = 'R8,000';
	rentalShortPrices[8] = 'R10,000';

	var rentalPrices = new Array();
	rentalPrices[1] = 'R2,050';
	rentalPrices[2] = 'R3,000';
	rentalPrices[3] = 'R4,000';
	rentalPrices[4] = 'R5,000';
	rentalPrices[5] = 'R6,000';
	rentalPrices[6] = 'R7,000';
	rentalPrices[7] = 'R8,000';
	rentalPrices[8] = 'R10,500';

	var salePrices = new Array();
	salePrices[1] = 'R250,000';
	salePrices[2] = 'R500,000';
	salePrices[3] = 'R750,000';
	salePrices[4] = 'R1,000,000';
	salePrices[5] = 'R1,500,000';
	salePrices[6] = 'R2,000,000';
	salePrices[7] = 'R3,000,000';
	salePrices[8] = 'R4,000,000';
	salePrices[9] = 'R5,000,000';
	salePrices[10] = 'R6,000,000';
	salePrices[11] = 'R8,000,000';
	salePrices[12] = 'R10,000,000';
	
	
	for (count = priceFromObj.options.length - 1; count >= 0; count--)
	{
		priceFromObj.options[count] = null;	
	}
	for (count = priceToObj.options.length - 1; count >= 0; count--)
	{
		priceToObj.options[count] = null;	
	}
	
	priceFromObj.options[0]       = new Option('Price From');
	priceFromObj.options[0].value = -1;
	
	priceToObj.options[0]       = new Option('Price To');
	priceToObj.options[0].value = -1;
	
	if (rentalCheck.checked && !saleCheck.checked) 
	{
		document.search_price.search_type.value = rentalCheck.value;
		for (loopcount = 0; loopcount < 2; loopcount++)
		{
			tempObj = (loopcount == 0)? priceFromObj : priceToObj ;
			var count = 1;
			while ( count < rentalPrices.length ) 
			{									
				tempObj[count]       = new Option(rentalPrices[count]);				
				tempObj[count].value = rentalPrices[count].replace('R','');	
				tempObj[count].value = tempObj[count].value.replace(',','');		
				count++
			}
			
			if (loopcount == 0) 
			{
				tempObj[count]       = new Option('Any');				
				tempObj[count].value = "any";				
			}
			else
			{
				tempObj[count]       = new Option('R10,000 +');				
				tempObj[count].value = "max";				
			}	
			
		}			
	}
	else if (rentalShortCheck.checked){
	  document.search_price.search_type.value = rentalShortCheck.value;
		for (loopcount = 0; loopcount < 2; loopcount++)
		{
			tempObj = (loopcount == 0)? priceFromObj : priceToObj ;
			var count = 1;
			while ( count < rentalShortPrices.length ) 
			{									
				tempObj[count]       = new Option(rentalShortPrices[count]);				
				tempObj[count].value = rentalShortPrices[count].replace('R','');	
				tempObj[count].value = tempObj[count].value.replace(',','');		
				count++
			}
			
			if (loopcount == 0) 
			{
				tempObj[count]       = new Option('Any');				
				tempObj[count].value = "any";				
			}
			else
			{
				tempObj[count]       = new Option('R10,000 +');				
				tempObj[count].value = "max";				
			}	
		}			
	}
	else
	{
		document.search_price.search_type.value = saleCheck.value;
		for (loopcount = 0; loopcount < 2; loopcount++)
		{
			tempObj = (loopcount == 0)? priceFromObj : priceToObj ;
			var count = 1;
			while ( count < salePrices.length ) 
			{				
				tempObj[count]       = new Option(salePrices[count]);				
				tempObj[count].value = salePrices[count].replace('R','');		
				tempObj[count].value = tempObj[count].value.replace(',','');
				// Hack to remove additional commas.  The previous line only removes 1 comma, but repeating this replace removes the second.
				// without this the values with 2 commas will cause validation problems.	
				tempObj[count].value = tempObj[count].value.replace(',','');		
				count++
			}
			
			if (loopcount == 0) 
			{
				tempObj[count]       = new Option('Any');				
				tempObj[count].value = "any";				
			}
			else
			{
				tempObj[count]       = new Option('R10,000,000 +');				
				tempObj[count].value = "max";				
			}				
		}
	}	
}	

function reloadPage(province_id, zone_type)
{ 
	var priceFrom = document.search_price.priceFrom[document.search_price.priceFrom.selectedIndex].value;
	var priceTo = document.search_price.priceTo[document.search_price.priceTo.selectedIndex].value;
	var search_type = document.search_price.search_type.value;
	var saletype = document.search_price.search_type.value;
	var from_index = document.search_price.priceFrom.selectedIndex
	var to_index = document.search_price.priceTo.selectedIndex
	
	document.search_price.from_index.value=document.search_price.priceFrom.selectedIndex;
	document.search_price.to_index.value=document.search_price.priceTo.selectedIndex;
	
  window.location.href = "search.php?search=go&province_options=" + province_id + "&zone_options=" + zone_type + "&search_type=" + search_type + "&saletype=" + saletype + "&priceFrom=" + priceFrom + "&from_index=" + from_index + "&priceTo=" + priceTo + "&to_index=" + to_index + "&button=Search";
}
function transferSelection(){
if(document.search_price.from_index.value > 0){
	document.search_price.priceFrom.selectedIndex = document.search_price.from_index.value;
	document.search_price.from_index.value = "";
}
if(document.search_price.to_index.value > 0){
  document.search_price.priceTo.selectedIndex = document.search_price.to_index.value;
  document.search_price.to_index.value = "";
}
}

function validateForm(){
 // Verify user has selected a province
 if(document.search_price.province_options.value ==""){
  	alert('Please select a province');
  	return false;
  }
  
  // verify user has selected a price from and price to options
  if(document.search_price.priceFrom.value == "-1" || document.search_price.priceTo.value == "-1"){
  	alert('Please select a price range');
  	return false;
  }
  	
  // verify user hasn't selected max value as an option.  If not then verify amounts are correct.
  if(document.search_price.priceTo.value != "max"){
    if(parseInt(document.search_price.priceTo.value) <= parseInt(document.search_price.priceFrom.value)){
      alert('price to ' + parseInt(document.search_price.priceTo.value));
      alert('price from ' + parseInt(document.search_price.priceFrom.value));
      alert('To Price Should be Larger than From Price');
      document.search_price.priceTo.value="-1";
      return false;
    }
  }
}
