﻿namespace('nnet');

nnet.User = $j.klass({
    initialize: function(config) {
        try {
            
            this.LoggedIn = false;
            this.ShoppingCart = null;
            this.ID = null;
            if (config != undefined && config.id) this.ID = config.id;
            else this.ShoppingCart = new nnet.fin.ShoppingCart(); // Site user as no id.
            onLogOut.subscribe(function(type, args) { NNet.CurrentUser.LoggedIn = false; });
            onLogIn.subscribe(function(type, args) { NNet.CurrentUser.LoggedIn = true; });
        } catch (e) { logE("nnet.User.initialize", e); }
    },

    // Show current User Profile, allow editing
    show: function() {
        try {
            var win = new nnet.PopUpWindow({ url: "/Security/Profile" + (this.ID != null ? "/" + this.ID : ""), minWidth: 400 });
            win.show();
        } catch (e) { logE("nnet.User.show", e); }
    },

    signUp: function() {
        try {
            var win = new nnet.PopUpWindow({ url: '/Security/Profile?F=Insert', onClose: this.signUPCloseWindowHandler, minWidth: 400 });
            win.show();
        } catch (e) { logE("nnet.User.show", e); }
    },

    signUPCloseWindowHandler: function() {
        SecCallback.TidyUpOnCloseProfileWizard();
    },

    // Show current User Profile, allow editing
    showRegConfirm: function() {
        try {
            if (this.ID != null) new nnet.PopUpWindow({ url: "/Security/Confirm/" + this.ID, minWidth: 400 }).show();
            else alert("User could not be found");
        } catch (e) { logE("nnet.User.showRegConfirm", e); }
    },

    showSiteSignUp: function() {
        try {
            new nnet.PopUpWindow({ url: '/Security/Profile?F=Add', minWidth: 400 }).show();
        } catch (e) { logE("nnet.User.showSiteSignUp", e); }
    },

    passwordReset: function() {
        try {
            new nnet.PopUpWindow({ url: '/Security/PasswordRecovery', minWidth: 400 }).show();
        } catch (e) { logE("nnet.User.passwordReset", e); }
    },

    resetPassword: function() {
        try {
            if (this.ID != null) new nnet.PopUpWindow({ url: "/Security/PasswordReset/" + this.ID, minWidth: 350 }).show();
            else alert("User could not be found");
        } catch (e) { logE("nnet.User.resetPassword", e); }
    }


});





