// ==== json ======================================================================================
json = new quick_class (
{
    // init vars
    request: Object,
    filename: String,
    instance: String,
    return_method: String,
    data: Object,
    
    // ==== init ==================================================================================
    // filename - the filename to send the request to
    // instance - the name of this instance (used when calling get_data)
    // ============================================================================================
    init: function(filename, instance)
    {
        // init vars
        this.request = this.get_request_object();
        this.filename = filename;
        this.instance = instance;
    },
    
    // ==== get_request_object ====================================================================
    get_request_object: function()
    {
        // get a valid request object if possible
        try {return new XMLHttpRequest()}
        catch (objException) {return new ActiveXObject('Microsoft.XMLHTTP')}
    },
    
    // ==== set_vars ==============================================================================
    // data - an object containing the name/value of the variables
    // ============================================================================================
    set_vars: function(data)
    {
        this.data = data;
    },
    
    // ==== get_vars ==============================================================================
    get_vars: function()
    {
        // get the variables set
        var result = '';
        for (var value in this.data)
            result += value + '=' + this.data[value] + '&';
        return result;
    },
    
    // ==== set_data ==============================================================================
    // return_method - the return method to return the found data to
    // ============================================================================================
    set_data: function(return_method) 
    {
        // store for later
        this.return_method = return_method;
        
        // set up the data, ready to post
        this.request.open('post', this.filename);
        this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        
        // define which function to be called on reply
        var temp_data = this.instance;
        this.request.onreadystatechange = function() {eval(temp_data + '.get_data()')};
        
        // send the data to the controller page
        this.request.send(this.get_vars());
    },
    
    // ==== get_data ==============================================================================
    get_data: function()
    {
        // make sure the xml is valid
        if (this.request.readyState != 4 || this.request.responseText == '')
            return;
        
        // retrieve the data from the server
        data = this.request.responseText;
        eval(this.return_method + '(data)');
    }
});