function checkFilled(textfield) {
	if (textfield.value.length == 0) {
		alert("The field \"" + textfield.name + "\" is required.");
		textfield.focus();
		textfield.select();
		return false;
		}
	return true;
}

	// This function checks that the STATE field is in the correct format.
function validateState(textfield) {
	stateOK = false;  // stateOK is a GLOBAL variable

	// Convert the field to upper case, for consistency
	textfield.value = textfield.value.toUpperCase();

	// Check that the state is exactly two chars long
	if ( textfield.value.length != 2 ) {
		alert("The state abbreviation must be two characters long.");
		textfield.focus();
		textfield.select();
		return false;
	}

	// Don't accept non-alphabetic characters
	if (!alphaOnly(textfield.value)) {
		alert("The State field must contain only alphabetic characters!");
		textfield.focus();
		textfield.select();
		return false;
	}
	
	//Check if the state code matches a code value in the array:
	for (var i=0; i<51; i++) {
	if (a[i] == textfield.value) {
		return (stateOK=true);
		}
	}
	alert ("The two-letter state code you entered is invalid.  Please enter a valid two-letter state code.");
	textfield.focus();
	textfield.select();
	return false;
//     return (stateOK = true);

}

	// This function checks lists an array of correct state codes / abbreviations:
function array(size) {
	for (var i=0; i<51; i++)
	this[i]=0;
	this.length=size;
}
a = new array (51);
a[ 0] = "AK";
a[ 1] = "AL";
a[ 2] = "AR";
a[ 3] = "AZ";
a[ 4] = "CA";
a[ 5] = "CO";
a[ 6] = "CT";
a[ 7] = "DC";
a[ 8] = "DE";
a[ 9] = "FL";
a[10] = "GA";
a[11] = "HI";
a[12] = "IA";
a[13] = "ID";
a[14] = "IL";
a[15] = "IN";
a[16] = "KS";
a[17] = "KY";
a[18] = "LA";
a[19] = "MA";
a[20] = "MD";
a[21] = "ME";
a[22] = "MI";
a[23] = "MN";
a[24] = "MO";
a[25] = "MS";
a[26] = "MT";
a[27] = "NC";
a[28] = "ND";
a[29] = "NE";
a[30] = "NH";
a[31] = "NJ";
a[32] = "NM";
a[33] = "NV";
a[34] = "NY";
a[35] = "OH";
a[36] = "OK";
a[37] = "OR";
a[38] = "PA";
a[39] = "RI";
a[40] = "SC";
a[41] = "SD";
a[42] = "TN";
a[43] = "TX";
a[44] = "UT";
a[45] = "VA";
a[46] = "VT";
a[47] = "WA";
a[48] = "WI";
a[49] = "WV";
a[50] = "WY";

	// This function checks that a ZIP code is in the correct format.

function validateZIP(textfield) {
	zipOK = false;  // zipOK is a GLOBAL variable

	// Check that the zip is the right length
	if ( textfield.value.length != 5 ) {
		alert("Zip codes must be exactly five characters!");
		textfield.focus();
		textfield.select();
		return false;
		}

	// don't accept non-numeric characters
	if (!numbersOnly(textfield.value)) {
		alert("Zip codes must be entirely numeric!");
		textfield.focus();
		textfield.select();
		return false;
		}
		return (zipOK=true);
}

	// This function checks that a ZIP2 code (4 DIGITS) is in the correct format.

function validateZIP2(textfield) {
	zip2OK = false;  // zip2OK is a GLOBAL variable

	// Check that the zip is the right length
	if ( textfield.value.length != 4 ) {
		alert("Zip codes must be exactly four characters!");
		textfield.focus();
		textfield.select();
		return false;
		}

	// DO NOT accept non-numeric characters
	if (!numbersOnly(textfield.value)) {
		alert("Zip codes must be entirely numeric!");
		textfield.focus();
		textfield.select();
		return false;
		}
		return (zip2OK=true);
}

	// Test for PHONE number in proper format.
 	// This is not particularly strict, but it's hard to do real regular expression 
	// matching in JavaScript.
function validatePhone(textfield) {
	phoneOK = true; // phoneOK is GLOBAL
	var digits = 0;
		// Check that the phone number only contains the characters "() -0-9"
		// and contains the right number of digits total
	for (var i=0; i < textfield.value.length; i++) {
		var theChar = textfield.value.charAt(i);
		if ((theChar >= "0") && (theChar <= "9")) {
			digits++;
			continue;
			}
		
		if (theChar == "-") continue;
		if (theChar == " ") continue;
		
		phoneOK = false;
	}

	// The string is OK if it contains only the allowed characters and the number of 
	// digits in the phone number is 10 total (area code + number)

	phoneOK = phoneOK && (digits >= 9);
	if (!phoneOK) {
		alert("Please enter a phone number in the format 0 5555-5555");
		textfield.focus();
		textfield.select();
	}
	return phoneOK;
}

	// Test for FAX number in proper format.
 	// This is not particularly strict, but it's hard to do real regular expression 
	// matching in JavaScript.
function validateFax(textfield) {
	faxOK = true; // faxOK is GLOBAL
	var digits = 0;
		// Check that the fax number only contains the characters "() -0-9"
		// and contains the right number of digits total
	for (var i=0; i < textfield.value.length; i++) {
	var theChar = textfield.value.charAt(i);
	if ((theChar >= "0") && (theChar <= "9")) {
		digits++;
		continue;
		}
	if (theChar == " ") continue;
	if (theChar == "-") continue;
	if (theChar == "(") continue;
	if (theChar == ")") continue;
	faxOK = false;
	}

	// The string is OK if it contains only the allowed characters and the number of 
	// digits in the FAX number is 10 total (area code + number)

	faxOK = faxOK && (digits == 10);
	if (!faxOK) {
		alert("Please enter a Fax number in the format (555) 555-5555");
		textfield.focus();
		textfield.select();
	}
	return faxOK;
}
    
	// Check that a string contains only alphabetic characters
function alphaOnly(theString) { 
	var OK = true;
	for (var i=0;i<theString.length;i++) {
		theChar = theString.charAt(i);
	if ( (theChar >= "a") && (theChar <= "z") )
		continue;
	if ( (theChar >= "A") && (theChar <= "Z") )
		continue;
	OK = false;
	}
	return OK;
}

	// Check that a field contains only numeric characters
function numbersOnly(theString) {
	var OK = true;
	for (var i=0;i<theString.length;i++) {
		theChar = theString.charAt(i);
	if ((theChar < "0") || (theChar > "9")) {
		OK = false;
		break;
		}
	}
	return OK;
}

	// The following is my ADAPTATION of an email validation function found on the web:
	// by Kevin Lynn Brown 
	// kevin@myer.com, http://www.myer.com/design/js/validateEmail2.html

function validateEmail(field) {
    url = field.value;
    if (url != null && url != "") {
        a = url.lastIndexOf("@");
        b = url.lastIndexOf(".");
        c = url.indexOf(":");
        d = url.indexOf("/");
        e = url.substring(0,a);
        f = e.indexOf("@");
        g = url.substring(a+1,url.length);
        h = g.indexOf("[");
        i = g.indexOf("]");
        j = g.indexOf("<");
        k = g.indexOf(">");
        l = url.substring(a+1,b);
        m = url.substring(b+1,url.length);
        n = url.substring(0,a);
        o = 0;
        if (a > b) {o++};
        if (c != -1) {o++};
        if (d != -1) {o++};
        if (f != -1) {o++};
        if (h != -1) {o++};
        if (i != -1) {o++};
        if (j != -1) {o++};
        if (k != -1) {o++};
        if (l.length < 3) {o++};
        if (m.length < 2) {o++};
        if (n.length < 1) {o++};
        if (o == 0) {
            //document[FillOutForm][field].value=url;
			return true;
		}
        else {
			return false;
            //alert("You have entered an invalid email address!");
        }
    }
    else {
        alert("You may enter your email address some other time.");
        url="";
		return false;
    }
	return false;
}
