function testing() {
	alert ('In Testing!');
}

function showMsgs(m) {
//  Function to show the messages that resulted from an add, update, or delete.
	smw=open("","smw","height=250,width=350,status=no,toolbar=no,scrollbars=no,directories=no,menubar=no,location=no,resizable=no,left=350,top=300");
	smw.document.write("<html><title>Maintenance Results</title>"
	+"<body bgcolor='ededed'>"
	+"<table height=100% width=100% border=0>"
	+"<tr><td align=center valign=center width='100%'>"
	+ m
	+"<tr><td align=center valign=center>"
	+"<b><a href='javascript:window.close()'>"
	+"Close window</a></b></td></tr>"
	+"</table></body></html><p>");
	smw.document.close();
	smw.focus();
}

function emailCheck (aEmailStr,aFieldNameStr) {
// Function to validate an email address.
// This function is based on one found at http://javascript.internet.com/forms/check-email.html
// First just see if it's blank
	aEmailStr=trim(aEmailStr);
 	if (aEmailStr.length==0) {
	 	alert(aFieldNameStr + " is a required field. Please try again.");
    return false;
 	}
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=aEmailStr.match(emailPat)
 if (matchArray==null) {
// Too many/few @'s or something; basically, this address doesn't
// even fit the general mould of a valid e-mail address.
 	alert("The email address in the " + aFieldNameStr + " field seems incorrect (make sure there is an '@' and '.')")
 	return false
 }
 var user=matchArray[1]
 var domain=matchArray[2]
// See if "user" is valid 
 if (user.match(userPat)==null) {
// User is not valid
     alert("The username doesn't seem to be valid for the email address in field " + aFieldNameStr + ".")
     return false
 }
// if the e-mail address is at an IP address (as opposed to a symbolic
// host name) make sure the IP address is valid.
 var IPArray=domain.match(ipDomainPat)
 if (IPArray!=null) {
// this is an IP address
 	  for (var i=1;i<=4;i++) {
 	    if (IPArray[i]>255) {
 	        alert("Destination IP address is invalid for the email address in field " + aFieldNameStr + ".")
 		return false
 	    }
     }
     return true
 }
// Domain is symbolic name
 var domainArray=domain.match(domainPat)
 if (domainArray==null) {
 	alert("The domain name doesn't seem to be valid for the email address in field " + aFieldNameStr + ".")
     return false
 }
// domain name seems valid, but now make sure that it ends in a
// three-letter word (like com, edu, gov) or a two-letter word,
// representing country (uk, nl), and that there's a hostname preceding 
// the domain or country.
// Now we need to break up the domain to get a count of how many atoms
// it consists of.
 var atomPat=new RegExp(atom,"g")
 var domArr=domain.match(atomPat)
 var len=domArr.length
 if (domArr[domArr.length-1].length<2 || 
     domArr[domArr.length-1].length>3) {
// the address must end in a two letter or three letter word.
    alert("The address must end in a three-letter domain, or two letter country for the email address in field " + aFieldNameStr + ".")
    return false
 }
// Make sure there's a host name preceding the domain.
 if (len<2) {
    var errStr="The hostname is missing for the email address in field " + aFieldNameStr + "."
    alert(errStr)
    return false
 }
// If we've gotten this far, everything's valid!
 return true;
}

function trim(strText) { 
	// This will get rid of leading and trailing spaces.
	// Found at http://developer.irt.org/script/1310.htm 
	// 		get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);
	// 		get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);
	return strText;
} 
function valButton(btn) {
// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

//************ Start of Sort Table functions ************
// Copyright 2001 Roman Koch (roman@romankoch.ch).
// See http://www.romankoch.ch/capslock/tablesort.htm for more information.

// Three changes were made to the code at this site. 
// (1)It was modified to sort based on the innerText, but then to move 
// the corresponding innerHTML. Otherwise, all the HTML formatting, including
// any hyperlinks, are lost. The key to this change was to add a third dimension
// to the table to hold both the innerText and the innerHTML. 
// (2)It was modified to ignore the header rows in the table. A parameter
// was added to TableSort to pass the number of header rows to 
// be ignored in the sort. 
// (3)It was modified to not sort the first 'x' columns, based on a parameter
// passed in the function call. This was done to allow for a column at the beginning
// of a row to stay intact, regardless of how the rest of the columns are sorted. For
// example, having an 'Edit' column at the start of a row that copies all values in
// that row to the header when it is clicked. 
// (Chuck Blessing, 02/18/02)

currentCol = 0
previousCol = -1

function CompareAlpha(a, b) {
	if (a[currentCol][0] < b[currentCol][0]) { return -1; }
	if (a[currentCol][0] > b[currentCol][0]) { return 1; }
	return 0;
}

function CompareAlphaIgnore(a, b) {
	strA = a[currentCol][0].toLowerCase();
	strB = b[currentCol][0].toLowerCase();
	if (strA < strB) { return -1; }
	else {
		if (strA > strB) { return 1; }
		else { return 0; }
	}
}

function CompareDate(a, b) {
	// this one works with date formats conforming to Javascript specifications, e.g. m/d/yyyy
	datA = new Date(a[currentCol][0]);
	datB = new Date(b[currentCol][0]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function CompareDateEuro(a, b) {
	// this one works with european date formats, e.g. d.m.yyyy
	strA = a[currentCol][0].split(".");
	strB = b[currentCol][0].split(".")
	datA = new Date(strA[2], strA[1], strA[0]);
	datB = new Date(strB[2], strB[1], strB[0]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function CompareNumeric(a, b) {
	//window.alert ("CompareNumeric");
	numA = a[currentCol][0]
	numB = b[currentCol][0]
	if (isNaN(numA)) { return 0;}
	else {
		if (isNaN(numB)) { return 0; }
		else { return numA - numB; }
	}
}

function TableSort(myTable, myCol, myType, myHdrRows, myColIgnore) {
	// Create a two-dimensional array and fill it with the table's content
	//myTable  = table id
	//myCol    = column to sort (first column is 0)
	//myType   = type of sort (a, ai, d, de, n, or default. See below.)
	//myHdrRows = # of table header rows to ignore when sorting, or 0 if no headers.
	//myColIgnore = A column to not sort (numbered from the left starting with 0), or
	//              -1 if all columns should be sorted. Used if you have a column
	//              that is tied to the physical table row, not the data in the table
	//              row. For example, an 'Edit' column that moves all the values in a
	//              row to the header.
	var mySource = document.all(myTable);
	var myRows = mySource.rows.length;
	var myCols = mySource.rows(0).cells.length;
	var startRow = myHdrRows;
	var ignoreColumn = myColIgnore;
	currentCol = myCol;
	// Build the table to be sorted
alert ('Begin building table');
	myArray = new Array(myRows);
	for (i=startRow; i < myRows; i++) {
		myArray[i] = new Array(myCols)
		for (j=0; j < myCols; j++) {
			myArray[i][j] = new Array(2)
			myArray[i][j][0] = document.all(myTable).rows(i).cells(j).innerText;
			myArray[i][j][1] = document.all(myTable).rows(i).cells(j).innerHTML;
		}
	}
alert ('End building table');
	if (myCol == previousCol) {
alert ('Begin reverse sort');
		myArray.reverse(); // clicked the same column as previously - reverse the sort;
alert ('End reverse sort');
	}
	else { // clicked on a new column - sort as indicated
		switch (myType) {
			case "a":
				myArray.sort(CompareAlpha);
				break;
			case "ai":
alert ('Begin sort');
				myArray.sort(CompareAlphaIgnore);
alert ('End sort');
				break;
			case "d":
				myArray.sort(CompareDate);
				break;
			case "de":
				myArray.sort(CompareDateEuro);
				break;
			case "n":
				myArray.sort(CompareNumeric);
				break;
			default:
				myArray.sort()
		}
	}
	// Re-write the table contents (innerHTML, only), ignoring the column 
	// specified by the myColIgnore parameter.
	// Need to offset by 'startRow' in myArray, the number of header rows that were
	// ignored in the sort.
alert ('Begin rebuilding table');
	for (i=startRow; i < myRows; i++) {
		for (j=0; j < myCols; j++) {
			if (j!=ignoreColumn) {
				mySource.rows(i).cells(j).innerHTML = myArray[i-startRow][j][1];
			}
		}
	}
alert ('End rebuilding table');
	previousCol = myCol; // remember the current sort column for the next pass
	return 0;
}
//************ End of Sort Table functions ************

//************ XML Functions ************
function ApplyStyleSheet(xsldoc,aSortField){
	//Check if clicked the same header twice in a row
	if (xsldoc.selectSingleNode("//xsl:sort/@select").value == aSortField) {
		//If so, reverse the sort order
		if (xsldoc.selectSingleNode("//xsl:sort/@order").value == "ascending") {
			xsldoc.selectSingleNode("//xsl:sort/@order").value = "descending";
		}
		else {
			xsldoc.selectSingleNode("//xsl:sort/@order").value = "ascending";
		}
	}
	else {
		xsldoc.selectSingleNode("//xsl:sort/@order").value = "ascending";
	}
	//Set the sort field
	xsldoc.selectSingleNode("//xsl:sort/@select").value = aSortField;
	TableDIV.innerHTML=xml.transformNode(xsldoc);
}
//************ End of XML Functions ************

//+++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++

//************ Start of Sort Table functions ************
// Copyright 2001 Roman Koch (roman@romankoch.ch).
// See http://www.romankoch.ch/capslock/tablesort.htm for more information.

// Three changes were made to the code at this site. 
// (1)It was modified to sort based on the innerText, but then to move 
// the corresponding innerHTML. Otherwise, all the HTML formatting, including
// any hyperlinks, are lost. The key to this change was to add a third dimension
// to the table to hold both the innerText and the innerHTML. 
// (2)It was modified to ignore the header rows in the table. A parameter
// was added to TableSort to pass the number of header rows to 
// be ignored in the sort. 
// (3)It was modified to not sort the first 'x' columns, based on a parameter
// passed in the function call. This was done to allow for a column at the beginning
// of a row to stay intact, regardless of how the rest of the columns are sorted. For
// example, having an 'Edit' column at the start of a row that copies all values in
// that row to the header when it is clicked. 
// (Chuck Blessing, 02/18/02)

currentCol = 0
previousCol = -1

function zzCompareAlpha(a, b) {
	if (a[currentCol][0] < b[currentCol][0]) { return -1; }
	if (a[currentCol][0] > b[currentCol][0]) { return 1; }
	return 0;
}

function zzCompareAlphaIgnore(a, b) {
	strA = a[currentCol][0].toLowerCase();
	strB = b[currentCol][0].toLowerCase();
	if (strA < strB) { return -1; }
	else {
		if (strA > strB) { return 1; }
		else { return 0; }
	}
}

function zzCompareDate(a, b) {
	// this one works with date formats conforming to Javascript specifications, e.g. m/d/yyyy
	datA = new Date(a[currentCol][0]);
	datB = new Date(b[currentCol][0]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function zzCompareDateEuro(a, b) {
	// this one works with european date formats, e.g. d.m.yyyy
	strA = a[currentCol][0].split(".");
	strB = b[currentCol][0].split(".")
	datA = new Date(strA[2], strA[1], strA[0]);
	datB = new Date(strB[2], strB[1], strB[0]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function zzCompareNumeric(a, b) {
	//window.alert ("CompareNumeric");
	numA = a[currentCol][0]
	numB = b[currentCol][0]
	if (isNaN(numA)) { return 0;}
	else {
		if (isNaN(numB)) { return 0; }
		else { return numA - numB; }
	}
}

function zzTableSort(myTable, myCol, myType, myHdrRows, myColIgnore, myResultsTable, myRowCount, myColCount) {
	// Create a two-dimensional array and fill it with the table's content
	//myTable  = table id
	//myCol    = column to sort (first column is 0)
	//myType   = type of sort (a, ai, d, de, n, or default. See below.)
	//myHdrRows = # of table header rows to ignore when sorting, or 0 if no headers.
	//myColIgnore = A column to not sort (numbered from the left starting with 0), or
	//              -1 if all columns should be sorted. Used if you have a column
	//              that is tied to the physical table row, not the data in the table
	//              row. For example, an 'Edit' column that moves all the values in a
	//              row to the header.
	var mySource = document.all(myTable);
	var myRows = myRowCount;
	var myCols = myColCount;
	var startRow = myHdrRows;
	var ignoreColumn = myColIgnore;
	currentCol = myCol;
	// Build the table to be sorted
alert ('Begin building table');
	myArray = myResultsTable;
alert ('End building table');
	if (myCol == previousCol) {
alert ('Begin reverse sort');
		myArray.reverse(); // clicked the same column as previously - reverse the sort;
alert ('End reverse sort');
	}
	else { // clicked on a new column - sort as indicated
		switch (myType) {
			case "a":
				myArray.sort(zzCompareAlpha);
				break;
			case "ai":
alert ('Begin sort');
				myArray.sort(zzCompareAlphaIgnore);
alert ('End sort');
				break;
			case "d":
				myArray.sort(zzCompareDate);
				break;
			case "de":
				myArray.sort(zzCompareDateEuro);
				break;
			case "n":
				myArray.sort(zzCompareNumeric);
				break;
			default:
				myArray.sort()
		}
	}
	// Re-write the table contents (innerHTML, only), ignoring the column 
	// specified by the myColIgnore parameter.
	// Need to offset by 'startRow' in myArray, the number of header rows that were
	// ignored in the sort.
alert ('Begin rebuilding table');
	for (i=startRow; i < myRows; i++) {
		for (j=0; j < myCols; j++) {
			if (j!=ignoreColumn) {
				mySource.rows(i).cells(j).innerHTML = myArray[i-startRow][j][1];
			}
		}
	}
alert ('End rebuilding table');
	previousCol = myCol; // remember the current sort column for the next pass
	return 0;
}
//************ End of Sort Table functions ************
function movepic(img_name,img_src) {
	document[img_name].src=img_src;
}


