// JavaScript Document

function Limpar() {
	document.contato.nome.value = "";
	document.contato.email.value = "";
	document.contato.ddd.value = "";
	document.contato.cidade.value = "";
	document.contato.uf.value = "";
	document.contato.telefone.value = "";
	document.contato.celular.value = "";
	document.contato.mensagem.value = "";
	document.contato.receber_copia.value = "";	
}
function Formata_Telefone(objeto,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = objeto.value;
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( " ", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8) {
		tam = vr.length + 1 ;
	}
	if (tecla == 8 ) {
		tam = tam - 1 ;
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
		if ( tam <= 4 ) { 
	 		objeto.value = vr ;
		}
	 	if ( (tam > 4) && (tam <= 8) ) {
	 		objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
		}
	 	if ( (tam >= 9) && (tam <= 10) ) {
			objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			
		}
	}		
}

function Validar_Email(email){
	if(email.length < 6) {
		return false;
	}
	var x = 0;
	for (var c=0;c<email.length;c++) {
		if (email.substring(c,c+1) == '@') {
			x = c;
		}
	}
	var y = 0;
	if (x > 0) {
		for (c=x;c<email.length;c++) {
			if (email.substring(c,c+1)=='.') {
				y = c;
				var valida = 1;
			}
		}
		if (y > 0) {
			var dominio = '';
			for (c=x;c<y;c++) {
				dominio = dominio + email.substring(1,c);
			}
		}
	}
	else {
		return false;
	}					
	if (y <= x+2){
		return false;
	}				
	if (valida == 1){
		return true;
	}
}

function Validar_Contato(){
	if (document.contato.nome.value=="") {
		document.contato.nome.focus();
		alert("O nome é um campo obrigatório!");
		return;
	}
	if (document.contato.email.value=="") {
		document.contato.email.focus();
		alert("O e-mail é um campo obrigatório!");
		return;
	}
	else {
		if (!Validar_Email(document.contato.email.value)) {
			document.contato.email.focus();
			alert("E-mail inválido!");
			return;
		}
	}
	if (document.contato.cidade.value=="") {
		document.contato.cidade.focus();
		alert("A cidade é um campo obrigatório!");
		return;
	}
	if (document.contato.uf.value=="") {
		document.contato.uf.focus();
		alert("O estado é um campo obrigatório!");
		return;
	}
	if (document.contato.ddd.value=="") {
		document.contato.ddd.focus();
		alert("O DDD é um campo obrigatório!");
		return;
	}
	if (document.contato.telefone.value=="") {
		document.contato.telefone.focus();
		alert("O telefone é um campo obrigatório!");
		return;
	}
	if (document.contato.assunto.value=="") {
		document.contato.assunto.focus();
		alert("O assunto é um campo obrigatório!");
		return;
	}
	
	if (document.contato.mensagem.value=="") {
		document.contato.mensagem.focus();
		alert("A mensagem é um campo obrigatório!");
		return;
	}
	else{document.contato.submit();}
}

function preloadAll() {
	/*
	 * loop no collection images[] para fazer preload das imagens
	 * e setar ações de over nas imagens que possuem a propriedade
	 * image.srcOver
	 */
	var imgs=document.images;
	var p=0;
	if (!document.imgPreloads)
		document.imgPreloads=new Array();
	if (imgs) {
		for (k=0; k<imgs.length;k++) {
			if (imgs[k].srcOver != null) {
				document.imgPreloads[p] = new Image;
				document.imgPreloads[p].src = imgs[k].srcOver;
				//ações
				imgs[k].onmouseover = img_mouse_over;
				imgs[k].onmouseout = img_mouse_out;
				//propriedades
				imgs[k].srcOriginal = imgs[k].src;
				imgs[k].srcSwap = imgs[k].srcOver;
				imgs[k].srcOverOriginal = imgs[k].srcOver;
				p++;
			}
		}
	}
}
//-- ** início das funções de over
function img_mouse_over() {
	objImg = this;
	objImg.srcRegular = objImg.src;
	objImg.src = objImg.srcSwap;
}
function img_mouse_out() {
	objImg = this;
	if (objImg.srcRegular!="" && objImg.srcRegular!=null) {
		objImg.src = objImg.srcRegular;
	}
}
function destacaItem(id) {
	//destaca botão com ID informado dentro do iframe MENU
	//(id) == nome do objeto imagem q deve ser destacado
	//captura iframe do MENU
		//destaca botão
	var newBtn = document.getElementById(id);
	if (newBtn.srcOver != "" && newBtn.srcOver!= null) {
		newBtn.srcRegular = newBtn.srcOver;
		newBtn.src = newBtn.srcOver;
		objAtual = newBtn;
	}
	if (id=="null") {
		//desseleciona item
		if (objAtual!=null && objAtual!="") {
			objAtual.srcRegular = objAtual.srcOrigem;
			objAtual.src = objAtual.srcOrigem;
			objAtual = null
		}
	}	
}
function destacaSub(id) {
	//destaca botão com ID informado dentro do iframe MENU
	//(id) == nome do objeto imagem q deve ser destacado
	//captura iframe do MENU
		//destaca botão
	var subMenu = document.getElementById(id);
	subMenu.style.backgroundColor = "#E5B0A2";
	
}
function menuAberto(divname,tdname,varX,varY){
	dv = document.getElementById(divname);
	dv.menuOpen = true;
	mostrar(divname,tdname,varX,varY);
	
}
function mostrar(divname,tdname,varX,varY) {
	/*
	 * recebe ID do DIV que possui o submenu e o ID da TD que possui o botão do menu.
	 * seta estilo para visível e alinha propriedade LEFT do DIV para a mesma posição
	 * do TD
	 * recebe também uma possível variação no eixo X e/ou no eixo Y
	 * ! Netscape não executa duas alteraçõe seguidas no estilo
	 */
	if (!varX) varX=0;
	if (!varY) varY=0;
	document.getElementById(divname).style.visibility='visible';
	currentEle=document.getElementById(tdname);
	var topo=0;
	var esq=0;
	var dif=0;
	while(currentEle.tagName.toLowerCase() != 'body') {
		topo += currentEle.offsetTop;
		esq += currentEle.offsetLeft;
		currentEle = currentEle.offsetParent;
	}
	topo += document.getElementById(tdname).offsetHeight;
	//esq += document.getElementById(tdname).offsetWidth;
	div= document.getElementById(divname);
	div.style.top=(topo+varY);
	div.style.left=esq+varX;
}
function ocultar(divname) {
	/*
	 * oculta o DIV informado
	 */
	dv = document.getElementById(divname);
	if(dv.menuOpen != true){
		dv.style.visibility='hidden';
	}
}

