﻿
function Repop(category) 
{
document.form1.HighPrice.length = document.form1.LowPrice.length+1;
//alert(document.form1.HighPrice.length);
for (var i = 0; i < document.form1.LowPrice.length; ++i) 
	{
	//alert(document.form1.LowPrice.options[1].value);
	document.form1.HighPrice.options[i].value = document.form1.LowPrice.options[i].value;
    document.form1.HighPrice.options[i].text = document.form1.LowPrice.options[i].text;	
	}
	//i++;
	if (category = 1)
	{
	document.form1.HighPrice.options[i].value = 10000000;
    document.form1.HighPrice.options[i].text = "10.0M";	
	document.form1.HighPrice.options[0].selected= true;
	}
	else if (category = 2)
	{
	document.form1.HighPrice.options[i].value = 10000;
    document.form1.HighPrice.options[i].text = "10000pw";	
	document.form1.HighPrice.options[0].selected= true;
	}
	else
	{
	document.form1.HighPrice.options[i].value = 10000000;
    document.form1.HighPrice.options[i].text = "10.0M";	
	document.form1.HighPrice.options[0].selected= true;
	}
	var k=0;
	var val=document.form1.LowPrice.options[document.form1.LowPrice.selectedIndex].value;	
	//alert(val);
	for (var i = 0; i < document.form1.HighPrice.length; i++) 
	{
        if (parseInt(document.form1.HighPrice.options[i].value) > parseInt(val)) 
        {       
				//alert(document.form1.HighPrice.options[i].value + ' ' + i);     
                document.form1.HighPrice.options[k].value = document.form1.HighPrice.options[i].value;
                document.form1.HighPrice.options[k].text = document.form1.HighPrice.options[i].text;
                k++;
                
                      
        }
        
    }
    document.form1.HighPrice.length = k;
}

function autoComplete (field, select, property, forcematch) {
	var found = false;
	for (var i = 0; i < select.options.length; i++) {
	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
		found=true; break;
		}
	}
	if (found) { select.selectedIndex = i; }
	else { select.selectedIndex = -1; }
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
			}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}
	}
	
function ClearFilterBox() {
	document.form1.SuburbFilter.value = '';
}

function LimitSelectBox() {
	var max = 10;
    var curr = 0;
    for (var i = 0; i < document.form1.SuburbName.length; ++i) {
        if (document.form1.SuburbName.options[i].selected) {
            if (++curr > max) {
                document.form1.SuburbName.options[i].selected = false;
            }
        }
    }
    if (curr > max) {
		toomany = curr-max;
        alert('You have selected '+toomany+' too many suburbs... Selecting top '+max+'.');
    }
}

function ValSearch() {
    with(document.form1) {
        if(parseInt(LowPrice.value) > parseInt(HighPrice.value)) {
        	alert("Price Range Error: FROM price cannot be greater than TO price");
        	LowPrice.focus();
        	return false;
        }
        if(parseInt(LowPrice.value) == parseInt(HighPrice.value)) {
        	alert("Price Range Error: FROM price cannot equal the TO price");
        	HighPrice.focus();
        	return false;
        }
        if(SuburbName.value.length < 1) {
			alert("At least one suburb must be selected");
			return false;
        }
        //form1.PID.value = "";
        action = "results.aspx";
        submit();
        return false;
    }
}

