﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("TraderMagazine");
TraderMagazine.Home = function() {
    TraderMagazine.Home.initializeBase(this);
}
TraderMagazine.Home.prototype = {
    initialize: function() {
    TraderMagazine.Home.callBaseMethod(this, 'initialize');
    this.init();
    },
    /// <summary>
    /// insert home content
    /// </summary>
    initHandler: function() {
        //  $addHandler($get("Teaser_MenuBlog"), "click", MENU.getMainMenuPage);
        if ($get("BuyIssueTable")) {
            PAGE.initBuyEMagazine();
        }
    },
    /// <summary>
    /// get home page
    /// </summary>
    init: function() {
        TradersMag.WebService.PageService.CreateDefaultPage(this.insertHomeContent, GLOBALS.callError);
    },
    /// <summary>
    /// insert home content
    /// </summary>
    insertHomeContent: function(html) {

        $get("Content").innerHTML = html;
        PAGE.initHandler();

    },
    /// <summary>
    /// insert home content
    /// </summary>
    initBuyEMagazine: function(html) {


        /*
        $get("DelFieldsBtn").onclick = function() {
        $get("BuyIssueName").value = "";
        $get("BuyIssueEmail").value = "";
        }
        */
        $get("BuyIssueBtn").onclick = function() {

            ERROR.hideError("BuyIssueNameError");
            ERROR.hideError("BuyIssueEmailError");
            var buyIssueName = $get("BuyIssueName").value;
            var buyIssueEmail = $get("BuyIssueEmail").value;

            var success = true;
            if (!ERROR.checkField(buyIssueName, "BuyIssueNameError", "multiline", 3, Text.errors.e17)) success = false;
            if (!ERROR.checkEMail(buyIssueEmail)) {
                ERROR.showError("BuyIssueEmailError", Text.errors.e19);
                success = false;
            }

            if (success) {
                $get("BuyIssueBtn").onclick = null;
                COMP.createLoaderWhite($get("OrderEMag_2_0"), 150);
                TradersMag.WebService.PageService.SendMail(buyIssueEmail, buyIssueName, PAGE.emailSended, GLOBALS.callError);


            }

        }
    },


    /// <summary>
    // editor function : edit text
    /// </summary>
    emailSended: function(result) {

        if (result) {
            $get("OrderEMag_2_0").innerHTML = "<div style='padding:10px;margin:10px;'>" + Text.magazine.confirmation + "</div>";

        } else {
            $get("OrderEMag_2_0").innerHTML = "<div style='padding:10px;margin:10px;'>" + Text.errors.e35 + "</div>";
        }
    },


    /// <summary>
    /// insert home content
    /// </summary>
    insertCoverStory: function(html) {
        MENU.Page = "-1";

        $get("Content").innerHTML = html;
    },
    dispose: function() {
        //Add custom dispose actions here
        TraderMagazine.Home.callBaseMethod(this, 'dispose');
    }
}
TraderMagazine.Home.registerClass('TraderMagazine.Home', Sys.Component);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
