﻿(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'); }
    });

    $(document).bind('loginModal_onRegistration', function () {


    });

    $(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?d=' + new Date().getTime(),
                'onCleanup': function () {
                    if (typeof 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?', ($(document).data('events')['open_registration'] == undefined) ? '' : 'iscontest=true&', 'd=' + new Date().getTime()].join(''),
                'onCleanup': function () {
                    if (typeof g_Click_To_Enter !== "undefined") {
                        g_Click_To_Enter = false;
                    }
                }
            });
        });

    });
})(jQuery);

function doSimulateLoginClick() {
    //Modified for TSSO project, in TSSO, we are not rendering the signIn link but the aSignInTsso link
    if (jQuery("#aSignInTsso").length > 0) {
        jQuery("#aSignInTsso").trigger('click');
    }
    else {
        jQuery("#signIn").trigger('click');
    }
}
