public static bool event_catched_and_performed(xAjax ajax, Global global)
    {
        bool bRetVal = true;

        string sProcedure = ajax.getProcedure();

        // ajax.WriteVariable("menu_2_click", sProcedure);


        if (sProcedure == "level_2_report_show_all_shops()")
        {
            ajax.WriteHtml("work_page", CHAIN_REPORT.getAllShopsReport(global));
        }
        else if (sProcedure == "level_1_report()")
        {
            // MENY 2 A
            StringBuilder sb = new StringBuilder();

            sb.Append(global.chain_level_2_2(global));

            ajax.WriteHtml("menu_2", sb.ToString());
            ajax.WriteHtml("work_page", "");
        }
        else if (sProcedure == "level_1_analyze()")
        {
            // MENY 2 A
            StringBuilder sb = new StringBuilder();

            sb.Append(global.chain_level_2_4());

            ajax.WriteHtml("menu_2", sb.ToString());
            ajax.WriteHtml("work_page", "");
        }

        else if (sProcedure == "level_2_report_2()")
        {
            StringBuilder sb = new StringBuilder();

            ChainStandardReport csr = new ChainStandardReport(global, 24);

            DateTime startDate = new DateTime(2015, 7, 1);
            DateTime endDate = new DateTime(2015, 8, 30);

            sb.Append("<div style='padding:10px;overflow:hidden;clear:both;'>");
            sb.Append(csr.A_StandardReport("A Antall medlemmer", global, startDate, endDate));
            sb.Append("</div>");

            sb.Append("<div style='padding:10px;overflow:hidden;clear:both;'>");
            sb.Append(csr.getReport_B_basket_sums("B Beløp Sum", (int)DateTime.Now.Year, startDate, endDate, STANDARD_REPORT_TYPE.B_BASKET_SUM));
            sb.Append("</div>");



            sb.Append("<div style='padding:10px;overflow:hidden;clear:both;'>");
            sb.Append(csr.getReport_B_basket_sums("C Beløp Snitt", (int)DateTime.Now.Year, startDate, endDate, STANDARD_REPORT_TYPE.C_BASKET_AVERAGE));
            sb.Append("</div>");

            sb.Append("<div style='padding:10px;overflow:hidden;clear:both;'>");
            sb.Append(csr.getReport_B_basket_sums("D Antall bonger", (int)DateTime.Now.Year, startDate, endDate, STANDARD_REPORT_TYPE.D_BASKET_COUNT));
            sb.Append("</div>");

            ajax.WriteHtml("work_page", sb.ToString());
        }

        else if (sProcedure == "level_2_report_3()")
        {
            StringBuilder sb = new StringBuilder();
            /*
            sb.Append("<table>");
            for (int i = 1; i <= 12; ++i)
            {
                if (iCol == 1 || iCol == 5 || iCol == 9)
                {
                    if (iCol == 1) sb.Append("<tr>"); else { sb.Append("</tr>"); sb.Append("<tr>"); }
                    sb.Append("<tr>");
                }
                sb.Append("<td><div id=" + CHAIN_DASHBOARD_ITEM.getContainerId(i.ToString()) + " style='float:left;' >");
                sb.Append(CHAIN_DASHBOARD_ITEM.A_get_minimized_dialog(i.ToString()));
                sb.Append("</div></td>");
                ++iCol;           
            }
            sb.Append("</tr>");
            sb.Append("</table>");
            */
            string sTitle = "";

            sb.Append("<div id=google_chart_sample_01 style='border:2px rgb(200,200,200) solid';width:100%;border-radius:6px;height:115px;background-color:rgb(255,200,200);margin-top:5px;overflow:hidden;'>Sample chart</div>");
            sb.Append("<div id=google_chart_sample_02 style='border:2px rgb(200,200,200) solid';width:100%;height:115px;background-color:rgb(255,200,200);margin-top:5px;overflow:hidden;'>Sample chart</div>");
            sb.Append("<div id=google_chart_sample_03 style='width:100%;height:115px;background-color:rgb(255,200,200);margin-top:5px;overflow:hidden;'>Sample chart</div>");
            
            for (int i = 0; i <= 8; ++i)
            {
                StringBuilder s = new StringBuilder();

                if (i == 0) sTitle = "Medlemsutvikling";
                else if (i == 1) sTitle = "Medlemskonvertering";
                else if (i == 2) sTitle = "Dasboard 3";
                else if (i == 3) sTitle = "Dasboard 4";
                else if (i == 4) sTitle = "Dasboard 5";
                else if (i == 5) sTitle = "Dasboard 6";
                else if (i == 6) sTitle = "Dasboard 7";
                else if (i == 7) sTitle = "Dasboard 8";
                else if (i == 8) sTitle = "Dasboard 9";

                string sMaximized = " data-maximized='false' ";

                s.Append("<div style='font-family:arial;font-size:14px;color:rgb(150,150,150);margin-top:5px;margin-bottom:5px;'>" + sTitle + "</div>");
                s.Append("<div style='width:100%;background-color:rgb(170,170,170);height:2px;'>&nbsp;</div>");
                s.Append("<div id=chart_div_" + i.ToString() + sMaximized + " style='width:100%;height:115px;background-color:rgb(255,255,255);margin-top:5px;'>&nbsp;</div>");

                if (i == 3 || i == 6)
                {
                    sb.Append(HTML_TOOLBOX.newline());                    
                }
                // sb.Append(CHAIN_DASHBOARD_ITEM.A_get_minimized_dialog("show_google_chart('" + i.ToString() + "')","<div>" + s.ToString() + "</div>"));
                
                sb.Append(CHAIN_DASHBOARD_ITEM.A_get_minimized_dialog("outer_chart_id_" + i.ToString(),"chain_get_dashboard_data('" + i.ToString() + "',false)", "<div>" + s.ToString() + "</div>"));

                // sb.Append(CHAIN_DASHBOARD_ITEM.A_get_minimized_dialog("outer_chart_id_" + i.ToString(), "chain_get_dashboard_data('" + i.ToString() + "',false)", "<div>" + s.ToString() + "</div>"));

            }
            
            // 9 sept

            ajax.WriteHtml("work_page", sb.ToString());
        }

        else if (sProcedure == "chain_get_dashboard_data()")
        {
            int iIndex = ajax.getInt("parameter_1");
            bool bMaximized = ajax.getBool("parameter_2");

            ajax.WriteVariable("dashboard_index", iIndex.ToString());
            ajax.WriteVariable("maximized", bMaximized.ToString());

            if (iIndex == 0)
            {
                if (bMaximized == false)
                {
                    List<backoffice.dim_value> monthList = global.www_backoffice().dash_mini_month_member_old(DateTime.Now.Year.ToString(),"24");
                    ajax.WriteVariable("json_chart_data", JSON_UTILITY.get_month_data(monthList));
                }
                else
                {
                    List<backoffice.dim_value> monthList = global.www_backoffice().dash_mini_month_member_old(DateTime.Now.Year.ToString(),"24");
                    ajax.WriteVariable("json_chart_data", JSON_UTILITY.get_month_data(monthList));
                }
            }
        }

        else if (sProcedure == "level_2_analyze_1()")
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Analyze 1");

            ajax.WriteHtml("work_page", sb.ToString());
        }
        else if (sProcedure == "level_2_analyze_2()")
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Analyze 2");

            ajax.WriteHtml("work_page", sb.ToString());
        }

        else if (sProcedure == "level_2_analyze_3()")
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Analyze 3");

            ajax.WriteHtml("work_page", sb.ToString());
        }

        else if (sProcedure == "level_2_analyze_4()")
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Analyze 4");

            ajax.WriteHtml("work_page", sb.ToString());
        }


        else if (sProcedure == "level_2_shop_report_show_chain_invoice()")
        {
            ajax.WriteHtml("work_page", CHAIN_REPORT.getChainInvoice(global));
        }
        else if (sProcedure == "level_1_campaign()")
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(global.chain_menu_2_3());

            ajax.WriteHtml("menu_2", sb.ToString());

            ajax.WriteHtml("work_page", "");
        }

        else if (sProcedure == "level_2_report_verifone_to_webservice()")
        {

            // List<backoffice.dim_dim_value> shop = global.www_backoffice().verifone_to_webservice(DateTime.Now);

            ajax.WriteHtml("work_page", "Not implemented");

            // 20 okt

            // ajax.WriteHtml("work_page", CHAIN_REPORT.getCampaign(global));
        }
        else if (sProcedure == "level_2_report_azure_deployment()")
        {

            // List<backoffice.dim_dim_value> shop = global.www_backoffice().verifone_to_webservice(DateTime.Now);

            StringBuilder sb = new StringBuilder();

            sb.Append("<br><a href='https://ws.bember.no/ecr/prosessor_vas.asmx'>Prod ECR</a>");
            sb.Append("<br><a href='http://test.ws.bember.no/ecr/prosessor_vas.asmx'>Test ECR</a><br>");
            sb.Append("<br><a href='https://ws.bember.no/frontend/frontend_webservice.asmx'>Prod Byte</a>");
            sb.Append("<br><a href='http://test.ws.bember.no/frontend/frontend_webservice.asmx'>Test Byte</a><br>");
            sb.Append("<br><a href='https://ws.bember.no/verifone/df_admin_webservice.asmx'>Prod Verifone</a>");
            sb.Append("<br><a href='http://test.ws.bember.no/verifone/df_admin_webservice.asmx'>Test Verifone</a>");

            ajax.WriteHtml("work_page", sb.ToString());

            // 20 okt

            // ajax.WriteHtml("work_page", CHAIN_REPORT.getCampaign(global));
        }

        
        else if (sProcedure == "shop_report_show_shop()")
        {
            string sShopId = ajax.getString("parameter_1");

            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            ajax.WriteHtml(CHAIN_REPORT.getContainerId(shop), CHAIN_REPORT.B_get_maximized_dialog(global, sShopId));
        }

        else if (sProcedure == "shop_report_close_shop()")
        {
            string sShopId = ajax.getString("parameter_1");
            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            ajax.WriteHtml(CHAIN_REPORT.getContainerId(shop), CHAIN_REPORT.A_get_minimized_dialog(shop));
        }

        else if (sProcedure == "shop_report_enrollment_click()")
        {
            string sShopId = ajax.getString("parameter_1");
            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);
            ajax.WriteHtml(CHAIN_REPORT.ENROLLMENT_REPORT.getContainerId(shop), CHAIN_REPORT.ENROLLMENT_REPORT.B_get_maximized_dialog(global, shop.iId.ToString()));
        }

        else if (sProcedure == "shop_report_enrollment_cancel()")
        {
            string sShopId = ajax.getString("parameter_1");

            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            string sEnrollmentContainerId = CHAIN_REPORT.ENROLLMENT_REPORT.getContainerId(shop);

            ajax.WriteHtml(
                sEnrollmentContainerId,
                CHAIN_REPORT.ENROLLMENT_REPORT.A_get_minimized_dialog(shop, false));
        }

        else if (sProcedure == "shop_report_enrollment_save()")
        {
            string sShopId = ajax.getString("parameter_1");
            bool bAcceptEnrollment = ajax.getBool("parameter_2");

            bool bOK = global.www_backoffice().update_shop_enrollment(sShopId, bAcceptEnrollment);

            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            string sEnrollmentContainerId = CHAIN_REPORT.ENROLLMENT_REPORT.getContainerId(shop);

            ajax.WriteHtml(
                sEnrollmentContainerId,
                CHAIN_REPORT.ENROLLMENT_REPORT.A_get_minimized_dialog(shop, false));
        }

        else if (sProcedure == "shop_report_merchant_id_click()")
        {
            string sShopId = ajax.getString("parameter_1");
            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            ajax.WriteHtml(CHAIN_REPORT.MERCHANT_REPORT.getContainerId(shop), CHAIN_REPORT.MERCHANT_REPORT.B_get_maximized_dialog(global, shop.iId.ToString()));
        }

        else if (sProcedure == "shop_report_merchant_id_save()")
        {
            string sShopId = ajax.getString("parameter_1");
            string sNewBax = ajax.getString("parameter_2");

            if (!CHAIN_REPORT.isBlank(sNewBax))
            {
                bool bOK = global.www_backoffice().update_shop_merchant_id(sShopId, sNewBax);
            }

            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            string sMerchantContainerId = CHAIN_REPORT.MERCHANT_REPORT.getContainerId(shop);

            ajax.WriteHtml(
                sMerchantContainerId,
                CHAIN_REPORT.MERCHANT_REPORT.A_get_minimized_dialog(shop, false));
        }

        else if (sProcedure == "level_2_report_4()")
        {
            int iDashboardPeriod = ajax.getInt("parameter_1");

            StringBuilder sb = new StringBuilder();

            DASHBOARD_NEW dbn = new DASHBOARD_NEW(global);

            DASHBOARD_PERIOD currentDashboardPeriod = DASHBOARD_PERIOD.THIS_MONTH;
            if (iDashboardPeriod == 1) currentDashboardPeriod = DASHBOARD_PERIOD.PREV_MONTH;
            else if (iDashboardPeriod == 2) currentDashboardPeriod = DASHBOARD_PERIOD.PREV_PREV_MONTH;

            List<backoffice.name_value_value_value_value> conversionList_6_months = global.www_backoffice().get_conversion_data(currentDashboardPeriod, "24", true); // 5 okt
            
            List<backoffice.name_value_value_value_value> conversionListCurrentPeriod = global.www_backoffice().get_conversion_data(currentDashboardPeriod, "24",false); // 5 okt

            List<backoffice.shop_top_bottom> shopConversionList = global.www_backoffice().get_conversion_data_in_shoplist(currentDashboardPeriod, "24");


            StringBuilder ss = new StringBuilder();


            sb.Append("<table style='width:100%;background-color:rgb(247,247,247);'>");
            sb.Append("<tr>");
            sb.Append("<td align=center>");
            sb.Append(dbn.get_BEMBER_CHAIN_Dashboard(currentDashboardPeriod, conversionListCurrentPeriod, shopConversionList)); 
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            List<backoffice.dim_value> monthList = global.www_backoffice().dash_maxi_month_member_old((int) DateTime.Now.Year,"24");

            ajax.WriteVariable("json_chart_global_info", JSON_UTILITY.get_chart_global_info("Dashboard for kjeden", 980, 800, dbn.cellList.Length));

            ajax.WriteVariable("json_two_dim_one_value", JSON_UTILITY.get_two_dim_one_value());

            for (int i = 0; i < dbn.cellList.Length; ++i)
            {
                // See also: Removed 19.oct.2015 to bind it together again ...
                if (dbn.cellList[i] != null)
                {
                    if (i == 1) // 3 lines 
                    {
                        ajax.WriteVariable("json_dim_and_values_" + i.ToString(), JSON_UTILITY.get_one_dim_three_values("Rekruttering","Godkjent avtale","Mobilnummer","Handler")); // 24 sept
                        ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_conversion_data_3_lines(conversionList_6_months)); // 24 sept
                        ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                    }
                    
                    else if (i == 3) // 4 lines 
                    {
                        
                        ajax.WriteVariable("json_dim_and_values_" + i.ToString(), JSON_UTILITY.get_one_dim_four_values("Rekruttering", "linje_1", "linje_2", "linje_3", "linje_4")); // 24 sept
                        ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_conversion_data_4_lines(conversionList_6_months)); // 24 sept
                        ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("4 lines", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                    }
                    else if (i == 4)
                    {
                        ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_month_data(monthList));
                        ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("Fin tittel", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                    }
                    else
                    {
                        ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_month_data(monthList));
                        ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("Fin tittel", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                    }
                    
                }
            }

            // ajax.WriteHtml("one_and_only_global_page", sb.ToString());
            

            ajax.WriteHtml("work_page",sb.ToString());
        }


        else if (sProcedure == "shop_report_merchant_id_cancel()")
        {
            string sShopId = ajax.getString("parameter_1");

            backoffice.admin_shop shop = global.www_backoffice().get_shop(sShopId);

            string sMerchantContainerId = CHAIN_REPORT.MERCHANT_REPORT.getContainerId(shop);

            ajax.WriteHtml(
                sMerchantContainerId,
                CHAIN_REPORT.MERCHANT_REPORT.A_get_minimized_dialog(shop, false));
            return true;
        }
        else
            bRetVal = false;

        return bRetVal;
    }
    public static void WRITE_DASHBOARD_TO_WORK_PAGE(int iDashboardPeriod, Global global, xAjax ajax)
    {

        StringBuilder sb = new StringBuilder();

        DASHBOARD_NEW dbn = new DASHBOARD_NEW(global);

        DASHBOARD_PERIOD currentDashboardPeriod = DASHBOARD_PERIOD.THIS_MONTH;
        if (iDashboardPeriod == 1) currentDashboardPeriod = DASHBOARD_PERIOD.PREV_MONTH;
        else if (iDashboardPeriod == 2) currentDashboardPeriod = DASHBOARD_PERIOD.PREV_PREV_MONTH;

        List<backoffice.name_value_value_value_value> conversionList_6_months = global.www_backoffice().get_conversion_data(currentDashboardPeriod, global.accessController.getChainID(), true); // 5 okt

        List<backoffice.name_value_value_value_value> conversionListCurrentPeriod = global.www_backoffice().get_conversion_data(currentDashboardPeriod, global.accessController.getChainID(), false); // 5 okt

        List<backoffice.shop_top_bottom> shopConversionList = global.www_backoffice().get_conversion_data_in_shoplist(currentDashboardPeriod, global.accessController.getChainID());

        StringBuilder ss = new StringBuilder();

        sb.Append(dbn.get_BEMBER_CHAIN_Dashboard(currentDashboardPeriod, conversionListCurrentPeriod, shopConversionList));

        List<backoffice.dim_value> monthList = global.www_backoffice().dash_maxi_month_member_old((int)DateTime.Now.Year, global.accessController.getChainID());

        ajax.WriteVariable("json_chart_global_info", JSON_UTILITY.get_chart_global_info("Dashboard for kjeden", 980, 800, dbn.cellList.Length));

        ajax.WriteVariable("json_two_dim_one_value", JSON_UTILITY.get_two_dim_one_value());

        for (int i = 0; i < dbn.cellList.Length; ++i)
        {
            // See also: Removed 19.oct.2015 to bind it together again ...
            if (dbn.cellList[i] != null)
            {
                if (i == 1) // 3 lines 
                {
                    ajax.WriteVariable("json_dim_and_values_" + i.ToString(), JSON_UTILITY.get_one_dim_three_values("Rekruttering", "Godkjent avtale", "Mobilnummer", "Handler")); // 24 sept
                    ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_conversion_data_3_lines(conversionList_6_months)); // 24 sept
                    ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                } else if (i == 3) // 4 lines 
                {
                    ajax.WriteVariable("json_dim_and_values_" + i.ToString(), JSON_UTILITY.get_one_dim_four_values("Rekruttering", "linje_1", "linje_2", "linje_3", "linje_4")); // 24 sept
                    ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_conversion_data_4_lines(conversionList_6_months)); // 24 sept
                    ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("4 lines", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                } else if (i == 4)
                {
                    ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_month_data(monthList));
                    ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("Fin tittel", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                } else
                {
                    ajax.WriteVariable("json_chart_data_" + i.ToString(), JSON_UTILITY.get_month_data(monthList));
                    ajax.WriteVariable("json_chart_graphic_" + i.ToString(), JSON_UTILITY.get_chart_graphic("Fin tittel", dbn.cellList[i].w, dbn.cellList[i].h, dbn.cellList[i].chartType, "X-Akse", "Y-Akse"));
                }
            }
        }

        ajax.WriteHtml("work_page", sb.ToString());

    }