//
// Package	: LookAndFeel
// Module	: support.js
// Programmer	: R. Stolfa (rstolfa@yahoo.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.
//
// Modification History:
//   20000203	Striped down to this from the master file
//

// ----------------------------------------------------------------
//
// 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;
}

//
// Allow anything but space
//
function okp_ao_nonSpace() {
	if ( event.keyCode == 32 )
		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 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";
}

// ----------------------------------------------------------------
//
// 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();
	}
}


