// JavaScript Document
/**
 * Request.js
 * Works as a wraper for $.post
 * Usage: Request -  pass a link, for with to post data. Pass data in form of javascript object {property:value, property2:value2}, properties vil be visible vie $_POST in php
 *        Respond -  receives json encoded data. data should be an object with propery 'script', so that Respond tries to eval, the script inside (eg. {script:AddDigits(2, 2)}). Shows ErrorConsole on failure
 *
 * @revision 2009.03.02: (LO) Created
 * @copyright iMeal
 * @author Linas
 * @package iMeal
 *
 */

function Request(link, obj)
{
    $.post(link, obj, function(data){Respond(data)});
}

function Respond(data)
{
    if(!data)
        return;
    var oldData = data;
    
    try
    {
        data = $.evalJSON(data);
        eval(data.script);
    }
    catch(e)
    {
        ErrorConsole.Show(e.message, oldData);
    }
}

function ThrowError(msg)
{
    try
    {
        AjaxWaitingScreen.Hide();
    }
    catch(e)
    {
        
    }
    alert(msg);
}