if(!window.Processing){
	window.Processing = {
	
		ignoredURLS: {},
		timerInterval: null,
	
		initialize: function(){
			Ajax.Responders.register(this);
			this.addIgnoredURL("/cities.generatedJS");
			this.addIgnoredURL("/hospitals.generatedJS");
			this.addIgnoredURL("/validateUserName.action");
			this.addIgnoredURL("/validateCPF.action");
			this.addIgnoredURL("/validateCep.action");
			this.addIgnoredURL("/validateCRM.action");

			Event.observe(window, "load", function(){
				if($("fundo_loading") == null){
					throw new Error("Inclua /pages/processing.jsp");
				}
				if(Prototype.Browser.IE){
					try{
						$("fundo_loading").show();
						$("plano_loading").show();
						$("fundo_loading").clonePosition($("content"));
						$("plano_loading").clonePosition($("content"));
					}catch(e){
						// Problemas no IE
					}finally{
						$("fundo_loading").hide();
						$("plano_loading").hide();
					}
				}
			});
		},
	
		show: function(fullScreen){
			var fundo_loading = $("fundo_loading");
			var plano_loading = $("plano_loading");
			var popup_loading = $("popup_loading");
			
			if(fullScreen){
				var resizeFunc = function(){
					var size = Consulte.getWindowSize();
					fundo_loading.style.top = "0px";
					fundo_loading.style.left = "0px";
					fundo_loading.style.width = size.width + "px";
					fundo_loading.style.height = size.height + "px";
					
					plano_loading.style.top = "0px";
					plano_loading.style.left = "0px";
					plano_loading.style.width = size.width + "px";
					plano_loading.style.height = size.height + "px";
				};
				resizeFunc();
				window.setTimeout(resizeFunc, 10);
				if(this.timerInterval == null){
					this.timerInterval = window.setInterval(resizeFunc, 500);
				}
			}else{
				fundo_loading.clonePosition($("content"));
				plano_loading.clonePosition($("content"));
			}
			
			fundo_loading.show();
			plano_loading.show();
			popup_loading.style.left = ((fundo_loading.offsetWidth - popup_loading.offsetWidth) / 2) + "px";
			
			if($("glossary")){
				$("glossary").setStyle({"position": "static"});
			}
		},
		
		hide: function(){
			$("plano_loading").hide();
			$("fundo_loading").hide();
			
			if($("glossary")){
				$("glossary").setStyle({"position": "relative"});
			}
			
			if(this.timerInterval != null){
				window.clearInterval(this.timerInterval);
				this.timerInterval = null;
			}
		},
	
		onCreate: function(request){
			if(this._shouldActivate(request)){
				var options = request.options.consulteOptions||{};
				this.show((options.processing||{}).fullScreen);
			}
		},
	
		onComplete: function(request){
			if(this._shouldActivate(request)){
				var delayHide = (((request.options||{}).consulteOptions||{}).processing||{}).delayHide||0;
				if(delayHide > 0){
					this.hide.bind(this).delay(delayHide);
				}else{
					this.hide();
				}
			}
		},
	
		addIgnoredURL: function(url){
			url = this._adjustURL(url);
			this.ignoredURLS[url] = true;
		},
	
		_shouldActivate: function(request){
			var url  = this._adjustURL(request.url);
			return (this.ignoredURLS[url] != true);
		},
	
		_adjustURL: function(url){
			url = Consulte.adjustURL(url);
			return "_"+url+"_";
		}
		
	};
}