// *********************************************************************************************************************************
//
// (c) Driftwood Interactive. All Rights Reserved.
// This code is licensed to Susan Loeb for use on the www.susanloeb.com site only.
//
// *********************************************************************************************************************************


// *********************************************************************************************************************************
// Global variables
//
var qConfirmLogouts = true;		// If you don't want confirmation alerts set this to false

var gMapBounds = null;

var kReturnKey = 13;
var kEscapeKey = 27;

// *********************************************************************************************************************************
function utRedirect(destination)
{
	window.location.href = destination;
}


// *********************************************************************************************************************************
function utFocusOnField(elementID, selectAll)
{
	textField = document.getElementById(elementID);
	if (textField != null) {
		textField.focus();
		if (selectAll) {
			textField.select();
		}
	}

	return;
}

// *********************************************************************************************************************************
function utEditFieldHasText(fieldID)
{
	hasText = false;
	editField = document.getElementById(fieldID);
	if (editField != null) {
		hasText = (editField.value.length > 0) ? true : false;
	}
	return hasText;
}

// *********************************************************************************************************************************
function utEditFieldHasIntegerValue(fieldID)
{
	hasText = false;
	editField = document.getElementById(fieldID);
	if ((editField != null) && (editField.value.length > 0)) {
		hasText = (parseInt(editField.value) > 0) ? true : false;
	}
	return hasText;
}

// *********************************************************************************************************************************
function utEditFieldHasFloatValue(fieldID)
{
	hasText = false;
	editField = document.getElementById(fieldID);
	if ((editField != null) && (editField.value.length > 0)) {
		hasText = (parseFloat(editField.value) > 0) ? true : false;
	}
	return hasText;
}

// *********************************************************************************************************************************
function utClearSelection()
{
	var sel;

	if (document.selection && document.selection.empty) {
		document.selection.empty();
	}
	else if (window.getSelection) {
		sel = window.getSelection();
		if(sel && sel.removeAllRanges) {
			sel.removeAllRanges();
			sel.collapse();
		}
	}
	return;
}

// *********************************************************************************************************************************
function utPopUpHasValue(popUpID)
{
	hasValue = false;
	popUp = document.getElementById(popUpID);
	if (popUp != null) {
		hasValue = (popUp.value != '') ? true : false;
	}
	return hasValue;
}

// *********************************************************************************************************************************
function utRadioBtnOn(radioBtnID)
{
	isOn = false;
	radioBtn = document.getElementById(radioBtnID);
	if (radioBtn != null) {
		isOn = radioBtn.checked;
	}
	return isOn;
}

// *********************************************************************************************************************************
function utCheckBoxOn(checkBoxID)
{
	isChecked = false;
	checkBox = document.getElementById(checkBoxID);
	if (checkBox != null) {
		isChecked = checkBox.checked;
	}
	return isChecked;
}

// *********************************************************************************************************************************
function utGetIsVisible(elementID)
{
	var isVisible = false;

	element = document.getElementById(elementID);
	if (element != null) {
		isVisible = (element.style.display != 'none') ? true : false;
	}

	return isVisible;
}

// *********************************************************************************************************************************
function utShowHideElement(elementID, showElement, displayType)
{
	if (typeof displayType == "undefined") {
		displayType = 'inline';
	}

	element = document.getElementById(elementID);
	if (element != null) {
		element.style.display = (showElement) ? displayType : "none";
	}
	return;
}


// *********************************************************************************************************************************
function utEnableElement(elementID, enableElement)
{
	element = document.getElementById(elementID);
	if (element != null) {
		element.disabled = ! enableElement;
	}
	return;
}

// *********************************************************************************************************************************
function utSetInnerHTML(elementID, html)
{
	theElement = document.getElementById(elementID);
	if (theElement != null) {
		theElement.innerHTML = html;
	}
	return;
}

// *********************************************************************************************************************************
function utGetFloat(fieldID)
{
	editField = document.getElementById(fieldID);
	if (editField != null) {
		return parseFloat(editField.value);
	}
	return "";
}

// *********************************************************************************************************************************
function utGetValue(fieldID)
{
	editField = document.getElementById(fieldID);
	if (editField != null) {
		return editField.value;
	}
	return "";
}

// *********************************************************************************************************************************
function utSetValue(elementID, value)
{
	theElement = document.getElementById(elementID);
	if (theElement != null) {
		theElement.value = value;
	}
	return;
}


// *********************************************************************************************************************************
// utGetKeyCode
//
function utGetKeyCode(theEvent)
{
	var keyCode = 0;

	if (theEvent == null) {
		var theEvent = window.event;
	}

	if (theEvent.keyCode) {
		keyCode = theEvent.keyCode;
	}
	else if (theEvent.which) {
		keyCode = theEvent.which;
	}

	return keyCode;
}


// *********************************************************************************************************************************
// utGetCookie
//
function utGetCookie(c_name)
{
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}

	return "";
}

// *********************************************************************************************************************************
// utSetCookie
//
function utSetCookie(c_name, value, expiredays)
{
	var expStr = '';

	if (expiredays == '0') {
		value = '';
		expStr = 'Thu, 01-Jan-1970 00:00:01 GMT';
	}
	else {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		expStr = exdate.toGMTString();
	}
	document.cookie = c_name + "=" + escape(value) + ((expStr == '') ? "" : ";expires=" + expStr);

	return;
}


// *********************************************************************************************************************************
// utCookiesEnabled
//
function utCookiesEnabled()
{
	var cookiesEnabled = false;

	utSetCookie('cookiesenabledtest', '1', 1);

	if (utGetCookie('cookiesenabledtest') == 1) {
		cookiesEnabled = true;
		utSetCookie('cookiesenabledtest', '0', '0');
	}

	return cookiesEnabled;
}

// *********************************************************************************************************************************
// utConfirmCancelOrder
//
function utConfirmCancelOrder(destination)
{
	return confirm("Are you sure you wish to cancel?");
}

// *********************************************************************************************************************************
// utConfirmLogOut
//
function utConfirmLogOut(destination)
{
	if ((!qConfirmLogouts) || confirm("Are you sure you wish to log out? Changes to your order will NOT be saved.")) {
		utRedirect(destination);
	}
}

// *********************************************************************************************************************************
function utPopup(theURL, theWidth, theHeight)
{
	var winSize = "width=" + theWidth + ",height=" + theHeight + ",resizable=yes";

	window.open(theURL, "", winSize);
}


// *********************************************************************************************************************************
function utLeft(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

// *********************************************************************************************************************************
function utRight(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// *********************************************************************************************************************************
function utRoundNumber(num, dec)
{
	var result = Math.round(num*Math.pow(10,dec)) / Math.pow(10,dec);

	return result;
}

// *********************************************************************************************************************************
function utAddCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

// *********************************************************************************************************************************
function utTimeToString(theTime)
{
	var timeStr = '';

	if (theTime != null) {
		hours = theTime.getHours();
		if (hours > 12)
			hours = hours - 12;
		if (theTime.getMinutes() < 10)
			minutes = "0" + theTime.getMinutes().toString();
		else
			minutes = theTime.getMinutes().toString();
		if (theTime.getHours() >= 12)
			ampm = "PM";
		else
			ampm = "AM";
		timeStr = hours.toString() +":"+ minutes +" "+ ampm;
	}

	return timeStr;
}

// *********************************************************************************************************************************
function utStringToTime(timeStr)
{
	var time = new Date();

	time.setTime(0);

	if ((timeStr != null) && (timeStr != '')) {
		timeStr = timeStr.trim();
		if (timeStr.length > 0) {
			while(timeStr.charAt(0) == String.fromCharCode(160)) {
				timeStr = timeStr.slice(1, timeStr.length);
			}
		}
		if (timeStr.length > 0) {
			while(timeStr.charAt(timeStr.length - 1) == String.fromCharCode(160)) {
				timeStr = timeStr.slice(0, timeStr.length - 1);
			}
		}

		if (timeStr.length > 0) {
			timeParts = timeStr.split(" ");
			hoursMinutes = timeParts[0];
			ampm = timeParts[1];
			hoursMinutesParts = hoursMinutes.split(":");
			hours = parseInt(hoursMinutesParts[0]);
			minutes = parseInt(hoursMinutesParts[1]);

			if (((ampm.toUpperCase() == 'PM') || (ampm.toUpperCase() == 'P.M.')) && (hours < 12)) {
				hours += 12;
			}

			time.setHours(hours);
			time.setMinutes(minutes);
			time.setSeconds(0);
		}

	//	alert('utStringToTime: _'+ hours +'_'+ minutes +"_"+ ampm +"_");

	}

	return time;
}

// *********************************************************************************************************************************
function utCreatePropertyMap(mapID, point, propertyAddress)
{
	var map = new GMap2(document.getElementById(mapID));
	map.addControl(new GSmallMapControl());

	map.setCenter(new GLatLng(0,0),0);
	if (gMapBounds == null) {
		gMapBounds = new GLatLngBounds();
	}

	if (point != null) {
		var marker = new GMarker(point, {title: propertyAddress, clickable: false});
		map.addOverlay(marker);
		zoomDelta = 2;
	}
	else {
		point = new GLatLng(41.876718930343934, -70.2520751953125);	// Center on Cape Cod
		zoomDelta = 9;
	}

	gMapBounds.extend(point);
	map.setZoom(map.getBoundsZoomLevel(gMapBounds) - zoomDelta);
	map.setCenter(gMapBounds.getCenter());
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
    	window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

//
// addUnloadEvent()
// Adds event to window.onunload without overwriting currently assigned onunload functions.
//
function addUnloadEvent(func)
{
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function')
	{
    	window.onunload = func;
	}
	else
	{
		window.onunload = function()
		{
			oldonunload();
			func();
		}
	}
}

String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/, "");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// Define methods for the Array data structure.
Array.prototype.indexOf = function(item, start)
{
	for (var i = (start || 0); i < this.length; i++)
	{
		if (this[i] == item)
		{
			return i;
		}
	}
	return -1;
}

function getElementsByClass(searchClass, node, tagName)
{
	var	classElements =	new	Array();
	if (node == null)
		node = document;
	if (tagName ==	null)
		tagName	= '*';

	var	els	= node.getElementsByTagName(tagName);
	var	elsLen = els.length;

	for	(i = 0,	j =	0; i < elsLen; i++)
	{
		if (hasClass(els[i], searchClass))
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getClasses(element)
{
	return element.className.trim().split(/\s+/);
}

function hasClass(element, className)
{
	return getClasses(element).indexOf(className) != -1;
}

function addClass(element, className)
{
    var classes = getClasses(element);

    if (classes.indexOf(className) == -1)
    {
        classes.push(className);
        element.className = classes.join(' ');
    }
}

function removeClass(element, className)
{
    var classes = getClasses(element);
    var index = classes.indexOf(className);

    if (index != -1)
    {
        classes.splice(index, 1);
        element.className = classes.join(' ');
    }
}

//function initRowHighlighting(tableClass, highlightClass)
function initRowHighlighting()
{
	if (!document.getElementsByTagName)
		{ return; }

	var tables = getElementsByClass('highlightTable', document, 'table');

	for(var i = 0; i < tables.length; i++)
	{
		var table = tables[i];
		//Make sure to use th tags for header row.
		attachRowMouseEvents(table.getElementsByTagName('tr'), 'highlight');
	}
}

function attachRowMouseEvents(rows, highlightClass)
{
	for(var i = 0; i < rows.length; i++)
	{
		var row = rows[i];

		if (! hasClass(row, 'noHighlight')) {
			row.onmouseover = function() { addClass(this, highlightClass); }
			row.onmouseout = function() { removeClass(this, highlightClass); }
		}
	}
}


function initCellHighlighting(tableClass, highlightClass)
{
	if (!document.getElementsByTagName)
		{ return; }

	var tables = getElementsByClass('highlightCellTable', document, 'table');

	for(var i = 0; i < tables.length; i++)
	{
		var table = tables[i];
		//Make sure to use th tags for header row.
		attachRowMouseEvents(table.getElementsByTagName('td'), 'highlight');
	}
}

function attachRowMouseEvents(rows, highlightClass)
{
	for(var i = 0; i < rows.length; i++)
	{
		var row = rows[i];

		if (! hasClass(row, 'noHighlight')) {
			row.onmouseover = function() { addClass(this, highlightClass); }
			row.onmouseout = function() { removeClass(this, highlightClass); }
		}
	}
}


function utIsIE6()
{
	if (document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1))
		return true;
	else
		return false;
}

// caHover function enables drop down menus in IE 6 - all modern browsers do not need this (IE 7, FF, Safari)
crHover = function() {
	if (document.getElementById("nav") != null) {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" crHover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" crHover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", crHover);


addLoadEvent(initRowHighlighting);

function utFindPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

// *********************************************************************************************************************************
// global variables //
var TIMER = 5;
var SPEED = 100;
var WRAPPER = 'wrapper';

// calculate the current window width //
function GetPageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function GetPageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function GetTopPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function GetLeftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,wrapper,autohide) {
	if(!type) {
		type = 'error';
	}
	var dialog;
	var dialogheader;
	var dialogclose;
	var dialogtitle;
	var dialogcontent;
	var dialogmask;
	var dialogwidth;
	var dialogheight;
	var width;
	var height;
	var left;
	var top;
	var topposition;
	var leftposition;
	var content;

	width = GetPageWidth();
	height = GetPageHeight();
	left = GetLeftPosition();
	top = GetTopPosition();

	content = document.getElementById(wrapper);
//	topLeft = utFindPos(content);

	if(!document.getElementById('dialog')) {
		dialog = document.createElement('div');
		dialog.id = 'dialog';
		dialogheader = document.createElement('div');
		dialogheader.id = 'dialog-header';
		dialogtitle = document.createElement('div');
		dialogtitle.id = 'dialog-title';
		dialogclose = document.createElement('div');
		dialogclose.id = 'dialog-close'
		dialogcontent = document.createElement('div');
		dialogcontent.id = 'dialog-content';
		dialogmask = document.createElement('div');
		dialogmask.id = 'dialog-mask';
		document.body.appendChild(dialogmask);
		document.body.appendChild(dialog);
		dialog.appendChild(dialogheader);
		dialogheader.appendChild(dialogtitle);
		dialogheader.appendChild(dialogclose);
		dialog.appendChild(dialogcontent);;
		dialogclose.setAttribute('onclick','hideDialog()');
		dialogclose.onclick = hideDialog;
	}
	else {
		dialog = document.getElementById('dialog');
		dialogheader = document.getElementById('dialog-header');
		dialogtitle = document.getElementById('dialog-title');
		dialogclose = document.getElementById('dialog-close');
		dialogcontent = document.getElementById('dialog-content');
		dialogmask = document.getElementById('dialog-mask');
		dialogmask.style.visibility = "visible";
		dialog.style.visibility = "visible";
	}

	dialog.style.opacity = .00;
	dialog.style.filter = 'alpha(opacity=0)';
	dialog.alpha = 0;
	dialogwidth = dialog.offsetWidth;
	dialogheight = dialog.offsetHeight;
	topposition = top + (height / 3) - (dialogheight / 2);
	leftposition = left + (width / 2) - (dialogwidth / 2);
	dialog.style.top = topposition + "px";
	dialog.style.left = leftposition + "px";
	dialogheader.className = type + "header";
	dialogtitle.innerHTML = title;
	dialogcontent.className = type;
	dialogcontent.innerHTML = message;
	dialogmask.style.height = content.offsetHeight + 'px';
	dialog.timer = setInterval("fadeDialog(1)", TIMER);
	if(autohide) {
		dialogclose.style.visibility = "hidden";
		window.setTimeout("hideDialog()", (autohide * 1000));
	}
	else {
		dialogclose.style.visibility = "visible";
	}

	if (utIsIE6()) {
		SelectFix.repairFloatingElement(dialogmask);
	}
}

// hide the dialog box //
function hideDialog() {
  var dialog = document.getElementById('dialog');
  if(!dialog.timer) {
    dialog.timer = setInterval("fadeDialog(0)", TIMER);
  }
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById('dialog');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    dialog.style.visibility = "hidden";
    document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
  }
}

function utHideDialog()
{
	hideDialog();
}

function utPleaseWaitRedirect(destination, message)
{
	addUnloadEvent(utHideDialog);

	if ((typeof message == "undefined") || (message == '')) {
		message = 'Please wait.<br /><br />This may take a few moments...<br /><br /><img src="images/loading.gif" height="32" width="32" />';
	}
	showDialog('', message, 'pleaseWaitMessage', 'propertyDetail', 0);

	if (destination != '') {
		utRedirect(destination);
	}
	return true;
}

// *********************************************************************************************************************************
// Uses JQuery's UI Dialog class to display a simple alert.
function utAlert(message)
{
	$('<div>'+ message +'</div>').dialog({
		modal: true,
		resizable: false,
		autoResize:true,
		overlay: { opacity: 0.6, background: "#99cc99" },
		buttons: { "OK": function() { $(this).dialog('destroy').remove(); } },
		close: function(ev, ui) { $(this).dialog('destroy').remove(); }
	});
}


// *********************************************************************************************************************************




// *********************************************************************************************************************************
startList = function() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i = 0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI") {
				node.onmouseover = function() {
				this.className +=" over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}
addLoadEvent(startList);


// *********************************************************************************************************************************

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*
**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];

			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

var MAX_DUMP_DEPTH = 10;

function dumpObj(obj, name, indent, depth) {
	  if (depth > MAX_DUMP_DEPTH) {
				return indent + name + ": <Maximum Depth Reached>\n";
	  }
	  if (typeof obj == "object") {
				var child = null;
				var output = indent + name + "\n";
				indent += "\t";
				for (var item in obj)
				{
						try {
								 child = obj[item];
						} catch (e) {
								 child = "<Unable to Evaluate>";
						}
						if (typeof child == "object") {
								 output += dumpObj(child, item, indent, depth + 1);
						} else {
								 output += indent + item + ": " + child + "\n";
						}
				}
				return output;
	  } else {
				return obj;
	  }
}


function ValidatePrice(inField)
{
	if ((inField.value == 0) || (inField.value.length == 0)) {
		alert ("This field can't be 0");
		inField.focus();
	}
	else {
		CalcPayment();
	}
}
function CalcMortgage()
{
	rate = document.getElementById('rate');
	price = document.getElementById('price');
	payment = document.getElementById('payment');
	if ((rate != null) && (price != null) && (payment != null)) {
		if ((price.value == 0) || (price.value.length == 0)) {
			alert ("The Price field can't be 0.");
			price.focus();
		}
		else if ((rate.value == 0) || (rate.value.length == 0)) {
			alert ("The Interest Rate field can't be 0.");
			rate.focus();
		}
		else {
			CalcPayment();
		}
	}
}
function CalcPayment()
{
	price = document.getElementById('price');
	rate = document.getElementById('rate');
	years = document.getElementById('years');
	payment = document.getElementById('payment');
	if ((rate != null) && (price != null) && (payment != null) && (years != null)) {
		interestRate = (rate.value / 100) / 12;
		amount = Math.floor((price.value * interestRate) / (1 - Math.pow(1 + interestRate, -(years.value * 12))) * 100) / 100, 2;
		payment.value = utAddCommas(amount.toFixed(2));
	}
}
