﻿var $j = jQuery.noConflict();
$j(document).ready(function() {
    Concurrent.Thread.create(function() {
        getRating('arenaRating', 'Personal Rating');
    });
    Concurrent.Thread.create(function() {
        getRating('arenaPoints', 'ArenaPoints');
    });
    Concurrent.Thread.create(function() {
        getRating('honorPoints', 'Honor Points');
    });
    Concurrent.Thread.create(function() {
        getHotPackages('s7');
    });
});

function getRating(seriesType, typeName) {
    $j('#rating_loading').show();
    $j.ajax({
        url: '/ItemAjax.aspx?rd=' + Math.random(),
        type: 'get',
        data: 'operate=GetData&type=' + seriesType + '&typeName=' + typeName,
        dataType: 'json',
        success: function(data) {
            $j('#rating_loading').hide();
            if (data == null) {
                return;
            }
            var html = '<table width="100%" class="table_pl" style="font-size:12px; margin:0px;">\
                                <tr>\
                                  <th width="46%">' + typeName + '</th>\
                                  <th width="22%">Price</th>\
                                  <th width="32%">&nbsp;</th>\
                                </tr>';
            var products = data[0].Packagelist;
            for (var i = 0; i < products.length; i++) {
                html += '<tr>\
                                <td>' + products[i].Name + '</td>\
                                <td>$' + products[i].Price + '</td>\
                                <td align="right">\
                                    <form action="/ItemsOrderInfo.aspx" method="post">\
                                        <input type="hidden" name="price" value="' + products[i].Price + '" />\
                                        <input type="hidden" name="series" value="' + products[i].SeriesType + '" />\
                                        <input type="hidden" name="guid" value="' + products[i].Guid + '" />\
                                        <input type="hidden" name="name" value="' + data[0].DisplayName + '_' + products[i].Name.replace('|', ' ') + '" />\
                                        <input type="hidden" name="promotion" value="0" />\
                                        <input name="Submit359" type="submit" class="but_a" value="Buy Now">\
                                    </form>\
                                </td>\
                             </tr>';
            }
            $j('#div_' + typeName.replace(' ', '')).html(html);
        }
    });
}

function getHotPackages(seriesType) {
    $j('#hotPackages_loading').show();
    $j.ajax({
        url: '/ItemAjax.aspx?rd=' + Math.random(),
        type: 'get',
        data: 'operate=GetData&type=' + seriesType + '&typeName=Hot Packages',
        dataType: 'json',
        success: function(data) {
            $j('#hotPackages_loading').hide();
            if (data == null) {
                return;
            }
            var html = '';
            var products = data[0].Packagelist;
            for (var i = 0; i < products.length; i++) {
                html += '<div class="itbox">\
                                <div style="height: 125px;">\
                                <h5>' + products[i].Name + '</h5>\
                                <p>' + products[i].Summary + '</p>\
                                <h6>Price: $' + products[i].Price + '</h6>\
                                </div>\
                                <p>\
                                    <form action="/ItemsOrderInfo.aspx" method="post">\
                                        <input type="hidden" name="price" value="' + products[i].Price + '" />\
                                        <input type="hidden" name="series" value="' + products[i].SeriesType + '" />\
                                        <input type="hidden" name="guid" value="' + products[i].Guid + '" />\
                                        <input type="hidden" name="name" value="' + data[0].DisplayName + '_' + products[i].Name.replace('|', ' ') + '" />\
                                        <input type="hidden" name="promotion" value="0" />\
                                        <input name="Submit359" type="submit" class="newbut" value="Buy Now">\
                                    </form>\
                                </p>\
                              </div>';
            }
            $j('#div_HotPackages').html(html);
        }
    });
}
