﻿///<reference path="jquery-1.3.2.js"/>

var webRoot = null;

function _getWebRoot() {
    /** Return directory of this relative to document URL. */
    if (webRoot != null) {
        return webRoot;
    }
    //derive the baseDir value by looking for the script tag that loaded this file
    $("head").children("[src*='jquery.custom.js']").each(function() {
        var src = this.src;
        index = src.indexOf("Scripts");
        webRoot = src.substring(0, index - 1);
    });

    return webRoot;
}
//init web root url
_getWebRoot();

$(this).ajaxError(function(a, b, c) {
    alert(a);
});
$(this).ajaxComplete(function(a, b, c) {
    //alert(a);
});

//获取session
$.extend({
    getSession: function(callback) {
        var url = webRoot + '/home/GetSession/';
        $.post(url, function(a, b, c) {
            var result = { UserName: '', GameName: '' };
            if (a != '') {
                result = JSON.parse(a)
            }
            callback(result);
        });
    }
});
//设置session
$.extend({
    createSession: function(data, callback) {
        var url = webRoot + '/home/CreateSession/';
        $.post(url, data, function(a, b, c) {
            var result = JSON.parse(a)
            callback(result);
        });
    }
});

