/*
	NGIT Functions
*/

function ShowDate() {
	// Return today's formatted date

	var now = new Date();

	var month = now.getMonth();
	switch (month) {
		case 0: month = "January"; break;
		case 1: month = "February"; break;
		case 2: month = "March"; break;
		case 3: month = "April"; break;
		case 4: month = "May"; break;
		case 5: month = "June"; break;
		case 6: month = "July"; break;
		case 7: month = "August"; break;
		case 8: month = "September"; break;
		case 9: month = "October"; break;
		case 10: month = "November"; break;
		case 11: month = "December"; break;
	}

	var day = now.getDay();
	switch (day) {
		case 0: day = "Sunday"; break;
		case 1: day = "Monday"; break;
		case 2: day = "Tuesday"; break;
		case 3: day = "Wednesday"; break;
		case 4: day = "Thursday"; break;
		case 5: day = "Friday"; break;
		case 6: day = "Saturday"; break;
	}

	return (day + ", " + month + " " + now.getDate() + ", " + now.getFullYear());
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function mm_openbrwindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}



/* Image Rollovers */

function PreloadImages() {
	// Preload images and create objects based on argument list of:
	// 	object name, over image filename, out/original image filename

	if (!document.images) return;

	var args = PreloadImages.arguments;
	var i = 0;

	while (i < args.length) {
		eval(args[i] + '_over = new Image()');
		eval(args[i] + '_over.src = "' + args[i + 1] + '"');
		eval(args[i] + '_out = new Image()');
		eval(args[i] + '_out.src = "' + args[i + 2] + '"');
		i = i + 3;
	}
}

PreloadImages('sectorES','/ngit/images/global/sectorESOn.gif', '/ngit/images/global/sectorES.gif');
PreloadImages('sectorMS','/ngit/images/global/sectorMSOn.gif', '/ngit/images/global/sectorMS.gif');
PreloadImages('sectorIS','/ngit/images/global/sectorISOn.gif', '/ngit/images/global/sectorIS.gif');
PreloadImages('sectorSS','/ngit/images/global/sectorSSOn.gif', '/ngit/images/global/sectorSS.gif');
PreloadImages('sectorNN','/ngit/images/global/sectorNNOn.gif', '/ngit/images/global/sectorNN.gif');
PreloadImages('sectorST','/ngit/images/global/sectorSTOn.gif', '/ngit/images/global/sectorST.gif');


function SwapImage() {
	// Changes given image objects with given sources:
	//		filename -> loads that file
	//		over, out, up, down -> uses preloaded image object
	//		nothing -> uses image object of opposite state

	if (!document.images) return;

	var imgName, imageObj, swapName, dotSpot, filePosition, overImageSrc, outImageSrc;
	var args = SwapImage.arguments;
	var i = 0;

	while (i < args.length) {
		imgName = args[i];
		swapName = args[i + 1];
		imageObj = getImageObject(imgName);

		if (!swapName) {

			// If no swapName used, determine current state from image's filename and switch states

			// For Gecko, image object only contains short path, so find that within full path
			overImageSrc = eval(imgName + '_over.src');
			filePosition = imageObj.src.lastIndexOf(overImageSrc);

			// If short image string is found and located at the end of (or is equal to) the full path
			if (filePosition >= 0 && (filePosition + overImageSrc.length == imageObj.src.length))
				imageObj.src = eval(imgName + '_out.src');
			else
				imageObj.src = overImageSrc;

		} else if ((dotSpot = swapName.lastIndexOf('.')) > 0) {

			// Filename given (with 3 or 4 character file type)
			if ((swapName.length - dotSpot >= 4) && (swapName.length - dotSpot <= 5))
				imageObj.src = swapName;    // File name

		} else

			// Uses preloaded image object
			imageObj.src = eval(imgName + '_' + swapName.toLowerCase() + '.src');

		i = i + 2;
	}
}

function SwapOver(imgName) {
	SwapImage(imgName, 'over');
}
function SwapOut(imgName) {
	SwapImage(imgName, 'out');
}

function getImageObject(imgName) {
	// Find image object

	if (document.all) return eval('document.all.' + imgName);			// IE4+
	if (document.images[imgName]) return document.images[imgName];		// W3C, NS
	if (document.layers) return findImage(imgName, document);			// NS4 w/layers

	return null;
}


function findImage(name, doc) {
	// Recurse through layers in NS4 to find image

	if (doc.images[name]) return doc.images[name];

	var i, img;
	for (i = 0; i < doc.layers.length; i++)
		if ((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
		}
	return null;
}
