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];
	  }
  }
}

// --------------------------------------
// Check for valid email address
// --------------------------------------
function checkEmail(varEmail) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(varEmail)){
      return (true)
  }
  return (false)
}

// --------------------------------------
// Format number to display certain number of decimal points
// --------------------------------------
function format(varNumber, noOfDecimalPoints) {
	var numValue = new Number(varNumber);
	return numValue.toFixed(noOfDecimalPoints);
}

// --------------------------------------
// Return true if strSearch can be found in strText
// --------------------------------------
function inStr(strSearch, strText) {
	// Note: indexOf returns -1 if string not found, returns 0 if found in first position
	return (strText.indexOf(strSearch)>=0);
}

// --------------------------------------
// Get Browser name
// --------------------------------------
function getBrowserName() {
	var strBrowser = navigator.userAgent.toLowerCase();
	if (inStr('konqueror', strBrowser))	return "Konqueror";
	else if (inStr('safari', strBrowser)) return "Safari";
	else if (inStr('omniweb', strBrowser)) return "OmniWeb";
	else if (inStr('opera', strBrowser)) return "Opera";
	else if (inStr('webtv', strBrowser)) return "WebTV";
	else if (inStr('icab', strBrowser)) return "iCab";
	else if (inStr('msie', strBrowser)) return "Internet Explorer";
	else if (inStr('firefox', strBrowser)) return "Firefox";
	else if (!inStr('compatible', strBrowser)) return "Netscape Navigator";
	else return "An unknown browser";
}

// --------------------------------------
// Get OS name
// --------------------------------------
function getOS() {
	var strBrowser = navigator.userAgent.toLowerCase();
	if (inStr('konqueror', strBrowser))	return "Linux";
	else if (inStr('linux', strBrowser)) return "Linux";
	else if (inStr('x11', strBrowser)) return "Unix";
	else if (inStr('mac', strBrowser)) return "Mac";
	else if (inStr('win', strBrowser)) return "Windows";
	else return "An unknown operating system";
}

// --------------------------------------
// Prerequisite: Field name must be "website"
// Note: Will replace web address if standard error such as http:// or http\\
// --------------------------------------
function verifyWebsite(oForm) {

	var bStatus=true;
	var varMsg;

	// Remove http:// from web site
	if (/http:\/\//.test(oForm.website.value)) {
		oForm.website.value = oForm.website.value.replace(/http:\/\//,"");
	}
	// Remove http// from web site
	else if (/http\/\//.test(oForm.website.value)) {
		oForm.website.value = oForm.website.value.replace(/http\/\//,"");
	}
	// Remove http:\\ from web site (user typo)
	else if (/http:\\\\/.test(oForm.website.value)) {
		oForm.website.value = oForm.website.value.replace(/http:\\\\/,"");
	}
	// Remove http\\ from web site (user typo)
	else if (/http\\\\/.test(oForm.website.value)) {
		oForm.website.value = oForm.website.value.replace(/http\\\\/,"");
	}

	// Ensure email address is not entered into the web address field
	if (oForm.website.value.length == 0) {
		// Blank website is acceptable
	}
	else if (oForm.website.value.indexOf("@") >= 0) {
		bStatus = false;
		varMsg = "You have entered an EMAIL address instead of a URL into the Web Site field. Please reenter."
					 + "\n\n"
					 + "NOTE: Please leave the Web Site field blank if you do not have a web site.";
		alert(varMsg);
	}
	else if (oForm.website.value.indexOf(".") == -1) {
		bStatus = false;
		varMsg = "The URL you entered is invalid. Please reenter."
					 + "\n\n"
					 + "NOTE: Please leave the Web Site field blank if you do not have a web site.";
		alert(varMsg);
	}

	return bStatus;
}

// --------------------------------------
// Check for whole number
// --------------------------------------
function IsWholeNumber(sText) {
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
	}

	return IsNumber;
}

// --------------------------------------
// Check for number
// --------------------------------------
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) {
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
   }

   return IsNumber;
}

// --------------------------------------
// Check for number, + or -
// --------------------------------------
function IsSignedNumeric(sText) {
   var ValidChars = "-0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) {
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
      if (i > 0 && Char == "-") { IsNumber = false; }	// Minus sign can only be the first char
   }

   return IsNumber;
}

// --------------------------------------
// Hide and Show division accordingly, assume blank means hidden
// --------------------------------------
function switchDiv(DivisionId) {

	var objDivision = document.getElementById(DivisionId);

	if (objDivision.style.display == "none") {
		objDivision.style.display = "block";
	}
	else {
		objDivision.style.display = "none";
	}
	
	return true;
}

function switchButton(objButton,DivisionId) {
	if (objButton.innerHTML == "Hide") objButton.innerHTML = "Show";
	else objButton.innerHTML = "Hide";
	switchDiv(DivisionId);
}

// --------------------------------------
// To support submenu
// --------------------------------------
startList = function() {
	nav_temp = document.getElementById("navcontainer");
	nav_temp = nav_temp.getElementsByTagName("UL");
	navRoot = nav_temp[0];	// First UL should be main menu
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {

			// Add spaces in front of text for better layout
			hasSubmenu = node.getElementsByTagName("UL");
			if (hasSubmenu.length>0) {		// Submenu exists
				submenu = hasSubmenu[0];		// First UL should be submenu
				for (j=0; j<submenu.childNodes.length; j++) {
					subnode = submenu.childNodes[j];		// Individual node in UL submenu, should be LIs
					if (subnode.nodeName=="LI") {
						anchorNodes = subnode.getElementsByTagName("A");	// Locate <a> in LI
						anchorNode = anchorNodes[0];			// There should only be one <a>
						newTextElement = document.createTextNode("\u00a0"+"\u00a0");	// "\u00a0" is a non-breaking space
						anchorNode.insertBefore(newTextElement, anchorNode.firstChild);
					}
				}	// for (j=0; j<submenu.childNodes.length; j++) {
			}	// if (hasSubmenu.length>0) {
		
			node.onmouseover=function() { this.className+="over"; }
  		node.onmouseout=function() { this.className=this.className.replace("over", ""); }

  	} // if (node.nodeName=="LI") {
  } // for (i=0; i<navRoot.childNodes.length; i++) {
}

// --------------------------------------
// Add flash object
// --------------------------------------
function addFlashObject(strFileName,intWidth,intHeight) {
	document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+intWidth+"\" height=\""+intHeight+"\">");
	document.writeln("<param name=\"movie\" value=\""+strFileName+"\">");
	document.writeln("<param name=\"quality\" value=\"high\">");
	// Submenu to float over flash
	document.writeln("<param name=\"wmode\" value=\"opaque\">");
	document.writeln("<param name=\"menu\" value=\"false\">");
	// Must include wmode in embeb for Firefox to allow submenu to float over flash
	document.writeln("<embed src=\""+strFileName+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" wmode=\"opaque\" menu=\"false\" width=\""+intWidth+"\" height=\""+intHeight+"\"></embed>");
	document.writeln("</object>");
}

function right(str, num) {
	return str.substring(str.length-num);  // pull out right num
}

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function writeProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
		 document.write (i+" "+obj[i]+"<br>");
   }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function moveObjectRelativeToParent(obj,parent,x,y) {
	var coors = findPos(parent);
	obj.style.left = eval(coors[0]+"+"+x)+"px";
	obj.style.top = eval(coors[1]+"+"+y)+"px";
//alert("top: "+obj.style.top);
//alert("left: "+obj.style.left);
}

function getStyle(el,styleProp) {
	if (el.currentStyle)
		var y = el.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	return y;
}

function changeCursor(prmCursorStyle) {
	if (typeof prmCursorStyle == "undefined") prmCursorStyle = "default";
	if (document.body.style.cursor == prmCursorStyle) { /* Less flashing on IE */ }
	else document.body.style.cursor = prmCursorStyle;
}
