function confirmPoints(source, clientside_arguments) {

    var ctl = entries_ClientID;
    var tble = document.getElementById(ctl);
    var entryQty = "";
    if (tble != null) {
        entryQty = tble.value;
    }
    ctl = hfMembersPoint_ClientID;
    var ctlMemPoints = document.getElementById(ctl);
    var memberPoints = ctlMemPoints.value;
    ctl = lblTicketPoints_ClientID;
    var entryPoints = document.getElementById(ctl).innerHTML;
    var message = ''
    var pointsError = false
    var re = /,/g;
    entryQty = entryQty.replace(re, "");
    if ((Number(entryQty) * Number(entryPoints)) > Number(memberPoints)) {
        pointsError = true
    }
    if (pointsError) {
        clientside_arguments.IsValid = false;
    }
    else
        clientside_arguments.IsValid = true;

}
function confirmPointsZero(source, clientside_arguments) {
    var ctl = entries_ClientID;
    var tble = document.getElementById(ctl);
    var entryQty = "";
    if (tble != null) {
        entryQty = tble.value;
    }
    var pointsError = false
    var re = /,/g;
    entryQty = entryQty.replace(re, "");
    if (entryQty == 0 || entryQty == "") {
        pointsError = true
    }
    if (pointsError) {
        clientside_arguments.IsValid = false;
    }
    else
        clientside_arguments.IsValid = true;

}
function confirmPointsMaxEntry(source, clientside_arguments) {
    var ctl = entries_ClientID;
    var tble = document.getElementById(ctl);
    var entryQty = "";
    if (tble != null) {
        entryQty = tble.value;
    }
    var memberPoints = MemberPoints;
    ctl = hfMaxEntries_ClientID;
    var maxEntries = document.getElementById(ctl).value;
    ctl = hfTicketsPurchased_ClientID;
    var memberEntries = document.getElementById(ctl).value;
    var message = ''
    var pointsError = false
    var re = /,/g;
    entryQty = entryQty.replace(re, "");

    if (maxEntries > 0 && (Number(entryQty) + Number(memberEntries)) > maxEntries) {
        message = document.getElementById(hfJSExceedMax_ClientID).value;
        pointsError = true
    }

    if (pointsError) {
        source.ErrorMessage = message;

        clientside_arguments.IsValid = false;
    }
    else {
        clientside_arguments.IsValid = true;
    }
}
function confirmSpentPoint(source, clientside_arguments) {
    var sConf = document.getElementById(hfJSSweepstake_ClientID).value + " " + document.getElementById(hfJSPointNotReturn_ClientID).value + " " + document.getElementById(hfJSSpendPoint_ClientID).value;
    var conf = confirm(sConf);
    clientside_arguments.IsValid = conf;
}
function validateEmail(source, clientside_arguments) {
    var ctl = Email_ClientID;
    var valEmail = document.getElementById(ctl).value;
    if (valEmail == "") {
        clientside_arguments.IsValid = false;
    }
    else
        clientside_arguments.IsValid = true;
}

function validatePassword(source, clientside_arguments) {
    var ctl = Email_ClientID;
    var valPassword = document.getElementById(ctl).value;
    if (valPassword == "") {
        clientside_arguments.IsValid = false;
    }
    else
        clientside_arguments.IsValid = true;
}
function pageLoad() {
    var ctl = hideLoginViaClientButton_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideLoginShowMessage);
    }
    ctl = hideRegViaClientButton_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideRegistryOpenMessage);
    }
    ctl = CreateAccount_ClientID;
    if ($get(ctl) != null && $get(ctl).href.toLowerCase().indexOf("javascript:void(0)") > -1) {
        $addHandler($get(ctl), 'click', openRegisterModal);
    }
    ctl = CreateAccountSA_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', openRegisterModal);
    }
    ctl = CancelButton_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideLoginShowMessage);
    }
    ctl = ForgotPassword_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideModalLoginPopupViaClient);
    }
    ctl = CancelForgotten_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', showModalLoginPopupViaClient);
    }
    ctl = OkFailed_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideModalFailedPopupViaClient);
    }
    ctl = returnPrevious_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideReturnPrevious);
    }
    ctl = "ConfirmShip";
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', showConfirmShipViaClient);
    }
    ctl = returnDiscardButton_ClientID;
    if ($get(ctl) != null) {
        $addHandler($get(ctl), 'click', hideModalRegMessagePopupViaClient);
    }
}
function hideModalLoginPopupShowRegViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    clearLoginControls();
    var modalPopupBehavior = $find('modalLoginControlBehavior');
    modalPopupBehavior.hide();
    showModalRegPopupViaClient(ev);
}
function hideModalLoginPopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    clearLoginControls();
    var modalPopupBehavior = $find('modalLoginControlBehavior');
    modalPopupBehavior.hide();
}
function hideReturnPrevious(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var ctl = hfLastControl_ClientID;
    var ctlst = document.getElementById(ctl);
    var slc = ctlst.value.trim();
    hideModalRegMessagePopupViaClient(ev)
    if (slc == "login") {
        showModalLoginPopupViaClient(ev);
    }
    if (slc == "register") {
        showModalRegPopupViaClient(ev);
    }
}
function openRegisterModal(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var ctl = hfRegisterlink_ClientID;
    var regl = document.getElementById(ctl);
    ctl = regframe_ClientID;
    var ifrm = document.getElementById(ctl);
    ifrm.setAttribute("src", regl.value);
    hideModalLoginPopupViaClient(ev);
    showModalRegPopupViaClient(ev)
}
function hideLoginShowMessage(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var ctl = hfLastControl_ClientID;
    var ctlst = document.getElementById(ctl);
    ctlst.value = "login";
    hideModalLoginPopupViaClient(ev);
    showModalRegMessagePopupViaClient(ev);
}
function hideRegistryOpenMessage(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    hideModalRegPopupViaClient(ev);
    var ctl = "hfRegistered";
    var ctlst = document.getElementById(ctl);
    if (ctlst.value != "1") {
        showModalRegMessagePopupViaClient(ev);
    }
    else {
        __doPostBack(btnEnterToWin_ClientID_Formatted, "");
    }
}
function hideRegOpenLogin(ev) {
    hideModalRegPopupViaClient(ev);
    showModalLoginPopupViaClient(ev);
}
function clearLoginControls() {
    var ctl = Password_ClientID;
    var oPassword = document.getElementById(ctl);
    oPassword.value = "";
}
function showModalLoginPopupViaClientNoReturn(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var ctl = hfLastControl_ClientID;
    var ctlst = document.getElementById(ctl);
    ctlst.value = "login";
    var modalPopupBehavior = $find('modalLoginControlBehavior');
    var ctl = hfRegisterlink_ClientID;
    var regl = document.getElementById(ctl);
    regl.value = [regl.value, '&CTE=1'].join('');
    regl = null;

    modalPopupBehavior.show();
    return true;
}
function showModalLoginPopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var ctl = hfLastControl_ClientID;
    var ctlst = document.getElementById(ctl);
    ctlst.value = "login";
    var modalPopupBehavior = $find('modalLoginControlBehavior');
    modalPopupBehavior.show();
    return true;
}

function showConfirmShipViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorConfShip');
    modalPopupBehavior.show();
}

function hideConfirmShipViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorConfShip');
    modalPopupBehavior.hide();
}

function hideModalRegPopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorReg');
    modalPopupBehavior.hide();
    var ctl = hfLastControl_ClientID;
    var ctlst = document.getElementById(ctl);
    ctlst.value = "register";
}
function showModalRegPopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var ctl = hfLastControl_ClientID;
    var ctlst = document.getElementById(ctl);
    ctlst.value = "register";
    var modalPopupBehavior = $find('modalControlBehaviorReg');
    modalPopupBehavior.show();
}
function hideModalForPopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorFor');
    modalPopupBehavior.hide();
    showModalLoginPopupViaClient(ev);
}
function hideModalFailedPopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorFailed');
    modalPopupBehavior.hide();
    showModalLoginPopupViaClient(ev);
}

function showModalRegMessagePopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorMessage');
    modalPopupBehavior.show();
}

function hideModalRegMessagePopupViaClient(ev) {
    if (ev != null) {
        ev.preventDefault();
    }
    var modalPopupBehavior = $find('modalControlBehaviorMessage');
    modalPopupBehavior.hide();
}

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}
function LoginCover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}
function ClickToEnterSSOR() {
    if (typeof (carnival) != "undefined") {
        var l = carnival.utils.listener;

        var cleanUrl = carnival.utils.cleanLocation();
        var compUrl = [cleanUrl, cleanUrl.indexOf('?') > -1 ? '&' : '?', 'RBX=1'].join('');

        l.kill(ExLoginPostLoginEvent.toString());
        l.listen(ExLoginPostLoginEvent.toString(), function () {
            window.location = compUrl;
        });

        l.listen('_carnival_after_newsletters', function () {
            window.location = compUrl;
        });

        var loginLink = $("#" + ExLoginLink_ClientID);

        if (tribuneInternalSignOn) {
            loginLink.trigger('click');
        }
        else {
            carnival.utils.popUp(loginLink.attr("href"));
        }
    }
    else {
        //- Opens Login Dialog for Sanban Template
        jQuery(document).unbind('after_login');
        jQuery(document).bind('after_login', function () {
            $.fancybox.close();
            window.location = window.location + '&RBX=1' + '&CTE=1';
        });

        //Global Variable that indicates the login modal triggered by click to enter. defined in SanbanContestLogin.js
        g_Click_To_Enter = true;

        $("#signIn").trigger('click');
    }
}

//This is used for non-synch site
jQuery(document).bind('open_registration', function () {
    $.fancybox.close();

    if (g_Click_To_Enter != undefined && g_Click_To_Enter) {

        var ctl = hfRegisterlink_ClientID;
        var regl = document.getElementById(ctl);
        ctl = regframe_ClientID;
        var ifrm = document.getElementById(ctl);
        ifrm.setAttribute("src", regl.value + '&CTE=1');

        showModalRegPopupViaClient();
    }
    else {
        var regiUrl = $("#logincontrol > a[ref*='register']").attr("href");

        window.location = regiUrl;
    }
});

//This is used for External Registration Sites Only
jQuery(document).bind('ex_registration', function () {
    if (g_Click_To_Enter != undefined && g_Click_To_Enter) {
        ContestExternalRegiRedirect(true);
    } else {
        var regiUrl = $("#logincontrol > a[ref*='register']").attr("href");
        window.location = regiUrl;
    }
});

function ContestExternalRegiRedirect(bCTE) {
    var regiLink = $("#" + hfRegisterlink_ClientID).val();

    if (regiLink !== null && regiLink !== undefined) {
        if (bCTE && !regiLink.match(/CTE\%3d1/)) {
            //$("#" + hfRegisterlink_ClientID).val(regiLink + 'CTE\%3d1')
            regiLink = [regiLink, '%26CTE\%3d1'].join('');
        }

        window.location = regiLink;
    }
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();