var strStatus = "";

function displayStatus() {
	if (strStatus != "") alert(strStatus);
}

function MM_swapImgRestore() { // v3.0

	var i, x, a = document.MM_sr;
	
	for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { // v3.0

	var d=document;
	
	if(d.images) {
		if(!d.MM_p) d.MM_p = new Array();
		
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		
		for(i = 0; i < a.length; i++) if (a[i].indexOf("#") != 0) {
			d.MM_p[j] = new Image;
			d.MM_p[j++].src = a[i];
		}
	}
}

function MM_findObj(n, d) { //v3.0

	var p, i, x;

	if(!d) d = document;
	if((p = n.indexOf("?")) > 0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if(!(x = d[n]) && d.all) x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
	return x;
}

function MM_swapImage() { //v3.0
	
	var i, j = 0, x, a = MM_swapImage.arguments;
	
	document.MM_sr = new Array;
	for (i = 0; i < (a.length - 2); i += 3) if ((x = MM_findObj(a[i])) != null) {
		document.MM_sr[j++] = x;
		if(!x.oSrc) x.oSrc = x.src;
		x.src = a[i + 2];
	}
}

// This function returns the screen postion on the calling object.
function elementPos(strElement, strPos) {

	var intPos = 0;
	
	obj = document.getElementById(strElement);

	if (!obj) return 0;

	if (document.getBoxObjectFor) {
	
		var bo = document.getBoxObjectFor(obj);
		
		if (strPos == "Left") {
			intPos = bo.x;
		} else if (strPos == "Right") {
			intPos = bo.x + bo.width;
		} else if (strPos == "Top") {
			intPos = bo.y;
		} else {
			intPos = bo.y + bo.height;
		}
	
	} else {
		if (obj.getBoundingClientRect) {
	
			var rect = obj.getBoundingClientRect();

			if (strPos == "Left") {
				intPos = rect.left;
			} else if (strPos == "Right") {
				intPos = rect.right;
			} else if (strPos == "Top") {
				intPos = rect.top + document.documentElement.scrollTop;
			} else {
				intPos = rect.bottom + document.documentElement.scrollTop;
			}
		} else if (obj.offsetParent != null) {
		
			var intHeight = obj.offsetHeight;
			var intWidth = obj.offsetWidth;
			
			while (obj) {
				if (strPos == "Left") {
					intPos += obj.offsetLeft;
				} else if (strPos == "Right") {
					intPos += obj.offsetLeft + intWidth;
				} else if (strPos == "Top") {
					intPos += obj.offsetTop;
				} else {
					intPos += obj.offsetTop + intHeight;
				}
				obj = obj.offsetParent;
			}
		}
	}
	return intPos;
}

// This function checks to see if a supplied email address is valid.
function emailCheck(strEmail) {

	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	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 = strEmail.toLowerCase().match(emailPat);

	if (strEmail == "") return true;

	if (matchArray == null) return false;

	var user = matchArray[1];
	var domain = matchArray[2];

	for (i = 0; i<user.length; i++) {
		if (user.charCodeAt(i) > 127) return false;
	}

	for (i = 0; i < domain.length; i++) {
		if (domain.charCodeAt(i) > 127) return false;
	}

	if (user.match(userPat) == null) return false;

	var IPArray = domain.match(ipDomainPat);

	if (IPArray != null) {
		for (var i = 1; i <= 4; i++) {
			if (IPArray[i] > 255) return false;
		}
		return true;
	}
 
	var atomPat = new RegExp("^" + atom + "$");
	var domArr = domain.split(".");
	var len = domArr.length;

	for (i = 0; i < len; i++) {
		if (domArr[i].search(atomPat) == -1) return false;
	}

	if (checkTLD && domArr[domArr.length - 1].length != 2 && domArr[domArr.length - 1].search(knownDomsPat) == -1) return false;

	if (len < 2) return false;

	return true;
}

// Check the length and lines of text for a form element.
function checkContent(objField, intLength, intLines) {

	var blnOK = true;
	
	if (intLength > 0) {
		if (objField.value.length >= intLength) {
			blnOK = false;
		}
	}
	if (intLines > 0) {
		if (objField.value.split("\n").length > intLines) {
			blnOK = false;
		}
	}
	return blnOK;
}

// This function returns part of the cookie object.
function getCookieVal(offset) {  
	var endstr = document.cookie.indexOf (";", offset);  

	if (endstr == -1) endstr = document.cookie.length;  

	return unescape(document.cookie.substring(offset, endstr));
}

// function to retrieve a cookie.
function getCookie(name) {  

	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		   
		i = document.cookie.indexOf(" ", i) + 1;
		
		if (i == 0) break;   
	}  
	return null;
}

// This function allows the language to be set from with the page's content.
function setLanguage(strLanguage) {

	var strContent = document.getElementById("MoSTContent").innerHTML;

	// Relaod the page to set the selected language and display it.
	if (window.location.href.indexOf("LANG=") > -1) {
		window.location.href = window.location.href.replace("LANG=" + getCookie("MoSTLanguage"), "LANG=" + strLanguage);
	} else {
		window.location.href = window.location.href + "?LANG=" + strLanguage;
	}
}

// This function is called from the body tag and is used for displaying the correct language.
function showLanguage(node) {

	if (document.getElementById("MoSTContent") != null) {

		var strContent = document.getElementById("MoSTContent").innerHTML;

		// If the page uses language blocks, then show the correct language.
		if (strContent.indexOf("MoSTLang_") > 0) {

			// Get the current language setting.
			var strLanguage = getCookie("MoSTLanguage");
			
			// If no language is selected then set it to English.
			if (strLanguage == null) strLanguage = "English";

			// Loop through all the page objects it find the language blocks.
			for (var i = 0; i < node.childNodes.length; i ++) { 
				if (node.childNodes[i].id != null) {
				
					// If the current object contains a reference to the current language then display it.
					if (node.childNodes[i].id.indexOf(strLanguage) > -1) {
						document.getElementById(node.childNodes[i].id).style.display = "inline";
					} else {
					
						// Reset all other languages so they aren't displayed.
						if (node.childNodes[i].id.indexOf("MoSTLang_") > -1 && node.childNodes[i].id.indexOf(strLanguage) == -1) {
							document.getElementById(node.childNodes[i].id).style.display = "none";
						}
					}
				}
				
				// Call the function again to find all object within the current object.
				showLanguage(node.childNodes[i]);
			}
		}
	}
}

// Pass the page content into the printable version of the DIV tag.
function printVersion() {

	var strContent = document.getElementById("MoSTContent").innerHTML;

	// You can't have duplicate ID's, so change them to be unique for language blocks.
	strContent = strContent.replace(/ name=/gi, " name=Print");
	strContent = strContent.replace(/ id=/gi, " id=Print");
	strContent = strContent.replace(/\n/g, "").replace(/\r/g, "");
	strContent = strContent.replace(/<script([^>]*)>.*?<\/script>/gi, "");
	strContent = strContent.replace(/rel=lightbox\[Images\]/gi, "");

	document.getElementById("MoSTPrintContent").innerHTML = strContent;
}

// Resize the window to fit the content.
function resizeMe() {

	var intWidth = document.body.scrollWidth + 70;
	var intHeight = document.body.scrollHeight + 70;
	var intTop = (screen.height / 2) - (intHeight / 2) - 100;
	var intLeft = (screen.width / 2) - (intWidth / 2);
	
	if (screen.width < intWidth) intWidth = screen.width - 100;
	if (screen.height < intHeight) intHeight = screen.height - 150;
	if (intTop < 10) intTop = 10;

	self.resizeTo(intWidth, intHeight);
	self.moveTo(intLeft, intTop);
}

function fixURL(strElement) {

	var objElement = document.getElementById(strElement);
	var strDesc = objElement.innerHTML;
	var strURL = objElement.href;
	
	if (strURL.indexOf("mailto:") == -1) {

		var strChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

		var strFix = "";

		strURL = strURL.substring(strURL.indexOf("#") + 1)

		for (var i = 0; i < strURL.length; i++) {

			strTemp = strURL.substring(i, i + 1);
			
			if (i / 2 == parseInt(i / 2)) {
				strFix += strTemp;
				if (strChars.indexOf(strTemp) != -1) strFix = strFix.replace(strTemp, "@");
			}
		}
		objElement.href = "mailto:" + strFix;
		objElement.innerHTML = strDesc;
	}
}

function formatCurrency(dblAmount) {

	dblAmount = dblAmount.toString().replace("/\$|\,/g", '');
	
	if (isNaN(dblAmount)) {
		dblAmount = "0";
	}

	blnSign = (dblAmount == (dblAmount = Math.abs(dblAmount)));

	dblAmount = Math.floor(dblAmount * 100 + 0.50000000001);
	
	intCents = dblAmount % 100;
	
	dblAmount = Math.floor(dblAmount / 100).toString();
	
	if(intCents < 10) {
		intCents = "0" + intCents;
	}
	
	for (var i = 0; i < Math.floor((dblAmount.length - (1 + i)) / 3); i++) {
		dblAmount = dblAmount.substring(0, dblAmount.length - (4 * i + 3)) + ',' + dblAmount.substring(dblAmount.length - (4 * i + 3));
	}
		
	return (((blnSign) ? '' : '-') + dblAmount + '.' + intCents);
}

function topLayer() {

	var intMaxZindex = 0;

	var objDivs = document.getElementsByTagName("DIV")
	
	for (var i = 0; i < objDivs.length; i++) {

		if (intMaxZindex < objDivs[i].style.zIndex) intMaxZindex = objDivs[i].style.zIndex + 1;
	}
	
	return intMaxZindex;
}