﻿var arrayMyMatchesSoccer = new Array();
var arrayMyMatchesBasketball = new Array();
var arrayMyMatchesTennis = new Array();
var arrayMyMatchesHockey = new Array();
var arrayMyMatchesHandball = new Array();
var arrayMyMatchesVolleyball = new Array();
var arrayMyMatchesNFL = new Array();
var jsonMyMatchesSoccer;
var jsonMyMatchesBasketball;
var jsonMyMatchesTennis;
var jsonMyMatchesVolleyball;
var jsonMyMatchesHockey;
var jsonMyMatchesHandball;
var jsonMyMatchesNfl;
var mSport = "";

function myMatches(idIN, sportIN) {
    if ($("#star_" + idIN).hasClass("star")) {
        jQuery($("#star_" + idIN)).attr('class', "star_selected");
        $("#star_" + idIN).html("<img src='media/images/start_blue.png' alt=''>");
        if (sportIN == "football") {
            arrayMyMatchesSoccer.push(idIN);
        } else if (sportIN == "basketball") {
            arrayMyMatchesBasketball.push(idIN);
        } else if (sportIN == "tennis") {
            arrayMyMatchesTennis.push(idIN);
        } else if (sportIN == "hockey") {
            arrayMyMatchesHockey.push(idIN);
        } else if (sportIN == "handball") {
            arrayMyMatchesHandball.push(idIN);
        } else if (sportIN == "volleyball") {
            arrayMyMatchesVolleyball.push(idIN);
        } else if (sportIN == "nfl") {
            arrayMyMatchesNFL.push(idIN);
        }
    } else {
        jQuery($("#star_" + idIN)).attr('class', "star");
        $("#star_" + idIN).html("<img src='media/images/start_gray.png' alt=''>");
        if (sportIN == "football") {
            arrayMyMatchesSoccer = jQuery.grep(arrayMyMatchesSoccer, function(value) {                
                return value != idIN;
            });
            if (type == "mymatches") {
                //                showMyMatchesSoccer(null, false);
                showMyMatchesAll(null, false);
            }
        } else if (sportIN == "basketball") {
            arrayMyMatchesBasketball = jQuery.grep(arrayMyMatchesBasketball, function(value) {
                return value != idIN;
            });
            if (type == "mymatches") {
                //showMyMatchesBasketball(null, false);
                showMyMatchesAll(null, false);
            }
        } else if (sportIN == "tennis") {
            arrayMyMatchesTennis = jQuery.grep(arrayMyMatchesTennis, function(value) {
                return value != idIN;
            }); 
            if (type == "mymatches") {
                //showMyMatchesBasketball(null, false);
                showMyMatchesAll(null, false);
            }
        } else if (sportIN == "hockey") {
            arrayMyMatchesHockey = jQuery.grep(arrayMyMatchesHockey, function(value) {
                return value != idIN;
            });
            if (type == "mymatches") {
               // showMyMatchesBasketball(null, false);
                showMyMatchesAll(null, false);
            }
        } else if (sportIN == "handball") {
            arrayMyMatchesHandball = jQuery.grep(arrayMyMatchesHandball, function(value) {
                return value != idIN;
            });
            if (type == "mymatches") {
                //showMyMatchesHandball(null, false);
                showMyMatchesAll(null, false);
            }
        } else if (sportIN == "volleyball") {
            arrayMyMatchesVolleyball = jQuery.grep(arrayMyMatchesVolleyball, function(value) {
                return value != idIN;
            }); 
            if (type == "mymatches") {
                //showMyMatchesBasketball(null, false);
                showMyMatchesAll(null, false);
            }
        } else if (sportIN == "nfl") {
            arrayMyMatchesNFL = jQuery.grep(arrayMyMatchesNFL, function(value) {
                return value != idIN;
            });
            if (type == "mymatches") {
                //showMyMatchesBasketball(null, false);
                showMyMatchesAll(null, false);
            }
        }
    }
}

function showMyMatchesSoccer(data, newFeed) {
    if (newFeed) {
        //        jsonMyMatchesSoccer = json_parse(data);
        jsonMyMatchesSoccer = data;
    }
    //$("#accordians").empty();
    $.each(jsonMyMatchesSoccer, function() {
        var postoji = false;
        $.each(this.Event, function() {
            if (jQuery.inArray(this.EventId, arrayMyMatchesSoccer) > -1) {
                postoji = true;
            }
        });
        if (postoji) {
            var html = "";
            var cName = this.ContestName;
            html = html + "<div id='td_" + this.SubContestId + "' class='toggler_detail'>" +
                        "<table class='toggler_table'>" +
                            "<tr class='last'>" +
                                "<td class='toggler_nametd'>FOOTBALL - " + cName + "</td>" +
                                "<td class='toggler_icontd toggler_icontd_alignright'>" +
                                    "<a href='#'>" +
                                        "<img onclick='openStats(\"" + this.SubContestId + "\",\"" + cName + "\")' src='media/images/result_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td class='toggler_icontd iconbrd'>" +
                                    "<a href='#'>" +
                                        "<img onclick='remove(\"" + this.SubContestId + "\")' src='media/images/cross_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td width=30>&nbsp;</td>" +
                            "</tr>" +
                        "</table>" +
                      "</div>" +
                      "<div id='t_" + this.SubContestId + "' class='toggler'>" +
                        "<div id='swap'>" +
                            "<img id='" + this.SubContestId + "' onclick='resize(\"" + this.SubContestId + "\")' src='media/images/neg.gif'/>" +
                        "</div>" +
                      "</div>" +
                      "<div id='acc_" + this.SubContestId + "' class='accordion' style='overflow: hidden; visibility: visible; opacity: 1;'>" +
                        "<div>" +
                            "<div id='swap'></div>" +
                            "<div>" +
                                "<table id='tab_" + this.SubContestId + "' width='100%' cellspacing='0' cellpadding='0' border='0'>";
            $.each(this.Event, function() {
                if (jQuery.inArray(this.EventId, arrayMyMatchesSoccer) > -1) {
                    var teamHome = this.Home;
                    var teamAway = this.Away;
                    var tHome = this.Home;
                    var tAway = this.Away;
                    if (this.Pobednik == 1) {
                        teamHome = "<b>" + teamHome + "</b>";
                    } else if (this.Pobednik == 2) {
                        teamAway = "<b>" + teamAway + "</b>";
                    }
                    if (this.ImaPenala) {
                        if (int.Parse(this.ScoreHome) > int.Parse(this.ScoreAway)) {
                            teamHome = teamHome + "*";
                            tHome = tHome + "*";
                        } else if (int.Parse(this.ScoreHome) < int.Parse(this.ScoreAway)) {
                            teamAway = teamAway + "*";
                            tHome = tHome + "*";
                        }
                    }
                    if (this.CardHome != "0") {
                        teamHome = "<span class='" + this.CardHome + "'>" + teamHome + "</span>";
                    }
                    if (this.CardAway != "0") {
                        teamAway = "<span class='" + this.CardAway + "'>" + teamAway + "</span>";
                    }
                    html = html + "<tr class='" + this.cssClassMinute + "'>" +
                            "<td class='" + this.cssClassSignal + "' style='border-right: medium none; width: 20px; text-align: right;'>";
                    if (this.Live) {
                        html = html + "<!-- ImageReady Slices (Untitled-1) -->" +
                                                    "<img src='media/images/second.gif' width='8' height='8' alt='' class='blkdot'>" +
                                                    "<!-- End ImageReady Slices -->"
                    }
                    html = html + "</td><td class='" + this.cssClassSignal + "'>" + this.Comment + "</td>" +
                            "<td class='team1'>" + teamHome + "</td>" +
                            "<td class='" + this.cssClassScore + "'>" +
                                "<a href='info.aspx?subContestID=" + this.EventId + "&comm=" + this.Comment.replace("'", "") + "&score=" + this.Score +
                                    "&name=" + cName + "&home=" + tHome + "&away=" + tAway + "' " +
                                    "onclick='openWinSmall(this.href); return false;' title=''>" + this.Score +
                                "</a>" +
                            "</td>" +
                            "<td class='team2'>" + teamAway + "</td>" +
                            "<td class='tviconsoccer'>";
                    if (this.LineUp == 1) {
                        html = html + "<a style='float:left;' onclick='openWinLineUp(this.href); return false;' href='lineup.aspx?subContestID="
                                            + this.EventId + "&comm=" + this.Comment.replace("'", "") + "&score=" + this.Score + "&name="
                                            + cName + "'><img src='media/images/luIcon.png' alt='lineup '></a>";
                    }
                    if (this.Tv == 1) {
                        html = html + "<a style='float:right;' href='#' onclick=\"refreshPageTV('liveOnTv', '" + this.EventId
                                            + "', 'football');\"><img src='media/images/tvIcon.png' alt='tv'></a>";
//                        html = html + "<a onclick='refreshPageTV(\"liveOnTv\", \"" + this.EventId + "\", \"football\");' href='#'>" +
//                                "<img alt='tv' src='media/images/tvicon.gif'/>" +
//                              "</a>";
                    }
                    html = html + "</td><td title='My Matches' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId
                                    + ",\"football\");' class='star_selected'><img src='media/images/start_blue.png' alt='grey_star' ></td></tr>";
                }
            });
            html = html + "</table></div><div class='bottomMargin'/></div></div>";
            $("#accordians").append(html);
        }
    });
//    if (arrayMyMatchesSoccer.length == 0) {
//        $("#accordians").empty();
//        $("#accordians").append("<span style='font-size:14px'>No My Matches Selected</span>");
//    }
    checkDoubleImages();
}

function showMyMatchesBasketball(data, newFeed) {
    var json;
    var array = new Array();
    if (newFeed) {
//        if (sport == "basketball") {
//            jsonMyMatchesBasketball = json_parse(data);
//        } else if (sport == "tennis") {
//            jsonMyMatchesTennis = json_parse(data);
//        } else if (sport == "volleyball") {
//            jsonMyMatchesVolleyball = json_parse(data);
//        } else if (sport == "hockey") {
//            jsonMyMatchesHockey = json_parse(data);
//        } else if (sport == "nfl") {
//            jsonMyMatchesNfl = json_parse(data);
        //        }
        if (mSport == "basketball") {
            jsonMyMatchesBasketball = data;
        } else if (mSport == "tennis") {
            jsonMyMatchesTennis = data;
        } else if (mSport == "volleyball") {
            jsonMyMatchesVolleyball = data;
        } else if (mSport == "hockey") {
            jsonMyMatchesHockey = data;
        } else if (mSport == "nfl") {
            jsonMyMatchesNfl = data;
        }
    }
    if (mSport == "basketball") {
        array = arrayMyMatchesBasketball;
        json = jsonMyMatchesBasketball;
    } else if (mSport == "tennis") {
        array = arrayMyMatchesTennis;
        json = jsonMyMatchesTennis;
    } else if (mSport == "volleyball") {
        array = arrayMyMatchesVolleyball;
        json = jsonMyMatchesVolleyball;
    } else if (mSport == "hockey") {
        array = arrayMyMatchesHockey;
        json = jsonMyMatchesHockey;
    } else if (mSport == "nfl") {
        array = arrayMyMatchesNFL;
        json = jsonMyMatchesNfl;
    }
    //$("#accordians").empty();
    $.each(json, function() {
        var postoji = false;
        $.each(this.Event, function() {
            if (jQuery.inArray(this.EventId, array) > -1) {
                postoji = true;
            }
        });
        if (postoji) {
            var html = "";
            var cName = this.ContestName;
            html = html + "<div id='td_" + this.SubContestId + "' class='toggler_detail'>" +
                        "<table class='toggler_table'>" +
                            "<tr class='last'>" +
                                "<td class='toggler_nametd'>" + mSport.toUpperCase() + " - " + cName + "</td>" +
                                "<td class='toggler_icontd toggler_icontd_alignright'>" +
                                    "<a href='#'>" +
                                        "<img onclick='openStats(\"" + this.SubContestId + "\",\"" + cName + "\")' src='media/images/result_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td class='toggler_icontd iconbrd'>" +
                                    "<a href='#'>" +
                                        "<img onclick='remove(\"" + this.SubContestId + "\")' src='media/images/cross_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td width=30>&nbsp;</td>" +
                            "</tr>" +
                        "</table>" +
                      "</div>" +
                      "<div id='t_" + this.SubContestId + "' class='toggler'>" +
                        "<div id='swap'>" +
                            "<img id='" + this.SubContestId + "' onclick='resize(\"" + this.SubContestId + "\")' src='media/images/neg.gif'/>" +
                        "</div>" +
                      "</div>" +
                      "<div id='acc_" + this.SubContestId + "' class='accordion' style='overflow: hidden; visibility: visible; opacity: 1;'>" +
                        "<div>" +
                            "<div id='swap'></div>" +
                            "<div>" +
                                "<table id='tab_" + this.SubContestId + "' width='100%' cellspacing='0' cellpadding='0' border='0'>";
            $.each(this.Event, function() {
                if (jQuery.inArray(this.EventId, array) > -1) {
                    var teamHome = this.Home;
                    var teamAway = this.Away;
                    var tHome = this.Home;
                    var tAway = this.Away;
                    var m_firstqH, m_firstqA, m_secondqH, m_secondqA, m_thirdqH, m_thirdqA, m_fourthqH, m_fourthqA, m_fifthqH, m_fifthqA;
                    try {
                        if (int.Parse(this.ScoreHome1P) < 10)
                            m_firstqH = "&nbsp;&nbsp;" + this.ScoreHome1P;
                    } catch (e) { m_firstqH = this.ScoreHome1P }
                    try {
                        if (int.Parse(this.ScoreAway1P) < 10)
                            m_firstqA = "&nbsp;&nbsp;" + this.ScoreAway1P;
                    } catch (e) { m_firstqA = this.ScoreAway1P }
                    try {
                        if (int.Parse(this.ScoreHome2P) < 10)
                            m_secondqH = "&nbsp;&nbsp;" + this.ScoreHome2P;
                    } catch (e) { m_secondqH = this.ScoreHome2P }
                    try {
                        if (int.Parse(this.ScoreAway2P) < 10)
                            m_secondqA = "&nbsp;&nbsp;" + this.ScoreAway2P;
                    } catch (e) { m_secondqA = this.ScoreAway2P }
                    try {
                        if (e) (int.Parse(this.ScoreHome3P) < 10)
                        m_thirdqH = "&nbsp;&nbsp;" + this.ScoreHome3P;
                    } catch (e) { m_thirdqH = this.ScoreHome3P }
                    try {
                        if (e) (int.Parse(this.ScoreAway3P) < 10)
                        m_thirdqA = "&nbsp;&nbsp;" + this.ScoreAway3P;
                    } catch (e) { m_thirdqA = this.ScoreAway3P }
                    try {
                        if (int.Parse(this.ScoreHome4P) < 10)
                            m_fourthqH = "&nbsp;&nbsp;" + this.ScoreHome4P;
                    } catch (e) { m_fourthqH = this.ScoreHome4P }
                    try {
                        if (int.Parse(this.ScoreAway4P) < 10)
                            m_fourthqA = "&nbsp;&nbsp;" + this.ScoreAway4P;
                    } catch (e) { m_fourthqA = this.ScoreAway4P }
                    try {
                        if (int.Parse(this.ScoreHome5P) < 10)
                            m_fifthqH = "&nbsp;&nbsp;" + this.ScoreHome5P;
                    } catch (e) { m_fifthqH = this.ScoreHome5P }
                    try {
                        if (int.Parse(this.ScoreAway5P) < 10)
                            m_fifthqA = "&nbsp;&nbsp;" + this.ScoreAway5P;
                    } catch (e) { m_fifthqA = this.ScoreAway5P }
                    if (this.Pobednik == 1) {
                        teamHome = "<b>" + teamHome + "</b>";
                    } else if (this.Pobednik == 2) {
                        teamAway = "<b>" + teamAway + "</b>";
                    }

                    if (this.EventStarted) {
                        html = html + "<tr class='" + this.cssClassMinute + "'>" +
//                                        "<td title='My Matches' align='center' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId +
//                                        ",\"" + mSport + "\");' class='star_selected'><img src='media/images/start_blue.png' alt='' ></td>" +
                                        "<td class='mtv'>";
                        if (this.Tv == 1) {
                            html = html + "<a onclick='refreshPageTV(\"liveOnTv\", \"" + this.EventId + "\", \"" + mSport + "\");' href='#'>" +
                                "<img alt='tv' src='media/images/tvicon.gif'/>" +
                              "</a>";
                        }
                        html = html + "</td><td class='" + this.cssClassSignal + "' style='border-right: medium none; width: 20px; text-align: right;'>";
                        if (this.Live) {
                            html = html + "<!-- ImageReady Slices (Untitled-1) -->" +
                                                    "<img src='media/images/second.gif' width='8' height='8' alt='' class='blkdot'>" +
                                                    "<!-- End ImageReady Slices -->";
                        }
                        html = html + "</td><td class='" + this.cssClassSignal + "'>" + this.Comment + "</td>" +
                                        "<td>" +
                                            "<table class='innertable'>" +
                                                "<tr>" +
                                                    "<td class='team2'>" + teamHome + "</td>" +
                                                    "<td class='team3'>" + m_firstqH + "&nbsp;&nbsp;" + m_secondqH + "&nbsp;&nbsp;" +
                                                        m_thirdqH + "&nbsp;&nbsp;" + m_fourthqH + "&nbsp;&nbsp;" + m_fifthqH + "</td>" +
                                                    "<td class='score1'>&nbsp;&nbsp;" + this.ScoreHome + "&nbsp;&nbsp;</td>" +
                                                "</tr>" +
                                                "<tr class='last'>" +
                                                    "<td class='team2'>" + teamAway + "</td>" +
                                                    "<td class='team3'>" + m_firstqA + "&nbsp;&nbsp;" + m_secondqA + "&nbsp;&nbsp;" +
                                                        m_thirdqA + "&nbsp;&nbsp;" + m_fourthqA + "&nbsp;&nbsp;" + m_fifthqA + "</td>" +
                                                    "<td class='score1'>&nbsp;&nbsp;" + this.ScoreAway + "&nbsp;&nbsp;</td>" +
                                                "</tr>" +
                                            "</table>" +
                                        "</td>";
                        html = html + "</td><td title='My Matches' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId
                                    + ",\"" + mSport + "\");' class='star_selected'><img src='media/images/start_blue.png' alt='grey_star' ></td></tr>";
                        //"</tr>";
                    } else {
                        html = html + "<tr class='" + this.cssClassMinute + "'>" +
                        //                        "<td title='My Matches' align='center' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId +
                        //                                        ",\"" + mSport + "\");' class='star_selected'><img src='media/images/start_blue.png' alt='' ></td>" +
                                        "<td class='mtv'>";
                        if (this.Tv == 1) {
                            html = html + "<a onclick='refreshPageTV(\"liveOnTv\", \"" + this.EventId + "\", \"" + mSport + "\");' href='#'>" +
                                "<img alt='tv' src='media/images/tvicon.gif'/>" +
                              "</a>";
                        }
                        html = html + "</td><td class='" + this.cssClassSignal + "' style='border-right: medium none; width: 20px; text-align: right;'></td>" +
                                        "<td class='" + this.cssClassSignal + "'>" + this.Comment + "</td>" +
                                        "<td>" +
                                            "<table class='innertable'>" +
                                                "<tr>" +
                                                    "<td class='team2'>" + teamHome + "</td>" +
                                                    "<td class='team3'>" + m_firstqH + "&nbsp;&nbsp;" + m_secondqH + "&nbsp;&nbsp;" +
                                                        m_thirdqH + "&nbsp;&nbsp;" + m_fourthqH + "&nbsp;&nbsp;" + m_fifthqH + "</td>" +
                                                    "<td class='score1' rowspan='2'>" + this.ScoreHome + "</td>" +
                                                "</tr>" +
                                                "<tr class='last'>" +
                                                    "<td class='team2'>" + teamAway + "</td>" +
                                                    "<td class='team3'>" + m_firstqA + "&nbsp;&nbsp;" + m_secondqA + "&nbsp;&nbsp;" +
                                                        m_thirdqA + "&nbsp;&nbsp;" + m_fourthqA + "&nbsp;&nbsp;" + m_fifthqA + "</td>" +
                                                "</tr>" +
                                            "</table>" +
                                        "</td>";
                        html = html + "</td><td title='My Matches' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId
                                    + ",\"" + mSport + "\");' class='star_selected'><img src='media/images/start_blue.png' alt='grey_star' ></td></tr>";
                        //"</tr>";
                    }
                }
            });
            html = html + "</table></div><div class='bottomMargin'/></div></div>";
            $("#accordians").append(html);
        }
    });
//    if (array.length == 0) {
//        $("#accordians").empty();
//        $("#accordians").append("<span style='font-size:14px'>No My Matches Selected</span>");
//    }
    checkDoubleImages();
}

function showMyMatchesHandball(data, newFeed) {
    if (newFeed) {
        //jsonMyMatchesHandball = json_parse(data);
        jsonMyMatchesHandball = data;
    }
//    $("#accordians").empty();
    $.each(jsonMyMatchesHandball, function() {
        var postoji = false;
        $.each(this.Event, function() {
            if (jQuery.inArray(this.EventId, arrayMyMatchesHandball) > -1) {
                postoji = true;
            }
        });
        if (postoji) {
            var html = "";
            var cName = this.ContestName;
            html = html + "<div id='td_" + this.SubContestId + "' class='toggler_detail'>" +
                        "<table class='toggler_table'>" +
                            "<tr class='last'>" +
                                "<td class='toggler_nametd'>HANDBALL - " + cName + "</td>" +
                                "<td class='toggler_icontd toggler_icontd_alignright'>" +
                                    "<a href='#'>" +
                                        "<img onclick='' src='media/images/result_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td class='toggler_icontd iconbrd'>" +
                                    "<a href='#'>" +
                                        "<img onclick='remove(\"" + this.SubContestId + "\")' src='media/images/cross_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td width=30>&nbsp;</td>" +
                            "</tr>" +
                        "</table>" +
                      "</div>" +
                      "<div id='t_" + this.SubContestId + "' class='toggler'>" +
                        "<div id='swap'>" +
                            "<img id='" + this.SubContestId + "' onclick='resize(\"" + this.SubContestId + "\")' src='media/images/neg.gif'/>" +
                        "</div>" +
                      "</div>" +
                      "<div id='acc_" + this.SubContestId + "' class='accordion' style='overflow: hidden; visibility: visible; opacity: 1;'>" +
                        "<div>" +
                            "<div id='swap'></div>" +
                            "<div>" +
                                "<table id='tab_" + this.SubContestId + "' width='100%' cellspacing='0' cellpadding='0' border='0'>";
            $.each(this.Event, function() {
                if (jQuery.inArray(this.EventId, arrayMyMatchesHandball) > -1) {
                    var teamHome = this.Home;
                    var teamAway = this.Away;
                    var tHome = this.Home;
                    var tAway = this.Away;
                    if (this.Pobednik == 1) {
                        teamHome = "<b>" + teamHome + "</b>";
                    } else if (this.Pobednik == 2) {
                        teamAway = "<b>" + teamAway + "</b>";
                    }
                    html = html + "<tr class='" + this.cssClassMinute + "'>" +
                            "<td class='" + this.cssClassSignal + "' style='border-right: medium none; width: 20px; text-align: right;'>";
                    if (this.Live) {
                        html = html + "<!-- ImageReady Slices (Untitled-1) -->" +
                                                    "<img src='media/images/second.gif' width='8' height='8' alt='' class='blkdot'>" +
                                                    "<!-- End ImageReady Slices -->"
                    }
                    html = html + "</td><td class='" + this.cssClassSignal + "'>" + this.Comment + "</td>" +
                            "<td class='team1'>" + teamHome + "</td>" +
                            "<td class='" + this.cssClassScore + "'>" +
                                "<a href='info.aspx?subContestID=" + this.EventId + "&comm=" + this.Comment.replace("'", "") + "&score=" + this.Score +
                                    "&name=" + cName + "&home=" + tHome + "&away=" + tAway + "' " +
                                    "onclick='openWinSmall(this.href); return false;' title=''>" + this.Score +
                                "</a>" +
                            "</td>" +
                            "<td class='team2'>" + teamAway + "</td>" +
                            "<td class='tviconsoccer'>";
                   
                    if (this.Tv == 1) {
                        html = html + "<a style='float:right;' href='#' onclick=\"refreshPageTV('liveOnTv', '" + this.EventId
                                            + "', \"handball\");\"><img src='media/images/tvIcon.png' alt='tv'></a>";
                    }
                    html = html + "</td><td title='My Matches' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId
                                    + ",\"handball\");' class='star_selected'><img src='media/images/start_blue.png' alt='grey_star' ></td></tr>";
                }
            });
            html = html + "</table></div><div class='bottomMargin'/></div></div>";
            $("#accordians").append(html);
        }
    });
//    if (arrayMyMatchesHandball.length == 0) {
//        $("#accordians").empty();
//        $("#accordians").append("<span style='font-size:14px'>No My Matches Selected</span>");
//    }
    checkDoubleImages();
}

function showMyMatchesTennis(data, newFeed) {
    if (newFeed) {
        jsonMyMatchesTennis = json_parse(data);
    }
    $("#accordians").empty();
    $.each(jsonMyMatchesTennis, function() {
        var postoji = false;
        $.each(this.Event, function() {
            if (jQuery.inArray(this.EventId, arrayMyMatchesTennis) > -1) {
                postoji = true;
            }
        });
        if (postoji) {
            var html = "";
            var cName = this.ContestName;
            html = html + "<div id='td_" + this.SubContestId + "' class='toggler_detail'>" +
                        "<table class='toggler_table'>" +
                            "<tr class='last'>" +
                                "<td class='toggler_nametd'>" + cName + "</td>" +
                                "<td class='toggler_icontd toggler_icontd_alignright'>" +
                                    "<a href='#'>" +
                                        "<img onclick='openStats(\"" + this.SubContestId + "\",\"" + cName + "\")' src='media/images/result_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td class='toggler_icontd iconbrd'>" +
                                    "<a href='#'>" +
                                        "<img onclick='remove(\"" + this.SubContestId + "\")' src='media/images/cross_icon.gif'/>" +
                                    "</a>" +
                                "</td>" +
                                "<td width=30>&nbsp;</td>" +
                            "</tr>" +
                        "</table>" +
                      "</div>" +
                      "<div id='t_" + this.SubContestId + "' class='toggler'>" +
                        "<div id='swap'>" +
                            "<img id='" + this.SubContestId + "' onclick='resize(\"" + this.SubContestId + "\")' src='media/images/neg.gif'/>" +
                        "</div>" +
                      "</div>" +
                      "<div id='acc_" + this.SubContestId + "' class='accordion' style='overflow: hidden; visibility: visible; opacity: 1;'>" +
                        "<div>" +
                            "<div id='swap'></div>" +
                            "<div>" +
                                "<table id='tab_" + this.SubContestId + "' width='100%' cellspacing='0' cellpadding='0' border='0'>";
            $.each(this.Event, function() {
                if (jQuery.inArray(this.EventId, arrayMyMatchesTennis) > -1) {
                    var teamHome = this.Home;
                    var teamAway = this.Away;
                    var tHome = this.Home;
                    var tAway = this.Away;
                    var m_firstqH, m_firstqA, m_secondqH, m_secondqA, m_thirdqH, m_thirdqA, m_fourthqH, m_fourthqA, m_fifthqH, m_fifthqA;
                    try {
                        if (int.Parse(this.ScoreHome1P) < 10)
                            m_firstqH = "&nbsp;&nbsp;" + this.ScoreHome1P;
                    } catch (e) { m_firstqH = this.ScoreHome1P }
                    try {
                        if (int.Parse(this.ScoreAway1P) < 10)
                            m_firstqA = "&nbsp;&nbsp;" + this.ScoreAway1P;
                    } catch (e) { m_firstqA = this.ScoreAway1P }
                    try {
                        if (int.Parse(this.ScoreHome2P) < 10)
                            m_secondqH = "&nbsp;&nbsp;" + this.ScoreHome2P;
                    } catch (e) { m_secondqH = this.ScoreHome2P }
                    try {
                        if (int.Parse(this.ScoreAway2P) < 10)
                            m_secondqA = "&nbsp;&nbsp;" + this.ScoreAway2P;
                    } catch (e) { m_secondqA = this.ScoreAway2P }
                    try {
                        if (e) (int.Parse(this.ScoreHome3P) < 10)
                        m_thirdqH = "&nbsp;&nbsp;" + this.ScoreHome3P;
                    } catch (e) { m_thirdqH = this.ScoreHome3P }
                    try {
                        if (e) (int.Parse(this.ScoreAway2P) < 10)
                        m_thirdqA = "&nbsp;&nbsp;" + this.ScoreAway2P;
                    } catch (e) { m_thirdqA = this.ScoreAway2P }
                    try {
                        if (int.Parse(this.ScoreHome4P) < 10)
                            m_fourthqH = "&nbsp;&nbsp;" + this.ScoreHome4P;
                    } catch (e) { m_fourthqH = this.ScoreHome4P }
                    try {
                        if (int.Parse(this.ScoreAway2P) < 10)
                            m_fourthqA = "&nbsp;&nbsp;" + this.ScoreAway2P;
                    } catch (e) { m_fourthqA = this.ScoreAway2P }
                    try {
                        if (int.Parse(this.ScoreHome5P) < 10)
                            m_fifthqH = "&nbsp;&nbsp;" + this.ScoreHome5P;
                    } catch (e) { m_fifthqH = this.ScoreHome5P }
                    try {
                        if (int.Parse(this.ScoreAway5P) < 10)
                            m_fifthqA = "&nbsp;&nbsp;" + this.ScoreAway5P;
                    } catch (e) { m_fifthqA = this.ScoreAway5P }
                    if (this.Pobednik == 1) {
                        teamHome = "<b>" + teamHome + "</b>";
                    } else if (this.Pobednik == 2) {
                        teamAway = "<b>" + teamAway + "</b>";
                    }

                    if (this.EventStarted) {
                        html = html + "<tr class='" + this.cssClassMinute + "'>" +
                                        "<td title='My Matches' align='center' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId +
                                        ");' class='star_selected'><img src='media/images/start_blue.png' alt='' ></td>" +
                                        "<td class='mtv'>";
                        if (this.Tv == 1) {
                            html = html + "<a onclick='refreshPageTV(\"liveOnTv\", \"" + this.EventId + "\", \"basketball\");' href='#'>" +
                                "<img alt='tv' src='media/images/tvicon.gif'/>" +
                              "</a>";
                        }
                        html = html + "</td><td class='" + this.cssClassSignal + "' style='border-right: medium none; width: 20px; text-align: right;'>";
                        if (this.Live) {
                            html = html + "<!-- ImageReady Slices (Untitled-1) -->" +
                                                    "<img src='media/images/second.gif' width='8' height='8' alt='' class='blkdot'>" +
                                                    "<!-- End ImageReady Slices -->";
                        }
                        html = html + "</td><td class='" + this.cssClassSignal + "'>" + this.Comment + "</td>" +
                                        "<td>" +
                                            "<table class='innertable'>" +
                                                "<tr>" +
                                                    "<td class='team2'>" + teamHome + "</td>" +
                                                    "<td class='team3'>" + m_firstqH + "&nbsp;&nbsp;" + m_secondqH + "&nbsp;&nbsp;" +
                                                        m_thirdqH + "&nbsp;&nbsp;" + m_fourthqH + "&nbsp;&nbsp;" + m_fifthqH + "</td>" +
                                                    "<td class='score1'>&nbsp;&nbsp;" + this.ScoreHome + "&nbsp;&nbsp;</td>" +
                                                "</tr>" +
                                                "<tr class='last'>" +
                                                    "<td class='team2'>" + teamAway + "</td>" +
                                                    "<td class='team3'>" + m_firstqA + "&nbsp;&nbsp;" + m_secondqA + "&nbsp;&nbsp;" +
                                                        m_thirdqA + "&nbsp;&nbsp;" + m_fourthqA + "&nbsp;&nbsp;" + m_fifthqA + "</td>" +
                                                    "<td class='score1'>&nbsp;&nbsp;" + this.ScoreAway + "&nbsp;&nbsp;</td>" +
                                                "</tr>" +
                                            "</table>" +
                                        "</td>" +
                                      "</tr>";
                    } else {
                        html = html + "<tr class='" + this.cssClassMinute + "'>" +
                                        "<td title='My Matches' align='center' valign='middle' id='star_" + this.EventId + "' onclick='myMatches(" + this.EventId +
                                        ");' class='star_selected'><img src='media/images/start_blue.png' alt='' ></td>" +
                                        "<td class='mtv'>";
                        if (this.Tv == 1) {
                            html = html + "<a onclick='refreshPageTV(\"liveOnTv\", \"" + this.EventId + "\", \"basketball\");' href='#'>" +
                                "<img alt='tv' src='media/images/tvicon.gif'/>" +
                              "</a>";
                        }
                        html = html + "</td><td class='" + this.cssClassSignal + "' style='border-right: medium none; width: 20px; text-align: right;'></td>" +
                                        "<td class='" + this.cssClassSignal + "'>" + this.Comment + "</td>" +
                                        "<td>" +
                                            "<table class='innertable'>" +
                                                "<tr>" +
                                                    "<td class='team2'>" + teamHome + "</td>" +
                                                    "<td class='team3'>" + m_firstqH + "&nbsp;&nbsp;" + m_secondqH + "&nbsp;&nbsp;" +
                                                        m_thirdqH + "&nbsp;&nbsp;" + m_fourthqH + "&nbsp;&nbsp;" + m_fifthqH + "</td>" +
                                                    "<td class='score1' rowspan='2'>" + this.ScoreHome + "</td>" +
                                                "</tr>" +
                                                "<tr class='last'>" +
                                                    "<td class='team2'>" + teamAway + "</td>" +
                                                    "<td class='team3'>" + m_firstqA + "&nbsp;&nbsp;" + m_secondqA + "&nbsp;&nbsp;" +
                                                        m_thirdqA + "&nbsp;&nbsp;" + m_fourthqA + "&nbsp;&nbsp;" + m_fifthqA + "</td>" +
                                                "</tr>" +
                                            "</table>" +
                                        "</td>" +
                                      "</tr>";
                    }
                }
            });
            html = html + "</table></div><div class='bottomMargin'/></div></div>";
            $("#accordians").append(html);
        }
    });
    if (arrayMyMatchesTennis.length == 0) {
        $("#accordians").empty();
        $("#accordians").append("<span style='font-size:14px'>No My Matches Selected</span>");
    }
    checkDoubleImages();
}

function checkMyMatches() {
    if (sport == "football") {
        $.each(arrayMyMatchesSoccer, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    } else if (sport == "basketball") {
        $.each(arrayMyMatchesBasketball, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    } else if (sport == "nfl") {
        $.each(arrayMyMatchesNFL, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    } else if (sport == "hockey") {
        $.each(arrayMyMatchesHockey, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    } else if (sport == "handball") {
        $.each(arrayMyMatchesHandball, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    } else if (sport == "volleyball") {
        $.each(arrayMyMatchesVolleyball, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    } else if (sport == "tennis") {
        $.each(arrayMyMatchesTennis, function() {
            if ($("#star_" + this).hasClass("star")) {
                jQuery($("#star_" + this)).attr('class', "star_selected");
                $("#star_" + this).html("<img src='media/images/start_blue.png' alt='blue_star'>");
            } else {
                jQuery($("#star_" + this)).attr('class', "star");
                $("#star_" + this).html("<img src='media/images/start_gray.png' alt='grey_star'>");
            }
        });
    }
}

function showMyMatchesAll(data, newFeed) {
    $("#accordians").empty();
    var dataAll = data;
    var jsonAllSports;
    if (data) {
        jsonAllSports = json_parse(data);
    } else {
        jsonAllSports = new Array();
        jsonAllSports[0] = { "football": jsonMyMatchesSoccer };
        jsonAllSports[1] = { "tennis": jsonMyMatchesTennis };
        jsonAllSports[2] = { "basketball": jsonMyMatchesBasketball };
        jsonAllSports[3] = { "hockey": jsonMyMatchesHockey };
        jsonAllSports[4] = { "volleyball": jsonMyMatchesVolleyball };
        jsonAllSports[5] = { "handball": jsonMyMatchesHandball };
        jsonAllSports[6] = { "nfl": jsonMyMatchesNfl };
    }
    $.each(jsonAllSports, function() {
        if (this.football) {
            showMyMatchesSoccer(this.football, newFeed);
        } else if (this.basketball) {
            mSport = "basketball";
            showMyMatchesBasketball(this.basketball, newFeed);
        } else if (this.tennis) {
            mSport = "tennis";
            showMyMatchesBasketball(this.tennis, newFeed);
        } else if (this.volleyball) {
            mSport = "volleyball";
            showMyMatchesBasketball(this.volleyball, newFeed);
        } else if (this.hockey) {
            mSport = "hockey";
            showMyMatchesBasketball(this.hockey, newFeed);
        } else if (this.handball) {
            mSport = "handball";
            showMyMatchesHandball(this.handball, newFeed);
        } else if (this.nfl) {
            mSport = "nfl";
            showMyMatchesBasketball(this.nfl, newFeed);
        }
    });
}
