var LoadPic4Src="/bin/wd.gif";
var LastSubsearch = null;


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 UpdatePrice(IsReq) {
	var PropStat = document.forms.Availability.PROP_SEARCH_STATUS;
	var PropertyStatus = PropStat.value;
	var PriceSel = document.forms.Availability.PROP_PRICE_ENTER;
	var PriceSelMin = document.forms.Availability.PROP_PRICE_MIN;
	
	if (	((PropertyStatus != null) && (PropertyStatus != '') && (PropertyStatus != 'For Sale')) ||
		((IsReq !=null) && (IsReq == 'Not Required')) 
	){

		if (	(PriceSel.options[PriceSel.options.length-1].text != null) && 
			(PriceSel.options[PriceSel.options.length-1].text != "Not Required")){
			PriceSel.options[PriceSel.options.length] = new Option("Not Required", "999999999",false,false);
		}
		if (	(PriceSelMin.options[PriceSelMin.options.length-1].text != null) && 
			(PriceSelMin.options[PriceSelMin.options.length-1].text != "Not Required")){
			PriceSelMin.options[PriceSelMin.options.length] = new Option("Not Required", "0",false,false);
		}
			PriceSel.selectedIndex = (PriceSel.options.length - 1);
			PriceSelMin.selectedIndex = (PriceSelMin.options.length - 1);
	}else{
		var OptionVal = PriceSel.options[PriceSel.options.length-1].text;
		if ((OptionVal != null) && (OptionVal == 'Not Required')){
			PriceSel.options[PriceSel.options.length-1] = null;
		}

		var OptionValMin = PriceSelMin.options[PriceSelMin.options.length-1].text;
		if ((OptionValMin != null) && (OptionValMin == 'Not Required')){
			PriceSelMin.options[PriceSelMin.options.length-1] = null;
		}

		PriceSel.selectedIndex = 8;
		PriceSelMin.selectedIndex = 0;
	}
}

function ChangePriceonStatus() {
	var PropStat = document.forms.Suburbs_Form.PROP_SEARCH_STATUS;
	var PropertyStatus = PropStat.value;
	var PriceSel = document.forms.Suburbs_Form.PROP_PRICE_ENTER;
	
	if (	(PropertyStatus != null) && (PropertyStatus != '') && (PropertyStatus != 'For Sale')
	){

		if (	(PriceSel.options[PriceSel.options.length-1].text != null) && 
			(PriceSel.options[PriceSel.options.length-1].text != "Not Required")){
			PriceSel.options[PriceSel.options.length] = new Option("Not Required", "999999999",false,false);
		}
		PriceSel.selectedIndex = (PriceSel.options.length - 1);

	}else{
		var OptionVal = PriceSel.options[PriceSel.options.length-1].text;
		if ((OptionVal != null) && (OptionVal == 'Not Required')){
			PriceSel.options[PriceSel.options.length-1] = null;
		}
		PriceSel.selectedIndex = 25;
	}
}



function UpdateSuburbs(){
	var ProvinceSelect = document.forms.Availability.province;
	var ProvinceSelected = ProvinceSelect.options[ProvinceSelect.selectedIndex].value;
	var AreaSelect = document.forms.Availability.suburb;
	var SubsPageToGet = "/Anon/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 = "/Anon/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 Available");
	}

}


function rungping(pg,cc){

	if (cc == null){cc = '';}
	var SearchPageToGet = "/Anon/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 Available");
	}else if ((SearchID == '0') || (SearchID == '-1')){
		//do nothing - user has selected history not available etc.
	}else{
		var SearchPageToGet = "/Anon/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 Available");
		}

	}

}

function RefreshSearchList(SearchArray, p_status, p_type, p_price_min, p_price, p_found, p_subs, p_beds, p_pics){ 

	var SearchSelect = document.forms.Availability.searchhist;
	SearchSelect.options[0] = null;
	if ((SearchArray != null) && (SearchArray.length > 0)){
		SearchSelect.options[0] = new Option("Select Search Below (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';	
			}		
		}
	}else{
		SearchSelect.options[0] = new Option("Search History Not Available");
	}
	RefreshSearchDetail(p_status, p_type, p_price_min, p_price, p_found, p_subs, p_beds, p_pics);
}

function RefreshSearchDetail(p_status, p_type, p_price_min, p_price, p_found, p_subs, p_beds, p_pics){

	// Only Run for Detailed Search Page
	if (document.forms.Availability.PROP_PRICE_ENTER){
		if (p_price != null){SetInd(document.forms.Availability.PROP_PRICE_ENTER, p_price);}
		if (p_beds != null){SetInd(document.forms.Availability.BEDS, p_beds);}
		//if (p_pics != null){SetInd(document.forms.Availability.PICS, p_pics);}
		if (p_price_min != null){SetInd(document.forms.Availability.PROP_PRICE_MIN, 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 == 'To Let'){
		UpdatePrice("Not Required");
	}
	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 = '/Anon/GoTo.jsp?ADD=g&PID=' + PD + '&FID=' + FD;
	//var ploc = '/images/page_cache/' + FD + '/' + PD + '.html';
	window.location = ploc;
}


function gopreview(GID){
var ploc = '/Anon/property-details.jsp?gid=' + 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 changcont(contype, sGID){

if (contype != null){
	if (contype == 'phone'){

		GO('phones').style.display = 'block';
		GO('phonesres').style.display = 'none';
		
		if ( (GO('phonesres')) && (GO('phonesres') != null) ){
		
			var repocordsrc = "/Anon/cd.jsp?tmstmp" + new Date().getTime() + "&z=" + sGID + "&y=" + contype;
			xmlhttpGET(repocordsrc, 'phonesres');
		}
	
	
	}else if (contype == 'emailadd'){


		if ( (GO('emailres')) && (GO('emailres') != null) ){

			var repocordsrc = "/Anon/cd.jsp?tmstmp" + new Date().getTime() + "&z=" + sGID + "&y=" + contype;
			xmlhttpGET(repocordsrc, 'emailres');
		}
	
	}else if (contype == 'linksite'){


		if ( (GO('detlink')) && (GO('detlink') != null) ){

			var repocordsrc = "/Anon/cd.jsp?tmstmp" + new Date().getTime() + "&z=" + sGID + "&y=" + contype;
			xmlhttpGET(repocordsrc, 'detlink');
		}
		setTimeout(GoSite(sGID), 3000);
		

	
	}
	


}

}



function GoSite(sGID){
   var Gotosite = "http://www.g.co.za/Anon/GoTo.jsp?ADD=g&PID=" + sGID;
	window.location = Gotosite;
}


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 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 mailagent(sDom, sUser, sLink){
  return("ma"+"ilto:"+sUser+"@"+sDom.replace(/%23/g,".") + "?subject=Listing Enquiry from Gravity User" + "&body=" + sLink);
}

