﻿(function ($) {
    $(document).bind('after_login', function () {
        $.fancybox.close();
        window.location = window.location;
    });

    $(document).bind('sb_Set_Cookie', function (event, arrCookies, triggerAfterLogin) {
        if (arrCookies) {
            $.each(arrCookies, function (index, elem) {
                //disableEncodeURIComponent parameter is added to the jQuery cookie lib to provide a way to disable the default behavior of this libary encodes cookie value.
                $.cookies.set(elem.key, elem.value, elem.options, elem.hasOwnProperty('disableEncodeURIComponent') && elem.disableEncodeURIComponent);
            });
        }

        if (triggerAfterLogin)
        { $(document).triggerHandler('after_login'); }
    });

    //Global varibale that will be assign a true value in CustomContest.aspx.js if it is click to enter
    var g_Click_To_Enter = false;

    $(document).bind('open_registration', function () {
        $.fancybox.close();

        if (g_Click_To_Enter != undefined && g_Click_To_Enter) {
            openRegisterModal();
        }
        else {
            openSignUpClick();
        }
    });

    $(document).ready(function () {
        $("a[ref*='signIn']").each(function () {
            $(this).fancybox(
            {
                'width': 730,
                'height': 385,
                'padding': 0,
                'scrolling': 'no',
                'hideOnOverlayClick': false,
                'titleShow': false,
                'transitionIn': 'none',
                'type': 'iframe',
                'href': '/LoginPage.aspx?iscontest=true&d=' + new Date().getTime(),
                'onCleanup': function () {
                    if (g_Click_To_Enter != undefined) {
                        g_Click_To_Enter = false;
                    }
                }
            });
        });

        $("a[ref*='signInTsso']").each(function () {
            $(this).fancybox(
            {
                'width': 730,
                'height': 449,
                'padding': 0,
                'scrolling': 'no',
                'hideOnOverlayClick': false,
                'titleShow': false,
                'transitionIn': 'none',
                'type': 'iframe',
                'href': '/LoginPage.aspx?iscontest=true&d=' + new Date().getTime(),
                'onCleanup': function () {
                    if (g_Click_To_Enter != undefined) {
                        g_Click_To_Enter = false;
                    }
                }
            });
        });
    });
})(jQuery);
