SP.Reelzr.Controllers.controllers=new SP.Reelzr.Caching.CacheObject("ControllerCache");SP.Reelzr.Controllers.getController=function(controllerTypeName){var controllers=SP.Reelzr.Controllers.controllers;if(!controllers.containsKey(controllerTypeName)){var newController=eval("new SP.Reelzr.Controllers."+controllerTypeName+"('"+controllerTypeName+"')");controllers.add(controllerTypeName,newController)}return controllers.items[controllerTypeName]};SP.Reelzr.Controllers.AJAXController=function(A){this.init(A);this.JSONReady=new YAHOO.util.CustomEvent("JSONReady",this,false);this.HTMLReady=new YAHOO.util.CustomEvent("HTMLReady",this,false);this.TransactionComplete=new YAHOO.util.CustomEvent("TransactionComplete",this,false)};SP.Reelzr.Controllers.AJAXController.prototype={name:null,logger:null,init:function(A){this.name=A||"defaultController";this.logger=new YAHOO.widget.LogWriter(this.name+"Logger")},JSONReady:null,HTMLReady:null,unbind:function(A,B,C){A.unsubscribe(B,C);A.subscribers=A.subscribers.compact()},getJSON:function(C,B,A,E){var F={requestId:C,outputType:"JSON"};var D=new Ajax.Request(B,{method:E,parameters:JSON.stringify(A),onSuccess:(function(H,G){this.successful(H,G,F)}).bind(this),onComplete:(function(H,G){this.completed(H,G,F)}).bind(this),onFailure:(function(H,G){this.serverError(H,G,F)}).bind(this),onException:(function(H,G){this.clientError(H,G)}).bind(this),requestHeaders:["Content-Type","text/plain; charset=utf-8"]})},getHTML:function(C,B,A,E){var F={requestId:C,outputType:"HTML"};var D=new Ajax.Request(B,{method:E,parameters:A,onSuccess:(function(H,G){this.successful(H,G,F)}).bind(this),onComplete:(function(H,G){this.completed(H,G,F)}).bind(this),onFailure:(function(H,G){this.serverError(H,G,F)}).bind(this),onException:(function(H,G){this.clientError(H,G)}).bind(this)})},submitData:function(C,B,A,E){var F={requestId:C,outputType:"JSONTRANS"};var D=new Ajax.Request(B,{method:E,parameters:JSON.stringify(A),onSuccess:(function(H,G){this.successful(H,G,F)}).bind(this),onComplete:(function(H,G){this.completed(H,G,F)}).bind(this),onFailure:(function(H,G){this.serverError(H,G,F)}).bind(this),onException:(function(H,G){this.clientError(H,G)}).bind(this),requestHeaders:["Content-Type","text/plain; charset=utf-8"]})},onJSONReady:function(C,B){this.JSONReady.fire(C,B);var A=this.JSONReady.subscribers.find(function(D){return(D.obj.eventId==C)});if(A!=null){this.JSONReady.unsubscribe(A.fn,A.obj);this.JSONReady.subscribers=this.JSONReady.subscribers.compact()}},onHTMLReady:function(B,A){this.HTMLReady.fire(B,A)},onTransactionComplete:function(C,B){this.TransactionComplete.fire(C,B);var A=this.TransactionComplete.subscribers.find(function(D){return(D.obj.eventId==C)});if(A!=null){this.TransactionComplete.unsubscribe(A.fn,A.obj);this.TransactionComplete.subscribers=this.TransactionComplete.subscribers.compact()}else{this.logger.log("TransactionComplete Subscriber with asyncId "+C+" was not found in the list of "+this.TransactionComplete.subscribers.length+" subscribers.","error")}},successful:function(request,json,extraParams){switch(extraParams.outputType){case"JSON":var rpcWrapper=JSON.eval(request.responseText);var jsonObj=null;if(rpcWrapper.result instanceof Object){jsonObj=rpcWrapper.result}else{if(rpcWrapper.error){this.jsonRPCError(rpcWrapper.error);return }jsonObj=JSON.eval(rpcWrapper.result)}this.onJSONReady(extraParams.requestId,jsonObj);break;case"HTML":var html=request.responseText;this.onHTMLReady(extraParams.requestId,html);break;case"JSONTRANS":var rpcResult=JSON.eval(request.responseText);var transactionResult=null;if(rpcResult.result instanceof Object){transactionResult=rpcResult.result}else{if(rpcResult.error){this.jsonRPCError(rpcResult.error);return }transactionResult=JSON.eval(rpcResult.result);if(transactionResult.error&&transactionResult.error.length>0){this.logger.log("Transaction Error:  "+transactionResult.error,"error")}}this.onTransactionComplete(extraParams.requestId,transactionResult);break;case"XML":break}},doTimeout:function(){},jsonRPCError:function(A){this.logger.log("JSON RPC Error:"+A.message+"\nStack Trace: "+A.stackTrace,"error")},serverError:function(B,A,C){this.logger.log("AJAX Server Error:"+B.responseText,"error")},clientError:function(B,A){this.logger.log("AJAX Client Error:"+A.message+"\n"+A.fileName+"\n"+A.lineNumber+"\n"+A.stack,"error")},completed:function(B,A){},generateAsyncId:function(){return Math.random()}};