
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()
  {
	pr = document.getElementById('searchform').propertytype;
    
    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 £'+addCommas(ps[0])+pcm,1);
    for (i=2;i<(ps.length+1);i++)
      {
        pr.options[i] = new Option('£'+addCommas(ps[i-2])+'-£'+addCommas(ps[i-1])+pcm,i);
      }
    pr.options[i] = new Option('Above £'+addCommas(ps[i-2])+pcm,i);
    pr.selectedIndex = 0;
    return true;
  }
  
  function newpopulatepricerange()
  {
    
    pr = document.getElementById('searchform').propertytype;
    
   	// alert( pr.options.length);

    return true;
  }
  
function minfillItems(intStart) {
    
   // alert('here');
    
    var fTypes = document.searchform.salestype;
    var fItems = document.searchform.minprice;
    var a = minarItems;
    var b, c, d, intItem, intType

    if ( intStart > 0 ) {
        for ( b = 0; b < a.length; b++ ) {
            if ( a[b][1] == intStart )
                intType = a[b][0];
        }

        for ( c = 0; c < fTypes.length; c++ ) {
            if ( fTypes.options[ c ].value == intType )
                fTypes.selectedIndex = c;
        }
    }

    if ( intType == null )
        intType = fTypes.options[ fTypes.selectedIndex ].value;

    fItems.options.length = 0;

    for ( d = 0; d < a.length; d++ ) {
        if ( a[d][0] == intType )
            fItems.options[ fItems.options.length ] = new Option( a[d][2], a[d][1] );

        if ( a[d][1] == intStart )
            fItems.selectedIndex = fItems.options.length - 1;
    }
}

function fillItems(intStart) {
    
   // alert('here');
    
    var fTypes = document.searchform.salestype;
    var fItems = document.searchform.maxprice;
    var a = arItems;
    var b, c, d, intItem, intType

    if ( intStart > 0 ) {
        for ( b = 0; b < a.length; b++ ) {
            if ( a[b][1] == intStart )
                intType = a[b][0];
        }

        for ( c = 0; c < fTypes.length; c++ ) {
            if ( fTypes.options[ c ].value == intType )
                fTypes.selectedIndex = c;
        }
    }

    if ( intType == null )
        intType = fTypes.options[ fTypes.selectedIndex ].value;

    fItems.options.length = 0;

    for ( d = 0; d < a.length; d++ ) {
        if ( a[d][0] == intType )
            fItems.options[ fItems.options.length ] = new Option( a[d][2], a[d][1] );

        if ( a[d][1] == intStart )
            fItems.selectedIndex = fItems.options.length - 1;
    }
}
