﻿$(document).ready(function() {
    // Apply toggle functionality to modern input fields
    $(".ModernInput").toggleVal();

    // Dynamic/automatic client-side validation
    $("#aspnetForm").validate({ onsubmit: false });

    $('.validationGroup .causesValidation').click(function(evt) {
        var $group = $(this).parents('.validationGroup');
        var isValid = true;
        var $firstitem = "";

        $group.find(':input').each(function(i, item) {
            if (!$(item).valid()) {
                    isValid = false;
                    if ($firstitem == "")
                        $firstitem = item;
            }
        });

        if (!isValid) {
            evt.preventDefault();
            $firstitem.focus();
        }
    });

    // Focus the cursor by default on every page to the QuickSearch box
    $("#ctl00_SearchPanel1_TxtSearch").focus();

    // Apply contextual overlay styling to any forms
    $('.form .left, .form input, .form textarea, .form select').focus(function() {
        $(this).parents('.row').addClass("over");
    }).blur(function() {
        $(this).parents('.row').removeClass("over");
    });
});

// Required for a few remaining legacy pages
function popUp(targetPage_, w_, h_) {
    window.open(targetPage_, "blank_", "toolbars=yes,scrollbars=yes,width=" + w_ + ",height=" + h_ + ",left=50,top=50");
}
