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);
       
        if(json){
            //alert("calling this.operation with json data");
            //console.log("inside json switch");
            this.operation(json, this.element);
        }else{
           //alert("calling this.operation with non-json data");
            //console.log("calling the operation");
            this.operation(response, this.element);
        }
        
    },
    
    errorHandler: function(transport){
        alert(transport);
    }
    
});