window.onresize = SetThreeColHeight;

function CommonInit()
{
	SetThreeColHeight();

	//setup the treeview control if it exists
	if (document.getElementById("treeview"))
	{
		Setuptreeview("treeview");
		ExpandTree("public-home");
		ExpandTree("owners-home");

		//detect page and expand the tree to the correct item in the tree
		var currentPage = window.location.href;
		var arrPath = currentPage.split('/');
		if (arrPath.length > 0)
		{
			var currentFile = arrPath[arrPath.length - 1];
			currentFile = currentFile.replace(".aspx", "");

			if (document.getElementById(currentFile))
				ExpandTree(currentFile);
		}
	}
}

function SetThreeColHeight()
{
	var loColumn1 = document.getElementById("divContent");
	var loColumn2 = document.getElementById("divRightNav");

	if (loColumn1 != null)
	{
		var liCol1Height = loColumn1.offsetHeight;
		var liCol2Height = loColumn2.offsetHeight;

		var liMaxHeight = loColumn1.offsetHeight;

		//determine column with the maximum height
		if (liCol2Height > liMaxHeight)
			liMaxHeight = loColumn2.offsetHeight;

		//apply maximum height to col2
		loColumn2.style.height = liMaxHeight + "px";
	}
}


//GetElement were copied from framecontent.js 
function GetElement(psId) 
{
	return document.getElementById(psId);
}
//end of copied functions


function MouseOverImage(poImg)
{
	var loImgCol = document.getElementsByName(poImg.name);

	if (loImgCol != null)
	{
		//set poImg[0] to image number 1 in collection
		try
		{
			loImgCol[0].src = loImgCol[1].src;
		}
		catch(e)
		{
			alert(poImg.name + ' does not contain three img tags');
		}
	}
}


function MouseOutImage(poImg)
{
	var loImgCol = document.getElementsByName(poImg.name);

	if (loImgCol != null)
	{
		//set poImg[0] to image number 2 in collection
		try
		{
			loImgCol[0].src = loImgCol[2].src;
		}
		catch(e)
		{
			alert(poImg.name + ' does not contain three img tags');
		}
	}
}


function OpenWindow( sURL, iHeight, iWidth, blnResizeable )
{
	//center window position
	var ScreenX = (screen.availWidth - iWidth)/2;
	var ScreenY = (screen.availHeight - iHeight)/2;

	var	objRet = window.open( sURL, '_blank', 'height=' + iHeight + ',width=' + iWidth + ',left=' + ScreenX + ',top=' + ScreenY + ',location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=' + (blnResizeable ? 'yes' : 'no'), true );
	objRet.focus();
	return objRet;
}

function OpenWindow2( sURL, iHeight, iWidth, blnResizeable, pbShowLocationBar )
{
	//center window position
	var ScreenX = (screen.availWidth - iWidth)/2;
	var ScreenY = (screen.availHeight - iHeight)/2;

	var	objRet = window.open( sURL, '_blank', 'height=' + iHeight + ',width=' + iWidth + ',left=' + ScreenX + ',top=' + ScreenY + ',location=' + (pbShowLocationBar ? 'yes' : 'no') + ',menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=' + (blnResizeable ? 'yes' : 'no'), true );
	objRet.focus();
	return objRet;
}



function OpenCalendarWindow()
{
	//center window position
	var lsUrl = '../calendar/calendar.htm';
	var liHeight = '205';
	var liWidth = '300';

	var ScreenX = (screen.availWidth - liWidth)/2;
	var ScreenY = (screen.availHeight - liHeight)/2;

	var objRet = OpenWindow2( lsUrl, liHeight, liWidth, true, true )
	//var	objRet = window.open( lsUrl, '_blank', 'height=' + liHeight + ',width=' + liWidth + ',left=' + ScreenX + ',top=' + ScreenY + ',location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no', true );
	objRet.focus();
	return objRet;
}


function OpenAvailabilityWindow(psUrl)
{
	var liHeight = '250';
	var liWidth = '960';

	var ScreenX = (screen.availWidth - liWidth)/2;
	var ScreenY = (screen.availHeight - liHeight)/2;

	var	objRet = window.open( psUrl, '_blank', 'height=' + liHeight + ',width=' + liWidth + ',left=' + ScreenX + ',top=' + ScreenY + ',location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no', true );
	objRet.focus();
}

function OpenReferAFriendPopup()
{
	var lsURL = '../public/ReferAFriend.aspx';
	var x = OpenWindow(lsURL, 320, 450, false);
}


function OpenOwnerTermsConditionsPopup()
{
	var lsURL = '../private/OwnerTermsConditionsPopup.aspx';
	var x = OpenWindow(lsURL, 320, 450, false);
}


function OpenEstablishmentRatesPopup(piEstablishmentId)
{
	var lsURL = '../public/EstablishmentRatesPopup.aspx?iEstablishmentId=' + piEstablishmentId.toString();
	var x = OpenWindow(lsURL, 320, 660, true);
}




if (typeof HTMLElement != "undefined" && typeof HTMLElement.prototype.__defineGetter__ != "undefined") 
{
	//emulate innertext property in non-ie browsers
	HTMLElement.prototype.__defineGetter__("innerText", function () 
		{
			var r = this.ownerDocument.createRange();
			r.selectNodeContents(this);

			var resultString = r.toString();
			resultString = resultString.replace(/\t/g, "");	//horizontal tab
			resultString = resultString.replace(/\n/g, "");	//newline
			resultString = resultString.replace(/\r/g, "");	//carriage return
			resultString = resultString.replace(/\f/g, "");	//form feed
			resultString = resultString.replace(/\b/g, "");	//backspace
			resultString = resultString.replace(/\v/g, "");	//vertical tab

			return resultString;
		}
	);

	HTMLElement.prototype.__defineSetter__("innerText", function (sText) 
		{
		this.innerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
		}
	);
}


function SetRefinedSearchSelection(Id, Description, TypeCode, SeoUrl) {
	$("#hidLocationId").val(Id);
	$("#txtLocationName").val(Description);
	$("#hidSearchTypeCode").val(TypeCode);

	$("#dialog-form").dialog('close');

	if (SeoUrl.length > 0) 
	{
		$.blockUI({ message: '<h1>Please wait while we are searching...</h1>' });
		setTimeout($.unblockUI, 25000);
		window.location.href = SeoUrl;
	}
}

