// JavaScript Document

var box;
var box2;

function validaEmail(email){	parte1 = email.value.indexOf("@");	parte2 = email.value.indexOf(".");	parte3 = email.value.length;    if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) 	{		if (email.value == '')		{		}		else		{			alert ("O campo E-mail deve ser conter um endereço eletrônico.");			email.focus();			return false;		}    }	else	{		return false;	}
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {

    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}





function ajax(url)
      {
      //alert(nick);
      //alert(dest);
      //alert(msg);
      req = null;
      // Procura por um objeto nativo (Mozilla/Safari)
      if (window.XMLHttpRequest) {
      req = new XMLHttpRequest();
      req.onreadystatechange = processReqChange;
      req.open("GET",url,true);
      req.send(null);
      // Procura por uma versão ActiveX (IE)
      } else if (window.ActiveXObject) {
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
      req.onreadystatechange = processReqChange;
      req.open("GET",url,true);
      req.send();
      }
      }
      }
      function processReqChange()
      {
      // apenas quando o estado for "completado"
      if (req.readyState == 4) {
      // apenas se o servidor retornar "OK"
      if (req.status ==200) {
      // procura pela div id="pagina" e insere o conteudo
      // retornado nela, como texto HTML
      document.getElementById('pagina').innerHTML = req.responseText;
      } else {
      alert("Houve um problema ao obter os dados:n" + req.statusText);
      }
      }
}



function handleHttpResponse()
{
  if (http.readyState == 4) {
    document.getElementById(box).innerHTML = http.responseText;
  }
}

function handleHttpResponse2()
{	
  if (http2.readyState == 4) {	  
	document.getElementById(box2).innerHTML = http2.responseText;
  }
}

function handleHttpResponse3(box)
{	
  if (http.readyState == 4) {
    document.getElementById(box).innerHTML = http.responseText; 	
  }
}

function executaAjax(parametro, valor, idlocal)
{
	if(parametro == 0)
	{
		return false;
	}
	http = getHTTPObject();
	box = idlocal;
	http.open("GET", valor, true);
	document.getElementById(idlocal).innerHTML = '<div style="width: 100%; min-height:50px; text-align:center; float: left;"><img src="img/ajax-loader.gif" align="absmiddle"></div>';
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function executaAjax2(parametro, valor, idlocal)
{
	if(parametro == 0)
	{
		return false;
	}
	http = getHTTPObject();
	box = idlocal;
	http.open("GET", valor, true);
	document.getElementById(idlocal).innerHTML = '<div id="carregando"></div>';
	http.onreadystatechange = handleHttpResponse; 
  	http.send(null);
}



function getHTTPObject() 
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();

function in_array(arrayVerificar, valorVerificar)
{	
	var status = 0;
	for(var i = 0; i < arrayVerificar.length; i++)
	{
		if(arrayVerificar[i] == valorVerificar)
		{
			status++;
		}
	}	
	if(status > 0)
	{
		return true;
	}
	else
	{
		return false;	}
}
function validarForm(form){	var form;	var elementosForm = new Array();	var elementosFormSelect = new Array();	var arrayCamposVazios = new Array();	var elementosFormTextarea = new Array();	var string;
	elementosForm = document.forms[form].getElementsByTagName('input');		for(var i = 0; i < elementosForm.length; i++)
	{		if(elementosForm[i].alt.substr(0, 1) != '*')		{						if(elementosForm[i].value.length == 0)			{				arrayCamposVazios.push(elementosForm[i].alt);			}		}
	}		elementosFormSelect = document.forms[form].getElementsByTagName('select');	 	for(var i = 0; i < elementosFormSelect.length; i++)	{				if(elementosFormSelect[i].value == '')		{			arrayCamposVazios.push(elementosFormSelect[i].title);		}	}		elementosFormTextarea = document.forms[form].getElementsByTagName('textarea');	 	for(var i = 0; i < elementosFormTextarea.length; i++)	{				if(elementosFormTextarea[i].value == '')		{			arrayCamposVazios.push(elementosFormTextarea[i].title);		}	}	
	if(arrayCamposVazios.length > 0)
	{
		string = 'Para envio deste formulário é necessário o preenchimento dos seguintes campos: <br /><br /><ul>';
		for(var i = 0; i < arrayCamposVazios.length; i++)
		{
			string += '<li>'+arrayCamposVazios[i]+'</li>';
		}
		string += '</ul>';
		invocaDialog(1, 'Campos de preenchimento obrigatório', string);
		return false;
	}
	else
	{
		return true;
	}	
}function validarFormRadio(form){	var form;	var elementosForm = new Array();	var contRadio = 0;		elementosForm = document.forms[form].getElementsByTagName('input');		for(var i = 0; i < elementosForm.length; i++)	{		if((elementosForm[i].type == 'radio') || (elementosForm[i].type == 'checkbox'))		{			if(elementosForm[i].checked == true)			{				contRadio++;			}		}	}		if(contRadio > 0)	{		return true;	}	else	{		invocaDialog(1, 'Preencha ao menos uma opção', 'Desta forma manteremos a exatidão das informações contidas neste formulário.');		return false;	}}

function enviarOuvidoria()
{
	var nomeOuvidoria = document.getElementById('nomeOuvidoria').value;
	var perfilOuvidoria = document.getElementById('perfilOuvidoria').value;
	var documentoOuvidoria = document.getElementById('documentoOuvidoria').value;
	var emailOuvidoria = document.getElementById('emailOuvidoria').value;
	var telefoneOuvidoria = document.getElementById('telefoneOuvidoria').value;
	var comentariosOuvidoria = document.getElementById('comentariosOuvidoria').value;

	if(nomeOuvidoria != "" && perfilOuvidoria != "" && documentoOuvidoria != "" && emailOuvidoria != "" && comentariosOuvidoria != "")
	{
		return true;
    } 
	else 
	{
        invocaDialog(1,"Campos de preenchimento obrigatório","Para envio de um Fale Conosco é necessário o preenchimento dos seguintes campos: <br /><br /><ul><li>Nome</li><li>Perfil</li><li>Documento</li><li>E-mail</li><li>Texto/Mensagem</li></ul>");
		return false;
    }

}



function enviarOportunidadeCarreira()
{
	var nomeCarreira = document.getElementById('nomeCarreira').value;
	var emailCarreira = document.getElementById('emailCarreira').value;
	var arquivo = document.getElementById('arquivo').value;
	var telefoneCarreira = document.getElementById('telefoneCarreira').value;
	var celularCarreira = document.getElementById('celularCarreira').value;
	var comentariosCarreira = document.getElementById('comentariosCarreira').value;

	if(nomeCarreira != "" && emailCarreira != "" && arquivo != "" && telefoneCarreira != "" && celularCarreira != "")
	{
        return true;
    } 
	else 
	{
        invocaDialog(1,"Campos de preenchimento obrigatório","Para envio de um currículo é necessário o preenchimento dos seguintes campos: <br /><br /><ul><li>Nome</li><li>E-mail</li><li>Telefone fixo</li><li>Telefone móvel</li><li>Currículo anexo</li></ul>");
		return false;
    }
}


function mascaraTelefone(objeto){
   if(objeto.value.length == 1)
     objeto.value = '(' + objeto.value;
   if(objeto.value.length == 3)
      objeto.value = objeto.value + ')';
   if(objeto.value.length == 8)
     objeto.value = objeto.value + '-';
}

function validaAcesso()
{
	var login = document.getElementById('login').value;
	var senha = document.getElementById('senha').value;

	if(login != "" && senha != "")
	{
        return true;
    } 
	else 
	{
        invocaDialog(1,"Campos de preenchimento obrigatório","Para acessar o sistema é necessário informar os seguintes campos: <br /><br /><ul><li>Login</li><li>Senha</li></ul>");
		return false;
    }
}

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 autotab(current, to){    if (current.getAttribute && current.value.length==current.getAttribute("maxlength"))	{    	to.focus()	}}function verificarEmail(email){	er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;  	if(er.exec(email))    {		return true;    }	else	{		invocaDialog(1, "validação de E-mail", "Por favor insira um e-mail válido.");				return false;    }}
function mostrar(classePadrao,div,nLinks)
{		
	var divDestino = div;
	var classePadraoLinks = classePadrao;
	var numeroLinks = nLinks;
				
	var arrayDiv = new Array(numeroLinks);
	var arrayMenu = new Array(numeroLinks);		
	
	for (y=0;y<numeroLinks;y++)
	{
		arrayDiv[y] = 'form' + (y+1);
		arrayMenu[y] = 'link' + (y+1);
	}
	
	for (i=0;i<numeroLinks;i++)
	{
		if(arrayDiv[i] == divDestino)
		{
			if (document.getElementById(arrayDiv[i]).className == 'displayVisible')
			{
				return false;
			}
			else
			{
				document.getElementById(arrayDiv[i]).className = 'displayVisible';
				document.getElementById(arrayMenu[i]).className = classePadraoLinks + ' current';
			}
		}
		else
		{
			document.getElementById(arrayDiv[i]).className = 'displayNone';
			document.getElementById(arrayMenu[i]).className = classePadraoLinks;
		}
	}
}function pesquisaDados(url, idlocal){	box = idlocal;	xmlhttp.open("GET", url, true);	xmlhttp.onreadystatechange = trataResposta;	xmlhttp.send(null);}function trataResposta(){	if (xmlhttp.readyState==4)	{		document.getElementById(box).innerHTML = xmlhttp.responseText;	}	else	{		document.getElementById(box).innerHTML = "Carregando...";	}}function fimCEP(form){	cep = document.getElementById('cepfinal').value;	estado = document.getElementById('nomeUF').value;	cidade = document.getElementById('nomeCidade').value;	bairro = document.getElementById('idBairro').value;	rua = document.getElementById('nomeRua').value;			document.forms[form].cep.value = cep;		document.forms[form].endereco.value = rua;	document.forms[form].estado.value = estado;	document.forms[form].cidade.value = cidade;	document.forms[form].bairro.value = bairro;	document.forms[form].numero.focus();			$.fn.colorbox.close();	}