﻿$(document).ready(function () {
    zBox_CreateBox('loginBox');
    zBox_CreateBox('boxEmailSync');
    zBox_CreateBox('boxPrivacyPolicy');
    zBox_CreateBox('boxInactive');

    if (queuedCommand != "")
        eval(queuedCommand);

    SetLoginButtons(null);
});

var queuedCommand = "";
var ajax_messageurl = "/ajax/common/GetMessage.aspx";
var ajax_contentUrl = "/ajax/common/GetContent.aspx";
var privacyPolicyContent = "";
var _authStatus = "anonymous";
var _transferHome = true;

var CookieGBLogin = "GBLogin";
var CookieFBLogin = "FBLogin";
var CookieFBConnect = "FBConnect";
var CookieSyncEmail = "SyncEmail";

function setTransferHome(value) {
    _transferHome = value;
}

function hasFacebookToken() {
    var results = false;
    FB.getLoginStatus(function (response) {
        if (response.session) {
            results = true;
        }
        else {
            results = false;
        }
    });
//    var obj = FB.getSession();
//    if (obj) {
//        obj = obj.access_token;
//        if (obj && obj != undefined)
//            results = true;
//    }

    return results;
}
function onClickGBLogin() {
    raiseAsyncLoginPostback();
    var a = 1;
}

function onClickGBRegister() {
    var element;
    element = $("#register-loading-panel");
    if (element != null)
        element.show();
    raiseAsyncRegisterCaptuaConfirmPostback();
}

function onClickGBResetPass() {
    raiseAsyncResetPassPostback();
    showForgotConfirmation();
}

function onClickGBLogout() {
    //ajaxCall("/ajax/common/common.aspx", "cmd=GBLogout");
    raiseAsyncLogoutPostback();
}

function onClickGBContinue() {
    SetLoginButtons(null);
    raiseAsyncRegisterFinalThankYouPostback();
}

// FB Login Callback
function facebookConnectCompleted(value) {
    raiseAsyncFacebookConnectCompleted();
    /*
    //alert("fConnect completed");
    //var lb = zBox_GetVisibleBox();
    //if (lb != null)
    //    lb.Hide();

    var queuedCommand = checkQueuedCommand();
    if (queuedCommand != "") {
    executeQueuedCommand(queuedCommand);
    }

    if (_transferHome) {
    closingCallBack = null;
    //SetLoginButtons(null);
    registerToHome();
    }
    else {
    closingCallBack = logOffFacebook;

    showFBLinkIntroForm();
    }
    */
}

function onClickFBConnectLogout() {
    return;

    if (hasFacebookToken()) {
        ajaxCall2("/ajax/common/common.aspx", "cmd=FBConnectLogout");
        FB.logout(logoutCallback);
    }
}


function onClickPanelFBLinkNoFailure() {
    logOffFacebook();
    closingCallBack = null;
}

function onClickLinkToGBAccounts(formNavBack) {
    closingCallBack = logOffFacebook;
    showLinkToGiveBackAccountsForm();
    if (formNavBack)
        navBackForm = formNavBack;
}
function onClickLinkToCurrentGBAcct(formNavBack) {
    closingCallBack = logOffFacebook;
    showLinkToCurrentGiveBackAccountForm();
    if (formNavBack)
        navBackForm = formNavBack;
}
function onClickLinkToOtherGBAcct(formNavBack) {
    closingCallBack = logOffFacebook;
    showFBLinkForm();
    if (formNavBack)
        navBackForm = formNavBack;
}
function closeLightBox() {
    logOffFacebook();
    closingCallBack = null; // clear callback on Close
}

function onClickWantSeparateAccount(formNavBack) {
    closingCallBack = logOffFacebook;
    showFBSeparateForm();
    if (formNavBack)
        navBackForm = formNavBack;
}

function onClickLinkFBToGBYes(formNavBack) {
    closingCallBack = logOffFacebook;

    showFBLinkForm();
    if (formNavBack)
        navBackForm = formNavBack;
}

function navBack() {
    if (navBackForm) {
        navBackForm();
    }
}

function closeFBLinkDialog() {
    showFBLinkIntroForm();
    return false;
}

function onClickCreateSeparateAccount(formNavBack) {
    showFBSeparateForm();
    if (formNavBack)
        navBackForm = formNavBack;
}

function onClickLinkToCurrentAccount(formNavBack) {
    showLinkToCurrentGiveBackAccountForm();
    if (formNavBack)
        navBackForm = formNavBack;
}
function onClickLinkToCurrentGBAccount() {
    onClickLinkFBToCurrentGB();
}

function onClickFBLinkToGBSuccess() {
    closingCallBack = null;
    raiseAsyncBtnClickCloseWindowFbConnected();
}

//function facebookConnectCompleted() {
//    //alert("fConnect completed");
//    //var lb = zBox_GetVisibleBox();
//    //if (lb != null)
//    //    lb.Hide();

//    var queuedCommand = checkQueuedCommand();
//    if (queuedCommand != "") {
//        executeQueuedCommand(queuedCommand);
//    }

//    if (_transferHome) {
//        closingCallBack = null;
//        //SetLoginButtons(null);
//        registerToHome();
//    }
//    else {
//        closingCallBack = logOffFacebook;

//        showFBLinkIntroForm();
//    }
//}

//function facebookLogoutCompleted() {
//    var i = 0;
//}

function onClickReadyRockGB() {
    //raiseAsyncRegisterFinalThankYouPostback();
    raiseAsyncRegisterFinalThankYouPostback();
}

function EndRequestGBLoginHandler(sender, args) {
    var dataItems = args.get_dataItems();
    var dataBack = dataItems['updatePanelLogin'];
    if (dataBack != "undefined") {
        if (dataBack == "Success") {
           // alert("handlerSetup");
            //closeLoginModal();
            SetLoginButtons(null);
        }
    }
}
function HideLogin() {
    closeLoginModal();
    SetLoginButtons(null);
}

function logOffFacebook() {
    var hasToken = hasFacebookToken();
    if (hasToken == true) {
        FB.logout(function () {
            window.location = window.location;
        });
    }
}

function logOffFacebookNoReload() {
    FB.logout(function () {
        SetLoginButtons(null);
    });
}

function EndRequestGBLogoutHandler(sender, args) {
}

function onClickFBConnect() {
    //ajaxCall("/ajax/common/common.aspx", "cmd=FBConnect");

}

function onClickTrack(trackignTagID) {
    ajaxCall("/ajax/common/tracking.aspx", "t="+ trackignTagID + "&url=" + window.location);
}


function checkAuthentication() {
    var status = ajaxCall2("/ajax/common/common.aspx", "cmd=CheckAuthentication");
    return status;
}

function checkQueuedCommand() {
    var status = ajaxCall2("/ajax/common/common.aspx", "cmd=QueuedCommand");
    return status;
}

function flushFormData() {
    return ajaxSyncCall("/ajax/common/common.aspx", "cmd=FlushFormData");
}

function ajaxCallBack(authStatus) {
    if (authStatus == "True")
        return true;
    else
        return false;
}

function executeQueuedCommand(cmd) {
    eval(cmd);
}

function ajaxCall2(ajaxUrl, urlData, successFunc) {
    var result = "";
    $.ajax({
        type: 'POST',
        url: ajaxUrl,
        data: urlData,
        success: function (html) {
            result = html;
        },
        async: false
    });
    return result;
}
function ajaxCall(ajaxUrl, urlData, successFunc) {
    $.ajax({
        type: 'POST',
        url: ajaxUrl,
        data: urlData,
        success: function (html) {
            if (successFunc != "undefined")
                eval(successFunc);
        }
    });
}

function ajaxSyncCall(ajaxUrl, urlData, successFunc) {
    $.ajax({
        type: 'POST',
        url: ajaxUrl,
        data: urlData,
        success: function (html) {
            if (successFunc != "undefined")
                eval(successFunc(html));
        },
        async: false
    });
}
function ensureUserIsAuthenticated(callbackMethod, messageKey, initialmode) {
    if (initialmode) 
        { 
        currentPanel = initialmode; 
        }
        var authStatus = getAuthenticationStatus();


    // if not authenticated, propmpt for authentication
        if (authStatus == "anonymous") {
            //queueCallback(callbackMethod);
        if (callbackMethod)
            ajaxCall("/ajax/common/common.aspx", "cmd=Queue&commandEnum=" + callbackMethod);


        showLoginModal(messageKey, initialmode);
    }
    if (authStatus == "anonymous")
        return false;

    return true;
}


function showEmailSyncDialog() {
    if (typeof $ != 'undefined') {
        zBox_GetBox('boxEmailSync').Show();
    }
}
function queueCallback(callback) {
    document.getElementById("QueuedCommand").value = callback;
}

function showLoginModal(messageKey, initialmode) {
    if (initialmode)
    { currentPanel = initialmode; }
    else 
    {currentPanel = 1;}
    HideTermsOfService();
    if (typeof $ != 'undefined') {
        var date = new Date();
        if (messageKey != null) {
            var date = new Date();
            $.ajax({
                type: 'POST',
                url: ajax_messageurl,
                data: "messageKey=" + messageKey + "&time=" + date.getTime(),
                success: function (html) {
                    var htmltitleobj = document.getElementById("loginmessagetitle");
                    var htmlbodyobj = document.getElementById("loginmessagebody");
                    if (htmltitleobj) {
                        if (html.indexOf('#Error:') > 0) {
                            htmltitleobj.innerHTML = "<p class='noresultsmessage'>" + html + "</p>";
                        }
                        else {
                            var messagearray = html.split("#")
                            htmltitleobj.innerHTML = messagearray[0];
                            htmlbodyobj.innerHTML = messagearray[1];
                        }
                    }
                    if (currentPanel == 1) {
                        focusLoginEmail();
                    }
                    else {
                        focusRegisterUsername();
                    }
                }
            });

        }
        else {
            var htmltitleobj = document.getElementById("loginmessagetitle");
            var htmlbodyobj = document.getElementById("loginmessagebody");
            htmltitleobj.innerHTML = "Please Login to Your Account";
            htmlbodyobj.innerHTML = "If you do not have an account please click to register";
        }
        zBox_GetBox('loginBox').Show();
    }
}

function closeLoginModal() {
    if (typeof $ != 'undefined') {
        var box = zBox_GetVisibleBox();
        if (box != null)
            box.Hide();
    }
}

function gbLogout() {
    //ajaxCall("/ajax/common/common.aspx", "cmd=GBLogout");
}

function XEndRequestGBLogoutHandler() {
    SetLoginButtons(null);
}

var _askUserToSyncEmails = false;

function ShowGBLogoutSection(emailLabelId, email) {
    // show GB logout
    var element = $("#logoutSection");
    if (element != null) {
        var label = $("#" + emailLabelId);
        if (label != null) {
            label.append(document.createTextNode(email));
        }
        element.show();
    }
}

function SetLoginButtons(hasFBToken) {
    var element;
    //alert(typeof fbSession);
    //alert("set login buttons");

    //alert("GetAuthStatus: " + authStatus);
    /*
    alert("GetAuthStatus: " + authStatus);
    if (typeof fbSession != "undefined") {
    if (fbSession) {

    // hide login modal access
    element = $("#loginSection");
    if (element != null)
    element.hide();

    // show facebook logout button
    element = $("#fbLogoutSection");
    if (element != null)
    element.show();
    }
    else {
    //alert('fb session is null');
    if (authStatus) {
    //alert('gb session');
    // hide login section
    element = $("#loginSection");
    if (element != null)
    element.hide();

    // show GB logout
    element = $("#logoutSection");
    if (element != null)
    element.show();
    }
    else {
    //alert('no gb session');
    // hide GB logout
    element = $("#logoutSection");
    if (element != null)
    element.hide();

    // show login section
    element = $("#loginSection");
    if (element != null)
    element.show();
    }

    // hide facebook logout button
    element = $("#fbLogoutSection");
    if (element != null)
    element.hide();
    }
    }
    else */
    if (hasFBToken) {
        // hide login modal access
        element = $("#loginSection");
        if (element != null)
            element.hide();

        // hide GB logout
        element = $("#logoutSection");
        if (element != null)
            element.hide();

        // show facebook logout button
        element = $("#fbLogoutSection");
        if (element != null)
            element.show();
    }
    else {
        _authStatus = getAuthenticationStatus();

        //alert('no fb session');
        if (_authStatus == "anonymous") {
            //alert('gb session');
            // hide logout section
            element = $("#logoutSection");
            if (element != null)
                element.hide();

            // show facebook logout button
            element = $("#fbLogoutSection");
            if (element != null)
                element.hide();

            // show GB login
            element = $("#loginSection");
            if (element != null)
                element.show();
        }
        else {
            if (_authStatus == "giveback") {
                // hide login section
                element = $("#loginSection");
                if (element != null)
                    element.hide();

                // show GB logout
                element = $("#logoutSection");
                if (element != null)
                    element.show();
            }
            else
                if (_authStatus == "facebook") {
                    // hide login modal access
                    element = $("#loginSection");
                    if (element != null)
                        element.hide();

                    // hide GB logout
                    element = $("#logoutSection");
                    if (element != null)
                        element.hide();

                    // show facebook logout button
                    element = $("#fbLogoutSection");
                    if (element != null)
                        element.show();
                }
        }
    }
}

function getAuthenticationStatus() {
    var session = "anonymous";
    /*
    var cookieCollection = unescape(document.cookie);
    if (cookieCollection != null) {
        var cookies = cookieCollection.split("; ");
        if (cookies.length > 0) {
            var i;
            for (i = 0; i < cookies.length; i++) {
                //alert("Cookie: " + cookies[i]);
                if (cookies[i].startsWith(CookieGBLogin)) {
                    session = "";
                }
                if (cookies[i].startsWith(CookieSyncEmail)) {
                    _askUserToSyncEmails = true;
                    //alert(cookies[i].expiry);
                }

                if (session == "") {
                    // call server to see if session state is valid
                    //session = checkAuthentication();
                }
            }
        }
    }
    */
    session = checkAuthentication();
    return session;
}

function removeGBSession() {
    removeCookie(CookieGBLogin);
    //var d = new Date();
    //document.cookie = "GBLogin=1;expires=" + d.toGMTString() + ";" + ";";
}

function setCookie(name) {
    document.cookie = escape(name) + ";";
}
function removeCookie(name) {
    //var d = new Date();
    //alert("delete: " + name);
    document.cookie = escape(name) + '; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function setPanelBodyText(sourceElement)
{
    var htmlbodyobj = document.getElementById("loginmessagebody");
    if (htmlbodyobj) {
        var contentHolder = document.getElementById(sourceElement);
        if (contentHolder)
            htmlbodyobj.innerHTML = contentHolder.innerHTML;
    }
}

function setGiveBackAcctEmail() {
    FB.api({ method: 'fql.query', query: 'SELECT email FROM user WHERE uid=' + FB.getSession().uid },
    function (response) {
        element = $("#gbLinkEmail");
        element.text(response[0].email);
    });
}

var currentPanel = 1;
var navBackForm = null;

function showRegistrationForm() {
    var element;
    currentPanel = 2;
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();
}
function showLoginForm() {
    var element;
    currentPanel = 1;
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#PanelTermsOfService");
    if (element != null)
        element.hide();
    element = $("#panelLogin");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();
}
function showFBLinkedToAnotherUserForm() {

    zBox_GetBox('loginBox').Show();

    var element;
    currentPanel = 1;
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#PanelTermsOfService");
    if (element != null)
        element.hide();
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkYes");
    if (element != null)
        element.hide();
    element = $("#panelFBNewAcct");
    if (element != null)
        element.hide();
    element = $("#panelLinkToGBAccts");
    if (element != null)
        element.hide();
    
    element = $("#panelFBLinkedToAnotherUser");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();

    var htmltitleobj = document.getElementById("loginmessagetitle");
    htmltitleobj.innerHTML = "Welcome to Inspireum";

    setPanelBodyText("panelFBLinkedToAnotherUserContent");

    closingCallBack = logOffFacebook;
}

function showFBLinkIntroForm() {
    var element;
    currentPanel = 1;
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#PanelTermsOfService");
    if (element != null)
        element.hide();
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkYes");
    if (element != null)
        element.hide();
    element = $("#panelFBNewAcct");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();

    setPanelBodyText("fbLinkIntroBodyText");
}
function showFBLinkForm() {
    var element;
    currentPanel = 1;
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkedToAnotherUser");
    if (element != null)
        element.hide();
    element = $("#panelLinkToCurrentGBAccount");
    if (element != null)
        element.hide();

    element = $("#panelLinkToGBAccts");
    if (element != null)
        element.hide();


    element = $("#panelFBLinkYes");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();

    setPanelBodyText("fbLinkBodyText");
    setGiveBackAcctEmail();

    navBackForm = showFBLinkIntroForm;
}

function showFBSeparateForm() {
    var element;
    currentPanel = 1;
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkedToAnotherUser");
    if (element != null)
        element.hide();
    element = $("#panelLinkToGBOrNewFBAcct");
    if (element != null)
        element.hide();

    element = $("#panelFBNewAcct");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();

    setPanelBodyText("panelFBNewAcctContent");
}

function showPanelLinkToGBOrNewFBAcct() {
    zBox_GetBox('loginBox').Show();

    var element;
    currentPanel = 1;
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkedToAnotherUser");
    if (element != null)
        element.hide();
    element = $("#panelFBNewAcct");
    if (element != null)
        element.hide();
    element = $("#panelLinkToCurrentGBAccount");
    if (element != null)
        element.hide();
    element = $("#panelLinkToGBOrNewFBAcct");
    if (element != null)
        element.show();
    element = $("#Div1");
    if (element != null)
        element.show();

    var htmltitleobj = document.getElementById("loginmessagetitle");
    htmltitleobj.innerHTML = "Welcome to Inspireum";

    setPanelBodyText("panelLinkToGBOrNewFBAcctContent");

    closingCallBack = logOffFacebook;
}

function showLinkToGiveBackAccountsForm() {
    var element;
    currentPanel = 1;
    element = $("#panelFBLinkedToAnotherUser");
    if (element != null)
        element.hide();
    element = $("#panelLinkToCurrentGBAccount");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkYes");
    if (element != null)
        element.hide();
    element = $("#panelLinkToGBAccts");
    if (element != null)
        element.show();

    element = $("#Div1");
    if (element != null)
        element.show();

    setPanelBodyText("panelLinkToGBAcctsContent");
    closingCallBack = logOffFacebook;

    navBackForm = showFBLinkedToAnotherUserForm;
}
function showLinkToCurrentGiveBackAccountForm() {
    var element;
    currentPanel = 1;
    element = $("#panelFBLinkedToAnotherUser");
    if (element != null)
        element.hide();
    element = $("#panelLinkToGBAccts");
    if (element != null)
        element.hide();
    element = $("#panelLinkToGBOrNewFBAcct");
    if (element != null)
        element.hide();
    element = $("#panelLinkToCurrentGBAccount");
    if (element != null)
        element.show();

    element = $("#Div1");
    if (element != null)
        element.show();

    setPanelBodyText("panelLinkToCurrentGBAccountContent");
    closingCallBack = logOffFacebook;

    navBackForm = showLinkToGiveBackAccountsForm;
}

function showForgotPasswordForm() {
    var element;
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#panelForgotPassword");
    if (element != null)
        element.show();

}
function showPasswordConfirmForm() {
    var element;
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#Div1");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.hide("fast");
    element = $("#panelForgotPassword");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.show();
}
function showThankYouForm() {
    var element;
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.hide("fast");
    element = $("#panelForgotPassword");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();

    element = $("#PanelRegistrationThankYou");
    if (element != null) {
        element.show();
        showAdditionalPostRegisterContent();
         $("textarea", "#PanelRegistrationThankYou").focus()
    }
}

function showForgotConfirmation() {
    var element;
    element = $("#panelForgotPassword");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelForgotConfirm");
    if (element != null)
        element.show();
}
function hideForgotPasswordForm() {
    var element;
    element = $("#panelForgotPassword");
    if (element != null)
        element.hide();
    element = $("#panelForgotConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#panelLogin");
    if (element != null)
        element.show();
}

function ShowTermsOfService() {
    var element;
    element = $("#panelLogin");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelRegister");
    if (element != null)
        element.hide();
    element = $("#PanelTermsOfService");
    if (element != null)
        element.show();
}

function HideTermsOfService() {
    var element;
    element = $("#PanelTermsOfService");
    if (element != null)
        element.hide();
    if (currentPanel == 1) {
        element = $("#panelRegister");
        if (element != null)
            element.hide();
        element = $("#panelFBLinkIntro");
        if (element != null)
            element.hide();
        element = $("#panelRegisterConfirm");
        if (element != null)
            element.hide();
        element = $("#panelLogin");
        if (element != null)
            element.show();
    }
    else {
        element = $("#panelLogin");
        if (element != null)
            element.hide();
        element = $("#panelRegisterConfirm");
        if (element != null)
            element.hide();
        element = $("#panelRegister");
        if (element != null)
            element.show();
    }
}
function hideLoadingReg() {
    var element;
    element = $("#register-loading-panel");
    if (element != null)
        element.hide();    
}
function setInitialLoginState() {
    var element;
    currentPanel = 1;
    element = $("#PanelTermsOfService");
    if (element != null)
        element.hide();
    element = $("#panelRegisterConfirm");
    if (element != null)
        element.hide();
    element = $("#panelFBLinkIntro");
    if (element != null)
        element.hide();
    element = $("#panelLogin");
    if (element != null)
        element.show();

    element = $("#panelRegister");
    if (element != null)
        element.hide();

}

function showCaptuaPanel() {
    showPasswordConfirmForm();
}

function showThankYouPanel() {
    showThankYouForm();
}

var closingCallBack = null;
function closeLoginRegisterBox() {
    // tell the server to flush out form data
    raiseAsyncBtnClickCloseWindow();
    // hide window
    zBox_GetVisibleBox().Hide();

    if (closingCallBack) {
        closingCallBack();

        closingCallBack = null;
    }
    else
        window.location = window.location;
}

function showPrivacyPolicy() {
    if (typeof $ != 'undefined') {        
        zBox_GetBox('boxPrivacyPolicy').Show();
       
    }
}

function setPrivaciyPolicyHtml(html) {
    // preserve policy content
    if (html.indexOf("Error #") == -1)
        privacyPolicyContent = html;
    else
        privacyPolicyContent = "";

    var element = $("#privatePolicyText");
    if (element != null) {
        if (privacyPolicyContent.length > 0)
            element.html(privacyPolicyContent);
        else
            element.html("Unable to retrieve Privacy Policy Contents");
    }
}

function closePrivacyPolicy() {
    var element;
    element = $("#boxPrivacyPolicy");
    if (element != null)
        element.hide();
    zBox_GetBox('loginBox').Show();
}

// Begin: Display additional post registration content
function showAdditionalPostRegisterContent() {
    if (typeof $ != 'undefined') {
        ajaxSyncCall(ajax_contentUrl, "ContentID=14", setAdditionalPostRegisterContent);
    }
}
function setAdditionalPostRegisterContent(html) {
    if (html.indexOf("Error #") == -1) {
        var element = $("#additionalPostRegisterContent");
        if (element != null) {
            element.html(html);
        }
    }
}
// End: Display additional post registration content
