﻿

var result = "";

$(document).ready(function() {
    LoadSportsTree();
    
    //         $('#btnGo').click(function() {
    //          alert($('input:checkbox[name=comp]:checked').val());

    //      });


    //          $('#btnGo').click(function() {
    //              result = "";
    //              // alert($('input:checkbox[name=comp]:checked').val());
    //              $('input:checkbox[name=comp]:checked').each(function() {
    //                  if (this.checked == true) {
    //                      //  alert(this.value);
    //                      result = result + this.value + ", ";
    //                  }
    //              });
    //              alert(result);
    //          });


    // Click Event for Clear Button
    $('#btnClear').click(function() {
        fnClearSel();
    });

    // Click Event for Clear Button
    $('#btnClear1').click(function() {
        fnClearSel();
    });

    // Click Event for Show Button
    $('#btnDispComp').click(function() {
        LoadCompetitions();
    });

    // Click Event for Show Button
    $('#btnDispComp1').click(function() {
        LoadCompetitions();
    });

    $('#divBetContent').hide(); // Hide the betting Content by default
    $('#divLoading').hide();
    $('#divCompContent').hide(); // Hide the betting Content by default


    // Click Event for Fast Bet Button
    $('#bQBet').click(function() {
        LoadFastBet();
    });

    // Click Event for Clear All Button
    $('#bClearAll').click(function() {
        $('#divpreQBet ul li').each(function() {
            if (jQuery(this).hasClass("token-input-token")) {
                jQuery(this).remove();
            }
        })
        // Clear the textbox value
        document.getElementById("eventLookup").value = "";

    });

    $('#cboEventTime').change(function() {
        LoadActiveSportsMenu();
    });

});

function LoadSportsTree() {
    $("ul.tree").checkTree({
        // You can add callbacks to the expand, collapse, check, uncheck, and  halfcheck
        // events of the tree. The element you use as the argument is the LI element of
        // the object that fired the event.
        onExpand: function(el) {
            //         console.log("expanded ", el.find("label:first").text());

        },
        onCollapse: function(el) {
            //       console.log("collapsed ", el.find("label:first").text());
        },
        onCheck: function(el) {
            //     console.log("checked ", el.find("label:first").text());
            //  alert(el.find("input:checkbox[name=comp]:checked").val()); 
        },
        onUnCheck: function(el) {
            //   console.log("un checked ", el.find("label:first").text());
            result = "";
        },
        onHalfCheck: function(el) {
            // console.log("half checked ", el.find("label:first").text());
        }
        /*
        // You can set the labelAction variable to either "check" or "expand" 
        // to change what happens when you click on the label item.
        // The default is expand, which expands the tree. Check will toggle
        // the checked state of the items.
        labelAction: "expand"
        */
        /*
        // You can also change what happens when you hover over a label (over and out)
        onLabelHoverOver: function(el) { alert("You hovered over " + el.text()); },
        onLabelHoverOut: function(el) { alert("You hovered out of " + el.text()); }
        */
    });
}


function LoadActiveSportsMenu() {
    
    //get selected option
    var timeFrame = $('#cboEventTime').val();

    $.post("../HttpHandlers/Competition.ashx", { mode: 'ActiveMenu', OddsType: 'DECIMAL', timeFrame: timeFrame }, function(data) {
        $('#' + ActiveSportsMenu).empty();
        $('#' + ActiveSportsMenu).append(data);
        LoadSportsTree();
    });
}

function LoadCompetitions() {
    result = "";
    $('input:checkbox[name=comp]:checked').each(function() {
        if (this.checked == true) {
            result = result + this.value + "-";
        }
    });
    if (result.length > 0) {
        $('#divMainContent').hide(); // Hide the Main content
        $('#divMainContent').empty(); // Clear the Main content
        $('#divQBetSelect').hide(); // Hide Q Bet Content
        $('#divCompContent').show(); // Display the betting Content
        $('#divBetContent').show(); // Display the betting Content
        
        UpdateCompetition();
    } else {
        alert(document.getElementById("JS_NoComp").value);
        return false;
    }
}

function LoadPopularCompetitions(CompID) {
    result = "";
    result = CompID + "-";

    if (CompID.length > 0) {
        $('#divMainContent').hide(); // Hide the Main content
        $('#divMainContent').empty(); // Clear the Main content
        $('#divQBetSelect').hide(); // Hide Q Bet Content
        $('#divCompContent').show(); // Display the betting Content
        $('#divBetContent').show(); // Display the betting Content

        UpdateCompetition();
    } else {
        alert(document.getElementById("JS_NoComp").value);
        return false;
    }
}



function fnClearSel() {

    result = "";
    // Clear all the Competitions Check Boxes only if they are selected.
    $('input:checkbox[name=comp]:checked').each(function() {
        if (this.checked == true) {

            jQuery(this)
                        .attr("checked", "")
                        .siblings(".checkbox")
                            .removeClass("checked")
                            .removeClass("half_checked")
                    ;

        }
    });

    // Clear all the Region Check Boxes only if they are selected.
    $('input:checkbox[name=region]:checked').each(function() {
        if (this.checked == true) {

            jQuery(this)
                        .attr("checked", "")
                        .siblings(".checkbox")
                            .removeClass("checked")
                            .removeClass("half_checked")
                    ;

        }
    });

    // Clear all the Sport Check Boxes
    $('input:checkbox[name=sport]').each(function() {
        jQuery(this)
                        .attr("checked", "")
                        .siblings(".checkbox")
                   .removeClass("checked")
                   .removeClass("half_checked")
                    ;

    });


}

function fnGo() {
    result = "";
    $('input:checkbox[name=comp]:checked').each(function() {
        if (this.checked == true) {
            //  alert(this.value);
            result = result + this.value + "-";
        }
    });

    if (result.length > 0)
        if (!typeof (hdnCompSelected) == "undefined")
        document.getElementById(hdnCompSelected).value = result;
    else
        document.getElementById("_ctl0_LeftMenu1_hdnCompSelected").value = result;

    else
        window.event.returnValue = false;
}

function UpdateCompetition() {

    var dropdownIndex = document.getElementById('cboEventTime').selectedIndex
    var dropdownValue = document.getElementById("cboEventTime")[dropdownIndex].value;
    
    $('#dvComp').empty();
    $('#dvComp').addClass("scroll-pane");
    $('#divLoading').show()
    var strOddType = document.getElementById(hdOddsType).value;
    $.post("../HttpHandlers/Competition.ashx", { CompID: result, OddsType: strOddType, MarketID: 0, TimeFrame: dropdownValue, mode: 'BET' }, function(data) {
        $('#dvComp').append(data);
         //$('#dvscrollCustom').show();
        $('#divLoading').fadeOut();
        SetSelectedOdds();
        // Initialize the scroll bar

        //$('#dvComp').jScrollPane({ scrollbarWidth: 10, scrollbarMargin: 10 });
        //$('#dvHolder').jScrollPane();
    });

   
}

function LoadFastBet() {
    $('#divMainContent').hide(); // Hide the Main content
    $('#divMainContent').empty(); // Clear the Main content
    $('#divBetContent').show(); // Display the betting Content
    $('#dvComp').removeClass("scroll-pane");
    //$('#dvscrollCustom').empty();
    //$('#dvscrollCustom').attr("style","")
    //$('#dvscrollCustom').hide();
    $('#dvComp').empty();
    //$('#dvHolder').empty();
    
    $('#divQBetSelect').show();


}

function LoadWorldCupOutrights() {
    result = "855-";
    $('#divMainContent').hide(); // Hide the Main content
    $('#divMainContent').empty(); // Clear the Main content
    $('#divQBetSelect').hide(); // Hide Q Bet Content
    $('#divCompContent').show(); // Display the betting Content
    $('#divBetContent').show(); // Display the betting Content

    UpdateCompetition();
}

function OpenLiveScore() {
    window.open("http://livescore.betradar.com?alias=globet", "_blank");
}

function OpenLiveScoreStatistics() {
    window.open("http://livescore.betradar.com/statistics/globet/", "_blank");
}
 
 