/// Defines/Displays all the places where players can place bets.  This is essentially
 /// a x*y grid where x is the number of betting stages and y is the number of hands that can be bet on
 /// See also: f_displayControl_Bettinf_update_seat_panels_with_info_from_serverrid
 public void f_createControl_Bettinf_update_seat_panels_with_info_from_serverrid()
 {
     for (int stageindex = 0; stageindex < _int_number_of_betting_stages; stageindex++)
     {
         for (int handindex = 0; handindex < _xxxHCnumber_of_hands; handindex++)
         {
             _hedgeem_betting_panels[stageindex, handindex] = new BETTING_PANEL(f_get_player_id());
         }
     }
 }
    // this function update labels
    public void f_update_labels()
    {
        string best_odds_token = "";
        log.Debug("f_update_labels called");
        try
        {
            log.Info("Call f_update_seat_panels_with_info_from_servers in f_update_labels");
            //f_update_seat_panels_with_info_from_servers();
        }
        catch (Exception e)
        {
            string err_message = string.Format("Unable to update seat panels method f_update_labels \nReason {}", e.Message);
            ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", err_message, true);
            HedgeEmLogEvent my_log = new HedgeEmLogEvent();
            my_log.p_message = "Exception caught in f_update_labels function - Unable to update seat panels method in f_update_labels " + e.Message;
            my_log.p_method_name = "f_update_labels";
            my_log.p_player_id = f_get_player_id();
            my_log.p_game_id = game_id;
            my_log.p_table_id = _table_id;
            log.Error(my_log.ToString());
        }

        //For each betting stage and each hand
        for (enum_betting_stage stage_index = enum_betting_stage.HOLE_BETS; stage_index <= enum_betting_stage.TURN_BETS; stage_index++)
        {

            for (int hand_index = 0; hand_index < _xxxHCnumber_of_hands; hand_index++)
            {
                // xxx should really use Doubles here 
                _hedgeem_betting_panels[(int)stage_index, hand_index] = new BETTING_PANEL(f_get_player_id());
                _hedgeem_betting_panels[(int)stage_index, hand_index] = new BETTING_PANEL(f_get_player_id());
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_betting_stage = stage_index;
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_draw = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_percent_draw_string;
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_win_or_draw = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_percent_win_or_draw_string;
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_actual = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_actual_string;
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_margin = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_margin_double.ToString();
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_win = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_percent_win_string;
                if (_global_game_state_object.p_hand_stage_info_list[hand_index].p_is_recommended_hand_to_bet_on_for_best_value_odds == true)
                {
                    best_odds_token = " *";
                }
                else
                {
                    best_odds_token = "";
                }
                double offered_odds = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_margin_rounded_double;
                _hedgeem_betting_panels[(int)stage_index, hand_index].p_odd_margin_rounded = offered_odds;
                String prefix;
                if (offered_odds < 0)
                {
                    prefix = "1/";
                    offered_odds = offered_odds * -1;
                }
                else
                {
                    prefix = "";
                }
                if (offered_odds == 0)
                {

                }
                else
                {

                }
                //// #####################################
                //// Display the chips for each player seated at the table (where bets have been placed)
                for (int seat_index = 0; seat_index < f_get_player_id(); seat_index++)
                {
                    string chip_icon_resource_name = "chip_icon_seat_" + seat_index.ToString();
                    try
                    {
                        // if a bet has been place (i.e. recorded bets for stage, seat and hand combination is > 0)
                        // make the chip icon for the relevant seat visible and update the chip value to match the bet placed
                        //if (my_hedgeem_table._bets[(int)stage_index, seat_index, hand_index] > 0)
                        if (true)
                        {
                            // Update bet value on 'chip' and show it.  eg. set to 5 for $5 bet
                            string bet_value = _global_game_state_object._recorded_bets[seat_index].p_bet_amount.ToString();
                            double bet_value_double = _global_game_state_object._recorded_bets[hand_index].p_bet_amount;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_players_bets[seat_index] = bet_value_double;
                            Place_Holder_Betting_Panel.Controls.Add(_hedgeem_betting_panels[(int)stage_index, hand_index]);
                        }
                        else
                        {
                            /* ----------------Hide the chip as no bets placed------------------*/
                            //_hedgeem_control_betting_panel.p_visible = "none";
                        }

                    }
                    catch (Exception e)
                    {
                        string my_error_popup = "alert('Error in f_update_labels" + e.Message.ToString() + "');";
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
                        HedgeEmLogEvent my_log = new HedgeEmLogEvent();
                        my_log.p_message = "Exception caught in f_update_labels function " + e.Message;
                        my_log.p_method_name = "f_update_labels";
                        my_log.p_player_id = f_get_player_id();
                        my_log.p_game_id = game_id;
                        my_log.p_table_id = _table_id;
                        log.Error(my_log.ToString());
                    }
                }
            }
        }
    }
    /// Defines/Displays all the places where players can place bets.  This is essentially
    /// a x*y grid where x is the number of betting stages and y is the number of hands that can be bet on
    /// See also: f_displayControl_Bettinf_update_seat_panels_with_info_from_serverrid
    public void f_createControl_Bettinf_update_seat_panels_with_info_from_serverrid()
    {
        int my_number_of_seats = _global_game_state_object.p_number_of_seats_int;

        for (int stageindex = 0; stageindex < _int_number_of_betting_stages; stageindex++)
        {
            for (int handindex = 0; handindex < number_of_hands; handindex++)
            {
                _hedgeem_betting_panels[stageindex, handindex] = new BETTING_PANEL(my_number_of_seats);
            }
        }
    }
    //  This function is used to maintain the value of bet placed on each time page is refreshed.
    protected void f_update_hedgeem_control_betting_panels_with_info_from_server()
    {
        /* Get value of Selected_Hand_Panel for bet from textbox and save it in a variable */
        try
        {
            log.Debug("f_update_hedgeem_control_betting_panels_with_info_from_server called");
            // xxxHC value of theme
            my_default_theme = enum_theme.ONLINE;
            if (my_default_theme == enum_theme.ONLINE)
            {
                // Do not show the betting panels 
                // return;
            }
            else
            {
                // Update the display
                string best_odds_token = "";
                //For each betting stage and each hand
                for (enum_betting_stage stage_index = enum_betting_stage.HOLE_BETS; stage_index <= enum_betting_stage.TURN_BETS; stage_index++)
                {

                    for (int hand_index = 0; hand_index < _xxxHCnumber_of_hands; hand_index++)
                    {
                        // xxx should really use Doubles here 
                        _hedgeem_betting_panels[(int)stage_index, hand_index] = new BETTING_PANEL(f_get_number_of_seats());
                        if (_global_game_state_object._hands.Count() != 0)
                        {
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_betting_stage = stage_index;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_draw = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_percent_draw_string;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_win_or_draw = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_percent_win_or_draw_string;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_actual = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_actual_string;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_margin = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_margin_double.ToString();
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_win = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_percent_win_string;
                            if (_global_game_state_object.p_hand_stage_info_list[hand_index].p_is_recommended_hand_to_bet_on_for_best_value_odds == true)
                            {
                                best_odds_token = " *";
                            }
                            else
                            {
                                best_odds_token = "";
                            }
                            double offered_odds = _global_game_state_object.p_hand_stage_info_list[hand_index].p_odds_margin_rounded_double;

                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odd_margin_rounded = offered_odds;
                            String prefix;
                            if (offered_odds < 0)
                            {
                                prefix = "1/";
                                offered_odds = offered_odds * -1;
                            }
                            else
                            {
                                prefix = "";
                            }
                            if (offered_odds == 0)
                            {

                            }
                            else
                            {

                            }
                        }

                        //// #####################################
                        //// Display the chips for each player seated at the table (where bets have been placed)
                        for (int seat_index = 0; seat_index < f_get_number_of_seats(); seat_index++)
                        {
                            if (_global_game_state_object._seats.Count() == 0)
                            {
                                string chip_icon_resource_name = "chip_icon_seat_" + seat_index.ToString();
                            }
                            // if a bet has been place (i.e. recorded bets for stage, seat and hand combination is > 0)
                            // make the chip icon for the relevant seat visible and update the chip value to match the bet placed
                            //if (my_hedgeem_table._bets[(int)stage_index, seat_index, hand_index] > 0)
                            // xxx hardcode to always execute
                            try
                            {
                                if (true)
                                {
                                    if (_global_game_state_object._recorded_bets.Count() != 0)
                                    {
                                        // Update bet value on 'chip' and show it.  eg. set to 5 for $5 bet
                                        double bet_value_double = _global_game_state_object._recorded_bets[seat_index].p_bet_amount;
                                        _hedgeem_betting_panels[(int)stage_index, hand_index].p_players_bets[seat_index] = bet_value_double;
                                        Place_Holder_Betting_Panel.Controls.Add(_hedgeem_betting_panels[(int)stage_index, hand_index]);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                string my_error_popup = "alert('Error in f_update_hedgeem_control_betting_panels_with_info_from_server " + e.Message.ToString() + "');";
                                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
                                HedgeEmLogEvent my_log = new HedgeEmLogEvent();
                                my_log.p_message = "Exception caught in f_update_hedgeem_control_betting_panels_with_info_from_server function " + e.Message;
                                my_log.p_method_name = "f_update_hedgeem_control_betting_panels_with_info_from_server";
                                my_log.p_player_id = f_get_player_id();
                                my_log.p_game_id = game_id;
                                my_log.p_table_id = _table_id;
                                log.Error(my_log.ToString());
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            string my_error_popup = "alert('Error in f_update_hedgeem_control_betting_panels_with_info_from_server" + ex.Message.ToString() + "');";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
            HedgeEmLogEvent my_log = new HedgeEmLogEvent();
            my_log.p_message = "Exception caught in f_update_hedgeem_control_betting_panels_with_info_from_server function " + ex.Message;
            my_log.p_method_name = "f_update_hedgeem_control_betting_panels_with_info_from_server";
            my_log.p_player_id = f_get_player_id();
            my_log.p_game_id = game_id;
            my_log.p_table_id = _table_id;
            log.Error(my_log.ToString());
        }
    }
    //  This function is used to maintain the value of bet placed on each time page is refreshed.
    protected void f_update_hedgeem_control_betting_panels_with_info_from_server()
    {
        // Create a 'log event' object to audit execution
        HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
        my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
        my_log_event.p_message = "Method Entered.";
        my_log_event.p_player_id = p_session_player_id;
        my_log_event.p_table_id = p_session_personal_table_id;
        log.Debug(my_log_event.ToString());

        /* Get value of Selected_Hand_Panel for bet from textbox and save it in a variable */
        try
        {
            log.Debug("f_update_hedgeem_control_betting_panels_with_info_from_server called");
            // xxxHC value of theme
            enum_theme my_theme = f_get_current_theme_as_enum();
            enum_betting_stage my_current_betting_stage = _global_game_state_object.p_current_betting_stage_enum;
            enum_game_state my_current_game_stage_state_hack = f_convert_hedgeem_stage_to_state(my_current_betting_stage);
            enum_game_state my_current_game_state2 = _global_game_state_object.p_current_state_enum;
            int my_number_of_seats = _global_game_state_object.p_number_of_seats_int;


            // Only show the betting panels for CASINO, MOBILE or WSOP Styles
            if (!(my_theme == enum_theme.CASINO || my_theme == enum_theme.MOBILE || my_theme == enum_theme.WSOP || my_theme == enum_theme.RETRO))
            {
                // Do not show the betting panels
                // return;
            }
            else
            {
                //For each betting stage and each hand ...
                for (enum_betting_stage stage_index = enum_betting_stage.HOLE_BETS; stage_index <= enum_betting_stage.TURN_BETS; stage_index++)
                {
                    enum_game_state my_game_state = f_convert_hedgeem_stage_to_state(stage_index);

                    for (int hand_index = 0; hand_index < number_of_hands; hand_index++)
                    {
                        // ... retrieve the HandStageInfo object, then ... 
                        HedgeEmHandStageInfo my_hand_stage_info;
                        my_hand_stage_info = f_get_hand_stage_info_object_for_stage_and_hand(my_game_state, hand_index);
                        if (my_hand_stage_info == null)
                        {
                            //string my_error_msg = String.Format("HedgeEmHandStageInfo object null for stage[0], hand_index[{1}]",my_game_state.ToString(),hand_index);
                            //throw new Exception(my_error_msg);
                            // xxx hack to create a empty object when no data returned from server (Simon 30 Jan 2016
                            my_hand_stage_info = new HedgeEmHandStageInfo(my_game_state, hand_index);
                        }

                        // Create a 'HedgeEmControl' to display the BettingPanel for this Betting stage and hand.
                        _hedgeem_betting_panels[(int)stage_index, hand_index] = new BETTING_PANEL(my_number_of_seats);
                        Place_Holder_Betting_Panel.Controls.Add(_hedgeem_betting_panels[(int)stage_index, hand_index]);
                        _hedgeem_betting_panels[(int)stage_index, hand_index].p_hand_index = hand_index;

                        if (_global_game_state_object._hands.Count() != 0)
                        {
                            // ... update the corresponding Betting Panel with info from server
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_betting_stage = stage_index;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_draw = my_hand_stage_info.p_odds_percent_draw_string;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_win_or_draw = my_hand_stage_info.p_odds_percent_win_or_draw_string;
                            // xxx WARN .p_odds_actual_string is not being set as of Nov 2014 hence calling double.ToString();
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_actual = my_hand_stage_info.p_odds_actual_double.ToString();
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_margin = my_hand_stage_info.p_odds_margin_double.ToString();

                            if (my_current_game_state2 == enum_game_state.STATUS_RIVER && my_hand_stage_info.p_is_hand_a_winner_at_this_stage)
                            {
                                _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_panel_display_status = enum_hand_in_play_status.IN_PLAY_WINNER;
                            }
                            if (my_current_game_state2 == enum_game_state.STATUS_RIVER && !my_hand_stage_info.p_is_hand_a_winner_at_this_stage)
                            {
                                _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_panel_display_status = enum_hand_in_play_status.IN_NON_BETTING_STAGE;
                            }

                            if (my_hand_stage_info.p_enum_game_state < my_current_game_stage_state_hack && my_current_game_state2 != enum_game_state.STATUS_RIVER)
                            {
                                _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_panel_display_status = enum_hand_in_play_status.IN_PLAY_PREVIOUS_BETTING_STAGE_NOT_ACTIVE;
                            }

                            if (my_hand_stage_info.p_enum_game_state == my_current_game_stage_state_hack && my_current_game_state2 != enum_game_state.STATUS_RIVER)
                            {
                                _hedgeem_betting_panels[(int)stage_index, hand_index].p_enum_panel_display_status = my_hand_stage_info.p_hand_inplay_status;
                            }

                            double my_offered_odds_double = my_hand_stage_info.p_odds_margin_rounded_double;
                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odd_margin_rounded = my_offered_odds_double;

                            String prefix;
                            string my_offered_odds_string = "";
                            if (my_offered_odds_double < 0)
                            {
                                prefix = "1/";
                                my_offered_odds_double = my_offered_odds_double * -1;
                                my_offered_odds_string = prefix + my_offered_odds_double.ToString();
                            }
                            else
                            {
                                prefix = "";
                                my_offered_odds_string = prefix + my_offered_odds_double.ToString();
                            }
                            if (my_offered_odds_double == 0)
                            {

                                my_offered_odds_string = "X";
                            }


                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_payout_string = my_offered_odds_string;


                            // xxx HC to true to show admin
                            string role = Session["user_role"].ToString();
                            // if user is admin, show cashier button
                            if (role == enum_user_role.ADMIN.ToString())
                            {
                                _hedgeem_betting_panels[(int)stage_index, hand_index]._show_admin_info = true;
                            }
                            else
                            {
                                _hedgeem_betting_panels[(int)stage_index, hand_index]._show_admin_info = false;
                            }

                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odds_percent_win = my_hand_stage_info.p_odds_percent_win_string;

                            double offered_odds = my_hand_stage_info.p_odds_margin_rounded_double;

                            _hedgeem_betting_panels[(int)stage_index, hand_index].p_odd_margin_rounded = offered_odds;

                        }

                        #region display_chips_for_each_player
                        //// #####################################
                        //// Display the chips for each player seated at the table (where bets have been placed)
                        for (int seat_index = 0; seat_index < my_number_of_seats; seat_index++)
                        {
                            if (_global_game_state_object._seats.Count() == 0)
                            {
                                string chip_icon_resource_name = "chip_icon_seat_" + seat_index.ToString();
                            }
                            // if a bet has been place (i.e. recorded bets for stage, seat and hand combination is > 0)
                            // make the chip icon for the relevant seat visible and update the chip value to match the bet placed
                            //if (my_hedgeem_table._bets[(int)stage_index, seat_index, hand_index] > 0)
                            // xxx hardcode to always execute
                            try
                            {
                                if (true)
                                {
                                    if (_global_game_state_object._recorded_bets.Count() != 0)
                                    {
                                        // Update bet value on 'chip' and show it.  eg. set to 5 for $5 bet
                                        double my_bet_value_double = f_get_total_previous_bets_for_stage_and_hand_player(stage_index, hand_index, Convert.ToInt32(Session["p_session_player_id"]));
                                        _hedgeem_betting_panels[(int)stage_index, hand_index].p_players_bets[seat_index] = my_bet_value_double;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                string my_error_popup = "Error in f_update_hedgeem_control_betting_panels_with_info_from_server " + e.Message.ToString();
                                // ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
                                my_log_event.p_message = "Exception caught in f_update_hedgeem_control_betting_panels_with_info_from_server function " + e.Message;
                                my_log_event.p_player_id = Convert.ToInt32(Session["p_session_player_id"]);
                                my_log_event.p_game_id = game_id;
                                my_log_event.p_table_id = p_session_personal_table_id;
                                log.Error(my_log_event.ToString());
                                HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
                                my_popup_message.p_detailed_message_str = "";
                                my_popup_message.p_is_visible = false;

                                //ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
                                my_popup_message.p_detailed_message_str = my_error_popup;
                                my_popup_message.p_is_visible = true;
                                Place_Holder_Popup_Message.Controls.Add(my_popup_message);
                            }


                        }
                        #endregion display_chips_for_each_player
                    }

                }
            }
        }
        catch (Exception ex)
        {
            string my_error_popup = "Error in f_update_hedgeem_control_betting_panels_with_info_from_server" + ex.Message.ToString();
            //my_error_popup = "Bollocks";
           // ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
            HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
            my_popup_message.p_detailed_message_str = "";
            my_popup_message.p_is_visible = false;

            //ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
            my_popup_message.p_detailed_message_str = my_error_popup;
            my_popup_message.p_is_visible = true;
            Place_Holder_Popup_Message.Controls.Add(my_popup_message);
            my_log_event.p_message = "Exception caught in f_update_hedgeem_control_betting_panels_with_info_from_server function " + ex.Message;
            my_log_event.p_method_name = "f_update_hedgeem_control_betting_panels_with_info_from_server";
            my_log_event.p_player_id = Convert.ToInt32(Session["p_session_player_id"]);
            my_log_event.p_game_id = game_id;
            my_log_event.p_table_id = p_session_personal_table_id;
            log.Error(my_log_event.ToString());
        }
    }