<!--
/* ======================================================================
FUNCTION:  	IsValidEmail
 
INPUT:    	str (string) - an e-mail address to be tested

RETURN:  	true, if the string contains a valid e-mail address which is a string
				plus an '@' character followed by another string containing at least 
				one '.' and ending in an alpha (non-punctuation) character.
				false, otherwise

CALLS:		IsBlank(), IsAlpha() which are defined elsewhere in the Script Library

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsValidEmail( str, allowmultiple ) {
	// return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;
	var isValid = true;

	str += "";

	// strip out preceding and succeeding email delimeters (we'll let them be valid)
	if (str.charAt(0) == "," || str.charAt(0) == ";") str = str.substring(1,str.length);
	if (str.charAt(str.length-1) == "," || str.charAt(str.length-1) == ";") str = str.substring(0,str.length-1);

    // initialize string parsing variables
	var listlen = str.length;
	var i = 0;
	var nextemail = 0;
	var emailcount = 0;
	
	//parse away
	while (i < listlen) {
		nextemail = str.indexOf(",");
		if (nextemail == -1) nextemail = str.indexOf(";");
		if (nextemail == -1) nextemail = listlen;
		
		currentstr = str.substring(0,nextemail); // current email address in list
   		namestr = currentstr.substring(0, currentstr.indexOf("@"));  // everything before the '@'
		domainstr = currentstr.substring(currentstr.indexOf("@")+1, nextemail); // everything after the '@'
		
//		var message = "IsBlank(currentstr): " + IsBlank(currentstr) + "\rnamestr.length: " + namestr.length + "\rdomainstr.indexof(.): " + domainstr.indexOf(".") + "\rdomainstr.indexOf(@): " + domainstr.indexOf("@") + "\rcurrentstr.charAt(domainstr.length-1): " + domainstr.charAt(domainstr.length-1);
//		var message = message + "\rList length: " + listlen + "\ri: " + i + "\rnextemail: " + nextemail + "\rstr: " + str + "\rcurrentstr: " + currentstr + "\rnamestr: " + namestr + "\rdomainstr: " + domainstr + "\risValid: " + isValid;
//		alert ("" + message);
		
		// Rules: namestr cannot be empty, or that would indicate no characters before the '@',
		// domainstr must contain a period that is not the first character (i.e. right after
		// the '@').  The last character must be an alpha.
	   	if (IsBlank(currentstr) || (namestr.length == 0) || (domainstr.indexOf(".") <= 0) || (domainstr.indexOf("@") != -1) || !IsAlpha(domainstr.charAt(domainstr.length-1))) {
			isValid = false;
			break;
		}
		// increment counter and remove processed email from str
		i = nextemail + 1;
		emailcount = emailcount + 1;
		
		str = str.substring(i,listlen);
		
		if ((!allowmultiple) && (emailcount > 1)) {
			isValid = false;
			break;
		}		
   }   
   	return isValid;
} 

/* ======================================================================
FUNCTION:  	IsAlpha

INPUT:		str (string) - the string to be tested

RETURN:  	true, if the string contains only alphabetic characters 
				false, otherwise.

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsAlpha( str ) {
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;

	var isValid = true;

	str += "";	// convert to a string for performing string comparisons.

	// Loop through string one character at time,  breaking out of for
	// loop when an non Alpha character is found.
  	for (i = 0; i < str.length; i++) {
		// Alpha must be between "A"-"Z", or "a"-"z"
		if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ) ) {
         				isValid = false;
         				break;
      			}
   } 
	return isValid;
}  // end IsAlpha 

/* ======================================================================
FUNCTION:	IsAlphaNum
 
INPUT:		str (string) - a string that will be tested to ensure that
      								each character is a digit or a letter.

RETURN:  	true, if all characters in the string are a character from 0-9
     			or a-z or A-Z;  
				false, otherwise

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsAlphaNum( str ) {
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;

	var isValid = true;
	
	// convert to a string for performing string comparisons.
   	str += "";	

	// Loop through length of string and test for any alpha numeric 
	// characters
   	for (i = 0; i < str.length; i++)
   	{
			// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
      	if (!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
      			((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))))
			{
				isValid = false;
				break;
			}	
   	} // END for   
   
   	return isValid;
}  // end IsAlphaNum

/* ======================================================================
FUNCTION:	IsAlphaNumOrUnderscore

INPUT:		str (string) - the string to be tested

RETURN:  	true, if the string contains only alphanumeric characters or underscores.
				false, otherwise.

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsAlphaNumOrUnderscore( str ) {
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;

	var isValid = true;

	str += "";	// convert to a string for performing string comparisons.
	// Loop through string one character at a time. If non-alpha numeric
	// is found then, break out of loop and return a false result

	for (i = 0; i < str.length; i++)
   	{
		// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
      		if ( !( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
      			((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ||
      			(str.charAt(i) == "_") ) )
      		{
   				isValid = false;
         		break;
      		}

	} // END for   
   
	return isValid;

}  // end IsAlphaNumOrUnderscore

/* ======================================================================
FUNCTION:	IsAlphaNumOrPeriod

INPUT:		str (string) - the string to be tested

RETURN:  	true, if the string contains only alphanumeric characters or underscores.
				false, otherwise.

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsAlphaNumOrPeriod( str ) {
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;

	var isValid = true;

	str += "";	// convert to a string for performing string comparisons.
	// Loop through string one character at a time. If non-alpha numeric
	// is found then, break out of loop and return a false result

	for (i = 0; i < str.length; i++)
   	{
		// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
      		if ( !( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
      			((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ||
      			(str.charAt(i) == ".") ) )
      		{
   				isValid = false;
         		break;
      		}

	} // END for   
   
	return isValid;

}  // end IsAlphaNumOrPeriod


/* ======================================================================
FUNCTION:	IsBlank
 
INPUT:		val - the value to be tested

RETURN:  	true, if the string is null, undefined or an empty string, ""
      		false, otherwise.

CALLS:		IsNull(), IsUndef() which are defined elsewhere in the Script Library

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0, Microsoft IIS/ASP 3.0.
====================================================================== */
function IsBlank( str ) {
	var isValid = false;

 	if ( IsNull(str) || IsUndef(str) || (str+"" == "") )
 		isValid = true;
		
	return isValid;
}  // end IsBlank

/* ======================================================================
FUNCTION:	IsNull
 
INPUT:		val - the value to be tested

RETURN:  	true, if the value is null;
      		false, otherwise.

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsNull( val ) {
	var isValid = false;

 	if (val+"" == "null")
 		isValid = true;
		
	return isValid;
}  

/* ======================================================================
FUNCTION:	IsUndef
 
INPUT:		val - the value to be tested

RETURN:  	true, if the value is undefined
      		false, otherwise.

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsUndef( val ) {
	var isValid = false;

 	if (val+"" == "undefined")
 		isValid = true;
		
	return isValid;
}  

/* ======================================================================
FUNCTION:  	IsInt
 
INPUT:  		numstr (string/number) 	 - the string that will be tested to ensure 
      										   that each character is a digit
				allowNegatives (boolean) - (optional) when true, allows numstr to be
													negative (contain a '-').  When false,
											      any negative number or a string starting
													with a '-' will be considered invalid.

RETURN:  	true, if all characters in the string are a character from 0-9,
				regardless of value for allowNegatives
				true, if allowNegatives is true and the string starts with a '-', and all other
				characters are 0-9.
     			false, otherwise.

PLATFORMS:	Netscape Navigator 3.01 and higher,
			  	Microsoft Internet Explorer 3.02 and higher,
			  	Netscape Enterprise Server 3.0,
			  	Microsoft IIS/ASP 3.0.
====================================================================== */
function IsInt( numstr, allowNegatives ) {
	// Return immediately if an invalid value was passed in
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	// Default allowNegatives to true when undefined or null
	if (allowNegatives+"" == "undefined" || allowNegatives+"" == "null")	
		allowNegatives = true;

	var isValid = true;

	// convert to a string for performing string comparisons.
	numstr += "";	

	// Loop through string and test each character. If any
	// character is not a number, return a false result.
 	// Include special case for negative numbers (first char == '-').   
	for (i = 0; i < numstr.length; i++) {
    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || (numstr.charAt(i) == "-"))) {
       	isValid = false;
       	break;
		} else if ((numstr.charAt(i) == "-" && i != 0) || 
				(numstr.charAt(i) == "-" && !allowNegatives)) {
       	isValid = false;
       	break;
      }
         	         	       
   } // END for   
   
   	return isValid;
}  // end IsInt
// -->
