﻿$(document).ready(function () {
    $('div.form div.submitBtn a').click(function () { setTimeout("toggleVals()", 100); });
    $('div.form input.txtInput').change(function () { toggleVals(); });
    $('div.form input.txtInput').blur(function () { toggleVals(); });
    $('div.form input').keydown(function (evt) { if (evt.keyCode == 13) { toggleVals(); } });

    $('#nlSignupBox .header a').click(function (event) {
        event.preventDefault();
        $('#nlSignupBox span.errorNotice').hide();
        $('#nlSignupBox .errorMsg ').hide();
        $('#nlSignupBox .thankYou').hide();
        $.fancybox.resize();
        $('#nlSignupBox .txtInput').removeClass('errorInput').val('');
        $.each($('#nlSignupBox :checked'), function () { document.getElementById($(this).attr("Id")).checked = false; });
    });

    $('a#nlSignup').click(function () {
        setTimeout("$('#nlSignupBox .firstName').focus()", 90);
    });
});

function toggleVals() {
    $('div.form span.errorNotice.required:not(:hidden)').parent().siblings('input').addClass('errorInput');
    $('div.form span.errorNotice.required:hidden').parent().siblings('input').removeClass('errorInput');

    if ($('div.form span.errorNotice.required:not(:hidden)').length > 0) {
        $('div.form div.errorMsg.required').show();
    }
    else {
        $('div.form div.errorMsg.required').hide();
    }

    if ($('div.form input.email').siblings('label').children('span.errorNotice.required:hidden').length > 0) {
        $('div.form span.errorNotice.email:not(:hidden)').parent().siblings('input').addClass('errorInput');
        $('div.form span.errorNotice.email:hidden').parent().siblings('input').removeClass('errorInput');

        if ($('div.form span.errorNotice.email:not(:hidden)').length > 0) {
            $('div.form div.email.errorMsg').show();
        }
        else {
            $('div.form div.email.errorMsg').hide();
        }
    }
    else {
        $('div.form div.email.errorMsg').hide();
    }
    $.fancybox.resize(); 
}

function CategoriesValidate(source, arguments) {
    if ($('div.form table.checkboxList input:checked').length == 0) {
        arguments.IsValid = false;
    } else {
        arguments.IsValid = true;
    }
    toggleVals();
}
