Controller=function(){};Controller.maxAttempts=3;Controller.maxRequests=7;Controller.requests=new Array(Controller.maxRequests);Controller.treeRequestObject=null;Controller.actions=new Array(Controller.maxRequests);Controller.attempts=new Array(Controller.maxRequests);Controller.scrollX,scrollY=-1;Controller.waitElement;Controller.getLoading=function(){var A=null;if(document.getElementById("loading_content")){A=document.getElementById("loading_content")}else{var B=new Element("div");B.id="loading";B.setHTML("loading...");B.injectBefore(document.body);A=$("loading")}return A};Controller.showLoading=function(){Controller.waitElement=Controller.getLoading();Controller.waitElement.style.display="block";window.addEvent("scroll",function(){var C;var A;if(typeof (window.pageYOffset)=="number"){C=window.pageYOffset;A=window.pageXOffset}else{if(document.body&&document.documentElement&&document.documentElement.scrollTop){C=document.documentElement.scrollTop;A=document.body.scrollLeft}else{if(document.body&&typeof (document.body.scrollTop)=="number"){C=document.body.scrollTop;A=document.body.scrollLeft}}}if(Controller.scrollX!=A||Controller.scrollY!=C){Controller.scrollX=A;Controller.scrollY=C;var B=document.body.clientWidth;Controller.waitElement.style.top=C+100+"px";Controller.waitElement.style.right=A+"px"}})};Controller.hideLoading=function(){Controller.waitElement=Controller.getLoading();var B;var A=true;for(B=0;B<Controller.requests.length;B++){if(Controller.requests[B]&&Controller.requests[B].running){A=false}}if(A){Controller.waitElement.style.display="none";window.removeEvents("scroll")}};Controller.cache=[];Controller.Feature=new Class({initialize:function(actions,options){var isTreeRequest=false;var notShowLoading=false;var checkIsLogged=false;var ignoreRequests=false;var chain=false;if(options){if(options.treeRequest&&options.treeRequest==1){isTreeRequest=true;notShowLoading=true}if(options.notShowLoading&&options.notShowLoading==1){notShowLoading=true}if(options.isLogged&&options.isLogged==1){checkIsLogged=true}if(options.ignoreRequests&&options.ignoreRequests==1){ignoreRequests=true;notShowLoading=true}}if(!actions.length){actions=[actions]}for(i in actions){if(typeof (actions[i])=="object"){if(typeof (actions[i].controllerId)=="undefined"&&actions[i].action!=null){actions[i].controllerId=actions[i].action;Controller.actions[actions[i].controllerId]=actions[i];Controller.attempts[actions[i].controllerId]=0}}}if(!notShowLoading){Controller.showLoading()}var requestsCount=0;var completedRequests=0;this.addEvent("endRequest",function(){completedRequests++;if(completedRequests>=requestsCount){Controller.hideLoading()}});for(i=0;i<actions.length;i++){if(actions[i].action!=null){requestsCount++}}if(isTreeRequest){if(Controller.treeRequestObject){Controller.treeRequestObject.cancel()}}else{if(!ignoreRequests){for(i=0;i<Controller.requests.length;i++){if(Controller.requests[i]){Controller.requests[i].cancel()}}}}if(checkIsLogged){var _actions=actions;var _options=options;var _index=indexURL;var checkAndExec={action:"ajaxRequests/checkLoggedIn.php",onComplete:function(response){if(response==1){var newOptions={};for(i in _options){if(i!="isLogged"){eval("newOptions."+i+" = "+_options[i]+";")}}new Feature(_actions,newOptions)}else{document.location=_index}}};new Feature(checkAndExec)}else{for(i=0;i<actions.length;i++){var action=actions[i].action;var parameters=actions[i].parameters;var form=actions[i].form;var cacheable=actions[i].cacheable;var overwriteCache=actions[i].overwriteCache;if(action!=null){if(action!=""){var _method="GET";var _body="";if(form!=null){_method="POST";_body=$(form).toQueryStringABA()}if(parameters!=null){_method="POST";if(_body!=""){_body+="&"}_body+=Object.toQueryStringABA(parameters)}var onCompleteFunction=actions[i].onComplete;var onFailureFunction=actions[i].onFailure;var controllerId=actions[i].controllerId;var obj=this;var _options=options;if(_options){_options.ignoreRequests="1"}var makeAjax=1;if(cacheable&&Controller.cache[action]){if(Controller.cache[action][_body]){this_cache=Controller.cache[action][_body];if(this_cache.onCompleteFunction){this_cache.onCompleteFunction(this_cache.response)}obj.fireEvent("endRequest");makeAjax=0}}if(makeAjax==1){var tmp=new Ajax(action,{postBody:_body,method:_method,onCompleteFunction:onCompleteFunction,onFailureFunction:onFailureFunction,controllerId:controllerId,evalScripts:true,onComplete:function(response){if(cacheable||overwriteCache){if(!Controller.cache[action]){Controller.cache[action]=[]}Controller.cache[action][_body]={onCompleteFunction:onCompleteFunction,response:response}}if(this.options.onCompleteFunction){this.options.onCompleteFunction(response)}obj.fireEvent("endRequest");Controller.actions[this.options.controllerId]=null},onFailure:function(){if(Controller.attempts[this.options.controllerId]++<Controller.maxAttempts){new Feature(Controller.actions[this.options.controllerId],_options)}else{obj.fireEvent("endRequest");if(this.options.onFailureFunction){this.options.onFailureFunction();if(Controller.nextAction!=null){new Feature(Controller.nextAction,Controller.nextOptions)}}else{alert("Ocorreu um erro durante a execução")}}}}).request();if(isTreeRequest){treeRequestObject=tmp}else{if(!ignoreRequests){Controller.requests[i]=tmp}}}}else{alert("Erro ao acessar a página")}}}}}});Controller.Feature.implement(new Events);var Feature=Controller.Feature;function checkRadio(B){var A=document.getElementsByName(B.name);for(i in A){if(A[i]){if(A[i].checked){A[i].checked="false"}}}B.checked="true"};
