var VelocityAjax =  {

	doCall : function(actionId, methodName)
	{
		var parms = "__ajax=" + actionId;
		parms += "&__method=" + encodeURIComponent(methodName);
		for(var a=2; a < arguments.length; a++)
		{
			parms += "&__arg" + (a - 2) + "=" + encodeURIComponent(arguments[a]);
		}
		
		var url = window.location.href;
		url = url.replace(window.location.hash, "");
		url = url.replace(window.location.search, "");

        var oAjax = new Ajax.Request( 
	            url + "?" + parms, 
                {   
                	method: 'get', 
                    asynchronous: false
                } 
            );	
            
        return oAjax.transport.responseText;
	},

   /**
   	* Get an URL with the specified request params and id
    */
    doGet : function(url, requestParam, id)
    {          
        //alert("doGet("+ url + "," +requestParam + ",", +id +")");
        var oAjax = new Ajax.Request( 
             url, 
                {   method: 'get', 
                    parameters: requestParam, 
                    onComplete: VelocityAjax._handleAjaxRequest.bind(this, id)
                } 
            );
    },    
    
    /*
     *
     */
    doPost : function(url, requestParam, id)
    {          
        var oAjax = new Ajax.Request( 
             url, 
                {   method: 'post', 
                    parameters: requestParam, 
                    onComplete: VelocityAjax._handleAjaxRequest.bind(this, id)
                } 
            );
    },    

    /*
     *
     */
    doSubmitForm : function(formId, url, id)
    {
		//alert("doSubmitForm(" + formId + "," + url + "," + id + ")");
    	var oForm = $(formId);
    	var pars = Form.serialize(oForm);
    	this.doPost(url, pars, id);       
    },

    /**
     * Handle the response by adding an extra element
     */
    _handleAjaxRequest: function(id, request)
    {
        //alert("_handleAjaxRequest(" + id + "," + request + ")");
        Element.Methods.update($(id), request.responseText);
    }
};
