// navigation hover fix for ie6
sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// form validation script
function validateFormOnSubmit(theForm) {
    var reason = "";

    reason += validateEmpty(theForm.name, 'Name');
    reason += validateEmpty(theForm.phone, 'Phone');
    reason += validateEmail(theForm.email);

    if (reason != "") {
        alert(reason);
        return false;
    }
    return true;
}
function validateEmpty(fld, fldName) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = '#FF7F7F';
        error = fldName + " is required.\n";
    } else {
        fld.style.background = '#fff';
    }
    return error;
}
function trim(s) {
    return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    if (fld.value == "") {
        fld.style.background = '#FF7F7F';
        error = "Email is required.\n";
    } else if (!emailFilter.test(tfld)) {
        fld.style.background = '#FF7F7F';
        error = "Please enter a valid email address.\n";
    } else {
        fld.style.background = '#fff';
    }
    return error;
}
