
if (document.all && !document.getElementById) { document.getElementById = function(id) { return document.all[id] } }

function initMaps() {
	//var mapIds = arguments;    // pass string IDs of containing map elements
	var i, j, area, areas;
	//alert(initMaps.arguments.length);
	for (i = 0; i < initMaps.arguments.length; i++) {
		//alert(initMaps.arguments[i]);
		areas = document.getElementById(initMaps.arguments[i]).getElementsByTagName("area");
	
		for (j = 0; j < areas.length; j++) {  // loop thru area elements
			area = areas[j];
			area.onmousedown = imgSwap;    // set event handlers
			area.onmouseout = imgSwap;
			area.onmouseover = imgSwap;
			area.onmouseup = imgSwap;
		}
	}
}

// image swapping event handling
function imgSwap(evt) {
   evt = (evt) ? evt : event;                   // equalize event models
   var elem = (evt.target) ? evt.target : evt.srcElement;
   var imgClass = elem.parentNode.name;         // get map element name
   var coords = elem.coords.split(",");         // convert coords to clip
   var clipVal = "rect(" + coords[1] + "px " +
                           coords[2] + "px " +
                           coords[3] + "px " +
                           coords[0] + "px)";
   var imgStyle;
   switch (evt.type) {
      case "mousedown" :
         imgStyle = document.getElementById(imgClass + "Down").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";
         break;
      case "mouseout" :
         document.getElementById(imgClass + "Over").style.visibility = "hidden";
         document.getElementById(imgClass + "Down").style.visibility = "hidden";
         break;
      case "mouseover" :
         imgStyle = document.getElementById(imgClass + "Over").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";
         break
      case "mouseup" :
         document.getElementById(imgClass + "Down").style.visibility = "hidden";
         // guarantee click in IE
         if (elem.click) {
             elem.click();
         }
         break;
   }
   evt.cancelBubble = true;
   return false;
}

function noenter() { return !(window.event && window.event.keyCode == 13); }

function emailCheck (val, elem) {
	
	var emailStr = val;

	if (emailStr == '') {
		alert("Please enter an email address before proceeding.");
		elem.focus();
		return false;
	}

	if (emailStr.indexOf(' ') > -1) {
		alert("Spaces are not allowed in email addresses. Please correct this before proceeding.");
		elem.focus();
		return false;
	}

	if (emailStr.length > 50) {
		alert("Email addresses cannot be more than 50 characters in length.\n\nInvalid email address: " + emailStr);
		elem.focus();
		return false;
	}

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD = 1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat = /^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars = "\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser = "(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom = validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word = "(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray = emailStr.match(emailPat);
	
	if (matchArray == null) {
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mold of a valid e-mail address. */
		alert("The email address seems incorrect (check @ sign and .'s).\n\nInvalid email address: " + emailStr);
		elem.focus();
		return false;
	}
	var user = matchArray[1];
	var domain = matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i = 0; i < user.length; i++) {
		if (user.charCodeAt(i) > 127) {
			alert("The username portion of the email address (before the @ sign) contains invalid characters.\n\nInvalid email address: " + emailStr);
			elem.focus();
			return false;
		}
	}
	for (i = 0; i < domain.length; i++) {
		if (domain.charCodeAt(i) > 127) {
			alert("The domain name portion of the email address (after the @ sign) contains invalid characters.\n\nInvalid email address: " + emailStr);
			elem.focus();
			return false;
		}
	}
	
	// See if "user" is valid 
	if (user.match(userPat) == null) {
		// user is not valid
		alert("The username portion of the email address (before the @ sign) doesn't seem to be valid.\n\nInvalid email address: " + emailStr);
		elem.focus();
		return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray = domain.match(ipDomainPat);
	if (IPArray != null) {
		// this is an IP address
		for (var i = 1; i <= 4; i++) {
			if (IPArray[i]>255) {
				alert("The destination IP address in the email address (after the @ sign) is invalid.\n\nInvalid email address: " + emailStr);
				elem.focus();
				return false;
			}
		}
		return true;
	}
	

	// Domain is symbolic name.  Check if it's valid.
	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) {
			alert("The domain name portion of the email address (after the @ sign) does not seem to be valid.\n\nInvalid email address: " + emailStr);
			elem.focus();
			return false;
		}
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	if ((checkTLD) && (domArr[domArr.length-1].length != 2) && (domArr[domArr.length-1].search(knownDomsPat) == -1)) {
		alert("The email address must end in a well-known domain or two-letter " + "country.\n\nInvalid email address: " + emailStr);
		elem.focus();
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	if (len < 2) {
		alert("The email address is missing its hostname portion. Please check this before proceeding.\n\nInvalid email address: " + emailStr);
		elem.focus();
		return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}

function fnReplace(str, strSearch, strWith) {
    var strLength = str.length;
	var txtLength = strSearch.length;
    if ((strLength == 0) || (txtLength == 0)) { return str; }

    var i = str.indexOf(strSearch);
    if ((!i) && (strSearch != str.substring(0, txtLength))) { return str; }
    if (i == -1) { return str; }

    var strNew = str.substring(0, i) + strWith;

    if ((i + txtLength) < strLength) {
		strNew += fnReplace(str.substring(i + txtLength, strLength), strSearch, strWith);
	}

    return strNew;
}

function IsInteger(strString) {
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	if (strString.length == 0) { return false };
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) { blnResult = false; }
	}
	return blnResult;
}

function IsTimeFormat(strString) {
	// Check to see it is not an empty string
	if (strString.length == 0) { return false; }
	var strChar;
	// Check for invalid charaters
	var strValidChars = "0123456789:";
	for (i = 0; i < strString.length; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) { return false; }
	}
	// Make sure there are only two colons (':') in the string
	var count = 0;
	for (i = 0; i < strString.length; i++) {
		strChar = strString.charAt(i);
		if (strChar == ':') { count++; }
	}
	if (count != 2) { return false; }
	// Make sure that the three values are of the proper length and are numbers
	strChar = strString.split(':');
	if ((strChar[0].length != 1) || (strChar[1].length != 2) || (strChar[2].length != 2)) { return false; }
	for (i = 0; i < strChar.length; i++) { if (!IsInteger(strChar[i])) { return false; } }
	return true;
}

function IsMoneyFormat(strString) {
	// Check to see it is not an empty string
	if (strString.length == 0) { return false; }
	var strChar;
	// Check for invalid charaters
	var strValidChars = "0123456789,.";
	for (i = 0; i < strString.length; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) { return false; }
	}
	// Make sure there is only one decimal ('.') in the string. Decimal is optional
	var count = 0;
	for (i = 0; i < strString.length; i++) {
		strChar = strString.charAt(i);
		if (strChar == '.') { count++; }
	}
	if (count > 1) { return false; }
	// Make sure that there are two numbers after the decimal, if provided.
	strChar = strString.split('.');
	if ((strChar.length > 1) && (strChar[1].length != 2)) { return false; }
	// Make sure that the part before and after decimal, if provided, are integers.
	// If a comma is in the first part of the amount entered, it is removed before testing.
	if (!IsInteger(strChar[0].replace(',',''))) 			{ return false; }
	if ((strChar.length > 1) && (!IsInteger(strChar[1]))) 	{ return false; }
	return true;
}

function IsDateFormat(strString) {
	// Check to see it is not an empty string
	if (strString.length == 0) { return false; }
	var strChar;
	// Check for invalid charaters
	var strValidChars = "0123456789/";
	for (i = 0; i < strString.length; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) { return false; }
	}
	// Make sure there are only two slashes ('/') in the string.
	var count = 0;
	for (i = 0; i < strString.length; i++) {
		strChar = strString.charAt(i);
		if (strChar == '/') { count++; }
	}
	if (count != 2) { return false; }
	// Make sure that there are one or two numbers for the month and day and four numbers for the year.
	strChar = strString.split('/');
	if ((strChar.length != 3) || (strChar[0].length == 0) || (strChar[0].length > 2) || (strChar[1].length == 0) || (strChar[1].length > 2) || (strChar[2].length != 4)) { return false; }
	// Make sure that the date parts are integers.
	if (!IsInteger(strChar[0].replace(',',''))) 			{ return false; }
	if ((!IsInteger(strChar[0])) || (!IsInteger(strChar[1])) || (!IsInteger(strChar[2]))) 	{ return false; }
	return true;
}

function alertInteger(e) {
	alert("The value you entered, '" + e.value + "' should contain only numbers [ 0 through 9 ].");
	e.focus();
}

function alertTimeFormat(e) {
	alert("The value you entered, '" + e.value + "' must be formatted in this manner: h:mm:ss\n\nExample: 'Fifteen minutes and thirty seconds' should be entered as '0:15:30'.");
	e.focus();
}

function alertMoneyFormat(e) {
	alert("The value you entered, '" + e.value + "' should contain only numbers [ 0 through 9 ], and comma(s), if necessary.\n\nYou may also use a decimal point provided there are only two numbers after it.\n\nAccepted Examples: '1,500' or '1500' or '1,500.00' or '1500.00'.");
	e.focus();
}

function alertDateFormat(e) {
	alert("The value you entered, '" + e.value + "' should contain only numbers [ 0 through 9 ], and two slashes ['/'].\n\nDates must be formatted like this: mm/dd/yyyy\n\nAccepted Example: '01/15/2005'.");
	e.focus();
}