//===========================================================================
// File:           baseUtils.js
// Purpose:        to provide basic javascript functionality
// History:        2005.10.10 - JQuattlebaum
//===========================================================================

//===========================================================================
// Function:       print_r()
// Purpose:        return structure of an object
// Example:        alert(print_r(OObj, true, '\t'));
// IMPORTANT NOTE: When using the recursive flag of this function
//                 you *have* to be careful as JS likes to loop back around
//                 between objects infinitly.  a future 'seen' flag will
//                 (hopefully) get built in.
// History:        2005.12.02 - JQuattlebaum - Initial Revision
//===========================================================================
function print_r(OObj, recurse, prependingSpace) {
	if(typeof OObj == 'object') {
		var treeDisplay = '';
		for(var key in OObj) {
			treeDisplay += prependingSpace+'['+key+'] => \''+OObj[key]+'\' ('+typeof OObj[key]+')\n';
			if(recurse && typeof OObj[key] == 'object') {
				treeDisplay += print_r(OObj[key], recurse, prependingSpace+'\t');
			}
		}
		return treeDisplay;
	} else {
		return 'not an object!';
	}
}
//===========================================================================

//===========================================================================
// Functions:     genPointerObject(), getObject(), getFormObject()
// Purpose:       to store a cached version of pointers to
//                objects we are focused on so we don't have
//                to keep calling getElementsById and document.forms
// History:       2005.10.10 - JQuattlebaum - Initial Revision
//===========================================================================
function genPointerObject() {
	if(typeof objectPointers != 'object') {
		objectPointers = Object();
		objectPointers.objPtr = Array();
		objectPointers.formPtr = Array();
	}
}
function getObject(pointerName) {
	genPointerObject();
	if(typeof objectPointers.objPtr[pointerName] != 'object') {
		objectPointers.objPtr[pointerName] = document.getElementById(pointerName);
	}
	return objectPointers.objPtr[pointerName];
}
function getFormObject(formName, pointerName) {
	genPointerObject();
	if(typeof objectPointers.formPtr[pointerName] != 'object') {
		objectPointers.formPtr[pointerName] = document.forms[formName][pointerName];
	}
	return objectPointers.formPtr[pointerName];
}
//===========================================================================

//===========================================================================
// Functions:     showCell(), hideCell(), swapCellDisplay()
// Purpose:       do basic display handling for specific cells
// History:       2006.01.09 - JQuattlebaum - Initial Revision
//===========================================================================
function showCell(id) {
	if(typeof getObject(id) == 'object') {
		getObject(id).style.display = '';
	}
}
function hideCell(id) {
	if(typeof getObject(id) == 'object') {
		getObject(id).style.display = 'none';
	}
}
function swapCellDisplay(id) {
	if(typeof getObject(id) == 'object') {
		if(getObject(id).style.display == '' || getObject(id).style.display == 'inline') {
			hideCell(id);
		} else {
			showCell(id);
		}
	}
}
//===========================================================================


