function checkbox (f) {
var e, i = 0, checked = false;
while (e = f[i++]) {if (e.checked) checked = true};
//if (!checked) alert ('Please pick one');
return checked;
}
function isBlank(str){
        var len = str.length
        var i
        for (i=0;i<len;++i){
                if (str.charAt(i) != " ") return false;
                }
        return true
        }

 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);
    }
    while (retValue.indexOf("  ") != -1) {
        // Note that there are two spaces in the string -
        //look for multiple spaces within the string
        retValue = retValue.substring(0, retValue.indexOf("  ")) +
            retValue.substring(retValue.indexOf("  ")+1, retValue.length);
        // Again, there are two spaces in each of the strings
            }
    return retValue; // Return the trimmed string back to the user
}
function emailCheck(emailStr) {
                var emailPat=/^(.+)@(.+)$/
                var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
                var validChars="\[^\\s" + specialChars + "\]"
                var quotedUser="(\"[^\"]*\")"
                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 + ")*$")
                var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
                var matchArray=emailStr.match(emailPat)
                if (matchArray==null) {
                                alert("Email address seems incorrect (check @ and .'s)")
                                return false
                }
                var user=matchArray[1]
                var domain=matchArray[2]
                

                if (user.match(userPat)==null) {
                    alert(" The username in the email doesn't seem to be valid")
                    return false
                }
                var IPArray=domain.match(ipDomainPat)
                if (IPArray!=null) {
                    // this is an IP address
                          for (var i=1;i<=4;i++) {
                            if (IPArray[i]>255) {
                                //alert(" Destination IP address is invalid ")
                                alert(" Please check the email address ")
                                return false
                            }
                    }
                    return true
                }
                

                // Domain is symbolic name
                var domainArray=domain.match(domainPat)
                if (domainArray==null) {
                        alert(" The domain name in the email address doesn't seem to be valid ")
                    return false
                }
                

                /* domain name seems valid, but now make sure that it ends in a
                   three-letter word (like com, edu, gov) or a two-letter word,
                   representing country (uk, nl), and that there's a hostname preceding 
                   the domain or country. */
                

                /* Now we need to break up the domain to get a count of how many atoms
                   it consists of. */
                var atomPat=new RegExp(atom,"g")
                var domArr=domain.match(atomPat)
                var len=domArr.length
                if (domArr[domArr.length-1].length<2 || 
                    domArr[domArr.length-1].length>3) {
                   // the address must end in a two letter or three letter word.
                   alert(" The email must end in a three-letter domain, or two letter country")
                   return false
                }
                

                // Make sure there's a host name preceding the domain.
                if (len<2) {
                   var errStr=" Email is missing a hostname!"
                   alert(errStr)
                   return false
		}
                return true;
	}


function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}


