var LoadPic4Src="/bin/wd.gif";
var LastSubsearch = 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) + '&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 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 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 GetReposExposure(status, bank, price, beds, subid, startdt, enddt, groupby, cursor){

	var repocordsrc = "/repo_exposure_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;}		

	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?";
	
	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 repocordsrc = "/repo_leads_list.jsp?";
	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 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 mailob(sDom, sUser, sLink){
  return("mai"+"lto:"+sUser+"@"+sDom.replace(/%23/g,".") + "?subject=Listing Enquiry from IOLProperty User" + "&body=" + sLink);
}


