//Função para Cálculo do Digito do CPF/CNPJ
function DigitoCPFCNPJ(numCIC) {
var numDois = numCIC.substring(numCIC.length-2, numCIC.length);
var novoCIC = numCIC.substring(0, numCIC.length-2);
switch (numCIC.length){
 case 11 :
  numLim = 11;
  break;
 case 14 :
  numLim = 9;
  break;
 default : return false;
}
var numSoma = 0;
var Fator = 1;
for (var i=novoCIC.length-1; i>=0 ; i--) {
 Fator = Fator + 1;
 if (Fator > numLim) {
  Fator = 2;
 }
 numSoma = numSoma + (Fator * Number(novoCIC.substring(i, i+1)));
}
numSoma = numSoma/11;
var numResto = Math.round( 11 * (numSoma - Math.floor(numSoma)));
   if (numResto > 1) {
 numResto = 11 - numResto;
   }
   else {
 numResto = 0;
   }
   //-- Primeiro dígito calculado.  Fará parte do novo cálculo.
   
   var numDigito = String(numResto);
   novoCIC = novoCIC.concat(numResto);
   //--
numSoma = 0;
Fator = 1;
for (var i=novoCIC.length-1; i>=0 ; i--) {
 Fator = Fator + 1;
 if (Fator > numLim) {
  Fator = 2;
 }
 numSoma = numSoma + (Fator * Number(novoCIC.substring(i, i+1)));
}
numSoma = numSoma/11;
numResto = numResto = Math.round( 11 * (numSoma - Math.floor(numSoma)));
   if (numResto > 1) {
 numResto = 11 - numResto;
   }
   else {
 numResto = 0;
   }
//-- Segundo dígito calculado.
numDigito = numDigito.concat(numResto);
if (numDigito == numDois) {
 return true;
}
else {
 return false;
}
}
//--< Fim da Função >--

//-- Retorna uma string apenas com os números da string enviada
function ApenasNum(strParm) {
strParm = String(strParm);
var chrPrt = "0";
var strRet = "";
var j=0;
for (var i=0; i < strParm.length; i++) {
 chrPrt = strParm.substring(i, i+1);
 if ( chrPrt.match(/\d/) ) {
  if (j==0) {
   strRet = chrPrt;
   j=1;
  }
  else {
   strRet = strRet.concat(chrPrt);
  }
 }
}
return strRet;
}
//--< Fim da Função >--

//-- Somente aceita os caracteres válidos para CPF e CNPJ.
function PreencheCIC(objCIC) {
var chrP = objCIC.value.substring(objCIC.value.length-1, objCIC.value.length);

if ( !chrP.match(/[0-9]/) && !chrP.match(/[\/.-]/) ) {
 objCIC.value = objCIC.value.substring(0, objCIC.value.length-1);
 return false;
}
return true;
}
//--< Fim da Função >--

function FormataCIC (numCIC) {
numCIC = String(numCIC);
switch (numCIC.length){
case 11 :
 return numCIC.substring(0,3) + "." + numCIC.substring(3,6) + "." + numCIC.substring(6,9) + "-" + numCIC.substring(9,11);
case 14 :
 return numCIC.substring(0,2) + "." + numCIC.substring(2,5) + "." + numCIC.substring(5,8) + "/" + numCIC.substring(8,12) + "-" + numCIC.substring(12,14);
default : 
 alert("Tamanho incorreto do CPF ou CNPJ!");
 return "";
}
}

//-- Remove os sinais, deixando apenas os números e reconstroi o CPF ou CNPJ, verificando a validade
//-- Recebe como parâmetros o número do CPF ou CNPJ, com ou sem sinais e o atualiza com sinais é validado.
function ConfereCPFCNPJ(objCIC) {
	if (objCIC.value == "") {
 		alert("Preenchimento obrigatório do CPF ou CNPJ");
 		return false;
	}
	var strCPFPat  = /^\d{3}\.\d{3}\.\d{3}-\d{2}$/;
	var strCNPJPat = /^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/;

	numCPFCNPJ = ApenasNum(objCIC.value);

	if (!DigitoCPFCNPJ(numCPFCNPJ)) {
 		alert("Atenção o Dígito verificador do CPF ou CNPJ é inválido!");
 		return false;
	}
	objCIC.value = FormataCIC(numCPFCNPJ);

	if (objCIC.value.match(strCNPJPat)) {
 		return true;
	}
	else if (objCIC.value.match(strCPFPat)) {
 		return true;
	}
	else {
 		alert("Digite um CPF ou CNPJ válido!");
 		return false;
	}
}

//Fim da Função para Cálculo do Digito do CPF/CNPJ
//==============================================================================================================
//Fim da Função para Cálculo do Digito do CPF/CNPJ
//==============================================================================================================


//===========================================================================================================================
//-- Somente aceita letras.
function Preencheletras(objnum) {
var chrP = objnum.value.substring(objnum.value.length-1, objnum.value.length);

if ( !chrP.match(/[a-z]/) && !chrP.match(/[ ]/) && !chrP.match(/[0-9]/)) {
 objnum.value = objnum.value.substring(0, objnum.value.length-1);
 return false;
}
return true;
}
//-- Somente aceita numeros.
function Preenchenum(objnum) {
var chrP = objnum.value.substring(objnum.value.length-1, objnum.value.length);

if ( !chrP.match(/[0-9]/) ) {
 objnum.value = objnum.value.substring(0, objnum.value.length-1);
 return false;
}
return true;
}

// Deixa so' os digitos no numero
function limpa_string(S){
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 isEmpty
* Verifica se um campo está vazio
* Input: campo a ser verificado
************************************************/

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}

/************************************************
* function isNumeric
* Verifica se um campo é numérico. Se contém apenas dígitos de 0 a 9
* Input: campo a ser verificado
************************************************/

function isNumeric(s){
	var i;
	if (isEmpty(s))
		return false;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}

// Verifica se o caracter é um dígito de 0 a 9
function isDigit (c)
{ return ((c >= "0") && (c <= "9")) }

// Retorna o código ASC do caracter passada por parâmetro
function asc(achar){
	var n=0;
	var ascstr = makeCharsetString()
	for(i=0;i<ascstr.length;i++){
		if(achar==ascstr.substring(i,i+1)){
			n=i;
			break;
		}
	}
	return n+32
}
// Verifica se campo preenchido
function CampoBranco(campo) {
	if(campo.value == "")
		return true;
	else
		return false;
}
function cxBranco(cax) {
	if (cax.checked != true) 
		return true;
	else
		return false;
}

function valida_email(email) {
	var array_arroba;
	var array_ponto;

	if ( email.indexOf("@") == -1 ) {
		return false;
	}
	else {
		array_arroba = email.split("@");
		if (array_arroba.length != 2) {
			return false;
		}
		if (array_arroba[0] == "" || array_arroba[1] == "")	{
			return false;
		}
		if ( array_arroba[1].indexOf(".") == -1 ) {
			return false;
		}
		else {
			array_ponto = array_arroba[1].split(".");
			for (i = 0 ; i < array_ponto.length ; i++) {
				if (array_ponto[i] == "") {
					return false;
				}
			}
		}	
	}
	
	return true;
}

//-->
<!--
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + 'R$' + num + '.' + cents);
}
//_____________________________________________________________________________________fale_conosco.asp______________________

function submit_page(form) {

		if(CampoBranco(form.nome) == true) {
    	alert("Preencha o NOME.");
   		form.nome.focus();
    	return false;
	}
		if(CampoBranco(form.empresa) == true) {
    	alert("Preencha a empresa.");
   		form.empresa.focus();
    	return false;
	}

	    if(CampoBranco(form.email) == true) {
    	alert("Preencha seu e-mail.");
   		form.email.focus();
    	return false;
	}
	
	    if ( ! valida_email(form.email.value) ){ 
	    alert ("E-mail Inválido !\n");
		form.email.select();    	
		form.email.focus() ;   
		return false;	
	}
		if(CampoBranco(form.msg) == true) {
    	alert("Por favor, preencha a mensagem.");
   		form.msg.focus();
    	return false;
	}

} 
//____________________________________________________________________________________________pessoa_fisica.asp_______________

function submit_page2(form) {
		if(CampoBranco(form.nome) == true) {
    	alert("Preencha o NOME.");
   		form.nome.focus();
    	return false;
	}
		if (!validaData(form.dnasc)) {
    	alert("Data invalida.");
   		form.dnasc.focus();
		form.dnasc.select();
    	return false;		
	}
		if(CampoBranco(form.ps_end) == true) {
    	alert("Preencha o ENDEREÇO.");
   		form.ps_end.focus();
    	return false;
	}
		if(CampoBranco(form.ps_bairro) == true) {
    	alert("Preencha o BAIRRO.");
   		form.ps_bairro.focus();
    	return false;
	}
		if(CampoBranco(form.ps_cidade) == true) {
    	alert("Preencha o CIDADE.");
   		form.ps_cidade.focus();
    	return false;
	}
		if(CampoBranco(form.ps_uf) == true) {
    	alert("Preencha o ESTADO.");
   		form.ps_uf.focus();
    	return false;
	}
		if(CampoBranco(form.ps_cep) == true) {
    	alert("Preencha o CEP.");
   		form.ps_cep.focus();
    	return false;
	}
			if(form.ps_cep.value.length < 8) {
    	alert("Preencha o CEP com 8 digitos.");
   		form.ps_cep.focus();
    	return false;
	}
		if(CampoBranco(form.ps_fone) == true) {
    	alert("Preencha o TELEFONE.");
   		form.ps_fone.focus();
    	return false;
	}
		if(form.ps_fone.value.length < 10) {
    	alert("O TELEFONE deve estar no formato DDNNNNNNNN \nEx: 1138652244.");
   		form.ps_fone.focus();
    	return false;
	}
		if(CampoBranco(form.ps_mail) == true) {
    	alert("Preencha o e-mail.");
   		form.ps_mail.focus();
    	return false;
	}
	    if ( ! valida_email(form.ps_mail.value) ){ 
	    alert ("E-mail Inválido !\n");
		form.ps_mail.select();    	
		form.ps_mail.focus() ;   
		return false;	
	}
		if(CampoBranco(form.faculdade1) == true) {
    	alert("Preencha Faculdade ou Instituição.");
   		form.faculdade1.focus();
    	return false;
	}
		if(CampoBranco(form.diploma1) == true) {
    	alert("Preencha o DIPLOMA.");
   		form.diploma1.focus();
    	return false;
	}
		if(CampoBranco(form.conclusao1) == true) {
    	alert("Preencha a CONCLUSÃO.");
   		form.conclusao1.focus();
    	return false;
	}
	
	var categoria 
	var pgto
	if (form.selectsocio[0].checked == true){
		categoria = form.selectsocio[0].value ;
	}else{
		categoria = form.selectsocio[1].value ;
	}
	if (form.selectpagto[0].checked == true){
		pgto = form.selectpagto[0].value ;
	}else{
		pgto = form.selectpagto[1].value ;
	}
	
	var txt = "A categoria é: "+categoria+"\nA forma de pagamento é: "+pgto+"\nConfirma?"
	if (window.confirm(txt) == false ) {
		return false;
	}
}
//____________________________________________________________________________________________pessoa_juridica.asp_______________

function submit_page3(form) {
		if(CampoBranco(form.empresa) == true) {
    	alert("Preencha a Empresa.");
   		form.empresa.focus();
    	return false;
	}
		if(CampoBranco(form.instituicao) == true) {
    	alert("Preencha a Instituição.");
   		form.instituicao.focus();
    	return false;
	}
		if(CampoBranco(form.ramo) == true) {
    	alert("Preencha a Ramo.");
   		form.ramo.focus();
    	return false;
	}

		if(CampoBranco(form.ende) == true) {
    	alert("Preencha o ENDEREÇO.");
   		form.ende.focus();
    	return false;
	}
		if(CampoBranco(form.bairro) == true) {
    	alert("Preencha o BAIRRO.");
   		form.bairro.focus();
    	return false;
	}
		if(CampoBranco(form.cidade) == true) {
    	alert("Preencha o CIDADE.");
   		form.cidade.focus();
    	return false;
	}
		if(CampoBranco(form.uf) == true) {
    	alert("Preencha o ESTADO.");
   		form.uf.focus();
    	return false;
	}
		if(CampoBranco(form.cep) == true) {
    	alert("Preencha o CEP.");
   		form.cep.focus();
    	return false;
	}
			if(form.cep.value.length < 8) {
    	alert("Preencha o CEP com 8 digitos.");
   		form.cep.focus();
    	return false;
	}
		if(CampoBranco(form.tel) == true) {
    	alert("Preencha o TELEFONE.");
   		form.tel.focus();
    	return false;
	}
		if(form.tel.value.length < 10) {
    	alert("O TELEFONE deve estar no formato DDNNNNNNNN \nEx: 1138652244.");
   		form.tel.focus();
    	return false;
	}
		if(CampoBranco(form.mail) == true) {
    	alert("Preencha o e-mail.");
   		form.mail.focus();
    	return false;
	}
	    if ( ! valida_email(form.mail.value) ){ 
	    alert ("E-mail Inválido !\n");
		form.mail.select();    	
		form.mail.focus() ;   
		return false;	
	}
		if(CampoBranco(form.rep_nome) == true) {
    	alert("Preencha o nome do representante.");
   		form.rep_nome.focus();
    	return false;
	}
		if(CampoBranco(form.rep_end) == true) {
    	alert("Preencha o endereço do representante.");
   		form.rep_end.focus();
    	return false;
	}
		if(CampoBranco(form.rep_bairro) == true) {
    	alert("Preencha o bairro do representante.");
   		form.rep_bairro.focus();
    	return false;
	}
		if(CampoBranco(form.rep_cep) == true) {
    	alert("Preencha o CEP do representante.");
   		form.rep_cep.focus();
    	return false;
	}
		if(form.rep_cep.value.length < 8) {
    	alert("Preencha o CEP com 8 digitos.");
   		form.rep_cep.focus();
    	return false;
	}
		if(CampoBranco(form.rep_cidade) == true) {
    	alert("Preencha o CIDADE.");
   		form.rep_cidade.focus();
    	return false;
	}
		if(CampoBranco(form.rep_uf) == true) {
    	alert("Preencha o ESTADO.");
   		form.rep_uf.focus();
    	return false;
	}
		if(CampoBranco(form.rep_tel) == true) {
    	alert("Preencha o TELEFONE.");
   		form.rep_tel.focus();
    	return false;
	}
		if(form.rep_tel.value.length < 10) {
    	alert("O TELEFONE deve estar no formato DDNNNNNNNN \nEx: 1138652244.");
   		form.rep_tel.focus();
    	return false;
	}
		if(CampoBranco(form.rep_depto) == true) {
    	alert("Preencha o departamento.");
   		form.rep_depto.focus();
    	return false;
	}
	
	var categoria 
	var pgto
	if (form.selectsocio[0].checked == true){
		categoria = form.selectsocio[0].value ;
	}else{
		categoria = form.selectsocio[1].value ;
	}
	if (form.selectpagto[0].checked == true){
		pgto = form.selectpagto[0].value ;
	}else{
		pgto = form.selectpagto[1].value ;
	}
	
	var txt = "A categoria é: "+categoria+"\nA forma de pagamento é: "+pgto+"\nConfirma?"
	if (window.confirm(txt) == false ) {
		return false;
	}
}
//____________________________________________________________________________________________publicacao_bj_avulsos.asp_______________

function submit_page4(form) {
		if(CampoBranco(form.nome2) == true) {
    	alert("Preencha a Nome.");
   		form.nome2.focus();
    	return false;
	}

		if(CampoBranco(form.endereco2) == true) {
    	alert("Preencha o ENDEREÇO.");
   		form.endereco2.focus();
    	return false;
	}
		if(CampoBranco(form.bairro2) == true) {
    	alert("Preencha o BAIRRO.");
   		form.bairro2.focus();
    	return false;
	}
		if(CampoBranco(form.cidade2) == true) {
    	alert("Preencha o CIDADE.");
   		form.cidade2.focus();
    	return false;
	}
		if(CampoBranco(form.uf2) == true) {
    	alert("Preencha o ESTADO.");
   		form.uf2.focus();
    	return false;
	}
		if(CampoBranco(form.cep2) == true) {
    	alert("Preencha o CEP.");
   		form.cep2.focus();
    	return false;
	}
			if(form.cep2.value.length < 8) {
    	alert("Preencha o CEP com 8 digitos.");
   		form.cep2.focus();
    	return false;
	}
		if(CampoBranco(form.tel2) == true) {
    	alert("Preencha o TELEFONE.");
   		form.tel2.focus();
    	return false;
	}
		if(form.tel2.value.length < 10) {
    	alert("O TELEFONE deve estar no formato DDNNNNNNNN \nEx: 1138652244.");
   		form.tel2.focus();
    	return false;
	}
		if(CampoBranco(form.mail2) == true) {
    	alert("Preencha o e-mail.");
   		form.mail2.focus();
    	return false;
	}
	    if ( ! valida_email(form.mail2.value) ){ 
	    alert ("E-mail Inválido !\n");
		form.mail2.select();    	
		form.mail2.focus() ;   
		return false;	
	}

		if(CampoBranco(form.pedido) == true) {
    	alert("Preencha o Pedido.");
   		form.pedido.focus();
    	return false;
	}
	

	var pgto

	if (form.selectpagto[0].checked == true){
		pgto = form.selectpagto[0].value ;
	}else{
		pgto = form.selectpagto[1].value ;
	}
	
	var txt = "A forma de pagamento é: "+pgto+"\nConfirma?"
	if (window.confirm(txt) == false ) {
		return false;
	}
}
//____________________________________________________________________________________________publicacao_bj_assina.asp_______________

function submit_page5(form) {
		if(CampoBranco(form.nome2) == true) {
    	alert("Preencha a Nome.");
   		form.nome2.focus();
    	return false;
	}

		if(CampoBranco(form.endereco2) == true) {
    	alert("Preencha o ENDEREÇO.");
   		form.endereco2.focus();
    	return false;
	}
		if(CampoBranco(form.bairro2) == true) {
    	alert("Preencha o BAIRRO.");
   		form.bairro2.focus();
    	return false;
	}
		if(CampoBranco(form.cidade2) == true) {
    	alert("Preencha o CIDADE.");
   		form.cidade2.focus();
    	return false;
	}
		if(CampoBranco(form.uf2) == true) {
    	alert("Preencha o ESTADO.");
   		form.uf2.focus();
    	return false;
	}
		if(CampoBranco(form.cep2) == true) {
    	alert("Preencha o CEP.");
   		form.cep2.focus();
    	return false;
	}
			if(form.cep2.value.length < 8) {
    	alert("Preencha o CEP com 8 digitos.");
   		form.cep2.focus();
    	return false;
	}
		if(CampoBranco(form.tel2) == true) {
    	alert("Preencha o TELEFONE.");
   		form.tel2.focus();
    	return false;
	}
		if(form.tel2.value.length < 10) {
    	alert("O TELEFONE deve estar no formato DDNNNNNNNN \nEx: 1138652244.");
   		form.tel2.focus();
    	return false;
	}
		if(CampoBranco(form.mail2) == true) {
    	alert("Preencha o e-mail.");
   		form.mail2.focus();
    	return false;
	}
	    if ( ! valida_email(form.mail2.value) ){ 
	    alert ("E-mail Inválido !\n");
		form.mail2.select();    	
		form.mail2.focus() ;   
		return false;	
	}

	var pgto

	if (form.selectpagto[0].checked == true){
		pgto = form.selectpagto[0].value ;
	}else{
		pgto = form.selectpagto[1].value ;
	}
	
	var txt = "A forma de pagamento é: "+pgto+"\nConfirma?"
	if (window.confirm(txt) == false ) {
		return false;
	}
}
//_____________________________________________________________________________________index.asp______________________

function submit_page6(form) {

		if(form.resposta[0].checked == false && form.resposta[1].checked == false && form.resposta[2].checked == false) {
    	alert("Indique uma Resposta.");
   		
    	return false;
	}
} 
//==================================================================================================================================
//==================================================================================================================================
function PressData(s){
	
	if (event.keyCode == 8){
		return s
	}	

	tamanho 	= s.length
	digito1		= s.substring(tamanho - 1,tamanho);
	digito2		= s.substring(tamanho - 2,tamanho - 1);
	
	if (digito1 == '/' && digito2 == '/'){s = s.substring(0,tamanho - 1); }
	
	if (s.length == 2){
		digito	= s.substring(1,2); 
		if (digito == '/'){
			temp 	= '0' + s;
			temp 	= temp.substring(0,3);
		}
		else{
			temp 	= s + '/';
			temp 	= temp.substring(0,3);
		}		
	} 	
	else if (s.length == 5){
		digito	= s.substring(4,5); 
		if (digito == '/'){
			digito	= s.substring(3,4); 
			temp 	= s.substring(0,3) + '0' + digito + '/';
			temp 	= temp.substring(0,6);
		}
		else{
			temp = s + '/';
			temp = temp.substring(0,6);
		}		
	} 	
	else if (s.length == 8){
		digito	= s.substring(6,8); 
		if (digito == '19' || digito == '20'){
			temp 	= s;
		}
		else{
			if (parseInt(digito) > 50){
				digito	= s.substring(6,8); 
				temp 	= s.substring(0,6) + '19' + digito;
			}
			else{
				digito	= s.substring(6,8); 
				temp 	= s.substring(0,6) + '20' + digito;
			}			
		}		
	} 
	else {temp = s}
	
	return temp
}
//==================================================================================================================================
function validaData(campo) { 

	if (campo.value.length != 10) return false; 

	dia = (campo.value.substring(0,2)); 
    mes = (campo.value.substring(3,5)); 
	ano = (campo.value.substring(6,10)); 

	
	// verifica se foram digitados números
	if (isNaN(dia) || isNaN(mes) || isNaN(ano)){
		return false;
	}
		
    // verifica o dia valido para cada mes 
    if ((dia < 01)||(dia < 01 || dia > 30) && (mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
		return false;
	} 

	// verifica se o mes e valido 
	if (mes < 01 || mes > 12 ) { 
		return false;
	} 

	// verifica se e ano bissexto 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
		return false;
	} 
	return true;
}