// Script library to hold commonly used JavaScript functions, TOGA, TORT, TOPSEC, etc. 

function AutoTab(input, len, e) {
	// Function is used to AutoTab text fields on a form.  No validation is perfomed
	// on data entered.  Accepts all keyboard characters between ASC 32 and 126.
	// It advances when end of field is reached based on the "LEN" variable passed
	
	// Variables:
	//		input	(object)	- text box of the object to test
	//		len		(numeric)	- length allowed before tabbing to next field 
	//		e		(method)	- event method from the onKeyUp Event
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 

	// If end of length reached, find next element to move to 
	if (keyCode > 31 && keyCode < 127) {
		if (input.value.length >= len) {
			input.form.elements[(getIndex(input)+1)].focus();
			input.form.elements[(getIndex(input)+1)].select();
		}
	}
	return true;
}

function getIndex(input) {
	// Finds element position on the form and returns the location in the form.elements.array
	var index = -1, i = 0;
	while (i < input.form.elements.length  && index == -1) {
		if (input.form.elements[i] == input) 
			index = (i == input.form.elements.length-1) ? i-1 : i;
		 else i++;
	}
	return index;
}

var gl_RIFWindow
function ShowRIF(filename) {
/* 	Use this function to pop up smaller windows used to contain text such as help
	or instructions.  It doesn't provide toolbars or buttons */	
	if (!gl_RIFWindow || gl_RIFWindow.closed) {
		gl_RIFWindow = window.open(filename,"","HEIGHT=400,WIDTH=700,toolbar=False,resizable,scrollbars")
	} else {
		gl_RIFWindow.location = filename
	}
	gl_RIFWindow.focus()
}

var gl_SystemWindow
function newWindow(filename) {
/* 	Use this function to pop up smaller windows used to contain text such as help
	or instructions.  It doesn't provide toolbars or buttons */	
	if (!gl_SystemWindow || gl_SystemWindow.closed) {
		gl_SystemWindow = window.open(filename,"","HEIGHT=500,WIDTH=600,toolbar,resizable,scrollbars")
	} else {
		gl_SystemWindow.location = filename
	}
	gl_SystemWindow.focus()
}

var gl_SystemWindowLarge
function newWindowLarge(filename) {
/* 	Use this function to pop up smaller windows (larger than newwindow function) used to contain text such as help
	or instructions.  It doesn't provide toolbars or buttons */	
	if (!gl_SystemWindowLarge || gl_SystemWindowLarge.closed) {
		gl_SystemWindowLarge = window.open(filename,"","HEIGHT=500,WIDTH=700,toolbar=False,resizable,scrollbars")
	} else {
		gl_SystemWindowLarge.location = filename
	}
	gl_SystemWindowLarge.focus()
}

function removeBlank(str){
// Removes all blanks from a string.  Similar to a TRIM function
	var retVal = ""
	for (var i=0; i < str.length; i++){
		if (str.charAt(i) != " "){
			retVal += str.charAt(i)
		}
	}
	return retVal
}

function IsEmpty(str){
// Checks to see if string is blank
	if (removeBlank(str) == "") {
		return true;
	}
	return false
}

function IsChecked(ButtonList){
// Checks to see if a box was selected from an array of checkboxes
	var iNumChecks = 0;
	for (var i=0; i < ButtonList.length; i++) {
		if (ButtonList[i].checked) {
			iNumChecks += 1;
		}
	}
	return iNumChecks;
}

function infoOn(q) {
// when mouse is on icon, change image
	if (document.images) {
		document[q].src = "ion.gif";
	}
}

function infoOff(q) {
// when mouse is off icon, change image
	if (document.images) {
		document[q].src = "i.gif";
	}
}
