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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
	
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
	
	// Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
		// Again, there are two spaces in each of the strings
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

//
// E-mail validation function with alert.
//
function is_email (email, msg)
{	
    if (!msg)    
        msg = 'Please enter a valid e-mail address.';
    
	if (email == "") {
		return false;
	}
	
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* This is the list of known TLDs that an e-mail address must end with. */
	var emailPat=/^(.+)@(.+)$/; /* This 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 specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* This string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */
	var validChars="\[^\\s" + specialChars + "\]"; /* This  string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/
	var quotedUser="(\"[^\"]*\")"; /* The 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 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 + ")*$"); /* The pattern describes the structure of the user */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=email.match(emailPat);
	if (matchArray==null) {
		alert(msg);
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert(msg);
			return false;
   		}
	}
	
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert(msg);
			return false;
   		}
	}
	
	if (user.match(userPat)==null) {
		alert(msg);
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert(msg);
				return false;
   			}
		}
	}
	
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	if (len<2) {
	   	alert(msg);
		return false;
	}
	
	for (i=0;i<len; i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert(msg);
			return false;
   		}
	}

	if (checkTLD && domArr[len-1].length!=2 && domArr[len-1].search(knownDomsPat)==-1) {
		alert(msg);
		return false;
	}
	return true;
}

//
// E-mail validation function without alert.
//
function is_valid_email (email)
{	
	if (email == "") {
		return false;
	}
	
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* This is the list of known TLDs that an e-mail address must end with. */
	var emailPat=/^(.+)@(.+)$/; /* This 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 specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* This string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */
	var validChars="\[^\\s" + specialChars + "\]"; /* This  string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/
	var quotedUser="(\"[^\"]*\")"; /* The 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 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 + ")*$"); /* The pattern describes the structure of the user */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=email.match(emailPat);
	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;   			
		}
	}
	
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	if (len<2)
		return false;	
	
	for (i=0;i<len; i++)
	{
		if (domArr[i].search(atomPat)==-1)			
			return false;
	}

	if (checkTLD && domArr[len-1].length!=2 && domArr[len-1].search(knownDomsPat)==-1)
		return false;
	
	return true;
}

//
// Removes all non-numeric characters from a string.
//
function StripNonNumeric(str)
{
    return str.replace(/[^0-9]/g, "");
}

//
// Formats a phone number.
//
function PhoneFormat (phone)
{    
    if (null == phone || "" == phone)
        return phone;
        
    phone = StripNonNumeric(phone);

    //
    // Format phone number if length is
    // from 6 to 15 characters.
    //
    var len = phone.length;

    switch (len)
    {
        case 6:
        case 7:
            return phone.substr(0, 3) + "-" + phone.substr(3, len - 3);            
        case 8:
            return phone.substr(0, 4) + "-" + phone.substr(4, len - 4);
        case 9:
        case 10:
            return "(" + phone.substr(0, len - 7) + ") " + phone.substr(len - 7, 3) + "-" + phone.substr(len - 4, 4);                
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
            return phone.substr(0, len - 10) + " (" + phone.substr(len - 10, 3) + ") " + phone.substr(len - 7, 3) + "-" + phone.substr(len - 4, 4);                            
    }
    
    //
    // In all other cases, 
    // just return the string as is.
    //
    return phone;        
}

function IsValidPostalCode(postal, ca, us)
{
    if (null == postal)
        return false;
        
    if (!ca && !us)
        return true; // Anything goes
    
    postal = postal.replace(/\s/g, "").toUpperCase();

    var len = postal.length;
    var usFormat = /^\d{5}([\-]\d{4})?$/;

    if (ca)
	return ca && null != postal.match("[A-Z][0-9][A-Z][0-9][A-Z][0-9]");
    else if (us)
	return usFormat.test(postal);
    

    return false;
}

function PostalCodeFormat(postal)
{
    if (null == postal || "" == postal)
        return postal;
        
    postal = postal.replace(/\s/g, "").toUpperCase();
    
    var len = postal.length;

    switch (len)
    {
        case 6: // Canadian Format: L5M 7G9            
            if (null != postal.match("[A-Z][0-9][A-Z][0-9][A-Z][0-9]"))
                return postal.substr(0, 3) + " " + postal.substr(3, len - 3);
            else
                return postal;

        case 9: // US Format: 75489-7894            
            if (null != postal.match("[0-9]{9}"))
                return postal.substr(0, 5) + "-" + postal.substr(5, len - 5);
            else
                return postal;
    }

    return postal;
}

function textLimit(field, maxlen, omitAlert) {
	if (field.value.length > maxlen)
	{
		field.value = field.value.substring(0, maxlen);
	
		if (!omitAlert)	
			alert('Your input has been truncated  to ' + maxlen + ' characters!');
	}
	
	return false;
}

function popWin(file,anchor) {
	var target = file + "#" + anchor
	var newWindow = window.open(target,"", "width=615px,height=450px,status=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes");
	return;
}

function popBigWin(file,anchor) {
	var target = file + "#" + anchor
	var newWindow = window.open(target,"","width=800px,height=600px,status=no,toolbar=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
	return;
}

function popVideo(videoID) {
  var target = '/popPages/popVideo.asp?videoID=' + videoID;
  var newWindow = window.open(target,"video", "width=615px,height=650px,status=yes,toolbar=yes,location=no,status=no,menubar=yes,resizable=yes,scrollbars=yes");
  	newWindow.focus();
  return;
} 	

function ValidatePhone(m) {
	var n=m.name;
	var p1=m;
	var p=p1.value;
	var pp=p1.value;
	p=p.split("(").join("");
	p=p.split(")").join("");
	p=p.split("-").join("");
	p=p.split(" ").join("");
	if (isNaN(p)){
		alert("Please enter numbers only in the Phone Number fields.\rOther valid characters are (  ) or -.");
		//m.value="";
		return false;
	}
	
	if (p.length==7) {
		pp = p.substring(0,3) + "-" + p.substring(3);
		m.value=pp;
		return true;
	}
	else if(p.length==10) {
		pp = "(" + p.substring(0,3) + ") " + p.substring(3,6) + "-" + p.substring(6);
		m.value=pp;
		return true;
	}
	else if(p.length==11) {
		pp = p.substring(0,1) + " (" + p.substring(1,4) + ") " + p.substring(4,7) + "-" + p.substring(7);
		m.value=pp;
		return true;
	}
	else {
		m.value=pp;
		return true;
	}
} //End function ValidatePhone

//
// Intended to allow input of positive integers only.
//
function AllowWhole(e, allowspace)
{
	var key = window.event ? e.keyCode : e.which;	
	
	//
	// Allow control keys, backspace, and enter.
	//
	if (null == key || 0 == key || 8 == key || 13 == key 
		|| (allowspace && 32 == key))
		return true;
		
	//
	// Allow numbers.
	//
	else
	{	
		var keychar = String.fromCharCode(key);
		reg = /\d/;
		return reg.test(keychar);
	}
}