<!--
/************************************************************************************/
/*																					*/
/* File: popWin.js													*/
/*																					*/
/* --------------------------------------------------------------------------------	*/
/*																					*/
/* popWin DOM access and modify functions, used mostly for UU stuff. This	*/
/* file was adapted from the tribridge dream version.								*/
/*																					*/
/* Created By:	Roger Smith/Tribridge												*/
/* Created On:	December 3, 2003													*/
/*																					*/
/* modified:																		*/
/*																					*/
/************************************************************************************/

//////////////////////////////////////////////////////////////////////////////////////
//
// GLOBAL VARIABLES:
//
//////////////////////////////////////////////////////////////////////////////////////

var isW3C = (document.getElementById) ? true:false;
var isNN4 = (document.layers||document.getElementById&&!document.all) ? true:false;
var isIE4 = (document.all) ? true:false;
var mouseX;
var mouseY;
var busyBoxBackgroundColor = "#CBCBB1";

//////////////////////////////////////////////////////////////////////////////////////
//
// GLOBAL FUNCTION HANDLERS:
//
//////////////////////////////////////////////////////////////////////////////////////

// ************************************
//
// Handler: Track Mouse Position
//
// The following handler will track the
// mouse position as the user moves it.
//
// Author: Roger Smith 12.03.2003
//
// ************************************

if (isIE4) document.onmousemove = getMousePos;
else if (isNN4) 
{
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=getMousePos;
}

// End Hanlder/Globals

//////////////////////////////////////////////////////////////////////////////////////
//
// GLOBAL FUNCTIONS:
//
//////////////////////////////////////////////////////////////////////////////////////

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*																					*/
/* Function: getMousePos( )															*/
/*																					*/
/* --------------------------------------------------------------------------------	*/
/* Returns the current mouse position as it is moving for tracking. This function	*/
/* is needed so we can "bind" the appropriate event to the document object so we	*/
/* can detect the current coords of the mouse.										*/
/*																					*/
/* Author: Roger Smith 12.03.2003													*/
/*																					*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function getMousePos(e) 
{
	if (isNN4) 
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else if (isIE4) 
	{
		mouseX=window.event.clientX
		mouseY=window.event.clientY
	}
}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*																					*/
/* Function: showLayerAtMouse( )													*/
/*																					*/
/* --------------------------------------------------------------------------------	*/
/* Shows the layer (name) at the coords where the mouse is currently located by		*/
/* using the correct event monitor for each browser (messy but works for 5+)		*/
/*																					*/
/* Author: Roger Smith 12.03.2003													*/
/*																					*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function showLayerAtMouse( name, bodyName ) 
{
	var screenW = screen.width;
	var screenH = screen.height;
	var boxW, boxH; /* these are used to enable "collision detection" for screen edges */
	var scrollPos = 0;
	
	var myObj = getObj( name );
	
	if ( isW3C ) 
	{
		/* fix IE's crappy implementation */
		if ( isIE4 ) scrollPos = document.getElementById( bodyName ).scrollTop;
		boxW = ( myObj.style.width ).substr( 0,( myObj.style.width ).length-2 );
		boxH = ( myObj.style.height ).substr( 0,( myObj.style.height ).length-2 );

		if ( boxW > ( screenW-mouseX ) ) { myObj.style.left=( mouseX-boxW ); }
		else { myObj.style.left=mouseX; }

		if ( boxH > ( screenH-mouseY ) ) { myObj.style.top=( mouseY-boxH+scrollPos ); }
		else { myObj.style.top=mouseY+scrollPos; }
			
		myObj.style.visibility = 'visible';
		
	} 
	else if ( isNN4 ) 
	{
		scrollPos = 0;
		boxW = ( myObj.width ).substr( 0,( myObj.width ).length-2 );
		boxH = ( myObj.height ).substr( 0,( myObj.height ).length-2 );
			
		if ( boxW > ( screenW-mouseX ) ) { myObj.left=( mouseX-boxW ); }
		else { myObj.left=mouseX; }
			
		if (boxH > ( screenH-mouseY ) ) { myObj.top=( mouseY-boxH+scrollPos ); }
		else { myObj.top=mouseY+scrollPos; }
			
		myObj.visibility = 'visible';

	} 
	else if ( isIE4 ) 
	{
		scrollPos = 0;
		boxW = ( myObj.style.width ).substr( 0,( myObj.style.width ).length-2 );
		boxH = ( myObj.style.height ).substr( 0,( myObj.style.height ).length-2 );
		scrollPos = document.all[container].scrollTop;
			
		if ( boxW > ( screenW-mouseX ) ) { myObj.style.left=( mouseX-boxW ); }
		else { myObj.style.left=mouseX; }
			
		if ( boxH > ( screenH-mouseY ) ) { myObj.style.top=( mouseY-boxH+scrollPos ); }
		else { myObj.style.top=mouseY+scrollPos; }
			
		myObj.style.visibility = 'visible';

	}
}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*																					*/
/* Function: openCenteredWindow( )													*/
/*																					*/
/* --------------------------------------------------------------------------------	*/
/* Opens a new browser window in the center of the user's screen.					*/
/*																					*/
/* Author: Roger Smith 12.03.2003													*/
/*																					*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function openCenteredWindow(mypage,myname,w,h,features) 
{
	if(screen.width) 
	{
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else 
	{
		winl = 0;wint =0;
	}
	
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*																					*/
/* Function: trapKeyDown( )															*/
/*																					*/
/* --------------------------------------------------------------------------------	*/
/* Traps a keydown off of a specific control. This function receives a button as a	*/
/* parameter. If the trap is successful, the button parameter is clicked via its	*/
/* "click" method.
/*																					*/
/* Author: Roger Smith 12.03.2003													*/
/*																					*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function trapKeyDown(theButton)
{
	if (event.keyCode == 13)
	{
		event.returnValue = false;
		event.cancel = true;
		theButton.click();
	}
}

//////////////////////////////////////////////////////////////////////////////////////
// 
// PRE-EXISTING TRIBRIDGE FUNCTIONS:
//
//////////////////////////////////////////////////////////////////////////////////////

function toggleLayer(name) 
{
	if (isW3C) 
	{
		if (document.getElementById(name).style.visibility == 'hidden')
			document.getElementById(name).style.visibility = 'visible';
		else
			document.getElementById(name).style.visibility = 'hidden';
	} 
	else if (isNN4) 
	{
		// alert('NN4 toggle '+name+'('+document.layers[name].visibility +')');
		if (document.layers[name].visibility == 'hide')
			document.layers[name].visibility = 'visible';
		else
			document.layers[name].visibility = 'hidden';
	} 
	else if (isIE4) 
	{
		if (document.all.name.style.visibility == 'hidden')
			document.all.name.style.visibility = 'visible';
		else
			document.all.name.style.visibility = 'hidden';
	}
}

function showLayer(name) 
{
	if (isW3C) 
	{
		document.getElementById(name).style.visibility = 'visible';
	} 
	else if (isNN4) 
	{
		document.layers[name].visibility = 'visible';
	} 
	else if (isIE4) 
	{
		document.all.name.style.visibility = 'visible';
	}
}
	
function hideLayer(name) 
{
	if (isW3C) 
	{
		document.getElementById(name).style.visibility = 'hidden';
	} 
	else if (isNN4) 
	{
		document.layers[name].visibility = 'hidden';
	} 
	else if (isIE4) 
	{
		document.all.name.style.visibility = 'hidden';
	}
}
	
function getObj(id) 
{
	if (isW3C) 
	{
		return document.getElementById(id);
	} 
	else if (isIE4) 
	{
		return document.all[id];
	} 
	else if (isNN4) 
	{
		return document.layers[id];
	}
}

function getStyle(id) 
{
	if (isW3C) 
	{
		return document.getElementById(id).style;
	} 
	else if (isIE4) 
	{
		return document.all[id].style;
	} 
	else if (isNN4) 
	{
		return document.layers[id];
	}
}

function selectOption(element, value) 
{
	var i;
	for (i=0;i<element.options.length;i++) 
	{
		if (element.options[i].value.toLowerCase() == value.toLowerCase()) 
		{
			element.selectedIndex = i;
		}
	}
}

function openWindow(pg,a,atxt,aparm) {
	var url = pg+'?said='+a+'&txt='+atxt+aparm
	window.open(url,'update','height=20,width=400,scrollbars=no');
}

function openGenWindow(pg,wname,xparm,ht,wd,sb) {
	var url = pg+xparm;
	var opts = 'height='+ht+',width='+wd+',scrollbars='+sb
	window.open(url,wname,opts);
}

function openWindowON(a,atxt) {
	var url = 'clientQAUpdate.asp?said='+a+'&txt='+atxt
	window.open(url,'update','height=20,width=200,scrollbars=no');
}

function openWindowAM(a,atxt) {
	var url = 'clientQAUpdate.asp?said='+a+'&txt='+atxt
	window.open(url,'update','height=20,width=200,scrollbars=no');
}

function openCert(a) {
	var url = 'mdtUpdate.asp?cid='+a+'&typ=4'
	window.open(url,'update','height=500,width=740,scrollbars=yes,menubar=yes');
}

function openCertBM() {
	var url = 'mdtUpdate.asp?bmode=y&typ=4'
	if(confirm('CONFIRM BATCH CERTIFICATE PRINTING!!\n\r\n\rConfirm batch printing of the Pending\n\rCertificates by selecting OK,\n\r\n\rOtherwise, select CANCEL\n\rand you will be taken to the list of\n\rstudents with pending certificates.')){
		window.open(url,'update','height=500,width=740,scrollbars=yes,menubar=yes');
	}
	else {
		navigate('client.asp?styp=6');
	}
}

function openHelpWindow() {
	var url = 'contact.htm';
	window.open(url,'update','height=320,width=542,scrollbars=no');
}

function openGaugeWindow(g) {
	var url = 'gauge/gaugehelp.asp?g='+g
	window.open(url,'update','height=320,width=542,scrollbars=no');
}

function viewRacer(t) {
	var url = 'racerview.asp?tk='+t
	window.open(url,'update','height=320,width=542,scrollbars=yes');
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function chgPType(frmNm,imgNm) {
	var frmelm=FP_getObjectByID(frmNm);
	var imgelm=FP_getObjectByID(imgNm);
	frmelm.action=frmelm.popt.value;
	//alert(frmelm.popt.value);
	if(frmelm.popt.value=="ReqPay.asp") imgelm.src='images/pay/pplogo2.gif';
	if(frmelm.popt.value=="auth.asp") imgelm.src='images/pay/wflogo2.gif';
}

function chgPOpt(frmNm,opt) {
	var frmelm=FP_getObjectByID(frmNm);
	frmelm.popt[opt].selected=true;
	frmelm.popt.onchange();
}

function hasHTMLTags(s){
	var i;
	var op = false;
	var cp = false;
	for (i = 0; i < s.length; i++){   
		// Check if current character is begin/ending HTML tag.
		var c = s.charAt(i);
		if (c == "<") op = true;
		if (c == ">" && op) cp = true;
		if (op && cp) return true;
	}
	// No HTML tags.
	return false;
}			

function ProperCase(txt){
	strTemp = txt.toLowerCase();

	var strNew="";
	var isFirstCharOfWord = 1;
	var tmp = "";

	for (var intCount = 0; intCount < strTemp.length; intCount++){
		tmp = strTemp.charAt(intCount);
		if (isFirstCharOfWord == 1) tmp = tmp.toUpperCase();
		strNew = strNew + tmp;
		if (tmp == " "){
			isFirstCharOfWord = 1;
		}else{
			isFirstCharOfWord = 0;
		}
	}
	return strNew;
}

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function isDollarAmount(s){
	var checkOK = "$,.";
	var chkStr = s;
	var decPoints = 0;
	var dolSigns = 0;
	// Check for valid number
	if (isInteger(stripCharsInBag(chkStr, checkOK))){
		for (i = 0;  i < chkStr.length;  i++){
			ch = chkStr.charAt(i);
			// Count number of decimals in value
			if (ch == ".") decPoints++;
			// Count number of dollar signs in value
			if (ch == "$") dolSigns++;
		}
		// If more than 1 decimal exists, fail
		if (decPoints > 1) return false;
		// If more than 1 dollar sign exists, fail
		if (dolSigns > 1) return false;
	}
	else return false;
	return true;
}
	
function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function countDown(ds, fts) {
	// Place the following vars in the head tag:
	// var sec = {number of seconds};
	// var SD; Timer Variable
	//
	// Pass parameters: countDown({ds - Do Submit (1/0)},{fts - Form name to submit})
	// 
	// Put following span tag in body:
	// <span id="theTime" class="timeClass" style="float:right"></span>
	//
	// Be sure to create a .timeClass style class
	//
	sec--;
	if (sec<=9) { sec = "0" + sec; }
	time = "&nbsp;" + sec + " Secs Remaining&nbsp;";
	if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }
	SD=window.setTimeout("countDown("+ds+", '"+fts+"');", 1000);
	if (sec == '00') { 
		sec = "00"; 
		window.clearTimeout(SD);
		if (ds) window.setTimeout("document.forms['"+fts+"'].submit();", 1000);
	}
}

// -->
