/*
 * Copyright  : rexx systems GmbH, 20097 Hamburg, Heidenkampsweg 101
 *              Veraenderung oder Nutzung der Scripte/Anwendung ist nur mit
 *              schriftlicher Genehmigung der rexx systems GmbH gestattet.
 *
 * Datei      : js/user.func.js
 *
 *              - Javascript, das im Login-Bereich verwendet wird
 *              - f-Aür die Anzeige des PW-vergessen Layers-M
 *              
 * $Id: user.func.js,v 1.11 2011-11-29 07:35:34 lutz Exp $
 */

shopUser = (function() {

     var ajaxHandler = 'inc/functions/xml_http_requests.php';

    return {

        /*
         * Intialisierung von Event-Handlern, etc.
         * wird am Ende dieser Datei per $(document).ready() aufgerufen
         */
        init: function() {
            ajaxHandler = basicJs.addSid(ajaxHandler);
        },
        
        showAccountoverview: function() {
            $.ajax({
                type: "GET",
                url:  "../inc/functions/xml_http_requests.php",
                data: {
                    f:   "get_accountoverview_html",
                    sid: mySession
                },
                success: function(phpData) {	
                    $("#userright").html(phpData);
                }
            });
        },

        showAccountdata: function() {
            $.ajax({
                type: "GET",
                url:  "../inc/functions/xml_http_requests.php",
                data: {
                    f:    "get_userdata_html",
                    sid:  mySession
                },
                success: function(phpData) {	
                    $("#userright").html(phpData);
                }
            });
        },

        displayPasswordRequest: function()  {
            $.ajax({
                type: "GET",
                url: "../inc/functions/xml_http_requests.php",
                data: {
                    f   : 'get_password_request_layer',
                    sid : mySession
                },

                success: function(response) {
                    shopUser.showLayer(response);
                }
            });
        },

        showLayer: function(content) {
            j$('.jqmWindow').jqmShow();
            $('.jqmWindowContent').html('<div>'+content+'</div>');
            shopUser.initPasswordRequestLayer();
        },

        /* Layer fuer Passwort-Anforderung ausblenden */
        hidePasswordRequest: function() {
            $('#passwordRequestMsg').html("");
            $('#passwordRequestMsg').hide();
            $('input[name=pw-email]')[0].value = "";
            j$('.jqmWindow').jqmHide();
        },

        /* Passwort-Anforderung pruefen, ggf. Mail versenden und Meldung ausgeben */
        sendPasswordRequest : function() {
            var email = $('input[name=pw-email]')[0].value;
            email = $.trim(email);
            if (email != '') {
                $('input[name=pw-submit]').hide();
                $('input[name=pw-cancel]').hide();
                $('#pw-sending').show();
                $.ajax({
                    type: "GET",
                    url:  "../inc/functions/xml_http_requests.php",
                    dataType: "json",
                    data: {
                        f:   "send_password_request",
                        p0:  email,
                        sid: mySession
                    },
                    success: function(phpData) {
                        if (phpData.result == "success") {
                            $('#passwordRequestMsg').attr("style", "color:green; font-weight:bold;");
                            $('#passwordRequestMsg').html(phpData.msg + "<br />" + email);
                            $('#passwordRequestLabel').hide();
                            $('#passwordRequestMsg').show();
                            $('#passwordRequestForm').hide();
                            $('#pw-sending').hide();
                        } else {
                            $('#passwordRequestMsg').attr("style", "color:red; font-weight:bold;");
                            $('#passwordRequestLabel').hide();
                            $('#passwordRequestMsg').show();
                            $('#passwordRequestMsg').html(phpData.msg + "<br />");
                            $('input[name=pw-submit]').show();
                            $('input[name=pw-cancel]').show();
                            $('#pw-sending').hide();
                        }
                    }
                });
            }
        },

            
        /* Passwort-Anforderung initialisieren */
        initPasswordRequestLayer: function() {
            // Click-Handler fuer die Buttons im PasswordRequest-Layer
            $('input[name=pw-submit]').click(shopUser.sendPasswordRequest);
            $('input[name=pw-cancel]').click(shopUser.hidePasswordRequest);
            this.initPasswordRequestLayerButtons();
        },

        /* Button-Anzeige zuruecksetzen */
        initPasswordRequestLayerButtons: function() {
            $('#passwordRequestForm').show();
            $('input[name=pw-submit]').show();
            $('input[name=pw-cancel]').show();
            $('#rexxJqmClose').click( function (){ j$('.jqmWindow').jqmHide(); } );
        },

        /**
         * bei Klick auf einen Logout-Link
         */
        logout: function() {
            $.get(ajaxHandler, { f: 'logout_user' }, function() {
                 window.location = basicJs.addSid('/');
            });
        }
    };
})();

/*
 * Initialisierung, wenn Dokument geladen
 */
$(document).ready(function(){  
    shopUser.init();
});

