// alert('priceranges loaded');

function addCommas(nStr)
  {
  	nStr += '';
  	x = nStr.split('.');
  	x1 = x[0];
  	x2 = x.length > 1 ? '.' + x[1] : '';
  	var rgx = /(\d+)(\d{3})/;
  	while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2');	}
  	return x1 + x2;
  }

function populatepricerange(stype)
  {
    alert(stype);
    
    pr = document.getElementById('propertysearchform').maxprice;
    ps = p[(stype-1)].split('|');
    pcm = (stype==2)?'pcm':'';
    pr.options.length = 0;
    pr.options[0] = new Option('Select price range',0);
    pr.options[1] = new Option('Below &pound;'+addCommas(ps[0])+pcm,1);
    for (i=2;i<(ps.length+1);i++)
      {
        pr.options[i] = new Option('&pound;'+addCommas(ps[i-2])+'-&pound;'+addCommas(ps[i-1])+pcm,i);
      }
    pr.options[i] = new Option('Above &pound;'+addCommas(ps[i-2])+pcm,i);
    pr.selectedIndex = 0;
    return true;
  }
  
//<![CDATA[ 
// array of possible prices in the same order as they appear in the price selection list 

var priceListsText = new Array(3) 
priceListsText[0] = ["Max Price", "50,000", '100,000', '125,000', '150,000', '200,000', '250,000', '300,000', '350,000', '400,000', '450,000', '500,000', '1,000,000']; 

priceListsText[1] = ["Max Price ","50,000", '100,000', '125,000', '150,000', '200,000', '250,000', '300,000', '350,000', '400,000', '450,000', '500,000', '1,000,000']; 
priceListsText[2] = ["Max Price ",'250 pcm', '350 pcm', '450 pcm', '550 pcm', '650 pcm', '750 pcm', '850 pcm', '950 pcm', '1,050 pcm', '1,150 pcm', '1,250 pcm', '1,500+ pcm']; 

var priceLists = new Array(3) 
priceLists[0] = ['50000', '100000', '125000', '150000', '200000', '250000', '300000', '350000', '400000', '450000', '500000', '1000000']; 
priceLists[1] = ['50000', '100000', '125000', '150000', '200000', '250000', '300000', '350000', '400000', '450000', '500000', '1000000']; 
priceLists[2] = ['250', '350', '450', '550', '650', '750', '850', '950', '1050', '1150', '1250', '1500+']; 

/* doPriceChange() is called from the onchange event of a select element. 
* param selectObj - the select object which fired the on change event. 
*/ 
function doPriceChange (selectObj) { 
		
	// get the index of the selected option 
	var idx = selectObj.selectedIndex; 
	
	// alert('here ' + idx );
	
	// get the value of the selected option 
	var which = selectObj.options[idx].value; 
	// use the selected option value to retrieve the list of items from the countryLists array 
	cList = priceLists[which]; 
	cListText = priceListsText[which]; 
	
	// get the country select element via its known id 
	var cSelect = document.getElementById("maxprice"); 
	// remove the current options from the maxprice select 
	var len=cSelect.options.length; 
	while (cSelect.options.length > 0) { 
		cSelect.remove(0); 
	} 
	
	var newOption; 
	// create new options 
	for (var i=0; i<=cList.length; i++) { 
		newOption = document.createElement("option"); 
		newOption.value = cList[i];  // assumes option string and value are the same 
		newOption.text=cListText[i]; 
		// add the new option 
		try { 
			cSelect.add(newOption);  // this will fail in DOM browsers but is needed for IE 
		} 
		catch (e) { 
			cSelect.appendChild(newOption); 
		} 
	} 
	
	cSelect.selectedIndex = ( cList.length  );
} 
