﻿function toBase16(data)
{
    res = ""
    for (i = 0; i < data.length ; i++) 
    {
        res = res + data.charCodeAt(i).toString(16);
    
    
    }
    return res;

}

function fromBase16(data)
{
    var s = "";
    for(x = 0; x < data.length; x+=2)
    {
        substr = data.substr(x, 2);
        s = s + String.fromCharCode(parseInt(substr, 16));
    
    }

    return s;

}

function fromMVCFormat(data)
{
    return JSON.parse(fromBase16(data))
}

function toMVCFormat(data)
{
    return toBase16(JSON.stringify(data))
}

function postToServer(controller, method, data, returnfunction)
{
    $.post("/"+controller+"/"+method, {data:toMVCFormat(data)}, returnfunction);
}