/* jcihlar.js
 * This javascript contains functions that enable dynamic content
 * on Jonathon E. Cihlar's Web page.
 * January 2002 -- Jonathon E. Cihlar
 */

function LastUpdate () {
		// Set up a two dimensional array of the months the first index is the language, the second is the index
		// corresponding to the number of the month.
	var Suffixes = new Array(31);
	var rawModified = document.lastModified;	// grab last date modified
	var rawDate = new Array();	// used to hold split date
	var separatedDate = new Array();	// used to hold pieces of the date
	var formattedDate;


	var Months = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

		// generate a list of suffixes for the dates
	for (i = 1; i < Suffixes.length; ++i) {
		// deal with various number cases
		if (i == 1 || i == 21 || i == 31) {
			Suffixes[i] = 'st';
		}
		else if (i == 2 || i == 22) {
			Suffixes[i] = 'nd';
		}
		else if (i == 3 || i == 23) {
			Suffixes[i] = 'rd';
		}
		else {
			Suffixes[i] = 'th';
		}
	}

	rawDate = rawModified.split(' ');	// split date on white space, first cell is the date, second is the time
	separatedDate = rawDate[0].split('/');	// split the date on the / delimiter -- the format is month/day/year

	for (i = 0; i <= 1; ++i) {
		separatedDate[i] = separatedDate[i].replace(/^0/, "");	// strip out leading zero on single digit months and dates
	}

		// format date into Month(text) Date(digit), Year
	formattedDate = (Months[separatedDate[0]] + " " + separatedDate[1] + '<sup>' + Suffixes[separatedDate[1]] + '</sup>' + ", " + separatedDate[2]);

		// replace LastUpdate id
	document.getElementById('LastUpdate').innerHTML = formattedDate;

	return;
}

	/* Validate ()
	 * This function validates the data entered into the form for the Register page
	 */
function Validate () {
	var Register = document.forms['register'];
		// set up a list of required fields
	var Required = new Array('name', 'email', 'affiliation', 'languages', 'projects');
		// give a description for each of the fields
	var Description = new Array('- Name', '- Email Address', '- Affiliation', '- Languages Working On', '- Projects Interested In');
	var ErrorMsg = "";
	var header = false; // descriptive header text
		// check the required fields for input data
	for (i = 0; i < Required.length; ++i) {
		if (! Register.elements[Required[i]].value) {
			if (! header) {
				ErrorMsg = "Error!\nThe following fields are blank:\n";
				header = true;
			}
				// concatenate an error message
			ErrorMsg += (Description[i] + "\n");
		}
	}
		// check email format
	if (Register.elements['email'].value && Register.email.match(/.*\@./)) {
		ErrorMsg += "The format of the email you provided is invalid\n";
	}

		// if an error message was created
	if (ErrorMsg) {
		alert (ErrorMsg);
		return false;
	}

	return true;

}

	/* OpenWindow(String URL)
	 * This simple function encapsulates a series of steps needed to open a stripped down javascript window.
	 * The only argument is the URL to open in the stripped down browser.
	 */

function OpenWindow (URL, Name) {
	var Window;
	var Base = 'file://d:\\Web\\';
	URL = (Base + URL);
	Window = window.open(URL, Name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width=500,height=650");
	Window.focus();
	return;
}
