﻿$(function () {
    if ($("#hdnLogged").val() != "1") {
        $.validator.setDefaults({
            submitHandler: function () { __doPostBack('__Page', 'MyCustomArgument'); },
            highlight: function (input) {
                $(input).addClass("ui-state-highlight");
            },
            unhighlight: function (input) {
                $(input).removeClass("ui-state-highlight");
            }
        });
    }
});

$().ready(function () {
    if ($("#hdnLogged").val() != "1") {
            $.fn.themeswitcher && $('<div/>').css({
            position: "absolute",
            right: 10,
            top: 10
        }).appendTo(document.body).themeswitcher();

    
        // Disable default/auto binding of all buttons
        $("#frmIndex").validate({
            onsubmit: false
        });
    
        $("#txtEmailLogin").rules("add", { required: true, email: true, messages: { required: "", email: ""} });
        $("#txtPass").rules("add", { required: true, messages: { required: ""} });
    
        // Bind the ASP.NET button with the ID "Search" to the "ValidateAndSubmit" custom validation function.
        $('#btnLogin').click(ValidateAndSubmitLogin);
    }
    
});

function ValidateAndSubmitLogin(evt) {
    // Find the parent control that contains the class validationGroup
    var $group = $(evt.currentTarget).parents('.validationLoginGroup');

    var isValid = true;

    // Look at all the input controls and run them against the rules
    $group.find(':input').each(function (i, item) {
        if (!$(item).valid())
            isValid = false;
    });

    // If any control is the group fails, prevent default actions (aka: Submit)
    if (!isValid)
        evt.preventDefault();
}
