///////////////////////////////////////////////////////////////////////////
//
//	Filename:	tbs.js
//
//	Authors:	Dave Phoebus
//
///////////////////////////////////////////////////////////////////////////


// Get Browser Info - OLD

	browserIE = 0;
	browserNetscape = 0;
	browserVersion = parseInt(navigator.appVersion);

	if (navigator.userAgent.indexOf('MSIE') >= 0)
		browserIE = 1;
	else if (navigator.userAgent.indexOf('Mozilla') >= 0)
		browserNetscape = 1;

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false



// Highliter

function cls(obj,clsname)
{
	obj.className=clsname;
}


function clsObj(ID,clsname)
{
	styleMe(document.getElementById(ID), clsname);
}


// Page Re-directs for HTML click-thru
function RelocateTo(pageid)
{
	window.top.document.location=pageid; return false;
}

function RelocateFrame(pageid)
{
	window.location=pageid; return false;
}

function RelocateToBlank(pageid)
{
	window.open(pageid,"NewWin000"); return false;
}


// POP-UP WINDOWS

function GetCursorPos()
{
	return "top=" + document.body.scrollLeft + event.screenY + "&left=" + document.body.scrollLeft + event.screenX;
}

var winStatus = 0;

function doWin(src,wd,ht,options)
{
	if (winStatus == 1) {		
		newWindow.close();
	}
	
	var sizable = 'yes';
	var scrolling = 'no';
	
	if (options == 'scroll') {
		scrolling = 'yes';
	}
	
	if (options == 'fixed') {
		sizable = 'no';
		scrolling = 'no';
	}
	
	x = (screen.width) ? (screen.width-wd)/2 : 0;
	y = (screen.height) ? (screen.height-ht)/2 : 0;
	
	winSettings = 'location=no,menubar=no,directories=no,toolbar=no,status=yes,personalbar=no,titlebar=no,scrollbars='+scrolling+',dependent=no,resizable='+sizable+',width='+wd+',height='+ht+',top='+y+',left='+x+''; // define window size and chrome
	
	newWindow=window.open(src,'newWin',winSettings);
	winStatus = 1;
}

function sizeWin(wd,ht)
{	
	if (!ht) {
		ht = document.body.scrollHeight+50;
	}
	
	if (ht > screen.height ) {
		ht = screen.height;
	}
	
	if (wd == 'wide') {
		wd = screen.width;
		x = 0;
		y = (screen.height-ht)/2;
		window.moveTo(x,y);
	}
	
	if (ht == 'tall') {
		ht = screen.height;
		x = (screen.width-wd)/2;
		y = 0;
		window.moveTo(x,y);
	}
	
	window.resizeTo(wd,ht);
}

function doReturn(dest)
{
		window.returnValue = "document.location = ' " + dest + " ' ";
		window.close();
}


// TREE TOGGLER

function doBranch(node) {

	if(node.parentNode.className == "closed") {
		node.parentNode.className = "open";
	}
	
	else if (node.parentNode.className == "open") {
		node.parentNode.className = "closed";
	}
}

function doFolder(node,iFr) {

	if(node.parentNode.className == "closed") {
		node.parentNode.className = "open";
	}
	window.parent.document.getElementById(iFr).src = 'ifr_folder_contents.php';
}	

function branchAll() {
	
	var nodes = document.getElementsByTagName('li');

	for (var i = 0; i < nodes.length; i++) {
	
		if (nodes[i].className == 'closed') {			
			nodes[i].className = 'open';
		}
	}	
}

function collapseAll() {
	
	var nodes = document.getElementsByTagName('li');

	for (var i = 0; i < nodes.length; i++) {
	
		if (nodes[i].className == 'open') {			
			nodes[i].className = 'closed';
		}
	}
}


// Image swapper

function swapImg(image,target) {
	document.getElementById(target).img.src = image;
}


// SHOW-HIDE

function showHide(event,node)
{
	event.cancelBubble=true;
	document.getElementById(node).style.display = (document.getElementById(node).style.display == "none")?"block":"none";
	event.cancelBubble=true;
}


// HELP TAB

function pullTab(event,tab,obj)
{
	event.cancelBubble=true;
	document.getElementById(tab).style.display = (document.getElementById(tab).style.display == "")?"block":"";
	document.getElementById(obj).style.width = (document.getElementById(obj).style.width == "")?"260px":"";
	event.cancelBubble=true;
}


// DIV SWAPPER

function showDIV(divName){
	document.getElementById(divName).style.display = 'block';
	document.getElementById(divName).style.visibility = 'visible';
}

function hideDIV(divName){
	document.getElementById(divName).style.visibility = 'hidden';
	document.getElementById(divName).style.display = 'none';
}

function doTab(obj,divName) {

	var aTabs = document.getElementsByTagName('a');
	var aPanels = document.getElementsByTagName('div');

	for (i = 0; i < aTabs.length; i++) {
	
		if (aTabs[i].className == 'on') {		
			aTabs[i].className = 'off';
		}
	}
	obj.className='on';
	
	for (i = 0; i < aPanels.length; i++) {
	
		if (aPanels[i].className == 'panel') {
			aPanels[i].style.visibility = 'hidden';
			aPanels[i].style.display = 'none';
		}
	}	
	document.getElementById(divName).style.display = 'block';
	document.getElementById(divName).style.visibility = 'visible';
}


// CONFIRMATIONS

function confirmAction(lyr) {

	var conf = top.document.getElementById(lyr);
	var IfrRef = top.document.getElementById(lyr+'Shim');
	
	var winWidth = top.document.documentElement.clientWidth;
	var winHeight = top.document.documentElement.clientHeight;
	var scrHeight = top.document.documentElement.scrollTop;
	
	conf.style.display = 'block';
	conf.style.visibility = 'visible';
	
	xPos = (winWidth - conf.offsetWidth)/2;
	yPos = (winHeight - conf.offsetHeight)/2 + scrHeight;

	conf.style.left = xPos + 'px';
	conf.style.top = yPos + 'px';	
	
	IfrRef.style.width = conf.offsetWidth + 'px';
	IfrRef.style.height = conf.offsetHeight + 'px';
	IfrRef.style.top = conf.style.top;
	IfrRef.style.left = conf.style.left;
	IfrRef.style.zIndex = conf.style.zIndex - 1;
	IfrRef.style.display = 'block';
}

function unConfirm(lyr)
{
	var conf = document.getElementById(lyr);
	var IfrRef = document.getElementById(lyr+'Shim');

	conf.style.display = 'none';
	IfrRef.style.display = 'none';
}


// All Checkbox Select/Deselect

function toggleChk(obj,iFr) {

	if (iFr) {
		chx = window.frames[iFr].document.getElementById(obj).getElementsByTagName('input');
		prefix = "window.frames[iFr].";
	} else {
		chx = document.getElementById(obj).getElementsByTagName('input');
		prefix = "";
	}

	for (var j = 1; j <= chx.length; j++) {
		box = eval(prefix+"document."+obj+".row" + j); 
		box.checked = !box.checked;
	}
}


// IFRAME CONTROLS

function doFrame(iFr,module) {
	window.parent.document.getElementById(iFr).style.display = 'none';
	window.parent.document.getElementById(iFr).style.visibility='hidden';
	window.parent.document.getElementById(iFr).src = 'ifr_'+module+'.php'; // FOR SIMULATION; MAY CAUSE PARENT PAGE TO RELOAD
	window.parent.document.getElementById(iFr).style.display = 'block';
	window.parent.document.getElementById(iFr).style.visibility='visible';
}

function doTopFrame(iFr,module) {
	window.top.document.getElementById(iFr).style.display = 'none';
	window.top.document.getElementById(iFr).style.visibility='hidden';
	window.top.document.getElementById(iFr).src = 'ifr_'+module+'.php'; // FOR SIMULATION; MAY CAUSE PARENT PAGE TO RELOAD
	window.top.document.getElementById(iFr).style.display = 'block';
	window.top.document.getElementById(iFr).style.visibility='visible';
}

function reloadFrame(iFr) {
	window.frames[iFr].location.reload(true);
}

function reloadSelf(iFr) {
	window.parent.frames[iFr].location.reload(true);
}

function killFrame(iFr){
	window.parent.document.getElementById(iFr).style.visibility='hidden';
	window.parent.document.getElementById(iFr).style.display = 'none';
}


// AUTO-SIZE IFRAME HEIGHT

function sizeFrame(iFr) {
	i = window.parent.document.getElementById(iFr)
	iHeight = document.body.scrollHeight
	i.style.height = iHeight + "px";
}


// Context Menu Creator

function ShowMenu()
{ 
	contextMenu.style.pixelLeft = event.clientX;
	contextMenu.style.pixelTop = event.clientY;
	contextMenu.style.visibility = 'visible';
} 

function hl(aObj, state)
{
	if(state)
	{
		aObj.style.backgroundColor = '#0A246A';
		aObj.style.color = '#FFFFFF';
	}
	else
	{
		aObj.style.backgroundColor = '#D4D0C8';
		aObj.style.color = '#000000';
	}
}


// INPUT CLEAR

function wipe(id) {
	if (id.defaultValue==id.value) el.value = ""
}


// Field ENABLE/DISABLE

function enableField(id)
{
	if (document.getElementById)
	{
		document.getElementById(id).className = ' ';
		document.getElementById(id).disabled = false;
	}
	
	else if (document.layers)
	{
		return false;
	}
}

function disableField(id)
{
	if (document.getElementById)
	{
		document.getElementById(id).className = 'disabled';
		document.getElementById(id).value = '';
		document.getElementById(id).disabled = true;
	}
	
	else if (document.layers)
	{
		return false;
	}
}


// MESSAGE LENGTH CHECKER

function check_size(str) {
	var memolimit = 255;

	if (str.length < memolimit + 1) {
		document.getElementById('memo_count').innerHTML = '(Max. ' + memolimit + ' characters; ' + str.length + ' characters entered)';
	}
	
	else {
		alert (+ memolimit + ' character limit exceeded. Please modify your text.');
		document.getElementById('memo').innerHTML = document.getElementById('memo').innerText.substring(0, memolimit);
	}
}


// SEND TO PRINTER

function printit(){  
	if (window.print) {
	    window.print() ;  
	} else {
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	    WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}

function printFrame(iFr) {
	window[iFr].focus();
	window[iFr].print();
}


// log-out warning on header and footer links

function logout_warn(o)
{
	if (alertresult == 0)
	{
		alertresult = -1;
		return true;
	}
	else
	{
		alertopen('<h2>Confirm Action</h2><p>Accessing this page will automatically log you out. To return to the logged-in area, you will need to log in again.</p>', 'question', o, 'OK', 'alertresult = -1; window.top.relocate(alertvalue.href);', 'Cancel', 'alertactioncancel');
		return false;
	}
}

function removeImg(c)
{
	var m = '<h2>Confirm Action</h2><p>Are you sure you want to remove this item.</p>';
	window.top.alertopen(m, 'question', c, 'Remove Item', "window.top.framefind('outerFrame.mainFrame').do_command(alertvalue)", 'Cancel', 'alertactioncancel');
}