var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

var str_in;
var str_out=""; 
var num_in;
var num_out="";
/*=======================================================*/
function chk_cad_fcex()   {
/*=======================================================*/
   if (document.cad_fcex.cpo_nome.value == "") {
     alert("Por favor, informe o seu nome.");
     document.cad_fcex.cpo_nome.focus();
     return (false);
   }

   if (!findEmail(document.cad_fcex.cpo_email.value))
	  {
      alert ("Por favor, o E-Mail precisa ser informado.");
      document.cad_fcex.cpo_email.focus();
      return (false);
   }
      
/*   if (document.cad_fcex.cpo_cargo.value == "") {
     alert("Por favor, informe qual o seu cargo.");
     document.cad_fcex.cpo_cargo.focus();
     return (false);
   }
   
   if (document.cad_fcex.cpo_emp.value == "")  {
     alert("Por favor, informe o nome de sua Empresa.");
     document.cad_fcex.cpo_emp.focus();
     return (false);
   }
*/
   if (document.cad_fcex.cpo_tel.value == "")  {
     alert("Por favor, informe o telefone de sua Empresa.");
     document.cad_fcex.cpo_tel.focus();
     return (false);
   }
/*
   if (document.cad_fcex.cpo_fax.value == "")  {
     alert("Por favor, informe o fax de sua Empresa.");
     document.cad_fcex.cpo_fax.focus();
     return (false);
   }
  */ 
return true;
}

/*=======================================================*/
function chk_cadastro()   {
/*=======================================================*/
   if (document.form_cadastro.empresa.value == "")  {
     alert("Por favor, informe o nome de sua Empresa.");
     document.form_cadastro.empresa.focus();
     return (false);
   }

   if (document.form_cadastro.nome.value == "") {
     alert("Por favor, informe o seu nome.");
     document.form_cadastro.nome.focus();
     return (false);
   }

   if (document.form_cadastro.cargo.value == "") {
     alert("Por favor, informe qual o seu cargo.");
     document.form_cadastro.cargo.focus();
     return (false);
   }

   if (!findEmail(document.form_cadastro.xemail.value))
	  {
      alert ("Por favor, o E-Mail precisa ser informado.");
      document.form_cadastro.xemail.focus();
      return (false);
   }

    var marcou = false;
	for (var idx = 5; idx <= document.form_cadastro.length-1; idx++) {
		box = eval("document.form_cadastro.elements[" + idx + "]"); 
		if (box.checked == true) {
			marcou = true;
        }
    }

    if (!marcou) {
	    alert("Nenhuma BASE foi selecionada.");
        return false;
    }

return true;
}

/*=======================================================*/
function chk_alt_senha(theform)   {
/*=======================================================*/
 if (theform.email.value == "")
		{
        alert ("Por favor, o E-Mail precisa ser informado.");
        theform.email.focus();
        return false;
	 }
	 if (theform.oldsenha.value == "")
		{
        alert ("Por favor, a senha precisa ser informada.");
        theform.oldsenha.focus();
        return false;
	 }
	 if (theform.newsenha1.value == "")
		{
        alert ("Por favor, a nova senha precisa ser informada.");
        theform.newsenha1.focus();
        return false;
	 }
	 if (theform.newsenha2.value == "")
		{
        alert ("Por favor, a nova senha de conferência precisa ser informada.");
        theform.newsenha2.focus();
        return false;
	 }
	 if (theform.newsenha1.value != document.alt_senha.newsenha2.value)
		{
        alert ("Por favor digite sua nova senha novamente.");
        theform.newsenha1.focus();
        return false;
	 }

return true;
}

/*=======================================================*/
function findEmail(StrObj) {
/*=======================================================*/
var separateEmailsBy = ", ";
var email = ""; // if no match, use this
var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
if (emailsArray) {
   email = "";
   for (var i = 0; i < emailsArray.length; i++) {
       if (i != 0) email += separateEmailsBy;
          email += emailsArray[i];
       }
   }
   if (email == "")
       {
       return false;		
	}
return true;
}

/*=======================================================*/
function chk_login(xopc,xop)   {
/*=======================================================*/
	if (document.form_log.xemail.value == "" & xopc != 3)	{
        alert ("Por favor, o E-Mail precisa ser informado.");
		document.form_log.xemail.focus();
		return false;
	}

	if (xopc == 10)	{
		location.href = "/basesbd/cad_base.asp?tp=111&xemail='" + document.form_log.xemail.value+"'";
		return true;
		}
	else
		{
		if (xopc == 3)	{
			location.href = "/basesbd/cad_base.asp?tp=311&xemail='" + document.form_log.xemail.value+"'";
			return true;
			}
	}
		
	if (document.form_log.senha.value == "") {
   	    alert ("Por favor, a Senha precisa ser informada.");
		document.form_log.senha.focus();
		return false;
	}

	if (xopc == 2)	{
		location.href = "/basesbd/cad_base.asp?tp=211&xemail='" + document.form_log.xemail.value+"'&xsenha='"+ str_to_num(document.form_log.xsenha.value)+"'";
	}

	if (xopc == 0)	{
	 document.form_log.submit();
	}	
return true;
}

/*=======================================================*/
function str_to_num(x_str){
/*=======================================================*/
  num_out="";
  if(x_str=="")alert("Preencha o campo");
  else
  {
    str_in=escape(x_str);
    for(i=0;i<str_in.length;i++)num_out+=str_in.charCodeAt(i)-23;
   }
return num_out
}

/*=======================================================*/
function num_to_str(form){
/*=======================================================*/
  str_out="";var flag=0;
  if(form.output.value=="")return alert(e);

  num_out=form.output.value;  
  for(i=0;i<num_out.length;i++)
  {
    if((num_out.charAt(i)>=0)||(num_out.charAt(i)<=9))flag=0;
    else{flag=1;break}
  }

  if(flag)alert("You may only enter numbers here");
  else
  {
    num_out=form.output.value;  
    for(i=0;i<num_out.length;i+=2)
    {
      num_in=parseInt(num_out.substr(i,[2]))+23;
      num_in=unescape('%'+num_in.toString(16));
      str_out+=num_in;
    }
  form.input.value=unescape(str_out);
  form.output.value="";
  }
}

/*=======================================================*/
function change_ord(){
/*=======================================================*/
	tt = eval("document.forms[0].Td_Ord.selectedIndex");
	tt = eval("document.forms[0].Td_Ord.options[tt].value");
	location.href = tt;
return true;
}

/*=======================================================*/
function new_win(x_win,cod_td,x_alt,x_larg){
/*=======================================================*/
if (x_win < 4) {
	    New_win = window.open("../janela.asp?tp=" + x_win + "&xcd=" + cod_td, "Informa","height="+ x_alt+ ",width="+x_larg+",scrollbars,resizable=no,menubar=no,alwaysLowered,left=280,top=15")
	}
else
	{	
	    New_win = window.open("../janela.asp?tp=" + x_win + "&xcd=" + cod_td, "Informa","height="+ x_alt+ ",width="+x_larg+",scrollbars,resizable=no,menubar=no,alwaysLowered,left=250,top=15")
	}
	
return true;
}

/*=======================================================*/
function chk_cep(Form){
/*=======================================================*/
     if (Form.cep1.value.length == 0) {
		alert("Por favor digite um CEP !");
        Form.cep1.focus();
        return false;
     }
     if (Form.cep2.value.length == 0) {
		alert("Por favor digite um CEP !");
        Form.cep2.focus();
        return false;
     }
     s = limpa_string(Form.cep1.value);
     if (s.length != 5) {
		alert("O CEP deve ter caracteres numericos !");
        Form.cep1.focus();
        return false;
     }
     s = limpa_string(Form.cep2.value);
     if (s.length != 3) {
		alert("O CEP deve ter caracteres numericos !");
        Form.cep2.focus();
        return false;
     }
return true;
}

/*=======================================================*/
function chk_tdrbce(xcep)   {
/*=======================================================*/
	if (!valida_cnpj(document.form_cadastro.cgccpf_td.value))
	 {
      alert("Por favor, preencha corretamente o campo CPF/CNPJ.");
      document.form_cadastro.cgccpf_td.focus();
      return (false);
     }
   
   if (document.form_cadastro.nome_td.value == "") {
     alert("Por favor, informe o seu nome.");
     document.form_cadastro.nome_td.focus();
     return (false);
   }

   if (!findEmail(document.form_cadastro.email_td.value))
	  {
      alert ("Por favor, o E-Mail precisa ser informado.");
      document.form_cadastro.email_td.focus();
      return (false);
   }
	if (xcep == 0) {
		if (document.form_cadastro.end_td.value == "") {
			alert("Por favor, informe o endereço corretamente.");
			document.form_cadastro.end_td.focus();
			return (false);
		}
		if (document.form_cadastro.num_td.value == "") {
			alert("Por favor, informe o número corretamente.");
			document.form_cadastro.num_td.focus();
			return (false);
		}
		if (document.form_cadastro.bairro_td.value == "") {
			alert("Por favor, informe o bairro corretamente.");
			document.form_cadastro.bairro_td.focus();
			return (false);
		}
		if (document.form_cadastro.cida_td.value == "") {
			alert("Por favor, informe o cidade corretamente.");
			document.form_cadastro.cida_td.focus();
			return (false);
		}
		if (document.form_cadastro.uf_td.value == "") {
			alert("Por favor, informe a UF corretamente.");
			document.form_cadastro.uf_td.focus();
			return (false);
		}
		if (document.form_cadastro.cep_td.value == "") {
			alert("Por favor, informe o CEP corretamente.");
			document.form_cadastro.cep_td.focus();
			return (false);
		}
	}
   
return true;
}
/*=======================================================*/
function limpa_string(S){
/*=======================================================*/
// Deixa so' os digitos no numero
var Digitos = "0123456789";
var temp = "";
var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}

/*=======================================================*/
function semtab() { checatab=false; } 
/*=======================================================*/
/*=======================================================*/
function comtab() { checatab=true; } 
/*=======================================================*/

/*=======================================================*/
function mostra_cep() {
/*=======================================================*/
   if ( (document.Form_frete.cep1.value.length == 5) && (checatab) ) { 
          document.Form_frete.cep2.focus();
          checatab=false;
   } 
  return true; 
} 

/*=======================================================*/
function chk_mantenedor(theForm){
/*=======================================================*/
  if (theForm.empresa_p1.value == "") {
    alert("Por favor, informe o nome da empresa.");
    theForm.empresa_p1.focus();
    return (false);
  }

  if (theForm.endereco_p1.value == "") {
    alert("Por favor, informe o endereco da empresa.");
    theForm.endereco_p1.focus();
    return (false);
  }

  if (theForm.bairro_p1.value == "") {
    alert("Por favor, informe o bairro onde fica a empresa.");
    theForm.bairro_p1.focus();
    return (false);
  }

  if (theForm.cidade_p1.value == "") {
    alert("Por favor, informe a cidade da empresa.");
    theForm.cidade_p1.focus();
    return (false);
  }

  if (theForm.uf_p1.value == "") {
    alert("Por favor, informe o estado.");
    theForm.uf_p1.focus();
    return (false);
  }

  if (theForm.cep_p1.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.cep_p1.focus();
    return (false);
  }

  if (theForm.fone_p1.value == "") {
    alert("Por favor, informe o Telefone da empresa.");
    theForm.fone_p1.focus();
    return (false);
  }

  if (theForm.fax_p1.value == "") {
    alert("Por favor, informe o Fax da empresa.");
    theForm.fax_p1.focus();
    return (false);
  }

  if (theForm.ramo_p1.value == "") {
    alert("Por favor, informe o Ramo de Atividade.");
    theForm.ramo_p1.focus();
    return (false);
  }

  if (theForm.nome1_p2.value == "") {
    alert("Por favor, você precisa informar o Nome de um Diretor.");
    theForm.nome1_p2.focus();
    return (false);
  }

 if (theForm.nome_p3.value == "") {
    alert("Por favor, informe o nome do Representante.");
    theForm.nome_p3.focus();
    return (false);
  }

  if (theForm.endereco_p3.value == "") {
    alert("Por favor, informe o endereco do representante.");
    theForm.endereco_p3.focus();
    return (false);
  }

  if (theForm.bairro_p3.value == "") {
    alert("Por favor, informe o bairro.");
    theForm.bairro_p3.focus();
    return (false);
  }

  if (theForm.cidade_p3.value == "") {
    alert("Por favor, informe a cidade do Representante.");
    theForm.cidade_p3.focus();
    return (false);
  }

  if (theForm.uf_p3.value == "") {
    alert("Por favor, você precisa informar o estado.");
    theForm.uf_p3.focus();
    return (false);
  }

  if (theForm.cep_p3.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.cep_p3.focus();
    return (false);
  }

  if (theForm.fone_p3.value == "") {
    alert("Por favor, informe o Telefone do Representante.");
    theForm.fone_p3.focus();
    return (false);
  }

  if (theForm.email_p3.value == "") {
    alert("Por favor, informe o E-mail do Representante.");
    theForm.email_p3.focus();
    return (false);
  }

 if (theForm.nome_p4.value == "") {
    alert("Por favor, informe o nome do Respon&aacute;vel pela &Aacute;rea de Treinamento.");
    theForm.nome_p4.focus();
    return (false);
  }

  if (theForm.endereco_p4.value == "") {
    alert("Por favor, informe o endereco.");
    theForm.endereco_p4.focus();
    return (false);
  }

  if (theForm.bairro_p4.value == "") {
    alert("Por favor, informe o bairro.");
    theForm.bairro_p4.focus();
    return (false);
  }

  if (theForm.cidade_p4.value == "") {
    alert("Por favor, você precisa informar a cidade.");
    theForm.cidade_p4.focus();
    return (false);
  }

  if (theForm.uf_p4.value == "") {
    alert("Por favor, você precisa informar o estado.");
    theForm.uf_p4.focus();
    return (false);
  }

  if (theForm.cep_p4.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.cep_p4.focus();
    return (false);
  }

  if (theForm.fone_p4.value == "") {
    alert("Por favor, você precisa informar o Telefone.");
    theForm.fone_p4.focus();
    return (false);
  }

  if (theForm.email_p4.value == "") {
    alert("Por favor, você precisa informar o E-mail.");
    theForm.email_p4.focus();
    return (false);
  }

  return (true);
}

/*=======================================================*/
function chk_curso(theForm){
/*=======================================================*/
  if (theForm.nome.value == "") {
    alert("Por favor, informe o seu nome.");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.empresa.value == "") {
    alert("Por favor, informe o nome da empresa.");
    theForm.empresa.focus();
    return (false);
  }
  
  if (theForm.endereco_emp.value == "") {
    alert("Por favor, informe o endereco da empresa.");
    theForm.endereco_emp.focus();
    return (false);
  }

  if (theForm.cidade_emp.value == "") {
    alert("Por favor, informe a cidade da empresa.");
    theForm.cidade_emp.focus();
    return (false);
  }

  if (theForm.uf_emp.value == "") {
    alert("Por favor, informe o estado.");
    theForm.uf_emp.focus();
    return (false);
  }

  if (theForm.cep_emp.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.cep_emp.focus();
    return (false);
  }

  if (theForm.fone_emp.value == "") {
    alert("Por favor, informe o Telefone da empresa.");
    theForm.fone_emp.focus();
    return (false);
  }

  if (theForm.fax_emp.value == "") {
    alert("Por favor, informe o Fax da empresa.");
    theForm.fax_emp.focus();
    return (false);
  }

  if (theForm.email_p3.value == "") {
    alert("Por favor, informe o E-mail do Representante.");
    theForm.email_p3.focus();
    return (false);
  }

    if (theForm.endereco_home.value == "") {
    alert("Por favor, informe o endereco residencial.");
    theForm.endereco_home.focus();
    return (false);
  }

  if (theForm.cidade_home.value == "") {
    alert("Por favor, informe a cidade.");
    theForm.cidade_home.focus();
    return (false);
  }

  if (theForm.uf_home.value == "") {
    alert("Por favor, informe o estado.");
    theForm.uf_home.focus();
    return (false);
  }

  if (theForm.cep_home.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.cep_home.focus();
    return (false);
  }

  if (theForm.fone_home.value == "") {
    alert("Por favor, informe o seu Telefone.");
    theForm.fone_home.focus();
    return (false);
  }
  
  return (true);

}

/*=======================================*/
function chk_cadastro_bb(xcep)   {
/*=======================================*/
   if (document.form_cadastro.empresa.value == "")  {
     alert("Por favor, informe o nome de sua Empresa.");
     document.form_cadastro.empresa.focus();
     return (false);
   }

	if (document.form_cadastro.cgccpf.value != "") {
		if (!valida_cnpj(document.form_cadastro.cgccpf.value))
		 {
	      alert("Por favor, preencha corretamente o campo CPF/CNPJ.");
	      document.form_cadastro.cgccpf.focus();
	      return (false);
	     }
   }
   
   if (document.form_cadastro.nome.value == "") {
     alert("Por favor, informe o seu nome.");
     document.form_cadastro.nome.focus();
     return (false);
   }

   if (document.form_cadastro.cargo.value == "") {
     alert("Por favor, informe qual o seu cargo.");
     document.form_cadastro.cargo.focus();
     return (false);
   }

   if (!findEmail(document.form_cadastro.xemail.value))
	  {
      alert ("Por favor, o E-Mail precisa ser informado.");
      document.form_cadastro.xemail.focus();
      return (false);
   }
	if (xcep == 0) {
		if (document.form_cadastro.end_td.value == "") {
			alert("Por favor, informe o endereço corretamente.");
			document.form_cadastro.end_td.focus();
			return (false);
		}
		if (document.form_cadastro.num_td.value == "") {
			alert("Por favor, informe o número corretamente.");
			document.form_cadastro.num_td.focus();
			return (false);
		}
		if (document.form_cadastro.bairro_td.value == "") {
			alert("Por favor, informe o bairro corretamente.");
			document.form_cadastro.bairro_td.focus();
			return (false);
		}
		if (document.form_cadastro.cida_td.value == "") {
			alert("Por favor, informe o cidade corretamente.");
			document.form_cadastro.cida_td.focus();
			return (false);
		}
		if (document.form_cadastro.uf_td.value == "") {
			alert("Por favor, informe a UF corretamente.");
			document.form_cadastro.uf_td.focus();
			return (false);
		}
		if (document.form_cadastro.cep_td.value == "") {
			alert("Por favor, informe o CEP corretamente.");
			document.form_cadastro.cep_td.focus();
			return (false);
		}
	}
   
return true;
}
/*=====================================================*/
function valida_cnpj(xform){
/*=====================================================*/
//alert(xform.cgccpf_TD.value.length);
//resposta = true;
	if (xform.length != 11 && xform.length != 14) 
		{
//		alert("Número informado inválido. Verifique !");
		resposta = false;
		}
	else
		{
		if (xform.length == 11)
			{
			resposta = cpf(xform);
			}
		else
			{
			resposta = cgc(xform);
			}	
		}	

return resposta;
}
/*=====================================================*/
function cgc(pcgc)
/*=====================================================*/
 {
 // verifica o tamanho
 if (pcgc.length != 14) {
  sim=false
  alert ("Tamanho Invalido de CGC")
  }
 else {sim=true}

  if (sim )  // verifica se e numero
  {
  for (i=0;((i<=(pcgc.length-1))&& sim); i++)
  {
   val = pcgc.charAt(i)
       // alert (val)
   if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") && (val!="5")&&(val!="6")&&(val!="7")&&(val!="8"))
    {sim=false}
   }
   if (sim)  // se for numero continua
   {
    m2 = 2
    soma1 = 0
    soma2 = 0
    for (i=11;i>=0;i--)
    {
     val = eval(pcgc.charAt(i))
       // alert ("Valor do Val: "+val)
     m1 = m2
  if (m2<9) { m2 = m2+1}
  else {m2 = 2}
  soma1 = soma1 + (val * m1)
  soma2 = soma2 + (val * m2)
    }  // fim do for de soma

  soma1 = soma1 % 11
  if (soma1 < 2) {  d1 = 0}
   else { d1 = 11- soma1}

     soma2 = (soma2 + (2 * d1)) % 11
  if (soma2 < 2) { d2 = 0}
   else { d2 = 11- soma2}
        // alert (d1)
       // alert (d2)
    if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13)))
   { return true }
   else return false
   }
 }

 }

/*=====================================================*/
 function cpf(pcpf)
/*=====================================================*/
 {

 if (pcpf.length != 11) {sim=false}
 else {sim=true}

  if (sim )  // valida o primeiro digito
  {
  for (i=0;((i<=(pcpf.length-1))&& sim); i++)
  {
   val = pcpf.charAt(i)
   if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") && (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) 
	   {sim=false}
   }

   if (sim)
	  {
    soma = 0
    for (i=0;i<=8;i++)
    {
     val = eval(pcpf.charAt(i))
     soma = soma + (val*(i+1))
    }

    resto = soma % 11
    if (resto>9) dig = resto -10
    else  dig = resto
    if (dig != eval(pcpf.charAt(9))) { sim=false }
   else   // valida o segundo digito
    {

     soma = 0
    for (i=0;i<=7;i++)
     {
     val = eval(pcpf.charAt(i+1))
      soma = soma + (val*(i+1))
    }

     soma = soma + (dig * 9)
    resto = soma % 11
     if (resto>9) dig = resto -10
     else  dig = resto
   if (dig != eval(pcpf.charAt(10))) { sim = false }
    else sim = true
   }
   }
  }

  if (sim) { return true }
  else
    return false
 }

/*=====================================================*/
function chk_num(campo,teclapres){
/*=====================================================*/
	var tecla = teclapres.keyCode;		
	if (tecla == 13)
		{
		return false;
		}
	if (tecla < 47 || tecla > 57)
		{
		alert('Digite apenas números!'); 
		event.returnValue = false;
		campo.focus();
		return false;
		}

return true;
}

/*======================================================*/
function chk_inc(nome_campo,xop,nom)   {
/*======================================================*/
if (xop <=  2) {
	if (nom > 0){
		box = eval("top.parent.frames[0].document.f_produtos.ncm6_" + nom);
		box.checked = false;
	}	
	top.parent.frames[1].location.href = "prod_inc_item.asp?operacao=3&produto="+nome_campo+"&xop="+xop;
	}
else if (xop ==  3)
	{
	top.parent.frames[1].location.href = "prod_atual.asp?operacao=1&produto="+nome_campo+"&xop="+xop
	}	
else if (xop ==  4)
	{
	top.parent.frames[1].location.href = "prod_exc.asp?operacao=1&produto="+nome_campo+"&xop="+xop
	}	
return true;
}

/*=======================================================*/
function chk_firjan(theForm){
/*=======================================================*/
var marcou = false;
for (var i = 1; i <= 9; i++)
	{
	 	campo = eval("document.form_firjan.n_mod_" + i);
		if (campo.checked == true)
			{
			marcou = true;
			}
	}

if (!marcou) {
    alert("Nenhum MÓDULO foi selecionado.");
       return false;
   }

  if (theForm.n_nome.value == "") {
    alert("Por favor, informe o seu nome.");
    theForm.n_nome.focus();
    return (false);
  }

   if (theForm.n_formacao.value == "") {
    alert("Por favor, informe a sua formação.");
    theForm.n_formacao.focus();
    return (false);
  }

	if (!chk_cnpj(theForm.n_cnpj.value))	{
        alert ("O CNPJ informado está incorreto. Verifique !");
		theForm.n_cnpj.focus();
		return false;
	}

  if (theForm.n_empresa.value == "") {
    alert("Por favor, informe o nome da empresa.");
    theForm.n_empresa.focus();
    return (false);
  }
  
  if (theForm.n_end_com.value == "") {
    alert("Por favor, informe o endereco da empresa.");
    theForm.n_end_com.focus();
    return (false);
  }

  if (theForm.n_cida_com.value == "") {
    alert("Por favor, informe a cidade da empresa.");
    theForm.n_cida_com.focus();
    return (false);
  }

  if (theForm.n_uf_com.value == "") {
    alert("Por favor, informe o estado.");
    theForm.n_uf_com.focus();
    return (false);
  }

  if (theForm.n_cep_com.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.n_cep_com.focus();
    return (false);
  }

  if (theForm.n_tel_com.value == "") {
    alert("Por favor, informe o Telefone da empresa.");
    theForm.n_tel_com.focus();
    return (false);
  }

  if (theForm.n_fax_com.value == "") {
    alert("Por favor, informe o Fax da empresa.");
    theForm.n_fax_com.focus();
    return (false);
  }

  if (theForm.n_email.value == "") {
    alert("Por favor, informe o seu E-mail");
    theForm.n_email.focus();
    return (false);
  }

    if (theForm.n_end_res.value == "") {
    alert("Por favor, informe o endereco residencial.");
    theForm.n_end_res.focus();
    return (false);
  }

  if (theForm.n_cida_res.value == "") {
    alert("Por favor, informe a cidade.");
    theForm.n_cida_res.focus();
    return (false);
  }

  if (theForm.n_uf_res.value == "") {
    alert("Por favor, informe o estado.");
    theForm.n_uf_res.focus();
    return (false);
  }

  if (theForm.n_cep_res.value == "") {
    alert("Por favor, você precisa informar CEP.");
    theForm.n_cep_res.focus();
    return (false);
  }

  if (theForm.n_tel_res.value == "") {
    alert("Por favor, informe o seu Telefone.");
    theForm.n_tel_res.focus();
    return (false);
  }

  if (theForm.n_convenio.value == "") {
    alert("Por favor, informe o Convênio.");
    theForm.n_convenio.focus();
    return (false);
  }  
  return (true);

}

/*=======================================================*/
function MascaraCEP (formato, keypress, objeto)	{
/*=======================================================*/
	campo = eval (objeto);
	if (formato=='CEP')
		{
		var tecla = keypress.keyCode;		
		if (tecla == 13)
			{
			return false;
			}
		if (tecla < 47 || tecla > 57)
			{
			alert('Digite apenas números!'); 
			event.returnValue = false;
			campo.focus();
			return false;
			}
		caracteres = '01234567890';
		separacoes = 1;
		separacao1 = '-';
		conjuntos = 2;
		conjunto1 = 5;
		conjunto2 = 3;
		if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		(conjunto1 + conjunto2 + 1))
			{
			if (campo.value.length == conjunto1) 
			   campo.value = campo.value + separacao1;
			}
		else 
			event.returnValue = false;
		}
	}    
/*=======================================================*/
function chk_cnpj(x_form) {
/*=====================================================*/
resposta = true;
	if (x_form.length != 11 && x_form.length != 14) 
		{
//		alert("Número informado inválido. Verifique !");
		resposta = false;
		}
	else
		{
		if (x_form.length == 11)
			{
			resposta = cpf(x_form);
			}
		else
			{
			resposta = cgc(x_form);
			}	
		}	

return resposta;
}
/*=======================================================*/	
function muda_db(box){
/*=======================================================*/
	atual     = box
	total_box = 6;
	mostrar   = box + 1;
	nome      = "";
	parametro = "&";	

	// Le campos selecionados para formacao do nome
	// e grava o nome no campo tipo hidden FORMACAO
	for (var num_box = 1; num_box <= box; num_box++) {
		vr_box = eval("document.f_base.cp_" + num_box); 

		if (num_box != 4 || vr_box.value == "BR") {
			nome += vr_box.value;
		}
		if (num_box <= box)
			{
			tt = eval("document.f_base.cp_"+num_box+".selectedIndex");
			tt = eval("document.f_base.cp_"+num_box+".options[tt].value");
			parametro += "xopc"+num_box+"="+tt;
			if (num_box <= box)
				{
				parametro += "&";
				}
			}	
		}
	top.document.f_base_1.xnom.value  = nome;
	location.href = "adm_bases_show.asp?tp=2"+parametro;
}
/*=======================================================*/	
function mostra_db(op4){
/*=======================================================*/

	if(op4 != "0" && op4 != "BR"){
		tt = eval("document.f_base.cp_4.selectedIndex");
		document.f_base.cpo_5.value = document.f_base.cp_4.options[tt].text;
	}
	if(op4 != "0" && op4 == "BR"){
		tt = eval("document.f_base.cp_4.selectedIndex");
		document.f_base.cp_5.value = "";
	}
}	

/*=====================================================*/
function marca_file(campo) {
/*=====================================================*/
if (campo.checked) {
		parent.document.f_num.num_sel.value++;
	}
else
	{
		parent.document.f_num.num_sel.value--;
	}
if (parent.document.f_num.num_sel.value > 0) {
		parent.document.f_num.down.disabled = false;
	}
else
	{
		parent.document.f_num.down.disabled = true;
	}	
}

/*=====================================================*/
function chk_down(arq_nome) {
/*=====================================================*/
	top.parent.frames[1].frames[1].location.href ="baixa.asp?arq="+arq_nome;
}
/*=====================================================*/
function showIt(lay) {
/*=====================================================*/
if (ie4) {document.all[lay].style.visibility = "visible";}
if (ns4) {document.layers[lay].visibility = "show";}
if (ns6) {document.getElementById([lay]).style.display = "block";}
}

/*=====================================================*/
function hideIt(lay) {
/*=====================================================*/
if (ie4) {document.all[lay].style.visibility = "hidden";}
if (ns4) {document.layers[lay].visibility = "hide";}
if (ns6) {document.getElementById([lay]).style.display = "none";}
}

/*=====================================================*/
function launchCenter(url, name, height, width) {
/*=====================================================*/
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  return window.open(url, name, str);
}

/*=======================================================*/
function ToggleDisplay(oButton, oItems) {
/*=======================================================*/
	if ((oItems.style.display == "") || (oItems.style.display == "none")) {
		oItems.style.display = "block";
		oButton.src = "/images/minus.jpg";
	}	else {
		oItems.style.display = "none";
		oButton.src = "/images/plus.jpg";
	}

	return false;

}

/*=======================================================*/
function HideDisplay(oItems) {
/*=======================================================*/
	oItems.style.display = "none";

}

/*=======================================================*/
function ShowDisplay(oItems) {
/*=======================================================*/
	oItems.style.display = "block";

}

/*======================================================*/
function inc_base(nome_campo,xop)   {
/*======================================================*/
//alert(nome_campo);
if (xop ==  1)
	{
	parent.frames[1].location.href = "base_inc_item.asp?base="+nome_campo+"&operacao="+xop
	}	
else if (xop ==  4)
	{
	parent.frames[1].location.href = "prod_exc.asp?operacao=1&produto="+nome_campo+"&xop="+xop
	}	
return true;
}

/*=======================================================*/
function baixa(par) {
/*=======================================================*/
if (par == 2) {
   if (document.f_base_atual.n_base_atual.value < 1)  {
	   alert("Nenhuma base foi selecionada para Download.");
	   return false;
		}
	else
		{
		parent.frames[0].location.href = "down_base.asp?tp=1";
		}
	}
else if (par == 1) 
	{
	location.href ="down_base.asp?tp=3";
	}
else if (par == 3) 
	{
	location.href ="bases.asp";
	}
}

/*=======================================================*/
function down_td(par) {
/*=======================================================*/
if (par == 2) {
   if (document.f_tds.n_tds.value < 1)  {
	   alert("Nenhuma base foi selecionada para Download.");
	   return false;
		}
	else
		{
		parent.frames[0].location.href = "/basesbd/down_base.asp?tp=1&op=2";
		}
	}
else if (par == 1) 
	{
	location.href ="/basesbd/down_base.asp?tp=3&op=2";
	}
else if (par == 3) 
	{
	location.href ="/textos_navega.asp";
	parent.frames[1].location.href = "/td_down.asp";
	top.div_compras.style.visibility="visible";
	}
}
/*=======================================================*/
function chk_log_ceb()   {
/*=======================================================*/
	if (document.f_login.login_user.value == "")	{
        alert ("Por favor, informe o LOGIN.");
		document.f_login.login_user.focus();
		return false;
	}

	if (document.f_login.login_pwd.value == "")	{
        alert ("Por favor, informe a SENHA.");
		document.f_login.login_pwd.focus();
		return false;
	}	
return true;
} 
/*=======================================================*/
function lembrar(opc)   {
/*=======================================================*/
	if (document.f_login.login_user.value == "")	{
        alert ("Por favor, o LOGIN precisa ser informado.");
		document.f_login.login_user.focus();
		return false;
	}
	if (opc == 2) {
		location.href = "/admin/adm_user.asp?tp=5&login_user=" + document.f_login.login_user.value;
		}
	else if (opc == 3) {
		location.href = "/admin/adm_senha.asp?login_user=" + document.f_login.login_user.value;
	}
	return true;

}
/*=======================================================*/
function chk_inc_base()   {
/*=======================================================*/
   if (document.f_base_1.xdesc.value == "")  {
     alert("Por favor, informe a descrição do série.");
     document.f_base_1.xdesc.focus();
     return (false);
   }

   if (document.f_base_1.xnom.value == "")  {
     alert("O nome do arquivo não foi composto.\n Por favor, use as opções ao lado.");
     document.f_base_1.xnom.focus();
     return (false);
   }

   if (document.f_base_1.xnum.value == "")  {
     alert("Por favor, informe o número do série");
     document.f_base_1.xnum.focus();
     return (false);
   }
return true;
}

/*=======================================================*/
function chk_carrinho()   {
/*=======================================================*/
	if (document.form_carrinho.ceprbce.value == "") {
		alert("Por favor, informe o CEP corretamente.");
		document.form_carrinho.ceprbce.focus();
		return (false);
	}
  
return true;
}

/*=====================================================*/
function Encrypt(theText) {
/*=====================================================*/
	output = new String;
	Temp = new Array();
	Temp2 = new Array();
	TextSize = theText.length;
	for (i = 0; i < TextSize; i++) {
		rnd = Math.round(Math.random() * 122) + 68;
		Temp[i] = theText.charCodeAt(i) + rnd;
		Temp2[i] = rnd;
	}
	for (i = 0; i < TextSize; i++) {
		output += String.fromCharCode(Temp[i], Temp2[i]);
	}
return output;
}

/*=====================================================*/
function unEncrypt(theText) {
/*=====================================================*/
	output = new String;
	Temp = new Array();
	Temp2 = new Array();
	TextSize = theText.length;
	for (i = 0; i < TextSize; i++) {
		Temp[i] = theText.charCodeAt(i);
		Temp2[i] = theText.charCodeAt(i + 1);
	}
	for (i = 0; i < TextSize; i = i+2) {
		output += String.fromCharCode(Temp[i] - Temp2[i]);
	}
return output;
}

/*=====================================================*/
function xor_str(str){
/*=====================================================*/
	var to_enc = str
	var xor_key=1
	var the_res="";//the result will be here
	for(i=0;i<to_enc.length;++i)
	{
		the_res+=String.fromCharCode(xor_key^to_enc.charCodeAt(i));
	}

	return the_res;
}

/*=====================================================*/
function decrypt_str(str){
/*=====================================================*/
	var to_dec=str
	var xor_key=1
	var the_res="";//the result will be here
	for(i=0;i<to_dec.length;i++)
	{
		the_res+=String.fromCharCode(xor_key^to_dec.charCodeAt(i));
	}
	return the_res;
}
/*=======================================================*/
/*             End    of    program                      */
/*=======================================================*/
