function checkinteger(object_value) {
    //Returns true if value is a number or is NULL
    //otherwise returns false   
    if (object_value.length == 0)
        return true;
    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
        var decimal_format = ".";
        var check_char;
    //The first character can be + -  blank or a digit.
        check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
        return checknumber(object_value);
    else
        return false;
}

function checkzip(object_value) {
    if (object_value.length == 0)
        return true;
                
    if (object_value.length != 5 && object_value.length != 10)
        return false;

        // make sure first 5 digits are a valid integer
        if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
        return false;

        if (!checkinteger(object_value.substring(0,5)))
                return false;

        if (object_value.length == 5)
                return true;
        
        // make sure

        // check if separator is either a'-' or ' '
        if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
        return false;

        // check if last 4 digits are a valid integer
        if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
        return false;

        return (checkinteger(object_value.substring(6,10)));
}

function validSelect(obj){
		selchoice = obj.selectedIndex;
		if (obj.options[selchoice].value == "None") {
			//alert("Please select your state.");
			//alert("value is " + form.state.options[stchoice].value);
			return false;
		}else{
			return true;
		}
}

function fillUS(form) {
			/* out for 508
	if (validSelect(form.state)){
		//form.country.selectedIndex = 1;
		for (i=0; i < form.country.length; i++) {
			//if (form.country.options[i].value == "US") {
			if (form.country.options[i].value == "840") {
				form.country.selectedIndex = i;
			}
		}
		form.postalcode.value = "n/a";
		form.zip.focus();
	}else {
		form.zip.value = "n/a";
		form.country.selectedIndex = 0;
		form.postalcode.value = "";
		form.country.focus();
	return true;
	} */
}

function stateNull(form){
				/* out for 508
		//if (form.country.selectedIndex == 1){
		cselchoice = form.country.selectedIndex;
		//if (form.country.options[cselchoice].value == "US") {
		if (form.country.options[cselchoice].value == "840") {
			form.postalcode.value = "n/a";
			if (!validSelect(form.state)){
				form.state.focus();
			}
			//alert("Please select a state");
			if  (!checkzip(form.zip.value)) {
				//alert("Please enter a valid zip code");
				form.zip.value = "";
			}	
		}else {
			form.state.selectedIndex = 0;
			form.zip.value = "n/a";
			form.postalcode.value = "";
			form.postalcode.focus();
		}
	return true; */	
}

function validateComments(){
	var msg="";
	if  (document.forms[0].Comments.value.length == 0) {
		msg += " * Please enter your comments\n";
        //return false;
	} else if (document.forms[0].Comments.value.length > 32000) {
		msg += " * Your comments cannot be larger than 32 KB\n";
	} else {
        //return true;
		//nothing
	}	
	
	if (msg=="") {
       return true;
    } else {
       alert("____________________________________________________\n\n" + "The form was not submitted because of the following error(s).\n Please correct these errors and re-submit.\n" + "____________________________________________________\n\n" +  msg);
       return false;
    }
}