﻿

var CartegieBodacc1 = {

    Profile: {

        ShowSignInPanel: function() {
            document.getElementById("layer_cn").style.display = "";
        },

        HideSignInPanel: function() {
            document.getElementById("layer_cn").style.display = "none";
        },

        DoSignIn: function() {
            Profile.Login(document.getElementById("connexion_email").value, document.getElementById("connexion_pwd").value, CartegieBodacc1.Profile.OnSuccess, CartegieBodacc1.Profile.OnFailed);
        },

        DoSignOut: function() {
            Profile.Logout(CartegieBodacc1.Profile.OnSuccessLogout, CartegieBodacc1.Profile.OnFailed);
        },

        ShowLostPwd: function() {
            document.getElementById("layer_lostpwd").style.display = "";
        },

        HideLostPwd: function() {
            document.getElementById("layer_lostpwd").style.display = "none";
        },

        /* EDIT ACCOUNT */

        EditValue: function(labeldiv, editdiv, textbox) {
            document.getElementById(editdiv).style.display = "";
            document.getElementById(labeldiv).style.display = "none";
            document.getElementById(textbox).value = document.getElementById(labeldiv).innerHTML;
        },

        SaveValue: function(labeldiv, editdiv, textbox, param) {
            document.getElementById(editdiv).style.display = "none";
            document.getElementById(labeldiv).style.display = "";
            document.getElementById(labeldiv).innerHTML = document.getElementById(textbox).value;
            //alert(param);
            Profile.SetValue(param, document.getElementById(textbox).value, CartegieBodacc1.Profile.OnSuccessAction, CartegieBodacc1.Profile.OnFailed);
        },

        /* CALLBACKS EVENTS */

        OnSuccessLogout: function(result) {
            if (result == "True") {
                window.location = "../";
            } else { }
        },

        OnSuccess: function(result) {
            if (result == "False") {
                alert("Impossible de se connecter avec ces paramètres");
            } else {
                window.location = result;
            }
        },

        OnSuccessAction: function(result) {
            // void
        },

        OnFailed: function(e) {
            alert("Erreur" + e);
        }
    },

    Details: {

        ToggleEventItem: function(v, s, i1, i2) {
            if (document.getElementById(v).style.display == "") {
                document.getElementById(v).style.display = "none";
                document.getElementById(s).innerHTML = "Ouvrir";
                document.getElementById(i1).src = "../library/img/toggle_light_south.gif";
                document.getElementById(i2).src = "../library/img/toggle_dark_east.gif";
            } else {
                document.getElementById(v).style.display = "";
                document.getElementById(s).innerHTML = "Fermer";
                document.getElementById(i1).src = "../library/img/toggle_light_north.gif";
                document.getElementById(i2).src = "../library/img/toggle_dark_south.gif";
            }
        },

        Veille: function() {
            window.open("./Details.Alert?alerteid=" + _CurrentDetails_Guid + "&alertesiret=" + _CurrentDetails_Siret, "veille", "height=200, width=350");
        },

        PrintPage: function() {
            if (navigator.appName == 'Microsoft Internet Explorer') {
                printHidden("./Details.Print?g=" + _CurrentDetails_Guid);
            } else {
                document.getElementById("hiddenframe").src = "./Details.Print?g=" + _CurrentDetails_Guid + "&m=mz";
            }
            //window.print();
        },

        CreatePdf: function() {
            window.open("./Details.Pdf?" + _CurrentDetails_Guid, "pdf", "height=100, width=100");
        },

        ShowSendByMail: function() {
            //window.open("./library/popup/SendByMail?uri=" + window.location, "sendmail", "height=350, width=400");
            document.getElementById("pop_sendbymail").src = "./library/popup/SendByMail?uri=" + window.location;
            document.getElementById("layer_sendto").style.display = "";

        },

        HideSendByMail: function() {
            document.getElementById("layer_sendto").style.display = "none";
        }

    },

    Search: {

        Validate: function() {
            alert("ok");
        },

        Start: function() {
            void (0);
        },

        Advanced: function() {

            if (window.location.toString().indexOf("?") > 0) {
                if (window.location.toString().indexOf("_ADV") <= 0)
                    window.location = window.location + "&_ADV";
            } else {
                window.location = window.location + "?_ADV";
            }

        },

        Normal: function() {

            window.location = window.location.toString().replace("&_ADV", "").replace("?_ADV", "");

        }

    }
}