function isZipCode (s,message){
	// s is a form element
	// message is a string
	// Does NOT change the value of form element, s
	//Uses loops instead of slice or substr because IE3 doesn't
	//support those methods.  -- Steve
	var strZip;
	
	strZip = s.value;
	
	//Convert 5 digit zip to 9 digit by adding "0000"
	if (strZip.length == 5){
		if (isInteger(strZip,message)){
			return true;
		}
		else{
			s.focus();
			return false;
		}
	}
	
	// If length ten (XXXXX-YYYY), remove non-numeric then check length 9
	if(strZip.length == 10){
		strZip=numericize(strZip);
	}
	
	//Check length 9
	if (strZip.length == 9){
		if (isInteger(strZip,message)){
			return true;
		}
		else{
			s.focus();
			return false;
		}
		
	}
	alert(message);
	s.focus();
	return false;
}

function formatZipCode(s){
	// s is a string
	var strZip;
	strZip = numericize(s);
	if (strZip.length == 5){ 
		return strZip+"-0000";
	}
	else if(strZip.length==9){
			strZip = strZip.substring(0,5)+"-"+strZip.substring(5,9);
			return strZip;
	}
	else{
		return s;
	}
}

function isMoney(s,message) {
	// s is a string
	// message is a string
	// accepts blank as good -- check that separately
	// does not accept $ or ,
	// does not modify s
	if ((s.length == 0) || (s == "") || (s == null)) {
		return true;
	}
	    
	// skip over any leading blanks added for right justification

	var j=0;
	for(var i=0; i<s.length; i++) {
		if (s.substring(i, i+1) != ' ') {
			j=i;
			break;
		}
	}
	for (i=j; i<s.length; i++) {
		var ch = s.substring(i, i +1)
		if ((ch < "0" || "9" < ch) && (ch != '.')) {
			alert(message);
			return false;
		}
	}
	return true;
} 


function isInteger (s,message){
	// s is a string
	// message is a string
	var i;
	for (i = 0; i < s.length; i++){   
	    // Check that current character is number.
	    var c = s.charAt(i);
	    if (!isDigit(c)){
	 	 	alert(message);			
			return false;
		}
	}
	return true;
}

function isDigit (c){
	// c is a character
	return ((c >= "0") && (c <= "9"))
}

function numericize(s){
	// s is a string
	// message is a string
	var i,j;
	j="";
	for (i=0;i<s.length;i++){
		if (isDigit(s.charAt(i))){
			 j=j+s.charAt(i);
		}
	}
	return j;
}

function isBlank(s,message){
	// s is a form element
	// message is a string
	if ((s.value.length > 0) && (s.value != null) && (s.value != "")){
		return false;
	}
	if ((message != null) && (message.length > 0) && (message != "")){
		alert(message);
		s.focus();
	}
	return true;
}

function isSSN (s,message){
	// s is a form element
	// CHANGES the value of form element, s
	// message is a string
	//Uses loops instead of slice or substr because IE3 doesn't
	//support those methods.  -- Steve
	var x,i;

	// Check blank
	if (isBlank(s,message)){
		s.focus();
		return false;
	}

	// Check 11 digit with dashes (strip out dashes, check if valid)
	if (s.value.length == 11){
		s.value=numericize(s.value);
	}
	
	// Check 9 digit integer
	if (s.value.length == 9){
		if (isInteger(s.value,message)){
			return true;
		}
		else{
			s.focus();
			return false;
		}
	}

	alert(message);
	s.focus();
	return false;
}

function isPhone (s,message){
	// s is a form element
	// message is a string
	// Does NOT change the value of form element, s

	var strPhone;
	strPhone = s.value;

	// If non-numeric characters, strip them, then check for length
	if (strPhone.length > 10){
		strPhone = numericize(strPhone);
	}
	
	//Check if first digit is 0 or 1. Invalid phone number.
	if ((strPhone.charAt(0) == '0') || (strPhone.charAt(0) == '1')){
		alert(message);
		s.focus();
		return false;
	}
	
	//Should be 3 digit area code + 7 digit phone number, as a 10 digit string
	if (strPhone.length == 10){
		if (isInteger(strPhone,message)){
			return true;
		}
		else{
			s.focus();
			return false;
		}
	}
	else{ 
		alert(message);
		s.focus();
		return false;
	}
	return true;
}

function formatPhone(s){
	// s is a string
	var strPhone;
	strPhone = numericize(s);
	if (strPhone.length != 10){ 
		return s;
	}
	else{
		strPhone = strPhone.substring(0,3)+"-"+strPhone.substring(3,6)+"-"+strPhone.substring(6,10);
		return strPhone;
	}
}

function isEmail (s,message){
	// s is a form element
	// message is a string
	// Does NOT change the value of form element, s
	var i,ii;
	var j;
	var k,kk;
    var jj;
    var len;
    
    // Check blank
	if (isBlank(s,message)){
		s.focus();
		return false;
	}

    // Check valid email
    // Must have a "@" and a "." to be valid.
    // Must have at least 1 character before "@"
    // Must have at least 1 character after "@" and before "."
    // Must have at least 2 characters after "."
    if (s.value.length >0){
		i=s.value.indexOf("@");
		ii=s.value.indexOf("@",i+1);
		j=s.value.indexOf(".",i);
		k=s.value.indexOf(",");
		kk=s.value.indexOf(" ");
		jj=s.value.lastIndexOf(".")+1;
		len=s.value.length;
		if ((i>0) && (j>(1+1)) && (k==-1) && (ii==-1) && (kk==-1) &&
			(len-jj >=2) && (len-jj<=3)) {}
		else {
	 		 	alert(message);
	 		 	s.focus();			
				return false;
		}
	}
    return true;
}

function isSelected (s,message){
	// s is a select form element
	// message is a string
	// Does NOT change the value of form element, s
	// Checks to see if a selectbox has been changed from its first value
	// Should be used on drop-boxes that have "Select an Item" or something
	// similar as their first OPTION
	if (s.selectedIndex==0){
		if ((message != null) && (message.length > 0) && (message != "")){
			alert(message);
			s.focus();
		}
		return false;
	}
	return true;
}