// JavaScript Document

// Alterar classe com mouseover de um elemento.
// id = id do elemento
function over(id){
  document.getElementById(id).className = 'mouseOver1';
}

// Alterar classe com mouseout de um elemento.
// id = id do elemento
function out(id){
  document.getElementById(id).className = 'mouseOut';
}

var x=0;
var imagem=new Array();
imagem[0]="_images/geral/graficos_ind1.jpg";
imagem[1]="_images/geral/graficos_ind2.jpg";
imagem[2]="_images/geral/graficos_ind.jpg";  
imagem[3]="_images/geral/graficos_ind3.jpg"; 
 
function mudar_imagem(){
	document.getElementById("imagem_indicador").src = imagem[x];
	x++;
		if (x==4){ 
			 x=0;
		}
}
setInterval('mudar_imagem()', 5000);

function troca(tipo){
	var img;
	switch (tipo){
		case 'empresa': { 
			img = 'bt-empresa-on.jpg'; break 
		}
		case 'representantes': { 
			img = 'bt-representantes-on.jpg'; break 
		}
		case 'parceiros': { 
			img = 'bt-parceiros-on.jpg'; break 
		}
		case 'noticias': { 
			img = 'bt-noticias-on.jpg'; break 
		}
		case 'contato': { 
			img = 'bt-contatos-on.jpg'; break 
		}
		case 'trabalhe': { 
			img = 'bt-trabalhe-on.jpg'; break 
		}
		case 'home': { 
			img = 'bt-home-on.jpg'; break 
		}		
	}
	var imagem = document.getElementById(tipo);
	imagem.src= "../_images/geral/" + img; 
}
function volta(tipo){
	var img;
	switch (tipo){
		case 'empresa': { 
			img = 'bt-empresa-off.jpg'; break 
		}
		case 'representantes': { 
			img = 'bt-representantes-off.jpg'; break 
		}
		case 'parceiros': { 
			img = 'bt-parceiros-off.jpg'; break 
		}
		case 'noticias': { 
			img = 'bt-noticias-off.jpg'; break 
		}
		case 'contato': { 
			img = 'bt-contatos-off.jpg'; break 
		}
		case 'trabalhe': { 
			img = 'bt-trabalhe-off.jpg'; break 
		}
		case 'home': { 
			img = 'bt-home-off.jpg'; break 
		}		
	}
	var imagem = document.getElementById(tipo);
	imagem.src= "../_images/geral/" + img; 
}
function trocaIng(tipo){
	var img;
	switch (tipo){
		case 'empresa': { 
			img = 'bt-empresa-on.jpg'; break 
		}
		case 'representantes': { 
			img = 'bt-representantes-on.jpg'; break 
		}
		case 'parceiros': { 
			img = 'bt-parceiros-on.jpg'; break 
		}
		case 'noticias': { 
			img = 'bt-noticias-on.jpg'; break 
		}
		case 'contato': { 
			img = 'bt-contatos-on.jpg'; break 
		}
		case 'trabalhe': { 
			img = 'bt-trabalhe-on.jpg'; break 
		}
		case 'home': { 
			img = 'bt-home-on.jpg'; break 
		}		
	}
	var imagem = document.getElementById(tipo);
	imagem.src= "../_images/ingles/geral/" + img; 
}
function voltaIng(tipo){
	var img;
	switch (tipo){
		case 'empresa': { 
			img = 'bt-empresa-off.jpg'; break 
		}
		case 'representantes': { 
			img = 'bt-representantes-off.jpg'; break 
		}
		case 'parceiros': { 
			img = 'bt-parceiros-off.jpg'; break 
		}
		case 'noticias': { 
			img = 'bt-noticias-off.jpg'; break 
		}
		case 'contato': { 
			img = 'bt-contatos-off.jpg'; break 
		}
		case 'trabalhe': { 
			img = 'bt-trabalhe-off.jpg'; break 
		}
		case 'home': { 
			img = 'bt-home-off.jpg'; break 
		}		
	}
	var imagem = document.getElementById(tipo);
	imagem.src= "../_images/ingles/geral/" + img; 
}
function trocaEsp(tipo){
	var img;
	switch (tipo){
		case 'empresa': { 
			img = 'bt-empresa-on.jpg'; break 
		}
		case 'representantes': { 
			img = 'bt-representantes-on.jpg'; break 
		}
		case 'parceiros': { 
			img = 'bt-parceiros-on.jpg'; break 
		}
		case 'noticias': { 
			img = 'bt-noticias-on.jpg'; break 
		}
		case 'contato': { 
			img = 'bt-contatos-on.jpg'; break 
		}
		case 'trabalhe': { 
			img = 'bt-trabalhe-on.jpg'; break 
		}
		case 'home': { 
			img = 'bt-home-on.jpg'; break 
		}		
	}
	var imagem = document.getElementById(tipo);
	imagem.src= "../_images/espanhol/geral/" + img; 
}
function voltaEsp(tipo){
	var img;
	switch (tipo){
		case 'empresa': { 
			img = 'bt-empresa-off.jpg'; break 
		}
		case 'representantes': { 
			img = 'bt-representantes-off.jpg'; break 
		}
		case 'parceiros': { 
			img = 'bt-parceiros-off.jpg'; break 
		}
		case 'noticias': { 
			img = 'bt-noticias-off.jpg'; break 
		}
		case 'contato': { 
			img = 'bt-contatos-off.jpg'; break 
		}
		case 'trabalhe': { 
			img = 'bt-trabalhe-off.jpg'; break 
		}
		case 'home': { 
			img = 'bt-home-off.jpg'; break 
		}		
	}
	var imagem = document.getElementById(tipo);
	imagem.src= "../_images/espanhol/geral/" + img; 
}
// Abre popup
// ex: abrir('arquivo.html', 'he100', 'wi100', 'scno');
function abrir() {
	var windowFeatures = "", nomeArquivo = "", nomeJanela = "", erro = null
	Argumentos = abrir.arguments; noArgumentos = Argumentos.length; nomeArquivo = Argumentos[0]
	for (i = 1; i < noArgumentos; i++) {
		valor = Argumentos[i].substring(2,Argumentos[i].length)
		switch(Argumentos[i].substring(0,2)) {
			case "nj" : nomeJanela = valor; break
			case "to" : windowFeatures += "top=" + valor + ", "; break
			case "le" : windowFeatures += "left=" + valor + ", "; break
			case "he" : windowFeatures += "height=" + valor + ", "; break
			case "wi" : windowFeatures += "width=" + valor + ", "; break
			case "lb" : windowFeatures += "location=" + valor + ", "; break
			case "mb" : windowFeatures += "menubar=" + valor + ", "; break
			case "sc" : windowFeatures += "scrollbars=" + valor + ", "; break
			case "st" : windowFeatures += "status=" + valor + ", "; break
			case "tb" : windowFeatures += "toolbar=" + valor + ", "; break
			case "tt" : windowFeatures += "titlebar=" + valor + ", "; break
			case "re" : windowFeatures += "resizable=" + valor + ", "; break
			default : erro = '"Código de atributo não informado no '+(i+1)+' º argumento (' +Argumentos[i]+ ')"'
		}
	}
	windowFeatures = windowFeatures.substring(0,windowFeatures.lastIndexOf(","))
	if (erro) { alert(erro) } else { novaJanela = window.open(nomeArquivo, nomeJanela, windowFeatures) }
}


// Conta caracteres de um campo texto
// textareaID = id do elemento texto
// spanId = id do elemento que aparece a contagem regressiva
// maxSize = número máxim de caracteres permitidos.
function contaCaracteres(textareaId, spanId, maxSize) 
{
  textarea = document.getElementById(textareaId);
  if (textarea == null) {
	return;
  }
  if (textarea.value.length > maxSize) {
	  textarea.value = textarea.value.substring(0, maxSize);
  }
  document.getElementById(spanId).innerHTML = maxSize - textarea.value.length;
}


// Formata campos textos passando uma máscara
// src = elemento que possuirá a máscara
// mask = tipo da máscara. 
// 0 = numérico
// # = não escreve nada
// A = letra
// evt = event
function formatar(src, evt, mask) {
	var i = src.value.length;
	var saida = mask.substring(i,i+1);
	var ascii = (window.event)?event.keyCode:evt.which;
	if (ascii <= 30) return true;
	if (saida == "A") {
		if ((ascii >=97) && (ascii <= 122)) { 
			return true;
			//event.keyCode -= 32;
		} else {
			return false
		}
	} else if (saida == "0") {
		if ((ascii >= 48) && (ascii <= 57)) {
			return true
		} else {
			return false
//			event.keyCode = 0
		}
	} else if (saida == "#") {
		return false;
	} else {
		src.value += saida;
		i += 1;
		saida = mask.substring(i,i+1);
		if (saida == "A") {
			if ((ascii >=97) && (ascii <= 122)) {
				return true; //event.keyCode -= 32;
			} else {
				return false; //event.keyCode = 0; 
			}
		} else if (saida == "0") {
			if ((ascii >= 48) && (ascii <= 57)) {
				return true;
			} else {
				return false; //event.keyCode = 0 
			}
		} else {
			return true;
		}
	}
}


///
// e = event
//
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}


function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode <= 30) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function aparece(id, acao){
	if (acao == ''){
		if (document.getElementById(id).style.display == 'none') {
		   document.getElementById(id).style.display = 'inline';
		} else {
		   document.getElementById(id).style.display = 'none';
		}
	} else {
	   document.getElementById(id).style.display = acao;
	}
}

var aLabelList = new Array()
var aErrorList = new Array()
var regEx = /^.+@.+\..{2,3}$/	
function fgFormValidate(oForm) {
	var iLabelCount = 0
	var sError = ""
	aLabelList.splice(0, aLabelList.length)
	aErrorList.splice(0, aErrorList.length)
	feFormValidate(oForm)
	if (aLabelList.length == 1)
		sError += "* O campo '" + aLabelList[0] + "' é obrigatório.\n"
		if (aLabelList.length > 1) {
			iLabelCount = 0
			sError += "* Os campos "
				for (i = 0; i < aLabelList.length; i++) {
					iLabelCount++
					sError += "'" + aLabelList[i] + "'"
						if (iLabelCount != aLabelList.length)
							if (iLabelCount == (aLabelList.length - 1)) sError += " e "; else sError += ", "}
							sError += " são obrigatórios.\n"
						}
				if (aErrorList.length > 0) {
					sError += "\n"
					for (i = 0; i < aErrorList.length; i++) sError += "* " + aErrorList[i] + "\n"
						sError = sError.substr(0, (sError.length - 1))
					}
					if (sError == "") { return true } else { alert(sError); return false }
}


