//
// Package	: TaskLog
// Programmer	: R. Stolfa (rjs@WebAmphibian.Com)
// SCCSid	: %Z% %M% %I% %D%
// RCSid	: $Header$
//
// Purpose:	To hide in a centralized way most, if not all, of the
//		JavaScript 1.2 support code for the TaskLog system
//
// Modification History:
//   19991007	Created
//   19991008	Integrated the "help" system
//      --	Added the "genDate()" functions.
//   19991013	Added the "fireup()" function.
//   19991021	Added the "showGLH()" functions to replace the
//		"help_bbox()" family
//

// ----------------------------------------------------------------
//
// onKeyPress event handlers
//
// ----------------------------------------------------------------

//
// Disallow ":"
//
function okp_nocolon() {
	if ( event.keyCode == 58 )
		event.keyCode = 0;
}

//
// Allow only digits to be entered
//
function okp_ao_digits() {
	if ( ( event.keyCode < 48 ) || ( event.keyCode > 57 ) )
		event.keyCode = 0;
}

//
// Convert keystrokes to uppercase on the fly
//
function okp_toUpper() {
	if ( ( event.keyCode >= 97 ) && ( event.keyCode <= 122 ) )
		event.keyCode = event.keyCode - 32;
}

//
// Convert keystrokes to uppercase on the fly
//
function okp_ao_Upper() {
	if ( ( event.keyCode < 97 ) || ( event.keyCode > 122 ) )
		event.keycode = 0;

	if ( ( event.keyCode >= 97 ) && ( event.keyCode <= 122 ) )
		event.keyCode = event.keyCode - 32;
}

//
// Convert keystrokes to lowercase on the fly
//
function okp_toLower() {
	if ( ( event.keyCode >= 65 ) && ( event.keyCode <= 90 ) )
		event.keyCode = event.keyCode + 32;
}

//
// Allow only +/- integers
//
function okp_ao_ints() {
	if ( ( ( event.keyCode < 48 ) || ( event.keyCode > 57 ) ) &&
	     ( event.keyCode != 43 ) &&
	     ( event.keyCode != 45 ) )
	     	event.keyCode = 0;
}

// ----------------------------------------------------------------
//
// Callable field validators
//
// ----------------------------------------------------------------

//
// Validate the field looks like an email address
//
function isEmail(email) {
	invalidChars = " /:,;"
	if ( email == "" )
		return ( false );
	for ( i = 0; i < invalidChars.length; i ++ ) {
		badChar = invalidChars.charAt( i );
		if ( email.indexOf( badChar, 0 ) != -1 ) {
			return ( false );
		}
	}
	atPos = email.indexOf( "@", 1 );
	if ( atPos == -1 )
		return ( false );
	if ( email.indexOf( "@", atPos + 1 ) != -1 )
		return ( false );
	periodPos = email.indexOf( ".", atPos );
	if ( periodPos == -1 )
		return ( false );
	if ( periodPos + 3 > email.length ) {
		return ( false );
	}
	return ( true );
}

//
// Validate a dollar amount field to the following RE.
//	[+-][0-9]+[.[0-9]*]*
//
function isDollar(amount) {
	state = 0;
	for ( i = 0; i < amount.length; i ++ ) {
		ch = amount.charCodeAt( i );
		if ( state == 0 ) {
			if ( ( ch == 43 ) || ( ch == 45 ) )
				// We have a plus or a minus
				nextState = 1;
			else if ( ( ch >= 48 ) && ( ch <= 57 ) )
				// We have a digit
				nextState = 2;
			else
				nextState = 99;
		}
		if ( state == 1 ) {
			if ( ( ch >= 48 ) && ( ch <= 57 ) )
				nextState = 2;
			else if ( ch == 46 )
				// We have a period
				nextState = 3;
			else
				nextState = 99;
		}
		if ( state == 2 ) {
			if ( ch == 46 )
				nextState = 3;
			else if ( ( ch >= 48 ) && ( ch <= 57 ) )
				nextState = 2;
			else
				nextState = 99;
		}
		if ( state == 3 ) {
			if ( ( ch >= 48 ) && ( ch <= 57 ) )
				nextState = 3;
			else
				nextState = 99;
		}
		state = nextState;
	}
	if ( state == 2 ) {
		// We have either [+-][0-9]+
		//           -or- [0-9]+
		return (true);
	}
	if ( state == 3 ) {
		// We have [+-][0-9]+[.][0-9]*
		return (true);
	}
	return (false);
}

// ----------------------------------------------------------------
//
// Help system
//
// ----------------------------------------------------------------

var time = null;
var helpMsg;
var lastHelp = -2;
var helpDelay = 2000;
var newWindow = "";
var posX;
var posY;

if (!document.layers&&!document.all&&!document.getElementById)
	event="test";

function showGLH(current,e,mnum){

	if ( document.all || document.getElementById ){
		thetitle = messages[ mnum ].split('<br>')
		if ( thetitle.length > 1 ){
			thetitles = '';
			for ( i = 0; i < thetitle.length; i++ )
				thetitles += thetitle[ i ];
			current.title = thetitles;
		} else {
			current.title = messages[ mnum ];
		}
	} else if ( document.layers ){
		document.GLH.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">' + messages[ mnum ] + '</layer>')
		document.GLH.document.close()
		document.GLH.left = e.pageX+5
		document.GLH.top = e.pageY+5
		document.GLH.visibility = "show"
	}
}
function hideGLH(){
	if (document.layers)
		document.GLH.visibility = "hidden";
}

// ----------------------------------------------------------------
//
// Date generator
//
// ----------------------------------------------------------------

function zeroPad(val) {
	var	ret;

	ret = "";

	if (val <= 9)
		ret = ret + "0";
	ret = ret + val;

	return (ret);
}

function genDate(dtype) {
	var	now = new Date;
	var	tmp;
	var	ret;

	ret = "";
	if (dtype == 0) {
		//
		// Generate YYYYMMDDhhmm
		//
		tmp = now.getYear();
		if (tmp < 100)
			ret = "19" + tmp;
		else
			ret = tmp + "";
		ret += zeroPad( now.getMonth() + 1 );
		ret += zeroPad( now.getDate() );
		ret += zeroPad( now.getHours() );
		ret += zeroPad( now.getMinutes() );
	}
	if (dtype == 1) {
	}
	return (ret)
}

// ----------------------------------------------------------------
//
// Window Functions
//
// ----------------------------------------------------------------
function fireup( url, h, w ) {
	options = "directories=no,"
	options = options + "height=" + h + ",";
	options = options + "location=no,";
	options = options + "menubar=no,";
	options = options + "toolbar=no,";
	options = options + "scrollbars=yes,";
	options = options + "status=no,";
	options = options + "titlebar=no,";
	options = options + "toolbar=no,";
	options = options + "width=" + w ;
	newWindow = window.open(url, "newWin", options);
	newWindow.focus();
}

function bail() {
	if (history.length == 0) {
		self.close();
	} else {
		history.back();
	}
}

/*
This script is written by Eric (Webcrawl@usa.net)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function printit(){
	/*
	 * Works generically, but the window must be closed, if created on the fly by JavaScript
	 */
	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 toggleSec( areaName, arrowName ) {
	var	areaObj;

	if ( document.getElementById ) {
		areaObj = document.getElementById( areaName ).style;
	} else {
		areaObj = eval( "document." + areaName );
	}

	//expand the paragraph and rotate the arrow; collapse and rotate it back

	if ( areaObj.display == "none" ) {
		areaObj.display = "";
		arrowName.src = "./images/dnArrow.gif"
	} else {
		areaObj.display = "none";
		arrowName.src = "./images/rtArrow.gif"
	}
}

/*
 * Image Roll over code:
 *
 * Called by adding:
 *	onMouseOver="doImgHover( this, 'hoversrc' )" onMouseOut="doImgRestore( this )"
 * to "<img ...>" tag
 */
function doImgHover( current, i ) {
	current.savedSrc = current.src;
	current.src = i;
}

function doImgRestore( current ) {
	current.src = current.savedSrc;
}

function jumpAlert() {
	text = "You are now leaving the OnCue Express Web site.\n\n"
	text += "We provide a link to this external Web page\n"
	text += "because it may contain related information of interest to you.\n"
	text += "This link does not constitute an endorsement by the OnCue Expresss,\n"
	text += "OnCue Marketing, L.L.C., it's employees, owners, or affiliates\n"
	text += "of any information, products or services on this external\n"
	text += "Web site.\n\n"
	text += "You can return to the OnCue Express Web site by clicking\n"
	text += "'Cancel' below.\n\n"
	text += "Continue?"
//	answer = window.confirm(text);
 	answer = confirm(text);
	return answer;
}
// used as: <a ... onClick="return jumpAlert()">
