function SlideShow(page){
	var w = window.open (page,"SlideShow","width=780,height=780,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}
function FloorPlans(page){
	var w = window.open (page,"SlideShow","width=780,height=780,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=1,toolbar=0");
	w.focus();
}
function PrintView(page)
{
	var w = window.open (page,"PrintBrochure","width=780,height=900,location=0,menubar=1,resizable=0,scrollbars=1,status=0,titlebar=1,toolbar=1");
	w.focus();
}
function EmailFriend(page){
	var w = window.open (page,"new_window","width=460,height=470,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}
function ContactAgent(page){
	var w = window.open (page,"new_window","width=455,height=470,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}
function ShowHits(page){
	var w = window.open (page,"ShowHits","width=200,height=124,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}
var charStartPositions = new Array;

// *** SEARCHES

function ClearFilterBox() {
	document.Form1.SuburbFilter.value = '';
}

function RemoveSelects() {
        for (; document.Form1.SuburbName.selectedIndex != -1;) {
	        document.Form1.SuburbName.options[document.Form1.SuburbName.selectedIndex].selected = false;
        }
}
function validatePID()
{
    if (document.GoToProperty.Pid.value == "")
    {
          alert('Please specify a PID value!');
          document.GoToProperty.Pid.focus();
    }
    else
    {
         if (IsNumeric(document.GoToProperty.Pid.value))
         {
                OpenDetails('Search/Details.asp?Pid=' + document.GoToProperty.Pid.value + '&Website=iproperty.com.au');
         }  
         else
         {
                alert('PID must be numeric!');
                document.GoToProperty.Pid.focus();
                document.GoToProperty.Pid.select();
         }
    }
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
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 fillSuburbFilter(selectedValue)
{
    if (selectedValue != '(Any)' && selectedValue != '(ANY)')
   {
         document.Form1.SuburbFilter.value = selectedValue;
   }
   else
         document.Form1.SuburbFilter.value = "";
}
function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }

function changeState(formName)
{
   var selectedState = eval("document." + formName + ".State.value");
   var locationString = document.location.href;
   
   if (locationString.indexOf("State") == -1)
       document.location = document.location + "?&State=" + selectedState;
   else
   {
       var pos = locationString.indexOf("State");
       var newLocationString = Mid(locationString,0, locationString.length-(locationString.length-pos)-1);
       newLocationString = newLocationString + "&State=" + selectedState;
       document.location =  newLocationString ;
   }
}



function ValSearch2() {
    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;
        }
        action ="soldproperties.aspx";
        submit();
        return false;
    }
}


function save() {
    with(document.Form1) {
        action = "savesearch.aspx";
        submit();
        return false;
    }
}

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 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;
}

//###### ajax stuffs			
function jax(url,target) {
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = '<div align=center><img src=images/ajax-loader.gif align=absmiddle> refreshing...</div>';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jaxDone(target);};
        req.open("POST", url, true);
	//req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
     //req.setRequestHeader('Content-length', '0');
        req.send(''); // hanve to send somthing (not null) or would get error 411 Leng-Required
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jaxDone(target);};
            req.open("POST", url, true);
            req.send();
        }
    }
}    

function jaxDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML="jax error:\n" +
                req.statusText + "..." + req.status;
        }
    }
}



