﻿function buy_now(p, b, l) {
    $(b).attr("disabled", "disabled");
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/services/serverservice.asmx/buynow",
        data: "{p:" + p + ",c:'" + $(".currency.selected").text() + "',l:'" + l + "'}",
        dataType: "json",
        success: function(result) {
            if (result.d.error) {
                show_error(result.d.error);
                $(b).removeAttr("disabled");
            }

            window.location = "/checkout/";
        },
        error: function(b, a, c) { show_error("Error Occured!") }
    });
}

function show_error(msg) {
    alert(msg);
}

function get_currency_char() {
    switch ($(".currency.selected").text()) {
        case "USD":
            {
                return "$";
                break;
            }
        case "EUR":
            {
                return "€";
                break;
            }
        case "GBP":
            {
                return "£";
                break;
            }
    }
}

function changePrice(el, r, w) {
    var o = $.trim($(el).text());
    if (!($(el).data('usa'))) {
        $(el).data('usa', parseFloat(o.substring(1, o.length)));
    }
    $(el).text(get_currency_char() + Math.round($(el).data('usa') * r * w) / w);
};

function gc(c) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/services/quickshoppingservice.asmx/getrate",
        data: '{ c:"' + $(".currency.selected").text() + '" }',
        dataType: "json",
        success: function(b) {
            $('.total_price', '#p_list').each(function() {
                changePrice(this, b.d, 100)
            });
            $('.unit_price', '#p_list').each(function() {
                changePrice(this, b.d, 10000);
            })
        }
    });
}

$(document).ready(function() {
    $("span", $("#currency")).bind("click", function() {
        if ($(".currency.selected").text() == $(this).text()) {
            return;
        }
        $(".currency.selected").removeClass("selected");
        $(this).addClass("selected");
        gc($(this).text());
    })
});

$(document).ready(function() {
    var n = $("#news").html();
    $("#news").html($(".gamelist").html());
    $(".gamelist").html(n);
    if (typeof (LiveReceptionCode_isonline) != 'undefined' && LR_GetObj('LR_User_Icon0') != null) { if (LiveReceptionCode_isonline) LR_GetObj('LR_User_Icon0').innerHTML = '<a ' + LiveReceptionCode_BuildChatWin('Click here for live help', 'Click here for live help!') + '><img src="/images/livehelp.gif" border="0" width="254" height="65"></a>'; else LR_GetObj('LR_User_Icon0').innerHTML = '<a ' + LiveReceptionCode_BuildChatWin('Click here for live help', 'Click here for live help.') + '><img src="/images/livehelp.gif" border="0" width="254" height="65"></a>'; }
});
