// JANELA EM DIV **************************************************************
function abreDiv(){ 
document.getElementById("abre_status").style.display = 'block';
document.getElementById("layer_um").style.display = 'none';
document.getElementById("Layer3").style.display = 'none';
}

function fechaTudo(){ 
document.getElementById("abre_status").style.display = 'block';
document.getElementById("abre_status").style.display = 'none';
document.getElementById("Layer3").style.display = 'none';
}

// ABRE POP UP REDIMENSIONÁVEL **************************************************************
	function MM_openBrWindow(theURL,winName,features) 
		{
		window.open(theURL,winName,features);
		}

// SELECIONA E COPIA TEXTEAREA **************************************************************
function selectCode()
    { 
  if(document.pad.text.value.length>0) 
      { 
    textRange = document.pad.text.createTextRange();
    textRange.execCommand("RemoveFormat");
    textRange.execCommand("Copy");
    document.pad.text.focus(); 
    document.pad.text.select();
    alert ("Código copiado.");
      } 
  else alert('Não há o que copiar!') 
    } 

// VALIDA FORM COMENTÁRIOS **************************************************************
function publicacomentesite(){

if(document.comentesite.nome.value=="" || document.comentesite.nome.value.length < 0)
{
alert( "Por favor, seu nome... Quem é você???" );
document.comentesite.nome.focus();
return false;
}

if( document.comentesite.email.value.length < 0  || document.comentesite.email.value.indexOf('@')==-1 || document.comentesite.email.value.indexOf('.')==-1 )
{
alert( "Por favor, informe seu e-mail! Você precisará validar seu comentário!" );
document.comentesite.email.focus();
return false;
}

if(document.comentesite.titulocomentario.value=="" || document.comentesite.titulocomentario.value.length < 0)
{
alert( "Esqueceu de dá um título a seu comentário..." );
document.comentesite.titulocomentario.focus();
return false;
}

if(document.comentesite.anti2.value=="" || document.comentesite.anti2.value.length < 0)
{
alert( "Por favor, verifique o ANTI-SPAM! Repita no segundo campo, os número que você ver no primeiro!" );
document.comentesite.anti2.focus();
return false;
}

if(document.comentesite.anti2.value!=document.comentesite.anti.value)
{
alert( "Por favor, verifique o ANTI-SPAM! Repita no segundo campo, os número que você ver no primeiro!" );
document.comentesite.anti2.focus();
return false;
}

if(document.comentesite.comentario.value=="" || document.comentesite.comentario.value.length < 0)
{
alert( "Bahhhh! Você não escreveu um comentário..." );
document.comentesite.comentario.focus();
return false;
}

return true;
}

// JANELA EM DIV LIVRO **************************************************************
function abreDivL(){ 
document.getElementById("box_menu_select_livros").style.display = 'block';
}

function fechaTudoL(){ 
document.getElementById("box_menu_select_livros").style.display = 'none';
}



// EXPANDE **************************************************************
function toggle(obj) { 
var el = document.getElementById(obj); 
if ( el.style.display != 'none' ) { 
el.style.display = 'none'; 
} 
else { 
el.style.display = ''; 
} 
}

var head="display:''"
img1=new Image()
img1.src="closed.gif"
img2=new Image()
img2.src="open.gif"

function change(){
   if(!document.all)
      return
   if (event.srcElement.id=="foldheader") {
      var srcIndex = event.srcElement.sourceIndex
      var nested = document.all[srcIndex+1]
      if (nested.style.display=="none") {
         nested.style.display=''
         event.srcElement.style.listStyleImage="url(open.gif)"
      }
      else {
         nested.style.display="none"
         event.srcElement.style.listStyleImage="url(closed.gif)"
      }
   }
}

document.onclick=change


// ABRE DIV **************************************************************
    function mostraPageDiv(nota) { 


        var tipBrowser = 0; 
        var mostraDiv= ""; 


        if ( mostraDiv != "" && mostraDiv != null ) { 
            escondeDiv(nota,'','show') 
        } 
        else escondeDiv(nota,'','show') 
    } 


    function econtaObj(n, d) { //v4.0 
        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=econtaObj(n,d.layers[i].document); 
        if(!x && document.getElementById) x=document.getElementById(n); 
return x; 
    } 


    function escondeDiv() { //v3.0 
      var i,p,v,obj,args=escondeDiv.arguments; 
      for (i=0; i<(args.length-2); i+=3) 
          if ((obj=econtaObj(args[i]))!=null) { 
              v=args[i+2]; 
            if (obj.style) { 
                obj=obj.style; 
v=(v=='show')?'visible':(v='hide')?'hidden':v; 
            } 
            obj.visibility=v; } 
    } 


// JANELA EM DIV MENU **************************************************************
function abreDivL(){ 
document.getElementById("div_canais").style.display = 'block';
}
function fechaTudoL(){ 
document.getElementById("div_canais").style.display = 'none';
}

// JANELA EM DIV login **************************************************************
function abreDivLogin(){ 
document.getElementById("div_login").style.display = 'block';
}
function fechaTudoLogin(){ 
document.getElementById("div_login").style.display = 'none';
}



// LOGIN **************************************************************
var navegador = navigator.userAgent.toLowerCase(); //Cria e atribui à variável global 'navegador' (em caracteres minúsculos) o nome e a versão do navegador

//Cria uma variável global chamada 'xmlhttp'
var xmlhttp; 


//Função que inicia o objeto XMLHttpRequest

function objetoXML() {

if (navegador.indexOf('msie') != -1) { //Internet Explorer

var controle = (navegador.indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; //Operador ternário que adiciona o objeto padrão do seu navegador (caso for o IE) à variável 'controle'

try {

xmlhttp = new ActiveXObject(controle); //Inicia o objeto no IE

} catch (e) { }

} else { //Firefox, Safari, Mozilla

xmlhttp = new XMLHttpRequest(); //Inicia o objeto no Firefox, Safari, Mozilla

}

}

//Função que envia o formulário

function enviarForm(url, campos, destino) {

//Atribui à variável 'elemento' o elemento que irá receber a página postada
var elemento = document.getElementById(destino); 

//Executa a função objetoXML()
objetoXML(); 

//Se o objeto de 'xmlhttp' não estiver true
if (!xmlhttp) {

//Insere no 'elemento' o texto atribuído
elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.'; 

return;

} else { 

//Insere no 'elemento' o texto atribuído
elemento.innerHTML = 'ddd'; 

}

xmlhttp.onreadystatechange = function () {

//Se a requisição estiver completada
if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { 

//Se o status da requisição estiver OK
if (xmlhttp.status == 200) {

//Insere no 'elemento' a página postada
elemento.innerHTML = xmlhttp.responseText; 

} else { 

//Insere no 'elemento' o texto atribuído
elemento.innerHMTL = 'Página não encontrada!'; 

}

}

}

//Abre a página que receberá os campos do formulário
xmlhttp.open('POST', url+'?'+campos, true);

//Envia o formulário com dados da variável 'campos' (passado por parâmetro)
xmlhttp.send(campos); 

setTimeout("location.reload();",3000)

}
// FIM LOGIN **************************************************************


// FORM CADASTRO PESSOA FÍSICA **************************************************************
function formcad(){

if(document.formcadastro.nomeusuario.value=="" || document.formcadastro.nomeusuario.value.length < 0)
{
alert( "Qual o seu nome, hein? Hum, diz aí... qual seu nome???" );
document.formcadastro.nomeusuario.focus();
return false;
}

if( document.formcadastro.emailusuario.value.length < 0  || document.formcadastro.emailusuario.value.indexOf('@')==-1 || document.formcadastro.emailusuario.value.indexOf('.')==-1 )
{
alert( "O e-mail é necessário..." );
document.formcadastro.emailusuario.focus();
return false;
}

if(document.formcadastro.apelido.value=="" || document.formcadastro.apelido.value.length < 0)
{
alert( "Epa!!! Escolha um apelido... diga-nos como deseja ser identificado no GuiaDoClique!" );
document.formcadastro.apelido.focus();
return false;
}

if(document.formcadastro.cidade.value=="" || document.formcadastro.cidade.value.length < 0)
{
alert( "Em que cidade você mora???" );
document.formcadastro.cidade.focus();
return false;
}

if(document.formcadastro.cidade.value=="" || document.formcadastro.cidade.value.length < 0)
{
alert( "Em que cidade você mora???" );
document.formcadastro.cidade.focus();
return false;
}

if(document.formcadastro.cep.value=="" || document.formcadastro.cep.value.length < 0)
{
alert( "Sem CEP, nada feito! Só pode se cadastrar se informar um CEP válido!" );
document.formcadastro.cep.focus();
return false;
}

if(document.formcadastro.digitocep.value=="" || document.formcadastro.digitocep.value.length < 0)
{
alert( "Sem CEP, nada feito! Só pode se cadastrar se informar um CEP válido!" );
document.formcadastro.digitocep.focus();
return false;
}

if(document.formcadastro.dataNascimentoD.value=="" || document.formcadastro.dataNascimentoD.value.length < 0)
{
alert( "Por favor, informe a data de Nascimento!" );
document.formcadastro.dataNascimentoD.focus();
return false;
}

if(document.formcadastro.dataNascimentoM.value=="" || document.formcadastro.dataNascimentoM.value.length < 0)
{
alert( "Por favor, informe a data de Nascimento!" );
document.formcadastro.dataNascimentoM.focus();
return false;
}

if(document.formcadastro.dataNascimentoA.value=="" || document.formcadastro.dataNascimentoA.value.length < 0)
{
alert( "Por favor, informe a data de Nascimento!" );
document.formcadastro.dataNascimentoA.focus();
return false;
}

if(document.formcadastro.senha1.value=="" || document.formcadastro.senha2.value.length < 0)
{
alert( "Escolha uma senha, e repita a mesma no campo indicado!" );
document.formcadastro.senha1.focus();
return false;
}

cpf = document.formcadastro.cpf.value;
erro = new String;
if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! "; 
var nonNumbers = /\D/;
if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! "; 
if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
erro += "Numero de CPF invalido!"
}
var a = [];
var b = new Number;
var c = 11;
for (i=0; i<11; i++){
a[i] = cpf.charAt(i);
                      if (i < 9) b += (a[i] * --c);
}
if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
b = 0;
c = 11;
for (y=0; y<10; y++) b += (a[y] * c--); 
if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
erro +="Digito verificador com problema!";
}
if (erro.length > 0){
alert(erro);
document.formcadastro.cpf.focus();
return false;
}

return true;
}

// FIM FORM CADASTRO **************************************************************


// FORM CADASTRO PESSOA JURÍDICA **************************************************************
function formcadPJ(){

if(document.formcadastro.nomeusuario.value=="" || document.formcadastro.nomeusuario.value.length < 0)
{
alert( "Qual o seu nome, hein? Hum, diz aí... qual seu nome???" );
document.formcadastro.nomeusuario.focus();
return false;
}

if( document.formcadastro.emailusuario.value.length < 0  || document.formcadastro.emailusuario.value.indexOf('@')==-1 || document.formcadastro.emailusuario.value.indexOf('.')==-1 )
{
alert( "O e-mail é necessário..." );
document.formcadastro.emailusuario.focus();
return false;
}

if(document.formcadastro.apelido.value=="" || document.formcadastro.apelido.value.length < 0)
{
alert( "Epa!!! Escolha um apelido... diga-nos como deseja ser identificado no GuiaDoClique!" );
document.formcadastro.apelido.focus();
return false;
}

if(document.formcadastro.cidade.value=="" || document.formcadastro.cidade.value.length < 0)
{
alert( "Em que cidade você mora???" );
document.formcadastro.cidade.focus();
return false;
}

if(document.formcadastro.cidade.value=="" || document.formcadastro.cidade.value.length < 0)
{
alert( "Em que cidade você mora???" );
document.formcadastro.cidade.focus();
return false;
}

if(document.formcadastro.cep.value=="" || document.formcadastro.cep.value.length < 0)
{
alert( "Sem CEP, nada feito! Só pode se cadastrar se informar um CEP válido!" );
document.formcadastro.cep.focus();
return false;
}

if(document.formcadastro.digitocep.value=="" || document.formcadastro.digitocep.value.length < 0)
{
alert( "Sem CEP, nada feito! Só pode se cadastrar se informar um CEP válido!" );
document.formcadastro.digitocep.focus();
return false;
}

if(document.formcadastro.dataNascimentoD.value=="" || document.formcadastro.dataNascimentoD.value.length < 0)
{
alert( "Por favor, informe a data de Nascimento!" );
document.formcadastro.dataNascimentoD.focus();
return false;
}

if(document.formcadastro.dataNascimentoM.value=="" || document.formcadastro.dataNascimentoM.value.length < 0)
{
alert( "Por favor, informe a data de Nascimento!" );
document.formcadastro.dataNascimentoM.focus();
return false;
}

if(document.formcadastro.dataNascimentoA.value=="" || document.formcadastro.dataNascimentoA.value.length < 0)
{
alert( "Por favor, informe a data de Nascimento!" );
document.formcadastro.dataNascimentoA.focus();
return false;
}

if(document.formcadastro.razaosocial.value=="" || document.formcadastro.razaosocial.value.length < 0)
{
alert( "Por favor, informe a RAZÃO SOCIAL!" );
document.formcadastro.razaosocial.focus();
return false;
}

if(document.formcadastro.senha1.value=="" || document.formcadastro.senha2.value.length < 0)
{
alert( "Escolha uma senha, e repita a mesma no campo indicado!" );
document.formcadastro.senha1.focus();
return false;
}

CNPJ = document.formcadastro.CNPJID.value;
erro = new String;
if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
}
//substituir os caracteres que nao sao numeros
if(document.layers && parseInt(navigator.appVersion) == 4){
x = CNPJ.substring(0,2);
x += CNPJ.substring(3,6);
x += CNPJ.substring(7,10);
x += CNPJ.substring(11,15);
x += CNPJ.substring(16,18);
CNPJ = x; 
} else {
CNPJ = CNPJ.replace(".","");
CNPJ = CNPJ.replace(".","");
CNPJ = CNPJ.replace("-","");
CNPJ = CNPJ.replace("/","");
}
var nonNumbers = /\D/;
if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n"; 
var a = [];
var b = new Number;
var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
for (i=0; i<12; i++){
a[i] = CNPJ.charAt(i);
b += a[i] * c[i+1];
}
if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
b = 0;
for (y=0; y<13; y++) {
b += (a[y] * c[y]); 
}
if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
erro +="Digito verificador com problema!";
}
if (erro.length > 0){
alert(erro);
document.formcadastro.CNPJID.focus();
return false;
} else {
alert("CNPJ valido!");
}

return true;
}

// FIM FORM CADASTRO **************************************************************

// FORMATA CNPJ **********************************************************************************************************************
function FormataCnpj(campo, teclapres)
	{
		var tecla = teclapres.keyCode;
		var vr = new String(campo.value);
		vr = vr.replace(".", "");
		vr = vr.replace("/", "");
		vr = vr.replace("-", "");
		tam = vr.length + 1;
		if (tecla != 14)
		{
			if (tam == 3)
				campo.value = vr.substr(0, 2) + '.';
			if (tam == 6)
				campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
			if (tam == 10)
				campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
			if (tam == 15)
				campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
		}
	}

// FIM FORMATA CNPJ **********************************************************************************************************************


// SÓ LETRAS **************************************************************
function PermiteSoLetras()
{
  var tecla = window.event.keyCode;
  tecla     = String.fromCharCode(tecla);
  if(!((tecla != "0") && (tecla != "1") && (tecla != "2") && (tecla != "3") && (tecla != "4") && (tecla != "5") && (tecla != "6") && (tecla != "7") && (tecla != "8") && (tecla != "9") && (tecla != "-") && (tecla != "=") && (tecla != "!") && (tecla != "@") && (tecla != "#") && (tecla != "$") && (tecla != "%") && (tecla != "¨") && (tecla != "&") && (tecla != "*") && (tecla != "(") && (tecla != ")") && (tecla != "_") && (tecla != "+") && (tecla != "|") && (tecla != ",") && (tecla != "<") && (tecla != ".") && (tecla != ">") && (tecla != ";") && (tecla != ":") && (tecla != "?") && (tecla != "/") && (tecla != "[") && (tecla != "]") && (tecla != "{") && (tecla != "}")))
  {
    window.event.keyCode = 0;
  }
}
// FIM SÓ LETRAS **************************************************************


// EXPANDE DIV **************************************************************
function mostra(item){
if (item.style.display=="none"){item.style.display="";}
else{item.style.display="none"}}

// LIMITA SELECT **************************************************************
var selectedOptions = []; // Written by: WillyDuitt@hotmail.com \\;
 function countSelected(select,maxNumber){ 
   for(var i=0; i<select.options.length; i++){
     if(select.options[i].selected && !new RegExp(i,'g').test(selectedOptions.toString())){
        selectedOptions.push(i); 
     }

     if(!select.options[i].selected && new RegExp(i,'g').test(selectedOptions.toString())){
      selectedOptions = selectedOptions.sort(function(a,b){return a-b});  
       for(var j=0; j<selectedOptions.length; j++){ 
         if(selectedOptions[j] == i){
            selectedOptions.splice(j,1);
         }
       } 
     }

     if(selectedOptions.length > maxNumber){
        alert('You may only choose '+maxNumber+' options!!');
        select.options[i].selected = false;
        selectedOptions.pop();
        document.body.focus();
     }  
   }    
 }



// CAMPOS EXTRAS DO FORMULÁRIO DE CURRÍCULO **************************************************************
function Alt (){
var x = document.form.nacionalidade;
var y = document.form.obsNacionalidade;

if (x.options[1].selected){
y.style.display="inline";
}else{
y.style.display="none";
}
}

function AltDois (){
var a = document.form.deficiencia;
var b = document.form.obsDeficiencia;

if (a.options[1].selected){
b.style.display="inline";
}else{
b.style.display="none";
}
}

function AltTres (){
var c = document.form.tipofone;
var d = document.form.obsRecado;

if (c.options[2].selected){
d.style.display="inline";
}else{
d.style.display="none";
}
}

function AltQuatro (){
var e = document.form.escolaridade;
var f = document.form.obsEscolaridade;
var g = document.form.obsEscolaridadeDois;

if (e.options[1].selected)
{
f.style.display="inline";
g.style.display="none";
}
else if (e.options[2].selected)
{
f.style.display="inline";
g.style.display="none";
}

else if (e.options[3].selected)
{
f.style.display="inline";
g.style.display="inline";
}

else if (e.options[4].selected)
{
f.style.display="inline";
g.style.display="inline";
}

else
{
f.style.display="none";
g.style.display="none";
}
}

function AltCinco (){
var h = document.form.idiomas;
var i = document.form.obsIdiomas;
var j = document.form.obsIdiomasDois;

if (h.options[1].selected)
{
i.style.display="inline";
j.style.display="inline";
}

else
{
i.style.display="none";
j.style.display="none";
}
}
// *** FIM *** CAMPOS EXTRAS DO FORMULÁRIO DE CURRÍCULO **************************************************************


function barra(objeto){
if (objeto.value.length == 2 || objeto.value.length == 5 ){
objeto.value = objeto.value+"/";
}

if (objeto.value.length == objeto.maxLength) {
  for (var i = 0; i < objeto.form.length; i++) {
   if (objeto.form[i] == objeto && objeto.form[(i + 1)] && objeto.form[(i + 1)].type != "hidden") {
    objeto.form[(i + 1)].focus();
    break;
   }
  }
 }
}


function formatTelefone(element, e){
  if (e.keyCode != 8){
    length = element.value.length;
    if (length == 4){
      if (element.value.charAt(0)!="")
        element.value = "" + element.value + "-";
    }
  }

if (element.value.length == element.maxLength) {
  for (var i = 0; i < element.form.length; i++) {
   if (element.form[i] == element && element.form[(i + 1)] && element.form[(i + 1)].type != "hidden") {
    element.form[(i + 1)].focus();
    break;
   }
  }
 }
}


function pula(objeto){
if (objeto.value.length == objeto.maxLength) {
  for (var i = 0; i < objeto.form.length; i++) {
   if (objeto.form[i] == objeto && objeto.form[(i + 1)] && objeto.form[(i + 1)].type != "hidden") {
    objeto.form[(i + 1)].focus();
    break;
   }
  }
 }
}


// EXPANDE DIV **************************************************************
function mostra(item){
if (item.style.display=="none"){item.style.display="";}
else{item.style.display="none"}}