// JavaScript Document
var tempo = 100, velocidade = 5;
var textos = new Array(3);
var alturas = new Array(5); 
alturas[0] = 54, alturas[1] = 54, alturas[2] = 81, alturas[3] = 27, alturas[4] = 108, alturas[5] = 54;
var tam = new Array(4); 
tam[0] = 0, tam[1] = 0, tam[2] = 0; tam[3] = 0; tam[4] = 0;
var flag = "nada";
var oldnum = 0;
var tam_item = 27;
var loopabrir = new Array(4);
var loopfechar  = new Array(4);

function abrefecha(categoria, num){
	var obj = document.getElementById("sub"+categoria);
	var obj2 = document.getElementById(categoria);
	altura = alturas[num]
	
	if(flag == categoria){//FECHAR
		flag = "nada";
		oldnum = 0;
		tam[num] = alturas[num];
		var menu = new fechar("sub"+categoria,num);
	}
	else if (flag == "nada"){//ABRIR
		obj.style.display = "block";
		flag = categoria;
		oldnum = num;
		tam[num] = 0;
		var menu = new abrir("sub"+categoria,num);

	}	
	else{//ABRIR E FECHAR O QUE ESTAVA ABERTO
		obj.style.display = "block";
		var oldflag = flag;
		flag = categoria;
		tam[num] = 0;
		var menu = new abrir("sub"+categoria,num);
		var menu = new fechar("sub"+oldflag,oldnum);
		oldnum = num;
	}
}

function fechar(objeto,num){
	clearTimeout(loopabrir[num])
	obj = document.getElementById(objeto);
	var futuro = tam[num] - (alturas[num]+tam[num])*.10
	
	if(tam[num] > 0 &&  futuro > 0){
		if(tam[num] < 2){
			clearTimeout(loopfechar[num])
			obj.style.height = "0px";
			tam[num] = 0;
		}
		else{
			tam[num] = tam[num] - (alturas[num]+tam[num])*.10;
			obj.style.height = (tam[num])+"px";
			loopfechar[num] = setTimeout("fechar('"+objeto+"','"+num+"')", velocidade);
		}
	}
	else{
		clearTimeout(loopfechar[num])
		obj.style.height = "0px";
		obj.style.display = "none";
		tam[num] = 0;
	}
}

function abrir(objeto, num){
	clearTimeout(loopfechar[num])
	obj = document.getElementById(objeto);
	var futuro = tam[num] + (alturas[num]-tam[num])*.10;
	
	if(tam[num] < alturas[num] && futuro < alturas[num]){
		if(tam[num]>(alturas[num]-2)){
			clearTimeout(loopabrir[num])
			obj.style.height = alturas[num]+"px";
			tam[num] = alturas[num];
		}
		else{
			tam[num] = tam[num] + (alturas[num]-tam[num])*.10;
			obj.style.height = (tam[num])+"px";
			loopabrir[num] = setTimeout("abrir('"+objeto+"','"+num+"')", velocidade);
		}
	}
	else{
		clearTimeout(loopabrir[num])
		obj.style.height = alturas[num]+"px";
		tam[num] = alturas[num];
	}
}


function trocaSeta(objeto){
	var obj = document.getElementById(objeto);
	if(objeto != flag){
		obj.style.backgroundPosition = "0px -27px";
	}
	else{
		obj.style.backgroundPosition = "0px -54px";
	}
}

function setaSobre(objeto){
	var obj = document.getElementById(objeto);
	if(objeto != flag){
		obj.style.backgroundPosition = "0px -27px";
	}
	else{
		obj.style.backgroundPosition = "0px -54px";
	}
}

function setaFora(objeto){
	var obj = document.getElementById(objeto);
	if(objeto != flag){
		obj.style.backgroundPosition = "0px 0px";
	}
	else{
		obj.style.backgroundPosition = "0px -54px";
	}
}

function setEfeito(){
	var vet = getElementsByClass("catg","li");
     for (i = 0; i < vet.length; i++) {
		var spans = vet[i].getElementsByTagName('span');
	     for (j = 0; j < spans.length; j++) {
			spans[j].onmouseover =  function(){ this.style.backgroundPosition = "0px -27px";}
			spans[j].onmouseout =  function(){ this.style.backgroundPosition = "0px 0px";}
		 }
	 }
}

function setTamanho(){
	var vet = getElementsByClass("catg","li");
	
    for (i = 0; i < vet.length; i++) {
		var numxx = 0;
		var vet2 = vet[i].getElementsByTagName("li");
//		alert(vet2[0].className);
		    for (j = 0; j < vet2.length; j++) {
					numxx ++;
				alturas[i+1] = numxx * tam_item;
			}
	 }
}



function seleciona(){
	var area = getQuery();
	var num = 0;
	if(area == "default" || area == "adestramento"){
		abrefecha("adestramento",0);
	}
	if(area == "servico"){
		abrefecha("servico",1);
	}
	if(area == "hospedagem"){
		abrefecha("hospedagem",2);
	}
}

function getElementsByClass(searchClass,tag) {
  var classElements = new Array();
  if (tag == null)
    tag = '*';
  var els = document.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function getQuery(){
	var query = ""+window.location;
	var vars = query.split("/");
	for (var i=0;i<vars.length;i++) { 
		var parte = vars[i];
		var parte = vars[i].split(".");
		if (parte[1] == "html") {
			return parte[0];
		}
	}
}
	
	
function enviaNews(){
	var fml=document.news
	var arroba = fml.emailnews.value.indexOf("@");
	var ponto = fml.emailnews.value.indexOf(".");
	
	//Valida o campo NOME.
	if(fml.nomenews.value.length < 3 || fml.nomenews.value == "Digite seu nome aqui." ){
		alert("Preencha seu NOME corretamente!");
		fml.nomenews.focus();
	}
	//Valida o campo E-MAIL.
	else if(fml.emailnews.value.length < 5 || arroba == -1 || ponto == -1 ||  fml.emailnews.value == "Digite seu e-mail aqui." ){
		alert("Preencha seu E-MAIL corretamente!");
		fml.emailnews.focus();
	}
	else{
     fml.action = "scripts/redirect_news.asp";		
	 fml.submit();	
	}
}

function enviaIndicacao(){
	var fml=document.ind
	var arroba = fml.emaili.value.indexOf("@");
	var ponto = fml.emaili.value.indexOf(".");
	
	//Valida o campo NOME.
	if(fml.nomei.value.length < 3 || fml.nomei.value == "Digite seu nome aqui." ){
		alert("Preencha seu NOME corretamente!");
		fml.nomei.focus();
	}
	else if(fml.nomei2.value.length < 3 || fml.nomei2.value == "Digite o nome de seu amigo aqui." ){
		alert("Preencha o NOME de seu amigo corretamente!");
		fml.nomei2.focus();
	}
	//Valida o campo E-MAIL.
	else if(fml.emaili.value.length < 5 || arroba == -1 || ponto == -1 ||  fml.emaili.value == "Digite o e-mail de seu amigo aqui." ){
		alert("Preencha o E-MAIL de seu amigo corretamente!");
		fml.emaili.focus();
	}
	else{
     fml.action = "scripts/redirect_indicacao.asp";		
	 fml.submit();	
	}
}