// V1
function OpenEmailFriend(page, isfocus) 
{
	var w = window.open(page,"EmailAFriend","width=440,height=370,location=0,menubar=0,resizable=0,scrollbars=0,status=1,titlebar=0,toolbar=0,top=20,left=20");	
}
function OpenMyProps(page, isfocus) {
	var w = window.open(page,"OpenMyProps","width=630,height=350,location=0,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=0,toolbar=0,top=20,left=20");
	if(isfocus)
		w.focus();
	else {
		w.blur();
		var mw = window.open("/ShortList/AddingMsg.asp","mw","width=50,height=25,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=10,top=10");
		mw.focus();
	}
}

function isInt(string) {
	if (string.length == 0) {
		return false;
	}
    	for (var i=0;i < string.length;i++) {
        	if ((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9')) {
            		return false;
               	}
    	}
    	return true;
}

function trim(strText) {
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function goNowBackend(url) {
	if (url.length > 1)
		location.href = url;
}

function AddtoPage(page){
	var w = window.open (page,"new_window","width=235,height=80,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function OpenDetails(url){
	var w = 0;
	var h = 0;
        if(screen.width >= 1024) {
			w = 700;
			h = 550;
        } else {
			w = 690;
			h = 430;
        }
	var w = window.open (url, "PropDetails", "top=10,left=10,width=" + w + ",height=" + h + ",location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=0,toolbar=0");
	w.focus();
}

function SlideShow(page){
	var w = window.open (page,"SlideShow","width=620,height=520,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=450,height=365,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function EmailFriend(page){
	var w = window.open (page,"new_window","width=358,height=354,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function InspectionTime(page){
	var w = window.open (page,"new_window","width=400,height=230,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function ShowImage(page){
	var w = window.open (page,"new_window","width=600,height=350,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function ShowFloorplan(page){
	var w = window.open (page,"new_window","width=600,height=450,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function ShowHits(page){
	var w = window.open (page,"new_window","width=200,height=124,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function ShowVR(page){
	var w = window.open (page,"new_window","width=640,height=430,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,top=15,left=15");
	w.focus();
}

function ShowIVR(page){
	var w = window.open (page,"new_window","width=572,height=484,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
	w.focus();
}

function ShowPIX(page){
		var w = window.open (page,"new_window","width=572,height=484,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0");
		w.focus();
}

function OpenLargeImage(url, pid, qs) {
	var w = window.open('Details_ShowLargeImage.asp?Image=' + url + '&' + qs, "OpenLargeImage","width=700,height=580,scrollbars=1,resizable=1,left=10,top=10");
}

// ** End V1


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

// *** Quick Search

function goqs() {
	with(document.QuickSearch) {
		action = thisPage.value;
		submit();
	}
	return false;
}

function startqs() {

	with(document.QuickSearch) {
		var lowPrice = trim(qs_LowPrice.value);
		var highPrice = trim(qs_HighPrice.value);

		if(lowPrice.length < 1)
			lowPrice = "0";

		if(highPrice.length < 1)
			highPrice = "99000000";

   		if(!isInt(lowPrice)) {
			alert('\'Low Price\' in price range can only be a whole number (integer)');
			qs_LowPrice.focus();
			return false;
		}

   		if(!isInt(highPrice)) {
			alert('\'High Price\' in price range can only be a whole number (integer)');
			qs_HighPrice.focus();
			return false;
		}

		if(parseInt(lowPrice) >= parseInt(highPrice)) {
			alert('\'High Price\' cannot be equal to or lesser than \'Low Price\'');
			qs_HighPrice.focus();
			return false;
		}

		var state1 = qs_State.options[qs_State.selectedIndex].value;
		var cat = qs_Category.options[qs_Category.selectedIndex].value;

		var suburbs = "";
		var styles = "";

		for(var i = 0; i < qs_Suburb.options.length; i++) {
		if(qs_Suburb.options[i].selected) {
			if(suburbs.length < 1)
				suburbs = qs_Suburb.options[i].value;
			else
				suburbs += "," + qs_Suburb.options[i].value;
			}
		}

		for(var i = 0; i < qs_Type.options.length; i++) {
		if(qs_Type.options[i].selected) {
			if(styles.length < 1)
				styles = qs_Type.options[i].value;
			else
				styles += "," + qs_Type.options[i].value;
			}
		}
		
		location.href = '/Content/Results.aspx?Page=1&state=' + state1 + '&catagory=' + cat + '&tab=' + (parseInt(cat) - 1) + '&LowPrice=' + lowPrice + '&HighPrice=' + highPrice + '&SuburbName=' + suburbs + '&Style=' + styles + '&PostCode=&Bedroom=20&Sortby=Property_Registration+Desc&Surrounding=0&Records=10&isqs=1';
	}
	return false;
}

function clear_price() {
	with(document.QuickSearch) {
		clearprice.checked = false;
                if(qs_LowPrice.value.length < 1 && qs_HighPrice.value.length < 1) {
                	alert('\'$ Range\' is already blank');
                	return false;
                }
		qs_LowPrice.value = "";
                qs_HighPrice.value = "";
	}
	return false;
}

// ***

// *** HierMenus

if(window.event + "" == "undefined") event = null;

function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};

popUp =		HM_f_PopUp;
popDown =	HM_f_PopDown;

HM_DOM =	(document.getElementById) ? true : false;
HM_NS4 =	(document.layers) ? true : false;
HM_IE =		(document.all) ? true : false;
HM_IE4 =	HM_IE && !HM_DOM;
HM_Mac =	(navigator.appVersion.indexOf("Mac") != -1);
MM_IE4M =	HM_IE4 && HM_Mac;

if(!HM_IE4) {
	HM_IsMenu =	(HM_DOM || HM_NS4 || (HM_IE4 && !HM_IE4M));
}
else
{
	HM_IsMenu =	true;
}

HM_BrowserString =	HM_NS4 ? "NS4" : HM_DOM ? "DOM" : "IE4";
Browser =			HM_NS4 ? "NS4" : "DOM";

// Hide Form Elements
function hideText() {
	MM_showHideLayers('textDiv','','hide');
}

// Show Form Elements
function showText() {
	MM_showHideLayers('textDiv','','show');
}

// ***

var isNetscape4 = (document.layers) ? 1:0;
var charStartPositions = new Array;


// *** SEARCHES

function RefreshSuburbs() {
        document.Search.SuburbFilter.value = document.Search.SuburbFilter.value.toUpperCase();

        var entry = document.Search.SuburbFilter.value;
        var first = entry.charCodeAt(0) - 65;

        RemoveSelects();

        if (entry.length == 0) {
        	document.Search.SuburbName.options[0].selected = true;
        } else if (charStartPositions[first] > 0) {
        	var stop = charStartPositions[first+1];

                for (var i = first + 2; stop < 0; ++i) {
			stop = charStartPositions[i];
                }
                for (var i = charStartPositions[first]; i < stop; ++i) {
                        if (document.Search.SuburbName.options[i].text.indexOf(entry,0) == 0) {
                                document.Search.SuburbName.options[i].selected = true;
                                document.Search.SuburbName.options[0].selected = false;
                                break;
                        }
                }
        }
}


function ClearFilterBox() {
	document.Search.SuburbFilter.value = '';
}

function RemoveSelects() {
        for (; document.Search.SuburbName.selectedIndex != -1;) {
	        document.Search.SuburbName.options[document.Search.SuburbName.selectedIndex].selected = false;
        }
}

// Be add
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.Main.SuburbFilter.value = selectedValue;
   }
   else
         document.Main.SuburbFilter.value = "";
}

// ***