var progBarStat 	= 0;
var progBarVis		= false;
var popupBoxVis		= false;
var promptBoxVis	= false;
var progDir			= 2;

if (!BLEND_MODE)
	var BLEND_MODE		= (document.all)?1:2;

var adapterFunction	= null;
var caller			= null;

function showProgressBar(doShow, showText) {
	if (typeof showText == 'undefined') showText = "";
	innerContent("progBarText", showText);
	centerIt("globalProgressBar", 0, -20);
	pbar = document.getElementById("globalProgressBar");
	pbar.style.visibility = (doShow)?"visible":"hidden";

//	gdim = document.getElementById("globalDimArea");
//	gdim.style.visibility = (doShow)?"visible":"hidden";

	if (!popupBoxVis && !promptBoxVis) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = (doShow)?"alpha(Opacity=40)":"";
	}

	progBarVis = doShow;
	//if (doShow) animateProgBar();
}

function showPopupBox(sTitle, sText, bIsError) {
	if (BLEND_MODE == 1
		&& document.getElementById("mainTable")) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = "alpha(Opacity=40)";
	}
	else if (BLEND_MODE == 2) {
		gdim = document.getElementById("globalDimArea");
		gdim.style.visibility = "visible";
	}

	innerContent("popupBoxTitle", sTitle);
	innerContent("popupBoxText", sText);
	
	playSound("pbox");
	
	centerIt("globalPopupBox", 0, -20);
	pbox = document.getElementById("globalPopupBox");
	pbox.style.visibility = "visible";
	
	popupBoxVis	= true;
}

function closePopupBox() {
	if (BLEND_MODE == 1
		&& document.getElementById("mainTable")) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = "";
	}
	else if (BLEND_MODE == 2) {
		gdim = document.getElementById("globalDimArea");
		gdim.style.visibility = "hidden";
	}

	pbox = document.getElementById("globalPopupBox");
	pbox.style.visibility = "hidden";

	popupBoxVis	= false;
}

function showConfirmBox(sTitle, sText, sAdapterFunction, oCaller) {
	if (BLEND_MODE == 1
		&& document.getElementById("mainTable")) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = "alpha(Opacity=40)";
	}
	else if (BLEND_MODE == 2) {
		gdim = document.getElementById("globalDimArea");
		gdim.style.visibility = "visible";
	}
	
	adapterFunction = sAdapterFunction;
	caller			= oCaller;

	innerContent("confirmBoxTitle", sTitle);
	innerContent("confirmBoxText", sText);
	
	playSound("cfrmbox");
	
	centerIt("globalConfirmBox", 0, -20);
	pbox = document.getElementById("globalConfirmBox");
	pbox.style.visibility = "visible";
	
	popupBoxVis	= true;
}

function showPromptBox(sTitle, sText, sDefault, sAdapterFunction, oCaller) {
	if (BLEND_MODE == 1
		&& document.getElementById("mainTable")) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = "alpha(Opacity=40)";
	}
	else if (BLEND_MODE == 2) {
		gdim = document.getElementById("globalDimArea");
		gdim.style.visibility = "visible";
	}
	
	adapterFunction = sAdapterFunction;
	caller			= oCaller;

	innerContent("promptBoxTitle", sTitle);
	innerContent("promptBoxText", sText);
	
	playSound("cfrmbox");
	
	centerIt("globalPromptBox", 0, -20);
	pbox = document.getElementById("globalPromptBox");
	pbox.style.visibility = "visible";
	getElement("pbfid").result.value = sDefault;
	getElement("pbfid").result.select();
	getElement("pbfid").result.focus();
	
	promptBoxVis	= true;
}

function closeConfirmBox() {
	if (BLEND_MODE == 1
		&& document.getElementById("mainTable")) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = "";
	}
	else if (BLEND_MODE == 2) {
		gdim = document.getElementById("globalDimArea");
		gdim.style.visibility = "hidden";
	}

	pbox = document.getElementById("globalConfirmBox");
	pbox.style.visibility = "hidden";

	popupBoxVis	= false;
}

function closePromptBox() {
	if (BLEND_MODE == 1
		&& document.getElementById("mainTable")) {
		mainb = document.getElementById("mainTable");
		mainb.style.filter = "";
	}
	else if (BLEND_MODE == 2) {
		gdim = document.getElementById("globalDimArea");
		gdim.style.visibility = "hidden";
	}

	pbox = document.getElementById("globalPromptBox");
	pbox.style.visibility = "hidden";

	promptBoxVis	= false;
}

function replyConfirm(bYesNo) {
	eval("caller."+adapterFunction+"("+bYesNo+")");
	closeConfirmBox();
}

function replyPrompt(bText) {
	eval("caller."+adapterFunction+"(\""+bText+"\")");
	closePromptBox();
}

function playSound(filename) {
//    var sndtxt='<embed src="sounds/'+filename+'.wav" hidden="true" loop="false" autostart="true" />';
//    document.getElementById("hiddenSnd").innerHTML = sndtxt;
}

function forcedLogout(cftoken) {
	location.href = "index.cfm?actionmodule=authentication&action=forced-logout&jsessionid="+cftoken;
}

function animateProgBar() {
	/*
	if (progBarVis) {
		progBarStat = progBarStat += 5;
		//pb = document.getElementById("progBar");
		
		pbhol = document.getElementById("progBarHolder");
/*		if (progBarStat==100 || progBarStat==0) {
			progDir *= -1;
			pbhol.style.textAlign = (progDir>=0)?"left":"right";
		}*
		pbhol.style.backgroundPosition = (progBarStat+"px 0px");
		setTimeout("animateProgBar()", 50);
	}
	else {
		progBarStat = 0;
		progDir		= 2;
	}
	*/
}

function minLeftBar() {
	bar = document.getElementById("leftBar");
	if (bar.style.display == "none") 
	{	
		bar.style.display = (navigator.appName == "Microsoft Internet Explorer")?"block":"table-row";
		document.getElementById("mainContent").style.width = "83%";
		bar.style.width = "17%";
		document.getElementById("menuSeparator").src = "images/hide-vertical-2.gif";
	}
	else 
	{
		bar.style.display = "none";
		document.getElementById("mainContent").style.width = "100%";
		bar.style.width = "0%";
		document.getElementById("menuSeparator").src = "images/hide-vertical-open-2.gif";
	}
}

function checkForPopupBox(e) {
	if (popupBoxVis) {
		if (!e) var e = window.event;
		if (e.keyCode) { code = e.keyCode; }
		else if (e.which) { code = e.which; }
		e.cancelBubble = true;
		if (code == 32 || code == 13 || code == 27) {
			closeConfirmBox();
			closePromptBox();
			
			if (promptBoxVis && (code == 13)) {
				/* Accept */
				replyPrompt(pbf.result.value);
			}

			closePopupBox();
		}
	}
}

function showStatus(aText) {
	innerContent("statusBar", aText);
}

function clearStatus() {
	innerContent("statusBar", "");
}

document.onkeydown = checkForPopupBox;
