
function ShowImage(lId,imgId)
{
	var url = "http://www.abcrealestate.com.au/Tools/SlideShow.aspx?ID=" + lId;
	if (imgId.length>0) url = url + "&IMG=" + URLEncoder(imgId);
	MM_OpenDialogWindow(url,780,650);
}

function PrintListing(lId)
{
	var url = "Property.aspx?ID=" + lId + "&PF=1";
	MM_OpenResWindow(url,700,500);
}

function OpenMap(lat1,lon1,lat2,lon2,ico,zm,padd)
{
	var url = "http://www.abcrealestate.com.au/Tools/MapNav.aspx?L1=" + lat1 + "&N1=" + lon1 + "&L2=" + lat2 + "&N2=" + lon2 + "&I=" + ico + "&Z=" + zm + "&P=" + URLEncoder(padd);
	MM_OpenDialogWindow(url,500,500);
}

function SlideShow(page) {
	var img = document.getElementById("imgSlideShow");
	var a = document.getElementById("aSlideShowLink");
	if (!img && !a) return;
	img.src = imageSource[current];
	
	if (page == "property")
		a.href = "javascript:ShowImage(" + imageLink[current] + ")";
	else if (page == "pow")
		a.href = imageLink[current];
	
	if (current == (totalImages - 1))
	{
		current = 0;
		if (totalImages > 1)
			allLoaded = true;
	}
	else
		current++;
	
	if (!allLoaded)
	{
		var newImage = new Image();
		newImage.src = imageSource[current];
	}

	// This call will make it loop
	setTimeout("SlideShow('" + page + "')", 4000);
}


function AddToShortList(listingId)
{
	Abc.Modules.AbcWebService.AddToShortList(listingId, OnAddShortListComplete);
}

function OnAddShortListComplete(result)
{
	if (result.indexOf('Listing has been added to shortlist') >=0)
		window.location.href = window.location.href;
	
	alert(result);
}

function RemoveShortListing(listingId)
{
	// Call webservice
	Abc.Modules.AbcWebService.DeleteFromShortList(listingId, OnDeleteShortListComplete);
}

function OnDeleteShortListComplete(result)
{
	window.location.reload(false);
}

function ClearLastViewed(listingId)
{
	// Call webservice
	Abc.Modules.AbcWebService.ClearLastViewed(OnClearLastViewedComplete);
}

function OnClearLastViewedComplete(result)
{
	window.location.reload(false);
}

function GetQueryVariable(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i < vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return null;
}

function GetControlById(id)
{
	// Because the Id of a control varies so do a search
	var i;
	for (i = 0; i < document.forms[0].length; i++)
	{
		var myObj = document.forms[0][i];
		if (myObj.id.indexOf(id) > 0)
		{
			return myObj;
		}
	}
	return null;
}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
function URLEncoder(str)
{
    var outSt = "";
    for(var c = 0;c < str.length;c++){
        var cCode = str.charCodeAt(c);
        if(((cCode > 47)&&(cCode < 58))||
            ((cCode > 64)&&(cCode < 91))||
            ((cCode > 96)&&(cCode < 123))){
            outSt += str.charAt(c);
        }else if(cCode == 32){
            outSt += "+";
        }else{
            var hex = cCode.toString(16);
            var len = hex.length;
            switch(len){
                case 0:
                    hex = "00";
                    break;
                case 1:
                    hex = "0"+hex;
                case 2:
                    break;
                defalt:
                    hex = hex.substring((len-2), len);
                    break;
            }
            outSt += "%"+hex;
        }
    }
    return outSt;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document;
  if((p=n.indexOf("?"))>0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&& d.all) x=d.all[n];
  for (i=0;!x && i < d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x && d.layers && i < d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_OpenDialogWindow(url, width, height)
{
	var x, y, hh, ww, vWin;
	x=(screen.availWidth - width)/2;
	y=(screen.availHeight - height)/2;		
	vWin = window.open(url,"","height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no,resize=no,left=" + x + ", top=" + y);
	if (vWin!=null)
	{
		vWin.opener = self;
		vWin.focus();
	}	
}

function MM_OpenResWindow(url, width, height)
{
	var x, y, hh, ww, vWin;
	x=(screen.availWidth - width)/2;
	y=(screen.availHeight - height)/2;		
	vWin = window.open(url,"","height="+height+",width="+width+",status=no,scrollbars=yes,toolbar=no,menubar=yes,location=no,resizable=yes,left=" + x + ", top=" + y);
	if (vWin!=null)
	{
		vWin.opener = self;
		vWin.focus();
	}	
}
