// 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';
}

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 }
}

<!--

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->
<!--
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 3;
var wint = (screen.height - h) / 3;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+', deve ser um endereço válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+', deve conter apenas números.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' \n'; }
  } if (errors) alert('Os seguintes campos devem ser preenchidos:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
