
// variable setup - don't customize
var MW_currentImage = null;
var MW_swap = (document.images)?true:false;
var MW_isLoaded = false;

// variables to customize
var MW_strDefaultPath = "/images/navigation/"; // strDefaultPath is the path to the images for rollovers
var MW_arrImages = new Array();

// create an object to hold the image name, its path and filenames
function MW_objRollover(strImageName, strImagePath, strImageFilename1, strImageFilename2) {
	this.imageName = strImageName;
	this.imagePath = (strImagePath)?strImagePath:MW_strDefaultPath;
	this.image1 = new Image();
	this.image1.src = this.imagePath + ((strImageFilename1)?strImageFilename1:this.imageName + '1' + '_' + charLanguage + '.' + ((strFileExtension)?strFileExtension:strDefaultFileExtension));
	this.image2 = new Image();
	this.image2.src = this.imagePath + ((strImageFilename2)?strImageFilename2:this.imageName + '2' + '_' + charLanguage + '.' + ((strFileExtension)?strFileExtension:strDefaultFileExtension))

	// add the event handlers to the anchor
	// try adding to the parentNode
	var loopLimit = 10;
	var loopCounter = 0;
	var nodeImgParent = document.images[strImageName].parentNode;
	if (nodeImgParent) {
		while (nodeImgParent.tagName.toLowerCase() != 'a' && loopLimit < loopCounter) {
			loopCounter++;
			nodeImgParent = nodeImgParent.parentNode;
		}
		if (nodeImgParent.tagName.toLowerCase() == 'a') {
			nodeImgParent.onmouseover = MW_swapImage;
			nodeImgParent.onmouseout = MW_turnOff;
			nodeImgParent.ptrArrImages = this;
		}
	}
}

function MW_swapImage() {
	if (MW_swap && MW_isLoaded) {
		document.images[this.ptrArrImages.imageName].src = this.ptrArrImages.image2.src;
		MW_currentImage = this.ptrArrImages;
		
		// added in to include popup menu of the same name (without the roll_)
		if (this.ptrArrImages.imageName.indexOf('roll_menu_') != -1) {
			//alert(document.images[this.ptrArrImages.imageName].src);
			popup(this.ptrArrImages.imageName.split('roll_')[1], 1);
		}
	}
}

function MW_turnOff() {
	if (MW_swap && MW_isLoaded && MW_currentImage) {
		document.images[MW_currentImage.imageName].src = MW_currentImage.image1.src;
		MW_currentImage = null;
		
		// added in to include popup menu of the same name (without the roll_)
		if (this.ptrArrImages.imageName.indexOf('roll_menu_') != -1) {
			popdown();
		}
	}
}

var MW_arrTabStrips = null; // declare this to stop errors, may use later if tabs are in use on the site

function MW_initUI() {
	// general variable that states if the page is loaded
	MW_isLoaded = true;

	// setup the image rollovers
	if (MW_swap) {
		// try preprocessing the page and looking for images named "roll_anything"
		for (var i = 0; i < document.images.length; i++) {
			if (document.images[i].name.indexOf('roll_') != -1) {
				// we have an image with this name...create the object accordingly
				strImagePath = document.images[i].src;
				strImageFilename1 = strImagePath.substring(strImagePath.lastIndexOf('/') + 1, strImagePath.length);
				strImageFilename2 = strImageFilename1;
				if (strImageFilename2.indexOf('1') != -1) {
					strImageFilename2 = strImageFilename2.replace(/([^1])1(.*)/, "$12$2");
				}
				else {
					strImageFilename2 = strImageFilename2.replace(/([^2])2(.*)/, "$11$2");
				}
	
				strImagePath = strImagePath.substring(0, strImagePath.lastIndexOf('/') + 1);
				MW_arrImages.push(new MW_objRollover(document.images[i].name, strImagePath, strImageFilename1, strImageFilename2));
			}
		}
	}
	
	// look for <tr> with the id = "UI_rollover"
	var arrTableRows = document.getElementsByTagName('tr');
	for (var i = 0; i < arrTableRows.length; i++) {
		if (arrTableRows[i].id == 'UI_rollover') {
			arrTableRows[i].onmouseover = MW_UI_row_onmouseover;
			arrTableRows[i].onmouseout = MW_UI_row_onmouseout;
		}
	}
	// look for <td> with the id = "UI_rollover"
	var arrTableRows = document.getElementsByTagName('td');
	for (var i = 0; i < arrTableRows.length; i++) {
		if (arrTableRows[i].id == 'UI_rollover') {
			arrTableRows[i].onmouseover = MW_UI_row_onmouseover;
			arrTableRows[i].onmouseout = MW_UI_row_onmouseout;
		}
	}
	
	// look for any form and set the validator function wrapper to it...
	var arrFormsVAL = document.getElementsByTagName('form');
	for (var i = 0; i < arrFormsVAL.length; i++) {
		arrFormsVAL[i].onsubmit = function () {
			return MW_validator_wrapper(this, 'input_valid', 'input_invalid');
		}
	}
	
	// look for confirm hyperlinks and add the onclick to them
	var arrConfirmVAL = document.getElementsByTagName('a');
	for (var i = 0; i < arrConfirmVAL.length; i++) {
		if (arrConfirmVAL[i].id == 'VAL_confirm') {
			arrConfirmVAL[i].onclick = function () {
				if (this.title) {
					return MW_confirmAction(this.title);
				}
				else {
					return MW_confirmAction(null);
				}
			}
		}
	}
	
	// initialize any tab strips on this page
	if (MW_arrTabStrips) 
		_MW_init_TABS();
}

//------------------------------------------------------------------------------------
// End - Image Rollover Code
//------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------
// Function to confirm action on an item
//------------------------------------------------------------------------------------
function MW_confirmAction(msg) {
	// if no message is passed, use a generic one
	if (!msg) {
		msg = 'Are you sure you want to do this?';
	}
	
	if (confirm(msg)) {
		return true;
	}
	else {
		return false;
	}
}

//------------------------------------------------------------------------------------
// Functions to activate tr on hover
//------------------------------------------------------------------------------------
function MW_UI_row_onmouseover() {
	this.className = 'displayTable2';
}

function MW_UI_row_onmouseout() {
	this.className = 'displayTable1';
}

//------------------------------------------------------------------------------------
// set the onload event handler to setup the UI functions and objects
//------------------------------------------------------------------------------------
window.onload = MW_initUI;