var AjaxReq = new Class({

    initialize: function(BASEPATH)
    {
        //console.log("AjaxReq object inited");
            
        this.reqObj = new Request({     method: 'post', 
                                        url: BASEPATH + 'ajax.php',
                                        link: 'chain',
                                        onSuccess: this._completeHandler.bind(this)
                                    });
        
        this.BASEPATH = BASEPATH;
        
        return true;
        
    },
    
    _completeHandler: function(responseText)
    {
        if(responseText.match("ERROR:"))
        {
            // an error has occurred on the server, therefore display error message
            Page.showError(responseText.replace("ERROR:", ""));
            
            return false;
        }
        
        // success!  check for custom success handler
        if(this._customComplete !== false)
            return this._customComplete.attempt(responseText);
        
        // otherwise just refresh this page
        //window.location.href = window.location.href;
        
        return true;
            
        
                
    },
    
    
    send: function(action, JSONparams, completeHandler)
    {
        if(!JSONparams)
            JSONparams = "";
            
        if(completeHandler)
            this._customComplete = completeHandler;
        else
            this._customComplete = false;
        
        this.reqObj.send({      'data': 'action=' + action + '&JSONdata=' + JSONparams
                        });
        
        return true; 
    
    }
    
});
