/* QwwJs_Service
 * 
 * Part of the QlikWeb WorkBench Javascript Library (http://www.qlikwebworkbench.com)
 *
 * Copyright (c) 2007 Industrial CodeBox Ltd. All Rights Reserved.
 * http://www.industrialcodebox.com
 * Email support@industrialcodebox.com for licensing and support information.
 */
function QwwJs_Service(url)
{
    if(url){
        this.Url = url;
    }
    else{
        this.Url = "QWWService.ashx";
    }
            
    this.GetResponse = function(data, onCompleteHandler)
    {
        var res = "notset";
        
        if(!onCompleteHandler)
        {
            async = false;
            onCompleteHandler = function(d)
                                {                      
                                    res = d;
                                }
        }
        else{
            async = true;
        }
        
        var handler = function(httpObj, status)
        {
            onCompleteHandler(httpObj.responseText, status);
        }
        
        $.ajax(
        {
        url : this.Url,
        type : "POST",
        data : {msg : data},
        async : async,
        complete : handler
        });
        
        return res;
    };
};

function QwwJs_SimpleDataStoreService(url)
{
    var s = new QwwJs_Service(url);
    
    this.SetValue = function(key, value, onCompleteHandler)
    {
        var xml = "<service provider=\"storage\" method=\"set\"><payload><args key='" + key + "' value='" + value + "'/></payload></service>";
        s.GetResponse(xml, onCompleteHandler);
    };
    
    this.GetValue = function(key, onCompleteHandler)
    {
        var xml = "<service provider=\"storage\" method=\"get\"><payload><args key='" + key + "'/></payload></service>";
        var x = s.GetResponse(xml, onCompleteHandler);
        return x;
    };
};