window.onload = function() {

	larguraBoxZoom();

	IEHoverPseudo();

	//Links ------------------------------------------

	var links = tags('a');

	for(var i = 0; i < links.length; i++) {

		

		if(links[i].className.match('ativo')) {

			links[i].onclick = function() {

				return false;

			} //function

		} //if ativo
		
		if(links[i].className.match('inativo')) {

			links[i].href = "javascript:void(0);";

		} //if ativo

		

		if(links[i].rel.match('prev')) {

			links[i].onclick = function() {

				window.history.back();

				return  false;

			} //function

		} // if prev

		
		if(links[i].rel.match('download')) {

			links[i].onclick = function() {

				return  true;

			} //function

		} // if prev

		

		if(links[i].className.match('popup')) {

			links[i].onclick = function() {

				window.open(this.href);

				return  false;

			} //function

		} // if prev



		if(links[i].className.match('popupImg')) {

			links[i].onclick = function() {

				if(this.href && this.href != "") {

					var titulo = (this.title) ? this.title : '';

					window.open('ampliaFoto.php?src='+this.href+'&desc='+titulo,'','width=500,height=457,resizable');

				}

				return  false;

			} //function

		} // if prev

	}// for

	

	//inputs -----------------------------------------------------

	var inputs = tags('input');

	for(var i = 0; i < inputs.length; i++) {

		inputs[i].onmouseover = function() { eventos(this,'onmouseover'); }

		inputs[i].onmouseout = function() { eventos(this,'onmouseout'); }

		inputs[i].onfocus = function() { eventos(this,'onfocus'); eventosEspeciais(this,'onfocus'); }

		inputs[i].onblur = function() { eventos(this,'onblur'); eventosEspeciais(this,'onblur'); }

		inputs[i].onkeyup = function() { eventos(this,'onkeyup'); eventosEspeciais(this,'onkeyup'); }

	}

	

	

	//textarea -----------------------------------------------------

	var textareas = tags('textarea');

	for(var i = 0; i < textareas.length; i++) {

		textareas[i].onmouseover = function() { eventos(this,'onmouseover'); }

		textareas[i].onmouseout = function() { eventos(this,'onmouseout'); }

		textareas[i].onfocus = function() { eventos(this,'onfocus'); eventosEspeciais(this,'onfocus'); }

		textareas[i].onblur = function() { eventos(this,'onblur'); eventosEspeciais(this,'onblur'); }

		textareas[i].onkeyup = function() { eventos(this,'onkeyup'); eventosEspeciais(this,'onkeyup'); }

	}

	

	//labels -----------------------------------------------------

	var labels = tags('label');

	for(var i = 0; i < labels.length; i++) {

		labels[i].onmouseover = function() { eventos(this,'onmouseover'); }

		labels[i].onmouseout = function() { eventos(this,'onmouseout'); }

		labels[i].onfocus = function() { eventos(this,'onfocus'); }

		labels[i].onblur = function() { eventos(this,'onblur'); }

	}

	

	//forms -----------------------------------------------------

	var forms = tags('form');

	for(var i = 0; i < forms.length; i++) {

		if(forms[i].id=='contatoForm') {

			forms[i].nomeOk = false;

			forms[i].emailOk = false;

			forms[i].onsubmit = function() {

				campoObrigatorio(den('nome'));

				campoObrigatorio(den('email'));

				campoObrigatorio(den('mensagem'));

				emailObrigatorio(den('email'));

				if(this.nomeOk && this.emailOk && this.mensagemOk) {

					return true;

				} else {					

						return false;

				}

			}

		}

	}

	// Função Menu POP UP para expandir o menu do link "Restrito"	
	var navItems = document.getElementById("primary-nav").getElementsByTagName("li");

	for (var i=0; i<navItems.length; i++) {
        
        if(navItems[i].className == "menuparent primeiroNivel") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "menuparent primeiroNivel"; }
		}
	}

	// Função para fechar o popup
	var popupSelecao = den("popup_selecao");
	var areas = tags("area");

	for(var i = 0; i < areas.length; i++)

	{

		if(areas[i].id == "fechaPopupSelecao")

		{

			areas[i].onclick = function(){popupSelecao.className = "escondePopup";}

		}

	}

	



}



function eventos(elemento,evento) {

	if(evento == 'onmouseover') {

		elemento.className += ' over';

	} else if (evento == 'onmouseout') {

		elemento.className = elemento.className.replace('over','');

	} 

	

	else if (evento == 'onfocus') {

		elemento.className += ' focus';

	} else if (evento == 'onblur') {

		elemento.className = elemento.className.replace('focus','');

		campoObrigatorio(elemento);

		emailObrigatorio(elemento);

	}

	

	else if (evento == 'onmousedown') {

		elemento.className += ' held';

	} else if (evento == 'onmouseup') {

		elemento.className = elemento.className.replace('held','');

	}

	

	else if (evento == 'onkeydown') {}

	else if (evento == 'onkeyup') {

		emailObrigatorio(elemento)

		campoObrigatorio(elemento);

	}



	

}



function eventosEspeciais(elemento,evento) {

	//input/email do newsletter

	if(elemento.id == 'nladdress') {

		if(evento == 'onfocus') {

			if(elemento.value == "cadastre seu e-mail") {

				elemento.value = '';

			}

		} else if(evento == 'onblur') {

			if(elemento.value == "") {

				elemento.value = 'cadastre seu e-mail';

			}

		}

	}	

}



function campoObrigatorio(elemento) {

	if(elemento.className.match('obrigatorio') || elemento.className.match('email')) {

		if(elemento.value == "") {

			insereHTML('status'+elemento.id,'Campo obrigat&oacute;rio!');

			eval('elemento.form.'+elemento.id+'Ok=false');

			elemento.className += ' problema';

		} else if(!elemento.className.match('email')) {

			insereHTML('status'+elemento.id,'Ok!');

			eval('elemento.form.'+elemento.id+'Ok=true');

			elemento.className = elemento.className.replace('problema','');

		}

	}

}

function emailObrigatorio(elemento) {

	if(elemento.className.match('email')) {

		checaEmailValidoTimer(elemento);

		if(elemento.value == "") {

			insereHTML('status'+elemento.id,'E-mail inv&aacute;lido!');

			elemento.form.emailOk=false;

			elemento.className += ' problema';

		}

		

		if(elemento.form.emailOk) {

			elemento.className = elemento.className.replace('problema','');

		} else {

			insereHTML('status'+elemento.id,'E-mail inv&aacute;lido!');

			elemento.form.emailOk=false;

			elemento.className += ' problema';

		}

	}	

}