var app = app || {};
app.Services = app.Services || {
    //baseUrl: "http://test.api.mackolik.com/footballapi/",
    baseUrl: "http://goal.cdn.md/footballapi/",
    requestRetryCount: 0,
    makeRequest: function (request, serviceCallback, uiCallback) {
        request.APP = 1020;
        request.tZ = -(new Date().getTimezoneOffset() / 60.0);
        request.lang = Settings.getLanguage().id;
        console.log(JSON.stringify(request));
        $.ajax({
            url: this.baseUrl + "Mobile/Default.aspx?d=" + JSON.stringify(request),
            dataType: "json",
            global: !(request.T == 200 || (request.T == 7 && request.isRefresh))
        }).done(function(data) {
            if (data.eRR) {
                if (app.Services.requestRetryCount < 2) {
                    app.Services.requestRetryCount += 1;
                    makeRequest(request, serviceCallback, uiCallback);
                } else {
                    alert("Connection error, would you like to try again?");
                    app.Services.requestRetryCount = 0;
                }
            } else {
                app.Services.requestRetryCount = 0;
                serviceCallback(data, request, uiCallback);
            }
        });
    }   
};

$.ajaxSetup({
    xhrFields: {
        mozSystem: true
    }
});

$(document).bind("ajaxSend", function () {
    $("#loading").show();
}).bind("ajaxComplete", function () {
    $("#loading").hide();
});



