﻿function createLiveBettingHTML(data) {
    var time = "";
    var domacin = "";
    var gost = "";
    var komentar = "";
    var specid = "";
    jQuery.each(data.Matches, function() {
        try {
            time = this.Datum.split("T")[1].substr(0, 5);
            domacin = this.domacin;
            gost = this.gost;
            komentar = this.Komentar;
        } catch (err) {
        }
        $("#ulLiveBetting").append("<li><a href='/ponuda/kvote.html?sport=football&spec=" + jQuery.trim(domacin) + "-" + jQuery.trim(gost) 
            + "'><strong>" + domacin + " - " + gost + "</strong><br />" +
            komentar + " " + time + "</a></li>");
    });
}

function createNagradeHTML(data) {
    var html = "";
    html += "<b>" + data.Naslov + "</b>";
    html += "<br />";
    html += "<table border='0' cellSpacing='1' cellPadding='1' width='250'><tr><th>Broj kartice</th><th>Nagrada</th></tr>";
    jQuery.each(data.Nagrade, function() {
        html += "<tr><td>" + this.Kartica + "</td><td>" + this.Nagrada + "</td></tr>";
    });

    html += "</table>";
    return html;
}

function createTopTenHTML(data) {
    var counter = 0;
    var date = "";
    var time = "";
    var sum = data.Count;
    var kvota = "";
    var domacin = "";
    var gost = "";
    jQuery.each(data.Matches, function() {
        try {
            counter++;
            date = this.Datum.split("T")[0];
            time = this.Datum.split("T")[1].substr(0, 5);
            kvota = "";
            domacin = this.domacin;
            gost = this.gost;
            if (this.b_jedan == "true") {
                kvota = domacin + "(1) - " + this.jedan;
            } else if (this.b_iks == "true") {
                kvota = domacin + "(X) - " + this.iks;
            } else {
                kvota = gost + "(2) - " + this.dva;
            }
        } catch (err) {
        }
        if (counter == 1) {
            $("#ulTopTen").append("<li style='position: absolute; top: 0px; left: 0px; display: block;' title='" + counter + " od " + sum + "// Top 10 - Kvote'>" +
                                "<div class='Top 10 - Kvote'>" +
"<p><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport= " + this.SportID.toLowerCase()
                                   + "&country=" + 
                                        this.Country + "&id="+ this.ContestID + "'>" +
                                    kvota + "</a><br /><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" 
                                    + this.SportID.toLowerCase() + "&country=" +
                                        this.Country + "&id=" + this.ContestID + "'>" +
                                    "(" + domacin + " - " + gost + ")</a><br /><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" 
                                    + this.SportID.toLowerCase() + "&country=" +
                                        this.Country + "&id=" + this.ContestID + "'>" +
                                    date + " u " + time + "</a></p>" +
                                  "<span class='author'></span> <a href='#'>www.atlantik.rs</a> </div>" +
                              "</li>");
            $("#slTopKvote").append("<div class='Top 10 - Kvote' style='float:left; margin-left:20px; margin-top:20px'>" +
"<p><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" 
                                  + this.SportID.toLowerCase() + "&country=" 
                                    + this.Country + "&id=" + this.ContestID + "'>" +
                                    kvota + "</a><br /><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" 
                                    + this.SportID.toLowerCase() + "&country=" +
                                        this.Country + "&id=" + this.ContestID + "'>" +
                                    date + " u " + time + "</a></p>");
        }
        else {
            $("#ulTopTen").append("<li style='position: absolute; top: 0px; left: 0px; display: none;' title='" + counter + " od " + sum + "// Top 10 - Kvote'>" +
                                "<div class='Top 10 - Kvote'>" +
"<p><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" + this.SportID.toLowerCase() 
                                  + "&country=" + this.Country + "&id=" + this.ContestID + "'>" +
                                    kvota + "</a><br /><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" 
                                    + this.SportID.toLowerCase() + "&country=" +
                                        this.Country + "&id=" + this.ContestID + "'>" +
                                    "(" + domacin + " - " + gost + ")</a><br /><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport="
                                    + this.SportID.toLowerCase() + "&country=" +
                                        this.Country + "&id=" + this.ContestID + "'>" +
                                    date + " u " + time + "</a></p>" +
                                  "<span class='author'></span> <a href='#'>www.atlantik.rs</a> </div>" +
                              "</li>");
            $("#slTopKvote").append("<div class='Top 10 - Kvote' style='float:left; margin-left:20px; margin-top:20px'>" +
"<p><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport=" + this.SportID.toLowerCase() 
                                  + "&country=" + this.Country + "&id=" + this.ContestID + "'>" +
                                    kvota + "</a><br /><a style='font-weight:bold;color:#999999;text-decoration:none;' href='/ponuda/kvote.html?sport="
                                    + this.SportID.toLowerCase() + "&country=" +
                                        this.Country + "&id=" + this.ContestID + "'>" +
                                    date + " u " + time + "</a></p>");
        }
    });
}

function createListeHTML(data) {
    jQuery.each(data.Liste, function() {
        $("#ulListe").append("<li><a href='Liste/" + this.Name + "' target='_blank'>" + this.Name + "</a></li>");
        $("#slLista").append("<a href='Liste/" + this.Name + "' target='_blank'>" + this.Name + "</a>");
    });
}

function createTickerHTML(data) {
    $("#ticker").empty();
    jQuery.each(data.Tickers, function() {
        $("#ticker").append("<p>" + this.Home + " - " + this.Away + "<br />" + this.HScore + "-" + this.AScore + "</p>");
    });
}

function createTickerBigHTML(data) {
    $("#ticker").empty();
    jQuery.each(data.Tickers, function() {
    $("#ticker").append("<li><a href='#' style='text-align:center'><strong>" + this.Home + " - " + this.Away + "</strong><br /><strong>"
        + this.HScore + " - " + this.AScore + "</strong></a></li>");
    });
}

function createScoresHTML(data) {
    var html = "";
    switch (data.Sport.Name) {
        case "Football":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var rezultat = "";
                        var rezultat1P = "";
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="180" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="126" style="text-align:center">' + rezultat + ' (' + rezultat1P + ')</td>';
                        } else {
                            html = html + '<td width="126" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="180">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "Basketball":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var h2 = this.HomeScore2P;
                        var a2 = this.AwayScore2P;
                        var h3 = this.HomeScore3P;
                        var a3 = this.AwayScore3P;
                        var h4 = this.HomeScore4P;
                        var a4 = this.AwayScore4P;
                        var h5 = this.HomeScore5P;
                        var a5 = this.AwayScore5P;
                        var rezultat = "";
                        var rezultat1P = "";
                        var rezultat2P = "";
                        var rezultat3P = "";
                        var rezultat4P = "";
                        var rezultat5P = "";
                        var periodsExists = false;
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h2 == "" && a2 == "") {
                            rezultat2P = "";
                        } else {
                            rezultat2P = h2 + ":" + a2;
                        }
                        if (h3 == "" && a3 == "") {
                            rezultat3P = "";
                        } else {
                            rezultat3P = h3 + ":" + a3;
                        }
                        if (h4 == "" && a4 == "") {
                            rezultat4P = "";
                        } else {
                            rezultat4P = h4 + ":" + a4;
                        }
                        if (h5 == "" && a5 == "") {
                            rezultat5P = "";
                        } else {
                            rezultat5P = h5 + ":" + a5;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        if (rezultat2P != "")
                            rezultat1P += ",";
                        if (rezultat3P != "")
                            rezultat2P += ",";
                        if (rezultat4P != "")
                            rezultat3P += ",";
                        if (rezultat5P != "")
                            rezultat4P += ",";
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="160" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="226" style="text-align:center">' + rezultat 
                            + ' (' + rezultat1P + rezultat2P + rezultat3P + rezultat4P + rezultat5P + ')</td>';
                        } else {
                            html = html + '<td width="226" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="160">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "Handball":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="180" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="126" style="text-align:center">' + this.HomeScore + ' - ' + this.AwayScore + '</td>';
                        } else {
                            html = html + '<td width="126" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="180">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "Hockey":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var h2 = this.HomeScore2P;
                        var a2 = this.AwayScore2P;
                        var h3 = this.HomeScore3P;
                        var a3 = this.AwayScore3P;
                        var h4 = this.HomeScore4P;
                        var a4 = this.AwayScore4P;
                        var h5 = this.HomeScore5P;
                        var a5 = this.AwayScore5P;
                        var rezultat = "";
                        var rezultat1P = "";
                        var rezultat2P = "";
                        var rezultat3P = "";
                        var rezultat4P = "";
                        var rezultat5P = "";
                        var periodsExists = false;
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h2 == "" && a2 == "") {
                            rezultat2P = "";
                        } else {
                            rezultat2P = h2 + ":" + a2;
                        }
                        if (h3 == "" && a3 == "") {
                            rezultat3P = "";
                        } else {
                            rezultat3P = h3 + ":" + a3;
                        }
                        if (h4 == "" && a4 == "") {
                            rezultat4P = "";
                        } else {
                            rezultat4P = h4 + ":" + a4;
                        }
                        if (h5 == "" && a5 == "") {
                            rezultat5P = "";
                        } else {
                            rezultat5P = h5 + ":" + a5;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        if (rezultat2P != "")
                            rezultat1P += ",";
                        if (rezultat3P != "")
                            rezultat2P += ",";
                        if (rezultat4P != "")
                            rezultat3P += ",";
                        if (rezultat5P != "")
                            rezultat4P += ",";
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="160" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="226" style="text-align:center">' + rezultat
                            + ' (' + rezultat1P + rezultat2P + rezultat3P + rezultat4P + rezultat5P + ')</td>';
                        } else {
                            html = html + '<td width="226" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="160">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "Tennis":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var h2 = this.HomeScore2P;
                        var a2 = this.AwayScore2P;
                        var h3 = this.HomeScore3P;
                        var a3 = this.AwayScore3P;
                        var h4 = this.HomeScore4P;
                        var a4 = this.AwayScore4P;
                        var h5 = this.HomeScore5P;
                        var a5 = this.AwayScore5P;
                        var rezultat = "";
                        var rezultat1P = "";
                        var rezultat2P = "";
                        var rezultat3P = "";
                        var rezultat4P = "";
                        var rezultat5P = "";
                        var periodsExists = false;
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h2 == "" && a2 == "") {
                            rezultat2P = "";
                        } else {
                            rezultat2P = h2 + ":" + a2;
                        }
                        if (h3 == "" && a3 == "") {
                            rezultat3P = "";
                        } else {
                            rezultat3P = h3 + ":" + a3;
                        }
                        if (h4 == "" && a4 == "") {
                            rezultat4P = "";
                        } else {
                            rezultat4P = h4 + ":" + a4;
                        }
                        if (h5 == "" && a5 == "") {
                            rezultat5P = "";
                        } else {
                            rezultat5P = h5 + ":" + a5;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        if (rezultat2P != "")
                            rezultat1P += ",";
                        if (rezultat3P != "")
                            rezultat2P += ",";
                        if (rezultat4P != "")
                            rezultat3P += ",";
                        if (rezultat5P != "")
                            rezultat4P += ",";
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="160" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="226" style="text-align:center">' + rezultat
                            + ' (' + rezultat1P + rezultat2P + rezultat3P + rezultat4P + rezultat5P + ')</td>';
                        } else {
                            html = html + '<td width="226" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="160">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "Volleyball":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var h2 = this.HomeScore2P;
                        var a2 = this.AwayScore2P;
                        var h3 = this.HomeScore3P;
                        var a3 = this.AwayScore3P;
                        var h4 = this.HomeScore4P;
                        var a4 = this.AwayScore4P;
                        var h5 = this.HomeScore5P;
                        var a5 = this.AwayScore5P;
                        var rezultat = "";
                        var rezultat1P = "";
                        var rezultat2P = "";
                        var rezultat3P = "";
                        var rezultat4P = "";
                        var rezultat5P = "";
                        var periodsExists = false;
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h2 == "" && a2 == "") {
                            rezultat2P = "";
                        } else {
                            rezultat2P = h2 + ":" + a2;
                        }
                        if (h3 == "" && a3 == "") {
                            rezultat3P = "";
                        } else {
                            rezultat3P = h3 + ":" + a3;
                        }
                        if (h4 == "" && a4 == "") {
                            rezultat4P = "";
                        } else {
                            rezultat4P = h4 + ":" + a4;
                        }
                        if (h5 == "" && a5 == "") {
                            rezultat5P = "";
                        } else {
                            rezultat5P = h5 + ":" + a5;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        if (rezultat2P != "")
                            rezultat1P += ",";
                        if (rezultat3P != "")
                            rezultat2P += ",";
                        if (rezultat4P != "")
                            rezultat3P += ",";
                        if (rezultat5P != "")
                            rezultat4P += ",";
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="160" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="226" style="text-align:center">' + rezultat
                            + ' (' + rezultat1P + rezultat2P + rezultat3P + rezultat4P + rezultat5P + ')</td>';
                        } else {
                            html = html + '<td width="226" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="160">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "NFL":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var h2 = this.HomeScore2P;
                        var a2 = this.AwayScore2P;
                        var h3 = this.HomeScore3P;
                        var a3 = this.AwayScore3P;
                        var h4 = this.HomeScore4P;
                        var a4 = this.AwayScore4P;
                        var h5 = this.HomeScore5P;
                        var a5 = this.AwayScore5P;
                        var rezultat = "";
                        var rezultat1P = "";
                        var rezultat2P = "";
                        var rezultat3P = "";
                        var rezultat4P = "";
                        var rezultat5P = "";
                        var periodsExists = false;
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h2 == "" && a2 == "") {
                            rezultat2P = "";
                        } else {
                            rezultat2P = h2 + ":" + a2;
                        }
                        if (h3 == "" && a3 == "") {
                            rezultat3P = "";
                        } else {
                            rezultat3P = h3 + ":" + a3;
                        }
                        if (h4 == "" && a4 == "") {
                            rezultat4P = "";
                        } else {
                            rezultat4P = h4 + ":" + a4;
                        }
                        if (h5 == "" && a5 == "") {
                            rezultat5P = "";
                        } else {
                            rezultat5P = h5 + ":" + a5;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        if (rezultat2P != "")
                            rezultat1P += ",";
                        if (rezultat3P != "")
                            rezultat2P += ",";
                        if (rezultat4P != "")
                            rezultat3P += ",";
                        if (rezultat5P != "")
                            rezultat4P += ",";
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="160" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="226" style="text-align:center">' + rezultat
                            + ' (' + rezultat1P + rezultat2P + rezultat3P + rezultat4P + rezultat5P + ')</td>';
                        } else {
                            html = html + '<td width="226" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="160">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
        case "Waterpolo":
            {
                jQuery.each(data.Leagues, function() {
                    html = "";
                    html = html + '<div class="intro_longer2"><span class="intro_longer"><strong>' + this.League + '</strong></span>' +
                      '<p><br />' +
	                      '</p>' +
                          '<ul class="skills">' +
                            '<li class="intro_longer2">' +
                              '<table width="658" height="29" border="1">';
                    jQuery.each(this.Events, function() {
                        var h = this.HomeScore;
                        var a = this.AwayScore;
                        var h1 = this.HomeScore1P;
                        var a1 = this.AwayScore1P;
                        var h2 = this.HomeScore2P;
                        var a2 = this.AwayScore2P;
                        var h3 = this.HomeScore3P;
                        var a3 = this.AwayScore3P;
                        var h4 = this.HomeScore4P;
                        var a4 = this.AwayScore4P;
                        var h5 = this.HomeScore5P;
                        var a5 = this.AwayScore5P;
                        var h6 = this.HomeScore6P;
                        var a6 = this.AwayScore6P;
                        var rezultat = "";
                        var rezultat1P = "";
                        var rezultat2P = "";
                        var rezultat3P = "";
                        var rezultat4P = "";
                        var rezultat5P = "";
                        var rezultat6P = "";
                        var periodsExists = false;
                        if (h1 == "" && a1 == "") {
                            rezultat1P = "";
                        } else {
                            rezultat1P = h1 + ":" + a1;
                            periodsExists = true;
                        }
                        if (h2 == "" && a2 == "") {
                            rezultat2P = "";
                        } else {
                            rezultat2P = h2 + ":" + a2;
                        }
                        if (h3 == "" && a3 == "") {
                            rezultat3P = "";
                        } else {
                            rezultat3P = h3 + ":" + a3;
                        }
                        if (h4 == "" && a4 == "") {
                            rezultat4P = "";
                        } else {
                            rezultat4P = h4 + ":" + a4;
                        }
                        if (h5 == "" && a5 == "") {
                            rezultat5P = "";
                        } else {
                            rezultat5P = h5 + ":" + a5;
                        }
                        if (h6 == "" && a6 == "") {
                            rezultat6P = "";
                        } else {
                            rezultat6P = h6 + ":" + a6;
                        }
                        if (h == "" && a == "") {
                            rezultat = "";
                        } else {
                            rezultat = h + ":" + a;
                        }
                        if (rezultat2P != "")
                            rezultat1P += ",";
                        if (rezultat3P != "")
                            rezultat2P += ",";
                        if (rezultat4P != "")
                            rezultat3P += ",";
                        if (rezultat5P != "")
                            rezultat4P += ",";
                        if (rezultat6P != "")
                            rezultat5P += ",";
                        html = html + '<tr>' +
                                  '<td width="60">' + this.StartTime + '</td>' +
                                  '<td width="160" class="box">' + this.Home + '</td>';
                        if (this.Started) {
                            html = html + '<td width="226" style="text-align:center">' + rezultat
                            + ' (' + rezultat1P + rezultat2P + rezultat3P + rezultat4P + rezultat5P + rezultat6P + ')</td>';
                        } else {
                            html = html + '<td width="226" style="text-align:center"> - </td>';
                        }
                        html = html + '<td width="160">' + this.Away + '</td>' +
                                  '<td width="100">' + this.Comment + '</td>' +
                                '</tr>';
                    });
                    html = html + '</table>' +
		                    '</li>' +
                          '</ul>' +
	                    '</div>'

                    $("#container").append(html);
                });
                break;
            }
    }
}

function createSportLeaguesHTML(data){
    jQuery.each(data.Sports, function() {
        var sport = this.Sport;
        jQuery.each(this.Leagues, function(){
            if(sport == 2){
                $("#pBasketball").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=basketball">' + this.Name + '</a>');
            } else if(sport == 4){
                $("#pHockey").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=hockey">' + this.Name + '</a>');
            } else if(sport == 7){
                $("#pHandball").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=handball">' + this.Name + '</a>');
            } else if(sport == 8){
                $("#pWaterpolo").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=waterpolo">' + this.Name + '</a>');
            } else if(sport == 9){
                $("#pTennis").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=tennis">' + this.Name + '</a>');
            } else if(sport == 10){
                $("#pWaleyball").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=volleyball">' + this.Name + '</a>');
            } else if(sport == 12){
                $("#pNfl").append('<a href="ponuda/kvote.html?id=' + this.ID + '&country=' + this.Country + '&sport=nfl">' + this.Name + '</a>');
            }
        });
    });
}

function createOddsForMayors(data){
    jQuery.each(data.Odds, function() {
        $("#" + this.TeamID).html(this.Name + " " + parseFloat(this.Odd).toFixed(2));
    });
}

function createBonusiHTML(data)
{
    $("#divLogin").show("slow");
    $("#imgLogin").show("slow");
    $("#login").hide("slow");
    $("#divLogin").empty();
    var html = '<ul>' +
                  '<li><strong id="Ime">' + data.User.Ime + '</strong><br/>' +
                    'Broj Vaših bodova je: ' + data.User.MemberPoints + 
                  '</li><br/>' +
                  '<li><strong>Kuponi</strong><br/>' +          
                    'Ukupno ostvareno: ' + data.User.Ukupno + '</li>' +
                    'Za podizanje: ' + data.User.Spremno + '</a></li><br/>' +
                  //'<li><a href="javascript:poptastic(\'preuzeto.html\');">Preuzeto: ' + data.User.Preuzeto + '</a></li><br/>' +
                  '<li><a href="#">Preuzeto: ' + data.User.Preuzeto + '</a></li><br/>' +
                  '<li><strong>Prize money</strong><br/>' +            
                    'Vrednost: ' + ThousandSeparator(2,data.User.PrizeValue) + ' din</li>' +
                    'Odigrano: ' + ThousandSeparator(2,data.User.Payed) + ' din</li><br/>' +
                    'Preostalo: ' + ThousandSeparator(2,data.User.Preostalo) + ' din</li><br/><br/>' +    
                  '<li><a href="javascript:logoutAction();">LOGOUT</a></li><br/>' +                                                             
                '</ul>';
    $("#divLogin").append(html);
    
}

function ThousandSeparator(decimalDigits, Value) {
	var separatorLength = 3;
	var OriginalValue = Value;
	var TempValue = "" + OriginalValue;
	var NewValue = "";
	var pStr;
	var dStr;

	if (TempValue.indexOf('.') == -1) {
		TempValue += ".";
	}

	dStr = TempValue.substr(0, TempValue.indexOf('.'));
	pStr = TempValue.substr(TempValue.indexOf('.'));

	while (pStr.length - 1 < decimalDigits) { pStr += "0" }
	if (pStr == ".") {
		pStr = "";
	}
	if (dStr.length > separatorLength) {
		while (dStr.length > separatorLength) {
			NewValue = "," + dStr.substr(dStr.length - separatorLength) + NewValue;
			dStr = dStr.substr(0, dStr.length - separatorLength);
		}
		NewValue = dStr + NewValue;
	} else {
		NewValue = dStr;
	}
	NewValue = NewValue + pStr;
	return NewValue;
}
	