var Ejax = Class.create(Enumerable, {
  
    initialize: function(elementId, referenceKey, reqLocation, action) {
        
        this.element = $(elementId);
        this.referenceKey = referenceKey;
        this.reqLocation = reqLocation;
        this.operation=action;
        
    },
    
    call: function(params) {
          params.set("ejaxKey", this.referenceKey);
          new Ajax.Request(this.reqLocation, {parameters:params.toObject(), onSuccess:this.process.bind(this), onFailure:this.errorHandler.bind(this)});  
    },
    
    process: function(transport, json){
        
        var response=eval(transport.responseText);
        //alert("inside process");
        if(json){
            //console.log("inside json switch");
            this.operation(json, this.element);
        }else{
            //console.log("calling the operation");
            this.operation(response, this.element);
        }
        
    },
    
    errorHandler: function(transport){
        alert(transport);
    }
    
});
