
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('minfillItems ' + intStart);
         
  	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;
        }
    }   
    
     return true;

}
 
function newfillItems(newintStart) {
        
    // alert('newfillItems ' + newintStart);
    
    var fTypes = document.searchform.salestype;
    var fItems = document.searchform.minprice;
    var a = minarItems;
    var b, c, d, intItem, intType

	var newfTypes = document.searchform.salestype;
    var newfItems = document.searchform.maxprice;
    var newa = arItems;
    var newb, newc, newd, newintItem, newintType

    if ( newintStart > 0 ) {
        for ( newb = 0; newb < newa.length; newb++ ) {
            if ( newa[newb][1] == newintStart )
                newintType = newa[newb][0];
        }

        for ( newc = 0; newc < newfTypes.length; newc++ ) {
            if ( newfTypes.options[ newc ].value == newintType )
                newfTypes.selectedIndex = newc;
        }
    }

    if ( newintType == null ) {
        newintType = newfTypes.options[ newfTypes.selectedIndex ].value;
        
        //alert(newintType);
	}
	
    // alert(newfItems.options.length);
    
    newfItems.options.length = 0;

	// alert(newa.length);
   
   for ( newd = 0; newd < newa.length; newd++ ) {
      	// alert(newa[newd][0] + ' ' + newintType);
        
        if ( newa[newd][0] == newintType ) {
            newfItems.options[ newfItems.options.length ] = new Option( newa[newd][2], newa[newd][1] );
         }
         
        // alert( newa[newd][1] + ' ' + newintStart);
        if ( newa[newd][1] == newintStart ) {
            // alert(newfItems.name);
            
            newfItems.selectedIndex = newfItems.options.length - 1;
	    }
    }  
   
 }
 
 function fillItems(intStart) {
        
    // alert('fillItems ' + intStart);
    
    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;

    // alert(intType);
    
    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;
    }
  
 }
