﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("TraderMagazine");
TraderMagazine.Menu = function() {
    TraderMagazine.Menu.initializeBase(this);
    this.Page = "MenuHome";
}
TraderMagazine.Menu.prototype = {
    initialize: function() {
        TraderMagazine.Menu.callBaseMethod(this, 'initialize');
        for (var i in Text.head_menu.item) {
            var id = Text.head_menu.item[i].id;
            // $addHandler($get(id), "click", this.getMainMenuPage);
            if (id == "HeadMediaData")
                $addHandler($get(id), "click", this.showMediaData);
            else
                $addHandler($get(id), "click", this.getHeadMenuPage);
        }


        for (var i in Text.main_menu.item) {
            var id = Text.main_menu.item[i].id;
            $addHandler($get(id), "click", this.getMainMenuPage);
            if (id != "MenuHome") {
                $addHandler($get(id), "mouseover", this.menuOver);
                $addHandler($get(id), "mouseout", this.menuOut);
            }
        }


        this.productIds = ["investor_0", "investor_6", "investor_12", "p4", "p5", "p6", "p7", "free_issue", "single_issue", "new_subscriber", "re_subscriber", "toolbox_basic", "toolbox_advanced", "toolbox_pro", "mini_subscription", "subscription_6", "toolbox_upgrade"];
    },
    //
    showMediaData: function() {
        var dats = "Content/MediaData/Mediadaten_" + Language + "_2010_Print.pdf";
        var newWindow = window.open(dats, "newWindow", "");

    },
    /// <summary>
    /// initialize head menu functions
    /// </summary>
    hideLangMenuPanel: function() {
        $get("LangMenuPanel").style.visibility = "hidden";
        $get("form1").onclick = null;
    },
    /// <summary>
    /// initialize head menu functions
    /// </summary>
    getHeadMenuPage: function(e) {
        var newId = this.id;

        if (GLOBALS.username != "" && newId == "HeadLogin") {
            MENU.logout();
        } else if (newId == "HeadLanguage") {
            if ($get("LangMenuPanel").style.visibility == "hidden") {
                $get("form1").onclick = null;
                var coords = Sys.UI.DomElement.getBounds($get("HeadLanguage"));
                $get("LangMenuPanel").style.visibility = "visible";
                $get("LangMenuPanel").style.left = (coords.x + coords.width - 160) + "px";
                $get("LangMenuPanel").style.top = (coords.y + 15) + "px";
                window.setTimeout(' $get("form1").onclick = function() { $get("LangMenuPanel").style.visibility = "hidden"; }', 100);
            } else {
                MENU.hideLangMenuPanel();
            }
        } else {
            Sys.Application.addHistoryPoint({ h: newId }, "TRADERS´ // Ihr persönlicher Tradingcoach");

        }
    },
    /// <summary>
    /// mouseover menu 
    /// </summary>
    menuOver: function(e) {

        $get(this.id).className = "main_menu_btn_over";
    },
    /// <summary>
    /// mouseover menu 
    /// </summary>
    menuOut: function(e) {
        if (MENU.Page != this.id) $get(this.id).className = "main_menu_btn";
    },
    /// <summary>
    ///  initialize main menu functions
    /// </summary>
    getMainMenuPage: function(e) {
        MENU.hideLangMenuPanel();
        var newId = this.id;
        if (newId.split("_")[0] == "Teaser") newId = newId.split("_")[1];
        Sys.Application.addHistoryPoint({ h: newId }, "TRADERS´ // Ihr persönlicher Tradingcoach");

    },
    /// <summary>
    /// logout function
    /// </summary>
    logout: function() {
        Sys.Services.AuthenticationService.logout("#h=MenuHome", MENU.logoutConfirm, GLOBALS.callError, "logout");
    },
    /// <summary>
    /// init function
    /// </summary>
    logoutConfirm: function(t) {
     	//location.href = "http://traders-mag.com/Default.aspx/#h=MenuHome";
	location.reload();



    },
    /// <summary>
    /// return to start page
    /// </summary>
    defaultPage: function() {
        $get("Content").innerHTML = "";
    },
    /// <summary>
    /// return to start page
    /// </summary>
    reloadPage: function() {
        /*
        var https = location.href.replace("http", "https");
        https = https.replace("httpss", "https");

        //window.location.href = https;
        window.location.href = location.href;


        MENU.getThisMenuPage("MenuHome");
        GLOBALS.setUser(user_name);
        */
    },
    /// <summary>
    /// reset PAGE pbject and reset content
    /// </summary>
    resetPage: function() {
        if (PAGE != null) {
            PAGE.dispose();
            PAGE = null;
        }
        $get("Content").innerHTML = "";
        COMP.createLoader($get("Content"), 400);
    },
    /// <summary>
    /// return to start page
    /// </summary>
    manageBrowserHistory: function(newId) {
        Sys.Debug.trace("manageBrowserHistory" + newId);


        var lastId = MENU.Page;
        MENU.Page = newId;
        if (lastId.substring(0, 4) == "Menu" && lastId != "MenuHome") $get(lastId).className = "main_menu_btn";
        if (newId.substring(0, 4) == "Menu" && newId != "MenuHome") $get(newId).className = "main_menu_btn_over";


        switch (MENU.Page) {
            case "HeadAbout":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.AboutUs, { id: "PAGE" }, null, null, null);
                break;
            case "HeadImpressum":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Imprint, { id: "PAGE" }, null, null, null);
                break;
            case "HeadContact":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Contact, { id: "PAGE" }, null, null, null);
                break;
            case "HeadRegister":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Register, { id: "PAGE" }, null, null, null);
                break;
            case "HeadLogin":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.UserManager, { id: "PAGE" }, null, null, null);
                break;
            case "MenuHome":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Home, { id: "PAGE" }, null, null, null);
                break;
            case "MenuMagazin":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Magazine, { id: "PAGE" }, null, null, null);
                break;
            case "MenuArchiv":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Archive, { id: "PAGE" }, null, null, null);
                break;
            case "MenuBlog":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Blog, { id: "PAGE" }, null, null, null);
                break;
            case "MenuProducts":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Products, { id: "PAGE" }, null, null, null);
                break;
            case "MenuForum":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Forum, { id: "PAGE" }, null, null, null);
                break;
            case "MenuSeminars":
                MENU.resetPage();
                PAGE = $create(TraderMagazine.Seminar, { id: "PAGE" }, null, null, null);
                break;

            case "payment_form":
                TradersMag.ShopService.ShopService.CreateProductPaymentForm(PURCHASE.Order.ProductCategory, PURCHASE.insertPaymentForm, GLOBALS.callError);
                break;

            case "confirm_payment":
                TradersMag.ShopService.ShopService.CreateProductPaymentForm(PURCHASE.Order.ProductCategory, PURCHASE.insertPaymentForm, GLOBALS.callError);
                break;
            case "init_page":
                PAGE.init();
                break;


        }
        if (Array.contains(MENU.productIds, MENU.Page))
            TradersMag.ShopService.ShopService.CreateProductDetailsPage(MENU.Page, PURCHASE.Order.ProductCategory, PURCHASE.insertDetails, GLOBALS.callError);
        if (pageTracker)
            pageTracker._trackPageview("User:  " + GLOBALS.username + " Page: " + MENU.Page);
    },
    /// <summary>
    ///  link to specifiv page
    /// </summary>
    getThisMenuPage: function(id) {

        var newId = id;
        if (newId.split("_")[0] == "Teaser") newId = newId.split("_")[1];
        var lastId = MENU.Page;
        MENU.Page = newId;


        Sys.Application.addHistoryPoint({ h: newId }, "TRADERS´ // Ihr persönlicher Tradingcoach");

        // MENU.manageBrowserHistory(newId);


    },
    /// <summary>
    ///  link to specifiv page
    /// </summary>
    gotoPage: function(id) {
        Sys.Debug.trace("getThisMenuPage" + newId);
        Sys.Application.addHistoryPoint({ h: id }, "TRADERS´ // Ihr persönlicher Tradingcoach");

        //  MENU.manageBrowserHistory(id);
    },
    /// <summary>
    /// dispose unused js classes 
    /// </summary>
    disposeClasses: function() {
        // BLOG.dispose();
    },
    dispose: function() {
        //Add custom dispose actions here
        TraderMagazine.Menu.callBaseMethod(this, 'dispose');
    }
}
TraderMagazine.Menu.registerClass('TraderMagazine.Menu', Sys.Component);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
