function setFocus(theInputField) {
    var mynode = document.getElementsByName(theInputField);
    mynode[0].focus();
    return;
}

// =====================================================================
//  FORM FIELD VALIDATION ROUTINES  (Copyright (c) 2006 by H Marc Lewis)
// ---------------------------------------------------------------------
// this.field.validate can take on the following values:
// 'F' = non-blank (Filled)
// 'E' = email address (required)
// 'e' = non-required email address (blank is okay)
// 'I' = integer (digits only) (range may be set, see below)
//        this.field.low       = Lowest allowed integer value
//        this.field.high      = Highest allowed integer value
//        this.field.numdigits = Required number of digits
// 'L' = Drop-down list (anything other than 1st must be selected)
// 'Z' = US Zip code or Canadian Postal Code
// =====================================================================

function isBlank(str)  { return(str.search(/[\S]/) < 0); }
function isDigits(str) { return(str.search(/[\D]/) < 0); }
function isEmail(str)  { return(str.search(/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i) > -1); }

function checkFields(f)
{
    var msg, i, e;
    var emptyfields = "";
    var errors = "";

    for (i=0; i < f.length; i++) {
        e = f.elements[i];
        if (e.validate) {
            // then we need to validate this field
            switch (e.validate) {
                case 'F':   if (isBlank(e.value))
                                emptyfields += "\n>> " + e.name;
                            break;
                case 'I':   if (isBlank(e.value))
                                emptyfields += "\n>> " + e.name;
                            if (!isDigits(e.value))
                                errors += e.name + " field must contain only decimal digits\n";
                            if (e.low && (e.value < e.low))
                                errors += e.name + " must be greater than or equal to "
                                        + e.low + "\n";
                            if (e.high && (e.value > e.high))
                                errors += e.name + " must be less than or equal to "
                                        + e.high + "\n";
                            if (e.numdigits && (e.numdigits != e.value.length))
                                errors += e.name + " must contain exactly "
                                        + e.numdigits + " digits\n";
                            break;
                case 'E':   if (isBlank(e.value))
                                emptyfields += "\n>> " + e.name;
                            // Fall thru to next case
                case 'e':
                            if (!isBlank(e.value) && !isEmail(e.value))
                                errors += e.name + " field must contain a valid email address\n";
                            break;
                case 'L':   if (e.selectedIndex <= 0)
                                errors += "You must make a slection from the " +
                                        e.name + " drop-down list\n";
                            break;
                case 'Z':   if (isBlank(e.value)) {
                                emptyfields += "\n>> " + e.name;
                                break;
                                }
                            e.value = e.value.replace(/\s/g,"");
                            if (e.value.search(/^\d\d\d\d\d$/) >= 0)
                                break;  // Valid USA Zip
                            if (e.value.search(/^[A-Z]\d[A-Z]\d[A-Z]\d$/i) >= 0) {
                                e.value = e.value.substr(0,3) + ' ' + e.value.substr(3);
                                e.value = e.value.toUpperCase();
                                break;  // Valid Canadian Postal Code
                                }
                            errors += "ZIP (Postal Code) must be 5 digits or of the form A9A 9A9\n";
                            break;
                }
            }
        }
    if (!emptyfields && !errors)
        return(true);
    msg  = "The form was not submitted because of the following error(s).\n";
    msg += "Please make the appropriate corrections and re-submit.\n";
    msg += "\n=========================================\n";
    if (emptyfields) {
        msg += "The following required field(s) are empty:"
                + emptyfields + "\n";
        if (errors)
            msg += "\n";
        }
    msg += errors;
    alert(msg);
    return false;
}


function isFormOk(theInputField) {
    var mynode = document.getElementsByName(theInputField);
    if (mynode[0].value == "") {
        alert("\nThe SEARCH STRING field cannot be blank");
        return(false);
        }
    return(true);
}
