
var apiURL = 'http://gra.archipelagmatematyki.pl/CommunicationService.svc';
var APIHelper = function () {
    return {
        saveResult: function (score, percent, callback) {
            if (!sessionId) {
                // offline mode. skip post
                return false;
            }
            var hash = CryptoJS.MD5(sessionId + score + percent).toString();
            var ajaxURL = [apiURL, 'saveresult', sessionId, score, percent].join('/');
            $.ajax({
                url: ajaxURL + '?hash=' + hash,
                 data:{
                  hash:hash
                },
                success: callback
            });
        },
        getHighscores: function (callback) {
            if (!sessionId) {
                // offline mode. skip and send false to callback function
                callback(false);
                return false;
            }
            var ajaxURL = [apiURL, 'gettopscores', sessionId].join('/');
            $.ajax({
                url: ajaxURL,
                success: callback
            });
        }
    }
}