var LoadPic4Src="/bin/wd.gif";
var LastSubsearch = null;
var s1cNameDef = "";
var s1cPhDefault = "";
var s1cEmailDefault = "";
var s1cSendContactDetails = "";

var objtopop = null;

function checkEnter(e){ 

	var characterCode ;
	if(e && e.which){ 
		e = e;
		characterCode = e.which;
	}else{
		e = event;
		characterCode = e.keyCode; 
	}

	if(characterCode == 13){ 
		return true;
	}
	return false;
}


function TickAll(){
	for( i=0; i<document.Availability.length; i ++){
		if ((document.Availability[i].type == "checkbox") && (document.Availability[i].checked == false)){
			document.Availability[i].checked = true;
		}
	}
}

function UnTickAll(){
	for( i = 0; i<document.Availability.length; i ++){
		if ((document.Availability[i].type == "checkbox") && (document.Availability[i].checked == true)){
			document.Availability[i].checked = false;
		}
	}
}

function CheckAll(){
	for( i=0; i<document.RelSubSel.length; i ++){
		if ((document.RelSubSel[i].type == "checkbox") && (document.RelSubSel[i].checked == false)){
			document.RelSubSel[i].checked = true;
		}
	}
}

function UnCheckAll(){
	for( i = 0; i<document.RelSubSel.length; i ++){
		if ((document.RelSubSel[i].type == "checkbox") && (document.RelSubSel[i].checked == true)){
			document.RelSubSel[i].checked = false;
		}
	}
}

function CheckOneIsTicked(TheForm, Item){

	var bTicked = false;
	for( i = 0; i < TheForm.length; i ++){
		if ((TheForm[i].type == "checkbox") && (TheForm[i].checked == true)){
			bTicked = true;
		}
	 }
	if (!bTicked){
	 	alert("Please select at least one " + Item);
	 	return false;
	}else{
		return true;
	}
}


function CheckSubEntered(TheForm){
	var rv = false;
	var SubValue = TheForm.SUBURB_NAME.value;
	if ((SubValue != null) && (SubValue != '') && (SubValue != 'Enter Suburb Name') && (SubValue != 'enter suburb names, comma separated') 
	){
		rv = true;
	}else{
		alert("Please Enter the Suburb You Wish to Search");
	}
	return rv;
}

function CheckSHSelected(SelectedValue){
	var SelecInd = SelectedValue.searchhist.selectedIndex;
	var SelValue = SelectedValue.searchhist[SelecInd].value;
	if ((SelecInd != null) & (SelecInd != '') || (SelecInd > 0)){	
		return true;
	}else{
		alert("Please Select a Search from the Search History Dropdown List. \n\n Note that to use the Search History facility, you need to have cookies enabled\n and you must have performed at least one search on g.");
		return false;

	}

}

function ClearVal(textfield){
	if ((textfield != null) && (textfield.value != null) && (textfield.value != '') ){
		if ((textfield.value == ' Suburb Name OR g Ref. #') || (textfield.value == 'Enter Suburb Name') || (textfield.value == 'enter suburb names, comma separated')){
			textfield.value = '';
		}
	}
}

function SearchSubInitiate(evt){

	var code = null;
	var targ = null;

	if(evt.keyCode) {
		code = evt.keyCode;
	} else if (evt.which){
		code = evt.which;
	}else{
		code = null;
	}

	if ((code != null) && (code == '13')){

		if (evt.target){
			targ = evt.target;
		}else if (evt.srcElement){ 
			targ = evt.srcElement;
		}else{
			targ = null;
		}

		if ((targ != null) && (targ.name != null) &&(targ.name == 'FindSub')){
			SearchSub();
			return false;
		}
	}else{
		return true;
	}

}

function GetSelectedSubs(){
return true;
}

function pic_popup(ThePageWithPhotId) {
	
	var obj_calwindow = window.open(ThePageWithPhotId, 'STR', 'toolbar=no,statusbar=no,location=no,resizable=yes,dependent=yes,scrollbars=yes');
	obj_calwindow.opener = window;
	obj_calwindow.resizeTo(600,600);
	obj_calwindow.focus();
}

function house_popup(ThePageWithPhotId) {
	
	var obj_calwindow = window.open(ThePageWithPhotId, 'STR', 'toolbar=yes,statusbar=no,location=yes,resizable=yes,dependent=yes,scrollbars=yes');
	obj_calwindow.opener = window;
	obj_calwindow.resizeTo(790,590);
	obj_calwindow.focus();
}

function the_gallery(PropGall) {
	
	var obj_calwindow = window.open(PropGall, 'STR','toolbar=no,statusbar=yes,resizable=yes,dependent=yes,scrollbars=yes');
	obj_calwindow.opener = window;
	obj_calwindow.resizeTo(600,700);
	obj_calwindow.focus();
}



function LaunchNewWindow(URLtoGo, wd, ht) {  
	var newWin = null;
	var proprietes = "width="+wd+",height="+ht+",resizable,scrollbars,status=yes,toolbar=yes,titlebar=yes,menubar=yes";
	newWin = window.open(URLtoGo, "", proprietes);
	window.status="Loaded";
}


function CheckProvinceIsSelected(){
	return true;
}


function CheckOneIsSelected(){
	var SuburbSelect = document.forms.Availability.suburbsel;
	if (CheckOneIsTicked(document.forms.Availability, 'Property Type')){
		if (CheckProvinceIsSelected()){
			if (SuburbSelect.length > 0){
				if (	(SuburbSelect.options[0].value != null) && (SuburbSelect.options[0].value != '')	){
					if (CheckMaxPriceEntered()){SelectAllSubs();return true;}
				}else{alert("Please select at least one suburb.");}
			}else{alert("Please select at least one suburb.");}
		}
	}
	return false;
}

function CheckMaxPriceEntered()
{
	return true;
}




function SuburbSelected(){

	var SelecInd = document.forms.Availability.suburb.selectedIndex;
	var SubSelect = document.forms.Availability.suburb;
	var SubSelectedValue = SubSelect.options[SelecInd].value;
	var SubSelectedName = SubSelect.options[SelecInd].text;
	var SubSelList = document.forms.Availability.suburbsel;

	if ((SubSelList.options[0] != null)&& (SubSelList.options[0].value != "undefined")
		&&(SubSelList.options[0].value == 0)
	){SubSelList.options[0] = null;}

	if ((SubSelectedValue != null) && (SubSelectedValue != "undefined") && (SubSelectedValue != '') &&
		(SubSelectedName != null) && (SubSelectedName != "undefined") && (SubSelectedName != '')
	){
		SubSelectedName = Trim(SubSelectedName.substring(0,SubSelectedName.indexOf(' [')));
		if ((SubSelList == null) || (SubSelList.length < 100)){
			
			var newOptionIndex = SubSelList.length;
			var bAlreadySelected = false;
			for (var k = 0; k < SubSelList.length; k++){
				if (SubSelList.options[k].value == SubSelectedValue){
					bAlreadySelected = true;
					break;
				}
			}
			if (! bAlreadySelected){SubSelList.options[newOptionIndex] = new Option(SubSelectedName, SubSelectedValue ,false,false);}	
		}else{
			alert("You have reached the maximum of 99 suburbs. \n \n As a result '" + SubSelectedName + "' has not been added.");
		}
	}

}

function ClearSelectedSubs(){
	var SubSelList = document.forms.Availability.suburbsel;
	var selectedIndex = SubSelList.selectedIndex;
	var bIsSelecetd = true;
	while(bIsSelecetd){
		bIsSelecetd = false;
		for (var k = 0; k < SubSelList.length; k++){
			if (SubSelList.options[k].selected == true){
				bIsSelecetd = true;
				SubSelList.options[k] = null;
			}
		}
	}
	return true;
}

function ClearAllSubs(){
	var SubSelList = document.forms.Availability.suburbsel;
	while (SubSelList.options[0] != null){
		SubSelList.options[0] = null;
	}
	return true;
}

function SelectAllSubs(){
	var SubSelList = document.forms.Availability.suburbsel;
	for (var i = 0; i < SubSelList.length; i++){
		SubSelList.options[i].selected=true;
	}
	return true;
}


function ChangePriceonStatus(){
	ChangePriceonStatusCheck(document.forms.Suburbs_Form.PROP_SEARCH_STATUS);
}
function ChangePriceonStatusCheck(PropStat) {

	var PropertyStatus = PropStat.value;
	var PriceField = document.forms.Suburbs_Form.PROP_PRICE_ENTER;
	var MinPriceField = document.forms.Suburbs_Form.PROP_PRICE_MIN;
	
	if (	(PropertyStatus != null) && (PropertyStatus != '') && (PropertyStatus != 'For Sale')
	){
		PriceField.value = 5000;
	}else{
		PriceField.value = 1000000;
	}
	MinPriceField.value = 0;
}

function UpdatePrice() {

	var PropertyStatus = document.forms.Availability.PROP_SEARCH_STATUS.value;
	var PriceField = document.forms.Availability.PROP_PRICE_ENTER;
	var MinPriceField = document.forms.Availability.PROP_PRICE_MIN;

	if (	(PropertyStatus != null) && (PropertyStatus != '') && (PropertyStatus != 'For Sale')
	){
		PriceField.value = 5000;
	}else{
		PriceField.value = 1000000;
	}
	MinPriceField.value = 0;
}


function UpdateSuburbs(){
	var ProvinceSelect = document.forms.Availability.province;
	var ProvinceSelected = ProvinceSelect.options[ProvinceSelect.selectedIndex].value;
	var AreaSelect = document.forms.Availability.suburb;
	var SubsPageToGet = "/Subs.jsp?ADD=" + ProvinceSelected + "&PID=" + SubVersionID;
	if ((ProvinceSelected != null) && (ProvinceSelected != "")	){
		AreaSelect.options[0] = new Option("Loading...");
		AreaSelect.options.length = 1; 	
		if( document.layers && document.layers['datadiv'].load ) {
			document.layers['datadiv'].load(SubsPageToGet,0);
		} else if( window.frames && window.frames.length) {
			window.frames['dataframe'].window.location.replace(SubsPageToGet);
		} else {
			alert( 'Doesn\'t work' );
		}
	}
}

function UpdateSearchHistory(cookid){

	var SearchSelect = document.forms.Availability.searchhist;
	SearchSelect.options[0] = null;
	SearchSelect.options[0] = new Option("Loading...");
	var SearchPageToGet = "/Searches.jsp?ADD=LIST&TMST=" + (new Date()).getTime();

	if( document.layers && document.layers['searchdiv'].load ) {
		document.layers['searchdiv'].load(SearchPageToGet,0);

	} else if( window.frames && window.frames.length) {
		window.frames['searchframe'].window.location.replace(SearchPageToGet);

	} else {
		SearchSelect.options[0] = null;
		SearchSelect.options[0] = new Option("Search History Not Yet Created");
	}

}


function rungping(pg,cc){

	if (cc == null){cc = '';}
	var SearchPageToGet = "/ping_g.jsp?ADD=" + pg + "&CC=" + cc + "&TMST=" + (new Date()).getTime(); 

	if( document.layers && document.layers['pingg'].load ) {
		document.layers['pingg'].load(SearchPageToGet,0);
	} else if( window.frames && window.frames.length) {
		window.frames['pingg_frame'].window.location.replace(SearchPageToGet);
	} else {
	}

}

function UpdateSearchParms(cookid){

	var SearchSelect = document.forms.Availability.searchhist;
	var SearchID = SearchSelect.options[SearchSelect.selectedIndex].value;
	var DivToUSe = 'searchdetdiv';
	var FrameToUSe = 'searchdetframe';

	if ( (SearchID == null) || (SearchID == '')	){
		SearchSelect.options[0] = new Option("Search History Not Yet Created");
	}else if ((SearchID == '0') || (SearchID == '-1')){
		//do nothing - user has selected history not available etc.
	}else{
		var SearchPageToGet = "/Searches.jsp?ADD=DET&CID=" + SearchID + "&TMST=" + (new Date()).getTime();
		if( document.layers && document.layers[DivToUSe].load ) {
			document.layers[DivToUSe].load(SearchPageToGet,0);
		} else if( window.frames && window.frames.length) {
			window.frames[FrameToUSe].window.location.replace(SearchPageToGet);
		} else {
			SearchSelect.options[0] = null;
			SearchSelect.options[0] = new Option("Search History Not Yet Created");
		}

	}

}

function RefreshSearchList(SearchArray, p_status, p_type, p_price_min, p_price, p_found, p_subs, p_beds, p_pics, p_baths, p_garages){ 

	var SearchSelect = document.forms.Availability.searchhist;
	SearchSelect.options[0] = null;
	if ((SearchArray != null) && (SearchArray.length > 0)){
		
		SearchSelect.options[0] = new Option("Select Prev. Search (Most Recent First)", "-1",false,false);
		for (var i = 0; i < SearchArray.length; i++){
			var TempStr = SearchArray[i].split("---");
			if((TempStr != null) && (TempStr.length == 2) && (TempStr[0] != null) && (TempStr[1] != null)){
				SearchSelect.options[i+1] = new Option(TempStr[1], TempStr[0],false,false);
				SearchSelect.options[i+1].className = 'suburbselect';	
			}		
		}
		if (GO('searchhistholder')){
			GO('searchhistholder').style.display = 'block';
			// repaint classbox for IE6 bug
			if (GO('classbox')){GO('classbox').style.display = 'block';}
		}
	}else{
		SearchSelect.options[0] = new Option("Search History Not Yet Created");
	}
	RefreshSearchDetail(p_status, p_type, p_price_min, p_price, p_found, p_subs, p_beds, p_pics, p_baths, p_garages);
}

function RefreshSearchDetail(p_status, p_type, p_price_min, p_price, p_found, p_subs, p_beds, p_pics, p_baths, p_garages){

	// Only Run for Detailed Search Page
	if (document.forms.Availability.PROP_PRICE_ENTER){

		if (p_price != null){document.forms.Availability.PROP_PRICE_ENTER.value = p_price;}
		if (p_beds != null){SetInd(document.forms.Availability.BEDS, p_beds);}
		if (p_baths != null){SetInd(document.forms.Availability.BATHS, p_baths);}
		if (p_garages != null){SetInd(document.forms.Availability.GARAGES, p_garages);}
		
		if (p_pics != null){SetInd(document.forms.Availability.PICS, p_pics);}
		if (p_price_min != null){document.forms.Availability.PROP_PRICE_MIN.value = p_price_min;}
		if (p_status != null){SetInd(document.forms.Availability.PROP_SEARCH_STATUS, p_status);}
		if (p_type != null){SetPropType(p_type);}
		if (p_found != null){SetInd(document.forms.Availability.PROPERTY_FOUND, p_found);}
		ClearAllSubs();
		var SubSelList = document.forms.Availability.suburbsel;
		if (p_subs != null){
			for (var i = 0; i < p_subs.length; i++){
				var TempStr = p_subs[i].split("---");
				if((TempStr != null) && (TempStr.length == 2) && (TempStr[0] != null) && (TempStr[1] != null)){
					SubSelList.options[i] = new Option(TempStr[1], TempStr[0],false,false);
					SubSelList.options[i].className = 'suburbselect';	
				}		
			}
		}
	}

}

function SetPropType(p_type){
	var TempStr = p_type.split(",");
	if((TempStr != null) && (TempStr.length > 0) ){
		if ((TempStr[0] == null) || (TempStr[0] == '') || (TempStr[0] == '-')){
			TickAll();
		}else{
			UnTickAll();
			for (var i = 0; i < TempStr.length; i++){
				if ((TempStr[i] != null) && (TempStr[i] != '')){
					var FoundTypeInd = -1;
					for(var j = 0; j < document.Availability.length; j ++){
						if ((document.Availability[j].type == "checkbox") && (document.Availability[j].name != null) && (TempStr[i] == document.Availability[j].name)){
							FoundTypeInd = j;
							break;
						}
					}
					if (j >= 0){
						document.Availability[FoundTypeInd].checked = true;
					}
				}
			}
		}
	}
}


function SetInd(sellist, value2find){
	var indexrv = 0;
	if ((value2find != null) && (value2find != '')){
		for (var i = 0; i < sellist.length; i++){
			if (sellist.options[i].value == value2find){
				indexrv = i;
				break;
			}
		}	
	}
	sellist.selectedIndex = indexrv;
}

function RefreshSubsList(SubArray){
	var ProvinceSelect = document.forms.Availability.province;
	var ProvinceSelected = ProvinceSelect.options[ProvinceSelect.selectedIndex].value;
	var AreaSelect = document.forms.Availability.suburb;	
	if ((ProvinceSelected != null) && (ProvinceSelected != "")){

		//for (var i = 0; i < SubArray.length; i++){AreaSelect.options[i+1] = new Option(SubArray[i][0]);}
		for (var i = 0; i < SubArray.length; i++){
			if (SubArray[i][0] == SubArray[i][1]){
				AreaSelect.options[i+1] = new Option(SubArray[i][0], "" ,false,false);
				AreaSelect.options[i+1].className = 'areaselect';
			}else{
				AreaSelect.options[i+1] = new Option("  " + SubArray[i][0] +"  [" + SubArray[i][1] + "]", SubArray[i][2],false,false);
				AreaSelect.options[i+1].className = 'suburbselect';
				AreaSelect.options[i+1].name = SubArray[i][0]+"  [" + SubArray[i][1] + "]";
			}
		}
		AreaSelect.options[0] = null;
	}else{
		AreaSelect.options.length = 0; 			// Clear the popup
		AreaSelect.options[0] = new Option("Select Province...");
	}
}	

function SearchSub(){
	var ProvinceSelect = document.forms.Availability.province;
	var ProvinceSelected = ProvinceSelect.options[ProvinceSelect.selectedIndex].value;
	var SearchVal = BeforeTrim(document.forms.Availability.FindSub.value);
	var AreaSelect = document.forms.Availability.suburb;
	var AreaIndex = AreaSelect.selectedIndex;
	if ((AreaIndex == null) || (AreaIndex < 0)){AreaIndex = 0;}
	if ((LastSubsearch == null) || (SearchVal == null) || (LastSubsearch != SearchVal)){
		AreaIndex = 0;
	}

	var SearchLen = SearchVal.length;
	var bFoundExpMatch = false;
	if ((ProvinceSelected != null) && (ProvinceSelected != '')){

		if (SearchLen > 0){
			LastSubsearch = SearchVal;
			for (var k = (AreaIndex + 1); k < AreaSelect.length; k++){

				if (AreaSelect.options[k].className == 'suburbselect'){
					// check for matches
					var bFoundMatch = true;
					var SuburbOption = BeforeTrim(AreaSelect.options[k].text).toLowerCase();
					SearchVal = SearchVal.toLowerCase();

					for (var i = 0; i < SearchVal.length; i++){
						if (SuburbOption.charAt(i) != SearchVal.charAt(i)){
							bFoundMatch = false;
							break;
						}
					}
					if (bFoundMatch){
						bFoundExpMatch = true;
						AreaSelect.selectedIndex = k;
						break;
					}
				}
			}
			if (!bFoundExpMatch){
				if (AreaIndex > 0){
					alert("No more matches were found.");
					AreaSelect.selectedIndex= 0;
				}else{
					alert("No matches were found.");
				}
			}
		}else{
			alert("Please enter the first few characters of the suburb.");
		}
	}else{
		alert("Please select a province.");
	}

return false;
}

function BeforeTrim(AmputeeString) {
	while (AmputeeString.substring(0,1) == ' '){
		AmputeeString = AmputeeString.substring(1, AmputeeString.length);
	}
	return AmputeeString;
}




function CheckSize(theimage, picnm){

	return CheckSize(theimage, picnm, 150, 120);
}


function CheckSize(theimage, picnm, maxwidth, maxheight){

	if ((maxheight == null) || (maxheight == 0)) {maxheight = 120;}
	if ((maxwidth == null) || (maxwidth == 0)) {maxwidth = 150;}


	var imagesrc = theimage.src;
	var origimage = new Image;
	origimage.src = imagesrc;

	var imagewidth = origimage.width;
	var imageheight = origimage.height;

	if ((imagewidth > maxwidth)||(imageheight > maxheight)){


		var heightratio = imageheight/maxheight;
		var widthratio = imagewidth/maxwidth;
	
		if (heightratio > widthratio){
			theimage.height = imageheight/heightratio;
			theimage.width =  imagewidth/heightratio;
			theimage.name =  heightratio;

		}else{
			theimage.height = imageheight/widthratio;
			theimage.width =  imagewidth/widthratio;
			theimage.name =  widthratio;
		}

		var finalimagename = theimage.name + ":" + picnm;
		theimage.name = finalimagename;
	
		var divnm = "d" + picnm.substring(1,picnm.length);

		if (document.getElementById) { //Netscape 6 & IE 5

			if ((document.getElementById(divnm) != null) && (document.getElementById(divnm).className != null)){
				document.getElementById(divnm).className = 'govisible';
			}

		}else{ //ie4

			thediv = eval('document.all.' + divnm);
			if (thediv != null){
				thediv.className = 'govisible';
			}
		}
	}else{
		//resize to it's natural size
		theimage.height = imageheight;
		theimage.width =  imagewidth;
	}

	return true;

}


function setMainPic(theimage, mainpicnm){

	if ((theimage != null) && (mainpicnm != null)){
mainpicnm.src = theimage.src;


	}



}

function FullSize(theimage, picnm){


	if ((theimage.name != null) && (theimage.name != '') ) {
			var imagenam = theimage.name;
			var Endmark = imagenam.indexOf(":");
			var aspectratio = imagenam.substring(0,Endmark);

			if (aspectratio > '1'){
				var imagewidth = theimage.width;
				var imageheight = theimage.height;

				theimage.height = imageheight*aspectratio;
				theimage.width =  imagewidth*aspectratio;
				theimage.name =  1/aspectratio + ":" + picnm;
			}

	}

	return true;

}

function SomeSize(theimage, picnm){

	var imagesrc = theimage.src;
	var origimage = new Image;
	origimage.src = imagesrc;
	theimage.width=origimage.width;
	theimage.height=origimage.height;

	return true;

}

function LoadPic(){
	if ((document.images['PreviewPic'] != null) && (document.images['PreviewPic'].src != null) && 
		(document.images['PreviewPic'].src != "/bin/na.gif") && (LoadPic4Src!="/bin/wd.gif")){
		document.images['PreviewPic'].width = 80;
		document.images['PreviewPic'].src = LoadPic4Src;
		return true;
	}

}

function NoPicFound(AnImage){

	AnImage.src = "/bin/na.gif";
	AnImage.width = 70;
	return true;
}


function BookmarkPage(url,PageTitle) { 
	if (window.external) {
			window.external.AddFavorite(url,PageTitle);
	} else { 
		alert("Please press Ctrl D"); 
	} 
	return true;
}


function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
	return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}else{
		return TRIM_VALUE;
	}
} 

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) != w_space){
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While

	return strTemp;

} 

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) != w_space){
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} 

function MM_preloadImages() { 
	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];/*alert(d.MM_p[j-1].width);*/}
	}
}

function LoadPage() {
	if (document.getElementById) {  
		document.getElementById('LoadingPage').style.visibility = 'hidden';
	}else {
		if (document.layers) {  
			document.LoadingPage.visibility = 'hidden';
		}else {  
			document.all.LoadingPage.style.visibility = 'hidden';
      	}
   	}
}

function cachedPage(FD,PD){
	var ploc = '/GoTo.jsp?ADD=g&PID=' + PD + '&FID=' + FD;
	//var ploc = '/images/page_cache/' + FD + '/' + PD + '.html';
	window.location = ploc;
}


function gopreview(GID){
var ploc = '/view-property.jsp?PID=' + GID;
window.open(ploc, '_blank', 'width=810,height=650,scrollbars,resizable');

}


function checkticker(theform){
	var refno = theform.PID.value;
	if ((refno != null) && (!isNaN(refno))){
		pingproperty(refno);
	}


}


function xmlhttpPostHideFormDiv(strURL, divid, formid, numparms, Div2Hide, TexttoHideOn) {
    var xmlHttpReq = false;
    var self = this;
    var qs = getquerystring(formid, numparms);
    
    updatepage('<image border=0px style="padding:10px;" src="/images/loading.gif">', divid);
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            var respstring = self.xmlHttpReq.responseText;
            updatepage(respstring, divid);
            if (respstring.indexOf(TexttoHideOn) >=0){
            	GO(Div2Hide).style.display="none";
            }
        }
    }
    self.xmlHttpReq.send(qs);
}


function xmlhttpPost(strURL, divid, formid) {
	xmlhttpPost(strURL, divid, formid, 2);
}


function xmlhttpPost(strURL, divid, formid, numparms) {
    var xmlHttpReq = false;
    var self = this;
    var qs = getquerystring(formid, numparms);
    
    updatepage('<image border=0px style="padding:10px;" src="/images/loading.gif">', divid);
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, divid);
        }
    }
    self.xmlHttpReq.send(qs);
}



function getquerystring(formid, numparms) {

	var form = document.forms[formid];
	var propstat = form.VerifyListingStatus.value;
	var thepropid = form.propid.value;
	var prop3 = "";
	var prop4 = "";
	var prop5 = "";	
	var prop6 = "";	
	var prop7 = "";	
	var prop8 = "";	
	
	if (numparms > 2){
		if (form.var3 != null){
			prop3 = form.var3.value;
		}
	}
	if (numparms > 3){
		if (form.var4 != null){
			prop4 = form.var4.value;
		}
	}
	if (numparms > 4){
		if (form.var5 != null){
			prop5 = form.var5.value;
		}
	}
	if (numparms > 5){
		if (form.var6 != null){
			prop6 = form.var6.value;
		}
	}
	if (numparms > 6){
		if (form.var7 != null){
			prop7 = form.var7.value;
		}
	}	
	if (numparms > 7){
		if (form.var8 != null){
			prop8 = form.var8.value;
		}
	}

    	qstr = 'x=' + escape(thepropid) + '&tmst=' + escape(new Date().getTime()) + '&w=' + escape(propstat);  // NOTE: no '?' before querystring
    	
    	if (numparms > 2){
	    	qstr = qstr + '&y=' + escape(prop3);
	}
	
    	if (numparms > 3){
	    	qstr = qstr + '&z=' + escape(prop4);
	}
	if (numparms > 4){
		qstr = qstr + '&zz=' + escape(prop5);
	}
	if (numparms > 5){
		qstr = qstr + '&z2=' + escape(prop6);
	}
	if (numparms > 6){
		qstr = qstr + '&z3=' + escape(prop7);
	}
	if (numparms > 7){
		qstr = qstr + '&z4=' + escape(prop8);
	}
	
	
    
    return qstr;
}

function updatepage(str, divid){
    GO(divid).innerHTML = str;
}


function GO(obid){
try{
if (obid != null){
	  if (document.getElementById){
		return document.getElementById(obid);
	  }else if (document.all){
		return document.all[obid];
	  }else if (document.layers){
		return document.layers[obid];
	  }
  
  }
}catch(err){return null;}
}

function changesearchdivs(activeanchorname, normalanchor){


if ((activeanchorname != null) && (normalanchor)){
	var  activediv = 'd' + activeanchorname;
	var  hiddendiv = 'd' + normalanchor;
	
	GO(activeanchorname).className='active';
	GO(normalanchor).className='';
	
	GO(hiddendiv).style.display = 'none';
	GO(activediv).style.display = 'block';

}



}

function toggleelement(elid){
  var elem, vis;
  elem = GO(elid); 
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}


function showhide(elid,showhidediv){

  var elem, vis;
  elem = GO(elid); 
  vis = elem.style;
  if (vis != null){

	if ((vis.display == null) || (vis.display == 'none')  || (vis.display == '')){
		vis.display = 'block';
		showhidediv.style.backgroundImage = "url(/images/contract.png)";
		showhidediv.innerHTML = "Less";
		
	}else if ((vis.display != null) && (vis.display == 'block')){
		vis.display = 'none';
		showhidediv.style.backgroundImage = "url(/images/expand.png)";
		showhidediv.innerHTML = "More";
	}


  }
  
}


function xmlhttpGET(strURL, divid) {
    var xmlHttpReq = false;
    var self = this;
    
    GO(divid).innerHTML = '<image border=0px style="padding:10px;" src="/images/loading.gif">';
        
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            var respstring = self.xmlHttpReq.responseText;
            GO(divid).innerHTML = respstring;
        }
    }
    self.xmlHttpReq.send(null);
}


function GetAdminRepoID(ref){

	var repocordsrc = "/repo_list.jsp?";
	if (ref != null){ repocordsrc = repocordsrc + "&ref=" + ref;}	
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, 'reporeslts');

}

function GetAdminAucID(ref){

	var repocordsrc = "/auc_list.jsp?";
	if (ref != null){ repocordsrc = repocordsrc + "&ref=" + ref;}	
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, 'reporeslts');

}

function GetAdminRepos(status, bank, price, beds){
	GetAdminRepos(status, bank, price, beds, null, 0);
}

function GetAdminRepos(status, bank, price, beds, subid, cursor){

	var repocordsrc = "/repo_list.jsp?";
	
	if (status != null){ repocordsrc = repocordsrc + "&repostat=" + status;}
	if (bank != null){ repocordsrc = repocordsrc + "&bank=" + bank;}
	if (price != null){ repocordsrc = repocordsrc + "&price=" + price;}
	if (beds != null){ repocordsrc = repocordsrc + "&beds=" + beds;}
	if (subid != null){ repocordsrc = repocordsrc + "&subid=" + subid;}	
	if (cursor != null){ repocordsrc = repocordsrc + "&cursor=" + cursor;}		
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, 'reporeslts');

}

function GetAdminAucs(status, bank, price, beds, subid, cursor){

	var repocordsrc = "/auc_list.jsp?";
	
	if (status != null){ repocordsrc = repocordsrc + "&repostat=" + status;}
	if (bank != null){ repocordsrc = repocordsrc + "&bank=" + bank;}
	if (price != null){ repocordsrc = repocordsrc + "&price=" + price;}
	if (beds != null){ repocordsrc = repocordsrc + "&beds=" + beds;}
	if (subid != null){ repocordsrc = repocordsrc + "&subid=" + subid;}	
	if (cursor != null){ repocordsrc = repocordsrc + "&cursor=" + cursor;}		
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, 'reporeslts');

}

function GetReposExposure(status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = "/repo_exposure_list.jsp?";
	GetLsExposure(repocordsrc, status, bank, price, beds, subid, startdt, enddt, groupby, cursor);
	
}

function GetAucssExposure(status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = "/auction_exposure_list.jsp?";
	GetLsExposure(repocordsrc, status, bank, price, beds, subid, startdt, enddt, groupby, cursor);
	
}

function GetFeatsExposure(status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = "/featured_exposure_list.jsp?";
	GetLsExposure(repocordsrc, status, bank, price, beds, subid, startdt, enddt, groupby, cursor);
	
}


function GetLsExposure(page2use, status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	GO('reporeslts').innerHTML = '<image border=0px style="padding:10px;" src="/images/loading.gif">';

	var repocordsrc = page2use;
	
	if (status != null){ repocordsrc = repocordsrc + "&repostat=" + status;}
	if (bank != null){ repocordsrc = repocordsrc + "&bank=" + bank;}
	if (price != null){ repocordsrc = repocordsrc + "&price=" + price;}
	if (beds != null){ repocordsrc = repocordsrc + "&beds=" + beds;}
	if (subid != null){ repocordsrc = repocordsrc + "&subid=" + subid;}
	if (cursor != null){ repocordsrc = repocordsrc + "&cursor=" + cursor;}		

	if (startdt != null){ repocordsrc = repocordsrc + "&startdt=" + startdt;}
	if (enddt != null){ repocordsrc = repocordsrc + "&enddt=" + enddt;}
	if (groupby != null){ repocordsrc = repocordsrc + "&groupby=" + groupby;}	
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, 'reporeslts');

}


function GetReposLeads(status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = "/repo_leads_list.jsp?";
	GetLsLeads(repocordsrc, status, bank, price, beds, subid, startdt, enddt, groupby, cursor);
	
}

function GetAucssLeads(status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = "/auction_leads_list.jsp?";
	GetLsLeads(repocordsrc, status, bank, price, beds, subid, startdt, enddt, groupby, cursor);
	
}


function GetLsLeads(page2use, status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = page2use;
	
	GO('reporeslts').innerHTML = '<image border=0px style="padding:10px;" src="/images/loading.gif">';
	
	if (status != null){ repocordsrc = repocordsrc + "&repostat=" + status;}
	if (bank != null){ repocordsrc = repocordsrc + "&bank=" + bank;}
	if (price != null){ repocordsrc = repocordsrc + "&price=" + price;}
	if (beds != null){ repocordsrc = repocordsrc + "&beds=" + beds;}
	if (subid != null){ repocordsrc = repocordsrc + "&subid=" + subid;}
	if (cursor != null){ repocordsrc = repocordsrc + "&cursor=" + cursor;}		

	if (startdt != null){ repocordsrc = repocordsrc + "&startdt=" + startdt;}
	if (enddt != null){ repocordsrc = repocordsrc + "&enddt=" + enddt;}
	if (groupby != null){ repocordsrc = repocordsrc + "&groupby=" + groupby;}	
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, 'reporeslts');

}


function GetReposDetails(div2hit, status, bank, price, beds, subid, startdt, enddt, groupby, lid){
	var Thepage = "/repo_leads_list.jsp?";
	GetReposDetails(Thepage, div2hit, status, bank, price, beds, subid, startdt, enddt, groupby, lid);
}

function GetAucDetails(div2hit, status, bank, price, beds, subid, startdt, enddt, groupby, lid){
	var Thepage = "/auction_leads_list.jsp?";
	GetLedsDetails(Thepage, div2hit, status, bank, price, beds, subid, startdt, enddt, groupby, lid);
}

function GetLedsDetails(Thepage, div2hit, status, bank, price, beds, subid, startdt, enddt, groupby, lid){
	var repocordsrc = Thepage;
	GO(div2hit).style.display = 'block';
	GO('zbut' + lid).style.display = 'block';
	
	if (status != null){ repocordsrc = repocordsrc + "&repostat=" + status;}
	if (bank != null){ repocordsrc = repocordsrc + "&bank=" + bank;}
	if (price != null){ repocordsrc = repocordsrc + "&price=" + price;}
	if (beds != null){ repocordsrc = repocordsrc + "&beds=" + beds;}
	if (subid != null){ repocordsrc = repocordsrc + "&subid=" + subid;}	

	if (startdt != null){ repocordsrc = repocordsrc + "&startdt=" + startdt;}
	if (enddt != null){ repocordsrc = repocordsrc + "&enddt=" + enddt;}
	if (groupby != null){ repocordsrc = repocordsrc + "&groupby=" + groupby;}
	if (lid != null){ repocordsrc = repocordsrc + "&lid=" + lid;}	
	
	repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
	xmlhttpGET(repocordsrc, div2hit);
	
	GO('but' + lid).style.display = 'none';

}

function ShowHideReposDetButs(lid){

	GO('d' + lid).style.display = 'none';
	GO('but' + lid).style.display = 'block';
	GO('zbut' + lid).style.display = 'none';
}


var nextp = '/images/nexttext.gif';
var prevp = '/images/prevtext.gif';
var nop = '/images/nop.png';

function getnext(CurrThumbIndex, FeatPicId, ListingId, Imgs){

    if (CurrThumbIndex < (Imgs.length - 1)){
      GO(FeatPicId).src = Imgs[CurrThumbIndex + 1];
      CurrThumbIndex++;
    }
    if ((CurrThumbIndex + 1) <  Imgs.length){
      GO('nextbutton' + ListingId).src= nextp;
    }else{
      GO('nextbutton' + ListingId).src= nop;
    }
    if (CurrThumbIndex > 0){
      GO('prevbutton' + ListingId).src= prevp;
    }else{
      GO('prevbutton' + ListingId).src= nop;
    }
    
    return CurrThumbIndex;
}

function getprev(CurrThumbIndex, FeatPicId, ListingId, Imgs){

    if (CurrThumbIndex > 0){
      GO(FeatPicId).src = Imgs[CurrThumbIndex - 1];
      CurrThumbIndex--;
    }
    if ((CurrThumbIndex + 1) <  Imgs.length){
      GO('nextbutton' + ListingId).src= nextp;
    }else{
      GO('nextbutton' + ListingId).src= nop;
    }
    if (CurrThumbIndex > 0){
      GO('prevbutton' + ListingId).src= prevp;
    }else{
      GO('prevbutton' + ListingId).src= nop;
    }
    return CurrThumbIndex;
}




function GetSubsList(){

	var propidsearch = false;
	var searchval = document.forms.subform.VerifyListingStatus.value;
	if ((searchval == null) || (Trim(searchval) == '')){
		alert("Please enter the first few letters of the suburb\n OR \n the property reference no.");
	}else{
		searchval = Trim(searchval);
		if (!isNaN(searchval)){
			propidsearch = true;
		}

		if (propidsearch){
			document.forms.GoThru.PID.value = searchval;
			document.forms.GoThru.submit();
		}else{
			xmlhttpPost("/find_suburb.jsp?ACT=s", "suburbseldiv", "subform");
			if (GO('searchhistholder')){
				GO('searchhistholder').style.display = 'none';
				//repaint claasifieds box
				if (GO('classbox')){GO('classbox').style.display = 'block';}
			}
		}
	}
}

function ClearSubForm(){
	if(GO('searchhistholder')){GO('searchhistholder').style.display = 'block';}
	if (GO('classbox')){GO('classbox').style.display = 'block';}
	if(GO('VerifyListingStatus')){GO('VerifyListingStatus').value = "";}
	if(GO('suburbseldiv')){GO('suburbseldiv').innerHTML = "enter the first few letters of the suburb<BR>or<BR>the property reference no.";}
	if(GO('selectedsubsdiv')){GO('selectedsubsdiv').innerHTML = "";}
	if(GO('recsubsdiv')){GO('recsubsdiv').innerHTML = "";}
	if(GO('qsform')){GO('qsform').style.display = 'none';}

	
}

function setsearchsuburb(theselecbox){
	if (GO('qsform')){
		GO('qsform').style.display = 'block';
	}

	var TheSelVal = theselecbox.options[theselecbox.selectedIndex].value;
	var DisplayVal = theselecbox.options[theselecbox.selectedIndex].text;
	var CurrentSubsHTHML = "";
	var CheckThese = "";
	var SubsListtoSub = "";
	
	// get list of all currently checked boxes

		
	for( i=0; i<document.Suburbs_Form.length; i ++){
		
		if ((document.Suburbs_Form[i].type == "checkbox") && (document.Suburbs_Form[i].checked == true)){
			var CheckBoxNam = document.Suburbs_Form[i].name;
			var SplitSubID = CheckBoxNam.split("_");

			if((SplitSubID != null) && (SplitSubID.length == 3) ){

				SubsListtoSub = SubsListtoSub + "-" + SplitSubID[2];
				var SelVal = SplitSubID[2];
				CheckThese = CheckThese + "-" + SelVal;

				if ((SelVal != null) && (SelVal != '')){
					var DivWithSelectedSub = 'divsubrb' + SplitSubID[2];
					var subpichtml = GO(DivWithSelectedSub).innerHTML;
					if (subpichtml != null){
						CurrentSubsHTHML = CurrentSubsHTHML + "<div style='width:49%;float:left;' name='divsubrb" + SelVal + "' id='divsubrb" + SelVal + "'>" + subpichtml + "</div>";
					}
				}
			}
		}
	}
	
	// now add the new one
	if (DisplayVal != null){	

		DisplayVals = DisplayVal.split("--");
		if((DisplayVals != null) && (DisplayVals.length > 0) ){
			SubsListtoSub = SubsListtoSub + "-" + TheSelVal;
			DisplayVal = DisplayVals[0];
			CurrentSubsHTHML = CurrentSubsHTHML + "<div style='width:49%;float:left;' name='divsubrb" + TheSelVal + "' id='divsubrb" + TheSelVal + "'><table style='width:99%;'><tr><td valign='top'>" + DisplayVal + "</td><td width=22px align=right valign='top'><input style='width:20px;' type='checkbox' id='g_sub_" + TheSelVal + "' name='g_sub_" + TheSelVal + "' ></td></tr></table></div>";
			CheckThese = CheckThese + "-" + TheSelVal;				
		
		}

	}
	
	// re-insert the selected suburbs
	GO('selectedsubsdiv').innerHTML = CurrentSubsHTHML;
	
	// check the checkboxes
	var SplitcheckIDs = CheckThese.split("-");
	if((SplitcheckIDs != null) && (SplitcheckIDs.length > 0) ){
		for( j=0; j < SplitcheckIDs.length; j ++){

			var SelValue = SplitcheckIDs[j];
			if ((SelValue != null) && (SelValue != '')){
				var CheckedID = 'g_sub_' + SelValue;
				GO(CheckedID).checked = true;
			}
		}
	}
	
	// set text in search box
	GO('VerifyListingStatus').value = "enter another ...";
	
	// remove the dropdown
	GO('suburbseldiv').innerHTML = "";	
	
	
	// update the relevant suburbs list
	GetRelSubs(SubsListtoSub);
	

}



function setTBsearchsuburb(Subidno, Subname){

ClearSubForm();   // clear standard simple search form
clearsublist();	  // clear the suburb dropdown

if ((Subname != null) && (Subidno != null)){
	if (GO('qsformTB')){
		GO('qsformTB').style.display = 'block';
	}
	
	var TheSelVal = Subidno;
	var DisplayVal = Subname;
	var CurrentSubsHTHML = "";
	var CheckThese = "";
	var SubsListtoSub = "";
	
	// get list of all currently checked boxes

		
	for( i=0; i < document.SuburbsFormTB.length; i ++){
		
		if ((document.SuburbsFormTB[i].type == "checkbox") && (document.SuburbsFormTB[i].checked == true)){
			var CheckBoxNam = document.SuburbsFormTB[i].name;
			var SplitSubID = CheckBoxNam.split("_");

			if((SplitSubID != null) && (SplitSubID.length == 3) ){

				SubsListtoSub = SubsListtoSub + "-" + SplitSubID[2];
				var SelVal = SplitSubID[2];
				CheckThese = CheckThese + "-" + SelVal;

				if ((SelVal != null) && (SelVal != '')){
					var DivWithSelectedSub = 'divsubrb' + SplitSubID[2];
					var subpichtml = GO(DivWithSelectedSub).innerHTML;
					if (subpichtml != null){
						CurrentSubsHTHML = CurrentSubsHTHML + "<div class='asubcbhldr' name='divsubrb" + SelVal + "' id='divsubrb" + SelVal + "'>" + subpichtml + "</div>";
						
					}
				}
			}
		}
	}
	
	// now add the new one
	if (DisplayVal != null){
		
		SubsListtoSub = SubsListtoSub + "-" + TheSelVal;
		CurrentSubsHTHML = CurrentSubsHTHML + "<div class='asubcbhldr' name='divsubrb" + TheSelVal + "' id='divsubrb" + TheSelVal + "'><table width='100%' cellpadding='0px' cellspacing='0px'><tr><td>" + DisplayVal + "</td><td><input type='checkbox' class='tbcb' id='g_sub_" + TheSelVal + "' name='g_sub_" + TheSelVal + "' style='width:20px;border:0px;' ></td></tr></table></div>";
		//alert(CurrentSubsHTHML);
		CheckThese = CheckThese + "-" + TheSelVal;				
	}
	
	// re-insert the selected suburbs
	GO('selectedsubsdivTB').innerHTML = CurrentSubsHTHML;
	
	// check the checkboxes
	var SplitcheckIDs = CheckThese.split("-");
	if((SplitcheckIDs != null) && (SplitcheckIDs.length > 0) ){
		for( j=0; j < SplitcheckIDs.length; j ++){

			var SelValue = SplitcheckIDs[j];
			if ((SelValue != null) && (SelValue != '')){
				var CheckedID = 'g_sub_' + SelValue;
				GO(CheckedID).checked = true;
			}
		}
	}
	
	// set text in search box
	GO('suburbpic').value = "enter another ...";
	
	
	// update the relevant suburbs list
	GetRelSubsTB(SubsListtoSub);
	
} // end if there is a sbnm & ID

}


function ClearSubFormTB(){

	//if (GO('classbox')){GO('classbox').style.display = 'block';}
	if(GO('suburbpic')){GO('suburbpic').value = "";}
	if(GO('selectedsubsdivTB')){GO('selectedsubsdivTB').innerHTML = "";}
	if(GO('recsubsdivTB')){GO('recsubsdivTB').innerHTML = "";}
	if(GO('qsformTB')){GO('qsformTB').style.display = 'none';}

	
}

function GetRelSubsTB(SubsListtoSub){

	//get & populate the relevant suburbs list
	var strURL = "/find_suburb.jsp?ACT=r&w=" + SubsListtoSub;
	xmlhttpGET(strURL, 'recsubsdivTB');


}

function GetRelSubs(SubsListtoSub){

	//get & populate the relevant suburbs list
	var strURL = "/find_suburb.jsp?ACT=r&w=" + SubsListtoSub;
	xmlhttpGET(strURL, 'recsubsdiv');


}

function ChangeCaptchaPic(CapImagId){
var newpicsrc = '/captcha?' + new Date().getTime();
if (GO(CapImagId)){
	GO(CapImagId).src=newpicsrc;
}


}


function CheckDigits(TheField){

	if ((isNaN(TheField.value)) || (TheField.value.indexOf(".") >=0) || (TheField.value.indexOf(" ") >=0)){
		alert("This field should contain digits only.\r\n e.g. \'280\' or \'450000\' are ok but \'4,500\' or \'1.5\' are not.");
		TheField.value = "";
	}
}

function CheckPhoneDg(TheField){

	if ((isNaN(TheField.value)) || (TheField.value.indexOf(".") >=0) || (TheField.value.indexOf(" ") >=0)){
		alert("This field should contain digits only.");
		TheField.value = "";
	}
}


function mailob(sDom, sUser, sLink){
  return("mai"+"lto:"+sUser+"@"+sDom.replace(/%23/g,".") + "?subject=Listing Enquiry from IOLProperty User" + "&body=" + sLink);
}

function showPopUp(el) {
var cvr = document.getElementById("cover")
var dlg = document.getElementById(el)
cvr.style.display = "block"
dlg.style.display = "block"
if (document.body.style.overflow = "hidden") {
  cvr.style.width = "100%"
  cvr.style.height = "100%"
  }
}

function closePopUp(el) {

var cvr = document.getElementById("cover");
var dlg = document.getElementById(el);
if (cvr != null){cvr.style.display = "none";}
if (dlg != null){dlg.style.display = "none";}


}

function GOC(className){

var results = [];
if (document.getElementsByClassName == undefined) {

		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
		var allElements = document.getElementsByTagName("*");
		

		var element;
		for (var i = 0; (element = allElements[i]) != null; i++) {
			var elementClass = element.className;
			if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
				results.push(element);
		}


}else{
	results = document.getElementsByClassName(className);
}
return results;

}

function showtabdata(DivIDtoShow){

// firsly set all the active tabs to inactive
var ActiveTabs = GOC('tabactive');
if ((ActiveTabs != null) && (ActiveTabs.length > 0)){
	for( i=0; i < ActiveTabs.length; i ++){
		ActiveTabs[i].className = 'inactivetab';
	}

}

// now set the clicked tab to active
if (GO(DivIDtoShow) != null){
	GO(DivIDtoShow).className = 'tabactive';

}

// now hide all the info display divs
var InfoDivs = GOC('infodiv');
if ((InfoDivs != null) && (InfoDivs.length > 0)){
	for( i=0; i < InfoDivs.length; i ++){
		InfoDivs[i].style.display='none';
	}

}

// finally display the clicked div
var clickddivname = DivIDtoShow + 'D';
GO(clickddivname).style.display='block';


}
function getsbrblistfromname(agentryfld, divtoupdnm){
	getsbrblistfromname(agentryfld, divtoupdnm, 400);
}


function getsbrblistfromnameTB(agentryfld, divtoupdnm, listwidth){

	// get agent
	
	if (listwidth == null){width = 400;}
	
	
	if ((agentryfld != null) && (agentryfld.value != null) && (agentryfld.value != '') && (agentryfld.value.length > 2)){

		//check we haven't already checked this string last time
		if (agentryfld.value != lastlookedupagstr){
		
			GO(divtoupdnm).style.display = 'block';
			GO("page").style.zIndex = 10;
			GO("container").style.zIndex = 20;
			GO(divtoupdnm).style.zIndex = -1;
			GO(divtoupdnm).style.zIndex = 999;
			
			//alert(GO("page").style.zIndex);
			lastlookedupagstr = agentryfld.value;
			GO(divtoupdnm).innerHTML = 'Loading...';
			
			var ref = agentryfld.value;
			var repocordsrc = "/sublookup.jsp?w=" + listwidth;
			if (ref != null){ repocordsrc = repocordsrc + "&sub=" + ref;}		
			repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
			//showPopUp('sbssdiv');
			xmlhttpGET(repocordsrc, divtoupdnm);
			
		}else{
			
		}
		
	}else{
		//clearsublist();
	}
}



function setagentsub(agentryfld, divtoupdnm, listwidth, lastsubvlkdUp, PropId, formnam){
	
	closesubpikls();

	
	if (listwidth == null){width = 400;}
	
	if ((PropId != null) && (agentryfld != null) && (agentryfld.value != null) && (agentryfld.value != '') && (agentryfld.value.length > 2)  ){


		//check we haven't already checked this string last time
		if (agentryfld.value != lastsubvlkdUp){
		
			GO(divtoupdnm).style.display = 'block';
			lastsubvlkdUp = agentryfld.value;
			GO(divtoupdnm).innerHTML = 'Loading...';
			
			var ref = agentryfld.value;
			var repocordsrc = "/allsublookup.jsp?w=" + listwidth;
			if (ref != null){ repocordsrc = repocordsrc + "&sub=" + ref + "&pid=" + PropId + "&frm=" + formnam;}		
			repocordsrc = repocordsrc + "&tmstmp" + new Date().getTime();
			//showPopUp('sbssdiv');
			xmlhttpGET(repocordsrc, divtoupdnm);
			
		}else{
			
		}
		
	}else{
		//clearsublist();
	}
}


function setclickdsubbd(theformname, srchfld, suburbId, suburbnme){

	GO(theformname).var7.value = suburbId;
	GO(srchfld).value = suburbnme;
	closesubpikls();
	


}

function closesubpikls(){

	var SubPicklidi = GOC('subpickldisp');
	if ((SubPicklidi != null) && (SubPicklidi.length > 0)){
		for( i=0; i < SubPicklidi.length; i ++){
			SubPicklidi[i].innerHTML='';
		}

	}


}




function changebackgg(objecttochg, newcolor){

	if ((objecttochg != null) && (newcolor != null)){
		objecttochg.style.background = newcolor;
	}


}

function clearsublist(){

	if (GO('subserchrs') != null){
		GO('subserchrs').innerHTML = '';
		GO('subserchrs').style.display = 'none';
		closePopUp('subserchrs');

	}
	if (GO('subserchrsTB') != null){
		GO('subserchrsTB').innerHTML = '';
		GO('subserchrsTB').style.display = 'none';
		closePopUp('subserchrsTB');
	
	}
	

}

function oneclickmesg(oneClickPropID){

	CloseOneClickForms();

	if ((s1cEmailDefault) && (s1cEmailDefault != null) && (s1cEmailDefault.indexOf('@') > 0)){

		// got details already, proceed
		var Divnm = "resagdivz" + oneClickPropID;
		GO(Divnm).style.display="block";
		PostOneClickForm("/1_click.jsp?ACT=r", Divnm, null, 7, oneClickPropID );

	}else{

		GetOneClickForm(oneClickPropID, '/1_click.jsp');
	}


}


function oneclickcotactme(oneClickPropID){

	CloseOneClickForms();

	if ((s1cEmailDefault) && (s1cEmailDefault != null) && (s1cEmailDefault.indexOf('@') > 0)){

		// got details already, proceed
		var Divnm = "resagdivz" + oneClickPropID;
		GO(Divnm).style.display="block";
		PostOneClickForm("/1_click_contact.jsp?ACT=r", Divnm, null, 7, oneClickPropID );

	}else{

		GetOneClickForm(oneClickPropID, '/1_click_contact.jsp');
	}

}


function GetOneClickForm(oneClickPropID, pagetoUse){

	// close other open forms
	CloseOneClickForms();
	

	// get the form to complete
	var strURL = pagetoUse + '?ACT=su&z=' + oneClickPropID + "&tmstmp" + new Date().getTime();
	var divid = 'resagdivz' + oneClickPropID;
	GO(divid).innerHTML = '<image border=0px style="padding:10px;" src="/images/loading.gif">';
	xmlhttpGET(strURL, divid) ;

}



function CloseOneClickForms(){

	var OnecCont = GOC("oneclickholder");
	if ((OnecCont) && (OnecCont != null) && (OnecCont.length > 0)){
		for (var k = 0; k < OnecCont.length; k++){
			OnecCont[k].innerHTML = "";
		}
	}
}


function PostOneClickForm(strURL, divid, formid, numparms, proptId) {
	var xmlHttpReq = false;
	var qs = "";
	if ((formid) && (formid != null)){
		qs = getquerystring(formid, numparms);
	}else{
		qs = "z=" + proptId;
	}


    	// reset on-page values
    
	if ((GO(formid)) && (GO(formid) != null)){
		// reset on page defaults
		if ((GO(formid).VerifyListingStatus) && (GO(formid).VerifyListingStatus != null)){ s1cNameDef = GO(formid).VerifyListingStatus.value;}
		if ((GO(formid).var3) && (GO(formid).var3 != null)){ s1cPhDefault = GO(formid).var3.value;}
		if ((GO(formid).propid) && (GO(formid).propid != null)){ s1cEmailDefault = GO(formid).propid.value;}
		if ((GO(formid).var6) && (GO(formid).var6 != null)){ s1cSendContactDetails = GO(formid).var6.value;}
	}
	

    
    updatepage('<image border=0px style="padding:10px;" src="/images/loading19.gif">', divid);
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            var respstring = xmlHttpReq.responseText;
            updatepage(respstring, divid);
        }
    }

    xmlHttpReq.send(qs);
}


function CreateBookmarkLink() {
		
	if (window.sidebar) { // Mozilla Firefox
		window.sidebar.addPanel(document.title, this.location,"");
	}
	else if (window.external) { // IE
		window.external.AddFavorite(this.location,document.title);
	}
	else if (window.opera && window.print) {
		window.external.AddFavorite(this.location, document.title);
	}
	else {
		alert('Not Supported for this Browser');
	}
}

function popMessg(Object2PopBelow, Text2Use, width, textalign){


if ((objtopop == null) || (objtopop != Object2PopBelow)){

objtopop = Object2PopBelow;

var popwidth = '200';
var textal = 'center';
if (width){popwidth = width;}
if (textalign){textal=textalign;}

var posx = getX(Object2PopBelow) + (Object2PopBelow.offsetWidth)/2 - popwidth/2;
var posy = getY(Object2PopBelow) + Object2PopBelow.offsetHeight + 5;

if (posx < 0){posx = 0;}
if (posy < 0){posy = 0;}


var thedivid = 'd' + Math.floor(Math.random()*1000) + (new Date()).getTime();

var divinnerhtml = "<table width='100%' cellspacing='0px' cellpadding='0px' border=0px><tr><td align=center><img border='0px' src='/images/beak_dark_grey.png'></td></tr>" + 
		"<tr><td ><div class='poptip'>" +
			"<div style='width:100%;'>" + Text2Use + "</div>" +
			"<div style='float:right;padding-top:5px;'>[ <a href='JavaScript:GO(\"" + thedivid + "\").innerHTML=\"\";objtopop=null;void(0);' style='color:white;text-decoration:underline'>Close</a> ]</div>" +
		"</div></td></tr></table>";

creatediv(thedivid, divinnerhtml, popwidth, null, posx, posy);

}else{
// already popped this one
}


}



function creatediv(id, html, dwidth, dheight, dleft, dtop) {

var newdiv = document.createElement('div');
if (id) {newdiv.setAttribute('id', id);}
if (dwidth) { newdiv.style.width = dwidth + 'px'; }else{ newdiv.style.width = '300px'; } 
if (dheight) { newdiv.style.width = dheigh + 'px'; }
if ((dleft || dtop) || (dleft && dtop)) { 
	newdiv.style.position = "absolute"; 
	if (dleft) { newdiv.style.left = dleft + 'px'; } 
	if (dtop) { newdiv.style.top = dtop + 'px'; } 
} 

if (html) { newdiv.innerHTML = html; } else { newdiv.innerHTML = ""; } 
document.body.appendChild(newdiv);
//newdiv.className += "poptip";


}


function getY( oElement ){
var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
return iReturnValue;
}

function getX( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getalformvals(theform){
	var sSubsStr = "";
	var sTypStr = "";
	var sNewsletter = "";
	for( i = 0; i<document.AlertSub.length; i ++){
		if ((document.AlertSub[i].type == "checkbox") && (document.AlertSub[i].checked == true)){
			var CheckName = document.AlertSub[i].name;
			if (CheckName != null){
				if (CheckName.substring(0, 5) == 'newsl'){
					sNewsletter = 'news';
				}else if (CheckName.substring(0, 5) == 'g_sub'){
					sSubsStr = sSubsStr + ',' + CheckName;
				}else if (CheckName.substring(0, 3) == 'tp_'){
					sTypStr = sTypStr + ',' + CheckName;
				}
				
			}

		}
	}
	
	document.AlertSub.var3.value = sSubsStr;
	document.AlertSub.var5.value = sTypStr;
	document.AlertSub.var4.value = sNewsletter;

}

function SendSMSContacts(){

GO('faediv').style.display = 'none';
GO('faediv').innerHTML = '';

var CheckdPropIDs = GOC('CheckdPropID');	
var sErroString = "";

var sNameSupp = document.forms.featuredageform.VerifyListingStatus.value;
var sEmailSupp = document.forms.featuredageform.propid.value;
var sPhoneSupp = document.forms.featuredageform.var3.value;
var sBudget = document.forms.featuredageform.var6.value;




if ((sNameSupp == null) || (sNameSupp == '')) {sErroString = sErroString + "<LI>Name  not supplied";}


if ((sEmailSupp == null) || (sEmailSupp == '')) {
	sErroString = sErroString + "<LI>Email address  not supplied";
}else{
	if (sEmailSupp.indexOf('@') <= 0){sErroString = sErroString + "<LI>Incorrect email address";}
}

if ((sPhoneSupp == null) || (sPhoneSupp == '')) {
	sErroString = sErroString + "<LI>Phone number not supplied";
}else{

	if ( (sPhoneSupp.length != 10) || (isNaN(sPhoneSupp) ) ){sErroString = sErroString + "<LI>Incorrect phone number supplied";}
}

if ((sBudget == null) || (sBudget == '')) {
	sErroString = sErroString + "<LI>Max Price not supplied";
}else{
	if (isNaN(sBudget) ){sErroString = sErroString + "<LI>Max Price should contain digits only";}
}



if (sErroString != ''){
	GO('faediv').style.display = 'block';
	sErroString = "<p><b>Please correct the following:</b><ul class='bullets'>" + sErroString + "</ul></p>"
	GO('faediv').innerHTML = sErroString;

}else{

if (CheckdPropIDs != null){

	for (var i = 0; i < CheckdPropIDs.length; i++){

		if ((CheckdPropIDs[i].name != null) && (CheckdPropIDs[i].checked)){
			var SplitcheckIDs = CheckdPropIDs[i].name.split("_");
			if((SplitcheckIDs != null) && (SplitcheckIDs.length ==2) && (SplitcheckIDs[1] != null) ){

				var FAPropId = SplitcheckIDs[1];
				var DPDivId = 'aghchk' + FAPropId;
				var ResDiv = 'aghchkres' + FAPropId;
				document.forms.featuredageform.var4.value = FAPropId;
				
				GO(DPDivId).style.display='none';
				GO(ResDiv).style.display='block';
				
				
				TSxmlhttpPost("/featured_agent.jsp?ACT=" + FAPropId, ResDiv, "featuredageform", 7);
			
			}
			
		}
	}


}

} //preproc ok


}


function TSxmlhttpPost(strURL, divid, formid, numparms) {
    var xmlHttpReq = false;

    var qs = getquerystring(formid, numparms);
    
    updatepage('<image border=0px style="padding:10px;" src="/images/loading19.gif">', divid);
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            updatepage(xmlHttpReq.responseText, divid);
        }
    }
    xmlHttpReq.send(qs);
}


function GetUpdatedShortList(){
	if ( (GO('myshtlst')) && (GO('myshtlst') != null) ){
		var repocordsrc = "/get_shortlist.jsp?tmstmp" + new Date().getTime();
		xmlhttpGET(repocordsrc, 'myshtlst');
	}

}

function BookMarkListing(strURL, divid, formid) {
    var xmlHttpReq = false;
    var self = this;
    var qs = getquerystring(formid, 2);
    
    updatepage('<image border=0px style="padding:10px;" src="/images/loading.gif">', divid);
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, divid);
            GetUpdatedShortList();
        }
    }
    self.xmlHttpReq.send(qs);
}


function changcont(contype, sGID){

if (contype != null){
	if (contype == 'email'){
		GO('MessageTab').className='contactive';
		GO('PhoneTab').className='contback';
		GO('dsearchbrs').style.display = 'none';
		GO('dsearchqs').style.display = 'block';
		
	
	}else if (contype == 'phone'){
		GO('MessageTab').className='contback';
		GO('PhoneTab').className='contactive';
		GO('dsearchbrs').style.display = 'block';
		GO('dsearchqs').style.display = 'none';
		
		if ( (GO('ctlgr')) && (GO('ctlgr') != null) ){
			var repocordsrc = "/contact_details.jsp?tmstmp" + new Date().getTime() + "&z=" + sGID + "&y=" + contype;
			xmlhttpGET(repocordsrc, 'ctlgr');
		}
	
	}else if (contype == 'emailadd'){


		GO('viewagmail').style.display = 'block';

		
		if ( (GO('viewagmail')) && (GO('viewagmail') != null) ){
			var repocordsrc = "/contact_details.jsp?tmstmp" + new Date().getTime() + "&z=" + sGID + "&y=" + contype;
			xmlhttpGET(repocordsrc, 'viewagmail');
		}
	
	}
	


}

}
