function GoToFirstChildLink(elem)
{
	for (i=0; i < elem.childNodes.length; i++)
		if (elem.childNodes[i].nodeName.toLowerCase() == 'a')
			document.location.href = elem.childNodes[i].href;
}

function hideElement(elemID) { HideElement(elemID); } // Legacy
function showElement(elemID) { ShowElement(elemID); }

//--------------------------------------------------
// A generic function that highlights the label of
// any item by parsing the DOM to find it.  The
// function assumes this structure:
//   <tr>
//    <th>[label here]</th>
//    <td>[selected item here]</td>
//   </tr>
// This is the layout of most of our forms, so using
// this in the onFocus and onBlur events of form
// elements can change the color of their labels when
// they are active.
//
function ChangeLabelColor(elem, newColor, backColor)
{
	var tableRow = elem;
	var count = 0;
	while (tableRow.nodeName.toLowerCase() != 'tr' && count < 10)
	{
		tableRow = tableRow.parentNode;
		count++;
	}
	if (count == 10) return;

	tableRow.style.backgroundColor = backColor;

	for (i=0; i < tableRow.childNodes.length; i++)
		if (tableRow.childNodes[i].nodeName.toLowerCase() == 'th')
			tableRow.childNodes[i].style.color = newColor;
}

//--------------------------------------------------
// Some shortcuts for accessing ChangeLabelColor
// in context
//
var highlightColor   = "#10147F";
var unHighlightColor = "#000000";
var backgroundColor  = "#E8ECF5";
var noColor          = "#FFFFFF";

function HighlightLabel(elem)
{
	ChangeLabelColor(elem, highlightColor, backgroundColor);
}

function UnHighlightLabel(elem)
{
	ChangeLabelColor(elem, unHighlightColor, noColor);
}

//--------------------------------------------------
// Opens the features tour window, starting at the
// selected feature.
//
function OpenFeaturesWindow(index)
{
    featuresWindow = window.open('http://www.ezlandlordforms.com/wizards/demos/tour.aspx?p=' + index,'FeaturesTour','width=740,height=480,resizable=no,scrollbars=yes,menubar=no,status=no');
    
    try
    {
        if (window.focus)
        	featuresWindow.focus();
    }
    catch (e) { }
}

//--------------------------------------------------
// Focuses the sign in form on the page
//
function FocusSignInForm()
{
	try
	{
		var emailField    = Get("LogInEmail");
		var passwordField = Get("LogInPassword");

		if (emailField != null && emailField.value == '') emailField.focus();
		else if (passwordField != null) passwordField.focus();

	}
	catch (e)
	{
		// .. no login form on the page
	}
}

//--------------------------------------------------
// Puts the cursor in a specified field
//
function SetCursorLocation(elemID)
{
	Get(elemID).focus();
}

//--------------------------------------------------
// Allows multiple in-script settings of onload
//
function WindowOnload(f) {
    if (f) window.onload = AddEventHandler(window.onload, f); // passing through to new library
}

function findPosX(obj) {
    return Pliner.Util.Display.FindXPosition(obj); // passing throught to new library
}

function findPosY(obj) {
    return Pliner.Util.Display.FindYPosition(obj); // passing throught to new library
}

//--------------------------------------------------
// A generic hide function the makes an element
// invisible, and pulls it out of relative alignment
// so it does not hold any space
//
function HideElement(elemID)
{
	Get(elemID).style.position   = "absolute";
	Get(elemID).style.visibility = "hidden";
}

//--------------------------------------------------
// A generic show function that makes an element
// visible, and pulls it back into relative
// alignment with it's surroundings so it will
// size to the content around it
//
function ShowElement(elemID)
{
	Get(elemID).style.position   = "relative";  // FF, NS want to hear 'relative' (so does W3c standard)
	Get(elemID).style.position   = "static";    // but IE will only listen to 'static'
	Get(elemID).style.visibility = "visible";
}

//--------------------------------------------------
// Functions for accessing cookies in JavaScript
// adapted from:
// http://www.quirksmode.org/js/cookies.html
//
function CreateCookie(name,value,days) {
    Pliner.Util.Forms.CreateCookie(name, value, days); // passing through to new library
}

function ReadCookie(name) {
    return Pliner.Util.Forms.ReadCookie(name); // passing through to new library
}

function EraseCookie(name) {
	Pliner.Util.Forms.EraseCookie(name); // passing through to new library
}

//--------------------------------------------------
// Handles fields with default text
//
function ClearDefaultText(elem, text)
{
    Pliner.Util.Display.ClearFieldDefaultText(elem, text, "#000000"); // passing though to new library
}

function SetupDefaultText(elem, text)
{
    Pliner.Util.Display.SetupFieldDefaultText(elem, text, "#969696"); // passing through to new library
}

//--------------------------------------------------
// Calls the specified function when the event key 
// is the enter key, and then cancels the keystroke.
//
function SubmitOnEnter(e, actionToDo)
{
    return Pliner.Util.Forms.CallbackOnEnterPressed(e, actionToDo); // passing through to new library
}

//--------------------------------------------------
// If the specified object is positioned in a way 
// where it is partially offscreen, it is moved 
// so that it is as close to the requested position 
// as possible without being offscreen.
//
function FixOffscreenPosition(objItem)
{
	var winHeight = 1000;
	var winWidth = 1000;

	if (parseInt(navigator.appVersion) > 3)
	{
		if (navigator.appName == "Netscape")
		{
			winWidth  = window.innerWidth;
			winHeight = window.innerHeight;
		}
		
		if (navigator.appName.indexOf("Microsoft") != -1)
		{
			winWidth  = document.documentElement.clientWidth;
			winHeight = document.documentElement.clientHeight;
		}
	}
	
	var scrollOffset = document.all ? ((document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body).scrollTop : pageYOffset;
	
	if (findPosY(objItem) + objItem.offsetHeight > scrollOffset + winHeight)
		objItem.style.top = (scrollOffset + winHeight - objItem.offsetHeight - 5) + "px";
    /*
	if (findPosX(objItem) + objItem.offsetWidth > winWidth)
		objItem.style.left = (winWidth - objItem.offsetWidth - 25) + "px";
    */
	
	/*	
	if (findPosX(objItem) < 2)
	    objItem.style.left = "2px";
	*/
	if (findPosY(objItem) < (scrollOffset + 2))
	    objItem.style.top = (scrollOffset + 2) + "px";
}

// ** do nothing
function nothing() { }

// ** alias to save code
// function Get(o) { return document.getElementById(o); } // replaced by new library

function FormatMoneyField(elem) { 
    if (!isNaN(elem.value) && elem.value.length > 0) elem.value = parseFloat(elem.value).toFixed(2);
}

// Block unintended backspaces to stop people from accidentally going back
// based on: http://mspeight.blogspot.com/2007/05/how-to-disable-backspace-in-ie-and.html
Pliner.Util.Forms.StopBackspaceFromGoingBackAPage(); // passing through to new library
	
function ClearChildNodes(elem) { 
    ClearElem(elem); // passing through to new library
}

function GetScreenCenteredX(itemWidth)
{
    return Pliner.Util.Display.FindScreenCenteredX(itemWidth); // passing through to new library
}

function GetScreenCenteredY(itemHeight)
{
    return Pliner.Util.Display.FindScreenCenteredY(itemHeight); // passing through to new library
}

/** -- Image Pre-Loading -- **/
var preloadedImages = [
    "/images/layout2009/header_nav_drop_body.png", 
    "/images/layout2009/header_nav_drop_bottom.png", 
    "/images/layout2009/header_nav_down_off.gif",
    "/images/layout2009/header_nav_down_on.gif", 
    "/images/layout2009/headerbuttons/header_help_blue_on.jpg", 
    "/images/layout2009/headerbuttons/header_help_blue_off.jpg", 
    "/images/layout2009/headerbuttons/header_tour_on.jpg", 
    "/images/layout2009/headerbuttons/header_tour_off.jpg", 
    "/images/layout2009/curtain_close.gif", 
    "/images/ajax-loader.gif", 
    "/images/layout2009/leftnav/arrow_right_on.jpg", 
    "/images/layout2009/leftnav/arrow_right_off.jpg", 
    "/images/layout2009/leftnav/arrow_down_on.jpg"
    ];

function PreloadImages() { 
    Pliner.Util.Display.PreloadImages(preloadedImages); // passing through to new library
}