/// <history>
///	 <change date="2006-04-08" author="Darrin Morgan">Original Version</change>
/// </history>

/// <summary>
/// Add a trim function to the existing String object.
/// </summary>
String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g,""); }



/// <summary>
/// This function is invoked by the browser on page load.
/// </summary>
function Main( scriptName )
{
	//	we're not gonna be loaded in frames
	if ( top.frames.length ) top.location.href = self.location.href;

	// if this is the home page, start rotating images.
	if (scriptName == "home" || scriptName == "default" )
	{
		top.HomeObject.NextSpecialPhoto();
	}

	
	// convert all characters to lowercase to simplify testing
	var agt = navigator.userAgent.toLowerCase();
	 
	// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie7up = ( is_ie && agt.indexOf("msie 7.")!=-1 );

	// need a floating sidebar menu if in Internet Explorer.
	if (is_ie && !is_ie7up) OnLoadFloat();



	var innerHeight;

	var footerMenuRow = document.getElementById("FooterMenuRow");
	footerMenuRow = (footerMenuRow==null) ? 0 : footerMenuRow.clientHeight;

	var footerBaseRow = document.getElementById("FooterBaseRow");
	footerBaseRow = (footerBaseRow==null) ? 0 : footerBaseRow.clientHeight;

	if (document.layers || (document.getElementById && !document.all)) // not IE
		innerHeight = self.innerHeight;
	else if (document.all) // IE
		innerHeight = document.documentElement.offsetHeight;

	// calculate height required to push footer to bottom.
	var newHeight = innerHeight - (footerMenuRow + footerBaseRow);

	var diff = (document.all) ? 114 : 100;

	// set height of body table appropriate to the window size.
	var bodyTable = document.getElementById("BodyTable");
	var bodyRow = document.getElementById("BodyRow");
	if (bodyTable!=null) bodyTable.style.height = newHeight + "px";
	if (bodyRow!=null) bodyRow.style.height = (newHeight-diff) + "px";
}



/// <summary>
/// Used to determine whether cookies are enabled on this browser.
/// </summary>
function IsCookieEnabled()
{
	var tmpcookie = new Date();
	var chkcookie = (tmpcookie.getTime() + '');

	document.cookie = "checkcookie=" + chkcookie + "; path=/";

	return (document.cookie.indexOf(chkcookie,0) < 0)
}



/// <summary>
/// Tables that were modified by the HTC for scrollbars can be resized by locating 
/// the generated DIV to which they belong and setting the height of it.
/// </summary>
/// <param name="id">Id of the table to be resized.</param>
/// <param name="amount">The number of pixels by which to resize the table.</param>
function ResizeTableHeight(id, amount)
{
	var container = document.getElementById(id);
	if (container==null)return;

	var newHeight = 0;
	var table;

	var div = container.getElementsByTagName("DIV");
	if (div==null || div.length==0)
	{
		var table = container.getElementsByTagName("tbody")[0];
		var originalHeight = parseInt(table.clientHeight);
	}
	else
	{
		var table = div[0]
		var originalHeight = parseInt(table.style.height);
	}
	var innerHeight = (document.all) ? document.body.scrollHeight : self.innerHeight;

	if (table!= null)
	{
		newHeight = parseInt(innerHeight) - amount;
		if (newHeight < 50) newHeight = originalHeight;
		table.style.height = "" + newHeight + "px";
	}
	setCookie("TableHeight", newHeight)
}


/// <summary>
/// Show the div containing the log of JavaScript Errors on the page.
/// </summary>
function ShowJavaScriptErrors()
{
	var log = document.getElementById("ExceptionLog");
	if (log) log.style.display = (log.style.display=="") ? "none" : "";
}


/// <summary>
/// Add a frame to the image by adding the frame class to the element.
/// </summary>
function FrameOn(src)
{
	// if the element does not use the thumb class just add a frame class.
	if (src.className.indexOf("ThumbNail") == -1)
		src.className = "FrameVisible";
	else
		src.className = "FrameVisible ThumbNail";
}



/// <summary>
/// remove the frame from the element by removing the frame class.
/// </summary>
function FrameOff(src) 
{
	if (src.className.indexOf("ThumbNail") == -1)
		src.className = "FrameHidden";
	else
		src.className = "FrameHidden ThumbNail";
}





var _RowHighlightColor = "#99A5BD";
var _RowIgnoreHighlightColor = "pink";

/// <summary>
/// When the mouse moves over an html element set its background color
/// to indicate our position.
/// </summary>
/// <param name="value">The source element to be hightlighted.</param>
function RowHighlight(src)
{
//	if (src.style.backgroundColor != _RowIgnoreHighlightColor)
		src.style.backgroundColor = _RowHighlightColor;
}

/// <summary>
/// When the mouse moves out of an html element set its background color
/// back to a default state.
/// </summary>
/// <param name="value">The source element to be hightlighted.</param>
function RowLowlight(src)
{
//	if (src.style.backgroundColor == _RowHighlightColor)
		src.style.backgroundColor = "";
}

/// <summary>
/// When the mouse moves out of an html element set its background color
/// back to a default state.
/// </summary>
/// <param name="value">The color to be used when hightlighting the row</param>
function SetRowHighlightColor(value) 
{
	_RowHighlightColor = value;
}





/// <summary>
/// Open a window and display the property image specified.
/// </summary>
function ShowSalesPhoto( agency, code, photo, title )
{
	var url = "../Photo.aspx?type=sales&property=" + agency + "." + code + "&photo=WebPhotos/" + agency + "/" + code + "/" + photo + "&title=" + title;
	window.open(url, "photo", "left=10,top=10,status=yes,width=470,height=550,resizable=yes,scrollbars=no");
}

/// <summary>
/// Open a window and display the property image specified.
/// </summary>
/// <param name="element">Name of html element to resize.</param>
function ShowRentalPhoto( code, photo, title )
{
	var url = "../Photo.aspx?type=rental&property=" + code + "&photo=WebPhotos/Rental/" + code + "/" + photo + "&title=" + title;
	window.open(url, "photo", "left=10,top=10,status=yes,width=470,height=550,resizable=yes,scrollbars=no"); 
}