$(function() {
    // <IE7 Navigation
    if ($.browser.msie && $.browser.version < 7) {
        // Style required labels
        $("span.required + label").addClass("required");
    }
});
function toggleSearchOptions() {
    var arrow = "right";
    $("#search-options").slideToggle();
    if ($("#search-options.hidden").length > 0) {
        $("#search-options").removeClass("hidden");
        arrow = "down";
    } else {
        $("#search-options").addClass("hidden");
    }
    $("img.search-options-twisty").attr("src", "images/twisty_" + arrow + ".gif");
}
function validate(form) {
    var valid = true;
    $("dd.mandatory").remove();
    $("#" + form + " :input.required").each(function() {
        if ($(this).val() === "") {
            if (valid) {
                // Give focus to the first invalid item
                $(this).focus();
            }
            $(this).parents("dd").after("<dd class='mandatory'>This is a required field</dd>");
            valid = false;
        }
    });
    $("#" + form + " :input.email").each(function() {
        if ($(this).val() !== "") {
            var isEmail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/i.test($(this).val());
            if (!isEmail) {
                if (valid) {
                    // Give focus to the first invalid item
                    $(this).focus();
                }
                $(this).parents("dd").after("<dd class='mandatory'>Please input a valid e-mail address</dd>");
                valid = false;
            }
        }
    });
    $("#" + form + " :input.pdf").each(function() {
        if ($(this).val() !== "") {
            var isPdf = /\.pdf$/i.test($(this).val());
            if (!isPdf) {
                if (valid) {
                    // Give focus to the first invalid item
                    $(this).focus();
                }
                $(this).parents("dd").after("<dd class='mandatory'>Please select a .PDF file</dd>");
                valid = false;
            }
        }
    });
    $("dd.mandatory+dd.mandatory").remove();
    return valid;
}
