﻿var entranceFee = false;
var dailyBonus = false;
var currentBounty = false;
var kingScore = false;
var toKing = false;
var toHost = true;
var toDonation = false;
var toBounty = false;

var isOptional = true;
var showCreate = false;
var isCreditsList = false;

var gameGuid;
var gamePlayLink;

function GetTopEarnedTable() {
    $.ajax({
        type: "POST",
        url: "webconnector.asmx/Get_User_Highest_Credits_Earned",
        //        data: "{'sortBy':'" + sortBy + "','isDescending':'" + isDescending + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            recieveTopEarnedTable(msg.d);
        },
        error: function (e) {
            //optional error handling
        }
    });
}

function recieveTopEarnedTable(data) {
    var obj = $.parseJSON(data);
    var shaded = true;
    var tableCount = 0;
    //Name, PlatformUserId, Score

    var table = '<div style="float:left; width:350px;"><div align="center" style="padding-bottom:10px"><b>Top Credits Earned</b></div>';

    $.each(obj, function (i) {
        try {

            if (obj[i].FirstName == null || obj[i].PlatformUserId == null || obj[i].PlatformId == null) {
                throw i + 1;
            }

            var tmpString = obj[i].FirstName;

            if (i < 4)
                table += '<div style="float:left;border: 0px grey dotted; border-bottom-width:2px; border-color:#dddddd; width:100%;';
            else
                table += '<div style="float:left; width:100%;';
            table += '">' + '<div style="float:left; padding-right:5px; padding-top:6px;"><img src="images/PlacedPics/' + i + '.png" width:25px; height=25px; alt="profile"/></div>';
            table += '<div class="FeedPic"><a href="http://www.facebook.com/' + obj[i].PlatformUserId + '"><img src="http://graph.facebook.com/' + obj[i].PlatformUserId + '/picture" width:30px; height=30px; alt="profile"/></a></div>';
            table += '<div style="float:left; width:160px; font-size:14px; padding-top:10px; margin-left:5px;"><a href="http://www.facebook.com/' + obj[i].PlatformUserId + '">' + CheckStringLength(tmpString, 25) + '</a></div>';
            table += '<div style="float:right; font-size:14px; padding-top:10px;">' + obj[i].CreditsEarned + '</div>';
            table += '</div>';
            tableCount++;
        } catch (err) {
            Log_Exception(err);

            if (i < 4)
                table += '<div style="float:left;border: 0px grey dotted; border-bottom-width:2px; border-color:#dddddd; width:100%; height:40px;">Unable to find Player Rank ' + err.toString() + ' at this Time</div>';
            else
                table += '<div style="float:left; width:100%; height:40px;">Unable to find Player at this Time</div>';

            tableCount++;
        }
    });

    table += '</div>';

    if (tableCount > 0) {
        $('#TopEarnedTable').html('');
        $('#TopEarnedTable').append(table);
    }
    else {
        var table = '<div style="float:left; width:300px; height:170px;">';
        table += '<div style ="float:left"; align="center">Unable to get table info</div></div>';
        $('#TopEarnedTable').html('');
        $('#TopEarnedTable').append(table);
    }

    //changing mouse cursor to pointer on clickable
    $('a').hover(function () {
        2.
        $(this).css('cursor', 'pointer');
        3.
    }, function () {
        4.
        $(this).css('cursor', 'auto');
        5.
    });


}

