/*
 * Script de inicializacao de eventos
 * baseados em mootools 1.11
 * inicia: efeitos de tool tips do calendario, limpar valores de layout de input text/password, desativar click em link com href="#", limpa valores de layout ao submeter
 *
 * desenvolvido por Leonardo Alves - SERAGI - leonardo.pereira at tjdft.jus.br
 */
window.addEvent('domready', function() {
//inicia os efeitos do calendario
	var tool = new Tips($$('.tool'), {
		maxTitleChars: 60,
		showDelay: 400,
		hideDelay: 400,
		fixed: true,
		className: 'tool',
	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
	},
	onShow: function(toolTip) {
		this.fx.start(1);
	},
	onHide: function(toolTip) {
		this.fx.start(0);
	}		
	});

//trabalha com valores de layout em formulario e limpa value em bracno " " por causa do dasilva
	$$('input[type=text]','input[type=password]','textarea').each(function(el){		
		if (el.hasClass('limpar')){
			el.valorLayout = el.value;//cria atributo para limpar campo preenchido com valores de layout e retorna-lo
			el.addEvents({
				'focus': function() {//limpa quando tiver o foco o valor de layout
					if (this.value == this.valorLayout)
						this.value = "";	
				},
				'blur': function() {//retornar o valor de layout quando vazio
					if (this.value == "")
						this.value = this.valorLayout;
				}
			});
		}
		else
			if (el.value == " "){
				el.addEvents({
					'focus': function() {//limpa quando tiver o foco
						if (this.value == " ")
							this.value = "";	
					}
				});
			}
	});
	
	$$('a[href=#]').each(function(el){//funcao para links com href="#" não responderem o click
		if (!el.hasClass('open'))
			el.addEvent('click', function(e){
				e = new Event(e);
				e.stop();
			});
	});
	if ($('linkVoltar') != null){
		$('linkVoltar').addEvent('click', function(e){
			e = new Event(e);
			e.stop();
			rgfile = /^HTTPS?:\/\/.*TJDFT?\.(JUS|GOV)\.BR/;
			if(!document.referrer.toUpperCase().match(rgfile)){//se for de algum dominio diferente do tjdft.jus.br
				window.location.href = "http://www.tjdft.jus.br/";
			}
			else{
				window.history.back();
			}
			
		});
	}
	$$('form').addEvent('submit', function(){//funcao para limpar valores de layout ao submeter
		this.getElements('input[type=text]').each(function(el){
			//if (el.valorLayout == el.value)
			if (el.value == " ")
				el.value = "";
		});
		this.getElements('select').each(function(el){
			//if (el.valorLayout == el.value)
			if (el.value == " ")
				el.value = "";
		});
	});
	
});