function Get(o) { return document.getElementById(o); }

function GoToFirstChlidLink(elem)
{
	for (i=0; i < elem.childNodes.length; i++)
		if (elem.childNodes[i].nodeName.toLowerCase() == 'a')
			document.location.href = elem.childNodes[i].href;
}

//--------------------------------------------------
// 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)
{
	document.getElementById(elemID).style.position   = "absolute";
	document.getElementById(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)
{
	document.getElementById(elemID).style.position   = "relative";  // FF, NS want to hear 'relative' (so does W3c standard)
	document.getElementById(elemID).style.position   = "static";    // but IE will only listen to 'static'
	document.getElementById(elemID).style.visibility = "visible";
}

//--------------------------------------------------
// 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    = document.getElementById("LogInEmail");
		var passwordField = document.getElementById("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)
{
	document.getElementById(elemID).focus();
}

//--------------------------------------------------
// Allows multiple in-script settings of onload
//
function WindowOnload(f) {
	var prev=window.onload;
	window.onload=function(){ if(prev)prev(); f; }
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1)
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

//--------------------------------------------------
// 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)
{
	document.getElementById(elemID).style.position   = "absolute";
	document.getElementById(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)
{
	document.getElementById(elemID).style.position   = "relative";  // FF, NS want to hear 'relative' (so does W3c standard)
	document.getElementById(elemID).style.position   = "static";    // but IE will only listen to 'static'
	document.getElementById(elemID).style.visibility = "visible";
}

//--------------------------------------------------
// Functions for accessing cookies in JavaScript
// adapted from:
// http://www.quirksmode.org/js/cookies.html
//
function CreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function ReadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function EraseCookie(name) {
	createCookie(name,"",-1);
}

//--------------------------------------------------
// Handles fields with default text
//
function ClearDefaultText(elem, text)
{
    if (elem.value == text)
    {
        elem.value = "";
        elem.style.color = "#000000";
    }
}

function SetupDefaultText(elem, text)
{
    if (elem.value == text)
    {
        elem.style.color = "#969696";
    }
}

//--------------------------------------------------
// Calls the specified function when the event key
// is the enter key, and then cancels the keystroke.
//
function SubmitOnEnter(e, actionToDo)
{
	var keynum;
	var keychar;

	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}

	if (keynum == 13)
	{
		actionToDo();
		return false;
	}

	return true;
}

//--------------------------------------------------
// 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() { }

// 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
if (typeof window.event != 'undefined') // IE
	document.onkeydown = function() // IE
	{
		var t = event.srcElement.type;
		var kc = event.keyCode;
		return (kc != 8 || t == 'text' || t == 'password' || t == 'textarea');
	}
else
	document.onkeypress = function(e)  // FireFox/Others
	{
		var t = e.target.type;
		var kc = e.keyCode;
		if (kc != 8 || t == 'text' || t == 'password' || t == 'textarea')
        	return true;
		else
			return false;
	}

function moneyFormat(textObj)
{
   var newValue = textObj.value;
   var decAmount = "";
   var dolAmount = "";
   var decFlag = false;
   var aChar = "";

   // ignore all but digits and decimal points.
   for(i=0; i < newValue.length; i++) {
      aChar = newValue.substring(i,i+1);
      if(aChar >= "0" && aChar <= "9") {
         if(decFlag) {
            decAmount = "" + decAmount + aChar;
         }
         else {
            dolAmount = "" + dolAmount + aChar;
         }
      }
      if(aChar == ".") {
         if(decFlag) {
            dolAmount = "";
            break;
         }
         decFlag=true;
      }
   }

   // Ensure that at least a zero appears for the dollar amount.

   if(dolAmount == "") {
      dolAmount = "0";
   }
   // Strip leading zeros.
   if(dolAmount.length > 1) {
      while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
         dolAmount = dolAmount.substring(1,dolAmount.length);
      }
   }

   // Round the decimal amount.
   if(decAmount.length > 2) {
      if(decAmount.substring(2,3) > "4") {
         decAmount = parseInt(decAmount.substring(0,2)) + 1;
         if(decAmount < 10) {
            decAmount = "0" + decAmount;
         }
         else {
            decAmount = "" + decAmount;
         }
      }
      else {
         decAmount = decAmount.substring(0,2);
      }
      if (decAmount == 100) {
         decAmount = "00";
         dolAmount = parseInt(dolAmount) + 1;
      }
   }

   // Pad right side of decAmount
   if(decAmount.length == 1) {
      decAmount = decAmount + "0";
   }
   if(decAmount.length == 0) {
      decAmount = decAmount + "00";
   }

   // Check for negative values and reset textObj
   if(newValue.substring(0,1) != '-' ||
         (dolAmount == "0" && decAmount == "00")) {
      textObj.value = dolAmount + "." + decAmount;

   }
   else{
      textObj.value = '-' + dolAmount + "." + decAmount;
   }
}

//changes an image elements src
function changeImage( elem, path )
{
    elem.src = path;
}