window.onload = function() {
	//Links ------------------------------------------
	var links = tags('a');
	for(var i = 0; i < links.length; i++) {
		
		if(links[i].className.match('menuAtivo')) {
			links[i].onclick = function() {
				return false;
			} 
		}
		
		if(links[i].rel.match('prev')) {
			links[i].onclick = function() {
				window.history.back();
				return  false;
			} //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('popup2')) {
			links[i].onclick = function() {
				window.open(this.href, null,"height=70,width=210,status=no,toolbar=no,menubar=no,location=no");
				return  false;
			} //function
		} // if prev

		if(links[i].rel.match('popupvideo')) {
			links[i].onclick = function() {
				window.open(this.href,'Player','status=yes,width=320,height=290');
				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.mensagemOk) {
					//&& this.emailOk 
					return true;
				} else {					
					return false;
				}
			}
		}
		
		if(forms[i].id=='representanteForm') {
			forms[i].nomeOk = false;
			//forms[i].emailOk = false;
			forms[i].onsubmit = function() {return validaPedido();}
		}
		
		
		
	}
}

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);
		
		for (i=1; i<= 25; i++){			
				if (elemento.id == 'unid'+i){subtotal(i);}			
			}
		
		
	}
	
	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 == 'Login') {
		if(evento == 'onfocus') {
			if(elemento.value == "seu login") {
				elemento.value = '';
			}
		} else if(evento == 'onblur') {
			if(elemento.value == "") {
				elemento.value = 'seu login';
			}
		}
	}
	if(elemento.id == 'Senha') {
		if(evento == 'onfocus') {
			if(elemento.value == "******") {
				elemento.value = '';
			}
		} else if(evento == 'onblur') {
			if(elemento.value == "") {
				elemento.value = '******';
			}
		}
	}
	if(elemento.id == 'Nome') {
	if(evento == 'onfocus') {
		if(elemento.value == "seu nome") {
			elemento.value = '';
		}
	} else if(evento == 'onblur') {
		if(elemento.value == "") {
			elemento.value = 'seu nome';
		}
	}
	

}
}


function campoObrigatorio(elemento) {
	if(elemento.className.match('obrigatorio') || elemento.className.match('email')) {
		if(elemento.value == "") {
			insereHTML('status'+elemento.id,'*');
			//alert('Campo obrigatório!');
			eval('elemento.form.'+elemento.id+'Ok=false');
			elemento.className += ' problema';
		} else if(!elemento.className.match('email')) {
			insereHTML('status'+elemento.id,'');
			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,'*');
			//alert('E-mail obrigatório!');
			elemento.form.emailOk=false;
			elemento.className += ' problema';
		}
		
		if(elemento.form.emailOk) {
			elemento.className = elemento.className.replace('problema','');
		} else {
			insereHTML('status'+elemento.id,'*');
			//alert('E-mail inválido!');
			elemento.form.emailOk=false;
			elemento.className += ' problema';
		}
	}	
}
