/*
 * 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.9 2010-01-29 10:35:30 dnemetz Exp $
 */

shopUser = (function() {
    return {

        /*
         * Intialisierung von Event-Handlern, etc.
         * wird am Ende dieser Datei per $(document).ready() aufgerufen
         */
        init: function() {
            this.initPasswordRequestLayer();
        },

        
	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);
                }
    	    });
        },

        /* Layer fuer Passwort-Anforderung anzeigen */
        displayPasswordRequest: function() {
            var div = $('#passwordRequestLayer');
            this.initPasswordRequestLayerButtons();
            $('#passwordRequestLabel').show();
            div.css('top', $(window).scrollTop() + 190);
            div.show('fast');
            $('#navigation-top ul ul').css('display', 'none');
            window.setTimeout(
                function() {
                	$('#navigation-top ul ul').css('display', '');
                },
                500
            );
        },

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

        /* 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();
                           $('input[name=pw-close]').show();
                           $('#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 f-Aür die Buttons im PasswordRequest-Layer-M
            $('input[name=pw-submit]').click(shopUser.sendPasswordRequest);
            $('input[name=pw-cancel]').click(shopUser.hidePasswordRequest);
            $('input[name=pw-close]').click(shopUser.hidePasswordRequest);
            this.initPasswordRequestLayerButtons();
        },

        /* Button-Anzeige zuruecksetzen */
        initPasswordRequestLayerButtons: function() {
			$('#passwordRequestForm').show();
            $('input[name=pw-submit]').show();
            $('input[name=pw-cancel]').show();
            $('input[name=pw-close]').hide();
        }
    }
})();

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