//=============================================================================
// W. Brian Dill's
// JavaScript (ECMAScript) functions
//=============================================================================
function testForMasterJ() {
	alert("This is a test from MasterJ.txt \n\n  If you see this, then "
	      + "you are reaching the MasterJ.txt file.");
}
//-----------------------------------------------------------------------------
function dw(m)  {
	//  document.write shortcut function
	m = "" + m + "";          //  verify that the m variable is a string.
	if (m != "undefined") {   //  Test for empty write or other undefined item.
	    document.write(m + "<br/>");
	}
}
//-----------------------------------------------------------------------------
function isInteger(strValue) {
	//  Validate user input to be integers.
	var num = "0123456789";
	for (var intLoop = 0 ; intLoop < strValue.length ; intLoop++)	// loop through every char

		if (num.indexOf(strValue.charAt(intLoop)) == -1) {		// if it's not in num string
			 return false;										// then exit
		}
	return true;
}
//-----------------------------------------------------------------------------
function isNumber(strValue) {
	//  Validate user input to be numeric characters only.
	var num = "0123456789.-";
	for (var intLoop = 0 ; intLoop < strValue.length ; intLoop++)	// loop through every char

		if (num.indexOf(strValue.charAt(intLoop)) == -1) {		// if it's not in num string
			 return false;										// then exit
		}
	return true;
}
//-----------------------------------------------------------------------------
function openWin(sPage, sName, sAttributes) {
	//  Opens the page sPage in a new browser instance.
	if(sPage == null) { return false; 	}
	if(sName == null) { sName = ""; }
	if(sAttributes == null) {
		sAttributes = 'directories=0,'
			+ ',menubar=1,toolbar=1,scrollbars=1,status=1,resizable=1'
			+ ',top=0,left=0,height=500,width=800';
	}
	return window.open(sPage, sName, sName);
}
//-------------------------------------------------------------------------
function startClock() {
	window.setInterval("clockTick()", 1000);
    clockTick();
}
//-------------------------------------------------------------------------
function clockTick() {
	var now = new Date();
    var t = now.getFullYear();
	t += '-' + padZero(now.getMonth()+1);
	t += '-' + padZero(now.getDate());
	t += '  ' + padZero(now.getHours());
	t += ':' + padZero(now.getMinutes());
	t += ':' + padZero(now.getSeconds());
	document.getElementById("spnClock").innerHTML = t;
}
//-----------------------------------------------------------------------------
function padZero(n) {
	try {
		if(!isNumber(n)) { return n; }
		if(parseInt(n) < 10) {
			return '0' + n.toString();
		}
		return n.toString();
	} catch(e) {
		alert('Error in padZero() ' + n + ' is not a number.\n' + e); return false;
	}
}
//-----------------------------------------------------------------------------
/*
function writeToCookie(sParam, sValue) {
	//  Writes one named pair value to the cookie.
	if (sParam == "" || sValue == "") {			// do nothing if they left out
		alert("Missing Parameter or Value");	// either the parameter or the value
		return;
	}
	document.cookie = escape(sParam) + "=" + escape(sValue);
	return;
}

//-----------------------------------------------------------------------------

function getCookieParamValue(sParam, bAlert) {

	//  Returns the value of the specified parameter in the cookie.
	//  if bAlert == 1 then it shows an alert box with the param value.
	var iParamLength = sParam.length;				// how long is the param name?
	var sParamValue = '';
	var iStart = document.cookie.indexOf(sParam);	// where is the param in the cookie?
	if(iStart == -1) {
		alert("Parameter \"" + sParam + "\" not found.");	// exit if you don't find
		return;												// the param in the cookie
	}

	var sChopPrefix = document.cookie.substring(iStart); // chop off the cookie string before the desired param
	var iNextDelim = sChopPrefix.indexOf(";");			 // how far to the next semicolon?

	if (iNextDelim != -1) {
		// if it is not the last named pair, substring only to the next semicolon.
		sParamValue = sChopPrefix.substring(iParamLength + 1, iNextDelim);
	}
	else {
		// if it is the last named pair, substring to the end of the cookie.
		sParamValue = sChopPrefix.substring(iParamLength +1);
	}

	sParamValue = unescape(sParamValue);

	if(bAlert == 1) {  											// alert the ParamValue if
		alert("Parameter " + sParam + " = " + sParamValue);  	// the user asked for it.
	}
	return sParamValue;
}

//------------------------------------------------------------------------

function tableIntoArray(sTableID) {

	//  DESCRIPTION:   	Assigns all selected rows from the HTML table sTableID into
	//					a simulated 2-dimensional array called arrRecordset.
	//  ARGUMENTS:		sTableID => the ID of the HTML table that is to be affected.
	//  REQUIREMENTS:	The table passed in must have a unique ID to the page and
	//					each row must have the same number of INPUT's.
	//					When passing sTableID don't use ticks or quotes.
	//  W. Brian Dill 7/21/99

	var arrRecordset = new Array();			//  Big array containing all the records
	var arrSingleRow = new Array();			//  array to hold a single row of data
	var irsIndex = 0;						//  Big array index that increments when assigning
	var iRowCount = sTableID.rows.length	//  Number of rows in the table
	var iNumOfInputs = sTableID.rows[0].tags("INPUT").length; // Number of INPUT tags in the first row


	//================ ( Loop through and do the assignment ) ================
	for (var i=0 ; i < iRowCount ; i++) {						//  For every row in the table
//		if(sTableID.rows(i).className == "clsSelectedRow") {	//  If the row was selected
			for(var j=0 ; j < iNumOfInputs ; j++) {				//  For every TD in the row
				arrSingleRow[j] = sTableID.rows(i).children(j).children(0).value;
			}

			alert("Row Values being assigned to Index " + irsIndex + " - " + arrSingleRow.join(' ; '));

			arrRecordset[irsIndex] = arrSingleRow;	//  assign that one row into the big array
			irsIndex++;
//		}
	}

	// ======================= ( Return the Array ) =========================
	if(arrRecordset.length > 0) {					//  If anything was assigned to the array

		// It seems that every row in the recordset contains the same data; the last table row
		// or else, it just ignores the first array index request, though it honors the 2nd index.
		for(var k=0 ; k < arrRecordset.length ; k++) {
			alert("arrRecordset[" + k + "].join() = " + arrRecordset[k].join(' --- '));
		}

		return arrRecordset;

	} else {
		return null;
	}
}
*/