// JavaScript Document

// [INICIO] funções para controlar o menu-drop
var timer = false;        // temporizador para manter o menu aberto
var lastMenuOpen = false; // indica qual o ultimo menu aberto

function openMenu (id) {
	/*
	!!params
	@id = nome do menu que deve ser aberto (sem a necessidade de colocar 'menu_')
	*/
	if (lastMenuOpen && lastMenuOpen != id) {
		menuDisappear (lastMenuOpen);
	}
	if (!lastMenuOpen) {
		document.getElementById(id).style.display = '';
	} else if (lastMenuOpen != id) {
		document.getElementById(id).style.display = '';
	}
	lastMenuOpen = id;
	window.clearTimeout(timer);
}

function closeMenu (id){
	timer = window.setTimeout("menuDisappear('"+id+"')", 500);
}

function menuDisappear (id) {
	if (timer) {
		window.clearTimeout(timer);
	}
	document.getElementById(id).style.display = 'none';
	lastMenuOpen = false;
}
// [FIM] funções para controlar o menu-drop

// [INÍCIO] função para alterar a classe CSS de algum elemento
function func_swapClass(ElementID, ClassName) {
	document.getElementById(ElementID).className = ClassName;
}
// [FIM] função para alterar a classe CSS de algum elemento

// [INICIO] função para controlar a abertura e persistência de uma camada layer
var openedLayer = Array();

function func_showAndHold (id) {
	/*
	!!params
	@id = nome da div que deve ser aberta
	*/
	var index = -1;
	var i;
	for (i = 0; i < openedLayer.length; i++) {
		if (openedLayer[i] == id) {
			index = i;
			break;
		}
	}
	if (index >= 0) {
		document.getElementById(id).style.display = 'none';
		for (i = index; i < openedLayer.length-1; i++) {
			openedLayer[i] = openedLayer[i+1];
		}
		openedLayer.pop();
	} else {
		document.getElementById(id).style.display = '';
		openedLayer.push(id);
	}
}
// [FIM] função para controlar a abertura e persistência de uma camada layer

// [INICIO] função para abrir os formulários de contato (legado)
function abreForm(tipoForm){
	var Timprensa = document.getElementById("Timprensa");
	var Tcurriculo = document.getElementById("Tcurriculo");
	var Tassunto = document.getElementById("Tassunto");
	var Trepresentante = document.getElementById("Trepresentante");
	var Tvisita = document.getElementById("Tvisita");
	var Tenviar = document.getElementById("Tenviar");
	var Tconsultora = document.getElementById("Tconsultora");

	if(tipoForm=="vazio"){
		Timprensa.style.display = 'none'
		Tcurriculo.style.display = 'none'
		Tassunto.style.display = 'none'
		Trepresentante.style.display = 'none'
		Tvisita.style.display = 'none'
		Tenviar.style.display = 'none'
		Tconsultora.style.display = 'none'
		Tconsultora.style.display = 'none'
		document.form1.action = "";
	}
	if(tipoForm=="Assuntos Gerais"){
		Timprensa.style.display = 'none'
		Tcurriculo.style.display = 'none'
		Tassunto.style.display = ''
		Trepresentante.style.display = 'none'
		Tvisita.style.display = 'none'
		Tconsultora.style.display = 'none'
		Tenviar.style.display = ''
		document.form1.action = "default.aspx?acao=enviarAssuntoGerais";
	}
	if(tipoForm=="Solicite uma Visita"){
		Timprensa.style.display = 'none'
		Tcurriculo.style.display = 'none'
		Tassunto.style.display = 'none'
		Trepresentante.style.display = 'none'
		Tvisita.style.display = ''
		Tconsultora.style.display = 'none'
		Tenviar.style.display = ''
		document.form1.action = "default.aspx?acao=enviarVisita";
	}
	if(tipoForm=="Seja Representante"){
		Timprensa.style.display = 'none'
		Tcurriculo.style.display = 'none'
		Tassunto.style.display = 'none'
		Trepresentante.style.display = ''
		Tvisita.style.display = 'none'
		Tconsultora.style.display = 'none'
		Tenviar.style.display = ''
		document.form1.action = "default.aspx?acao=enviarRepresentante";
	}
	if(tipoForm=="Oportunidades de Trabalho"){
		Timprensa.style.display = 'none'
		Tcurriculo.style.display = ''
		Tassunto.style.display = 'none'
		Trepresentante.style.display = 'none'
		Tvisita.style.display = 'none'
		Tconsultora.style.display = 'none'
		Tenviar.style.display = ''
		document.form1.action = "default.aspx?acao=enviarOportunidades";
	}
	if(tipoForm=="Imprensa"){
		Timprensa.style.display = ''
		Tcurriculo.style.display = 'none'
		Tassunto.style.display = 'none'
		Trepresentante.style.display = 'none'
		Tvisita.style.display = 'none'
		Tconsultora.style.display = 'none'
		Tenviar.style.display = ''
		document.form1.action = "default.aspx?acao=enviarImprensa";
	}
	if(tipoForm=="Seja uma Consultora"){
		Timprensa.style.display = 'none'
		Tcurriculo.style.display = 'none'
		Tassunto.style.display = 'none'
		Trepresentante.style.display = 'none'
		Tvisita.style.display = 'none'
		Tconsultora.style.display = ''
		Tenviar.style.display = ''
		document.form1.action = "default.aspx?acao=enviarConsultora";
	}
}
// [FIM] função para abrir os formulários de contato (legado)

function getBrowser() {
if (window.XMLHttpRequest) { 
	a=new XMLHttpRequest(); } //Objeto nativo (FF/Safari/Opera7.6+)
else {
  try { 
	 a=new ActiveXObject("Msxml2.XMLHTTP");  //activeX (IE5.5+/MSXML2+)
  }   
  catch(e) {
	try { 
 a=new ActiveXObject("Microsoft.XMLHTTP"); //activeX (IE5+/MSXML1)
	}   
	catch(e) { /* O navegador não tem suporte */ 
 a=false; 
	}
  }
} 
return a;
}





/* FUNCTIONS AJAX */
function func_ajax(caminho, divMostra){
	
	urlLink = caminho
	
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET",urlLink, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){

				document.getElementById(divMostra).innerHTML = "Carregando...";

			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {

					 document.getElementById(divMostra).innerHTML =  ajax.responseText;

       			} else {

					document.getElementById(divMostra).innerHTML = ajax.responseText;
      			}
			}
		}
		ajax.send(null);
	}
}

function func_redireciona(url){
	window.location = url
}