function valida_CPF(s){
var i;
var c = s.substr(0,9);
var dv = s.substr(9,2);
var d1 = 0;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
	return true;
}
function valida_cnpj(s){
var i;
var c = s.substr(0,12);
var dv = s.substr(12,2);
var d1 = 0;
if (s.length < 14) {
	return false;
}
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
	return true;
}
function valida_cep(cep) {
    //var teste;teste = cep.indexOf("-");	alert(teste);
	//var tamanho;tamanho = cep.length;alert(tamanho);
	//Se (nao tiver o "-" retorna -1) e se o tamanho for < 8)
	if(cep.indexOf("-")==-1 || cep.length < 9)
	  return false;
	
	var pat = /((\d{5})(-)(\d{3}))|(\d{8})/;
	//Verifica se o "-" foi colocado no local correto
	var cepdiv = cep.match(pat);//alert(cepdiv); 
	if(cepdiv==null)
	 	return false;
	
	return true;
		
}

function raydt(){
   var texto, msgaux, erro; 
   msgaux = 'Volte ao campo correspondente e complete as seguintes informações.' 
   erro=false;

   if ( (document.frm_orc.TP_PESSOA[0].checked == false) && (document.frm_orc.TP_PESSOA[1].checked == false) ){ 
       msgaux+='\n- Escolha o Tipo de Contribuinte: Pessoa Jurídica ou Pessoa Física'; 
       erro=true;
   } 

  
   //Pessoa Jurídica
   if (document.frm_orc.TP_PESSOA[0].checked == true ){   
	   texto = document.frm_orc.CPF_CNPJ.value; 
	   if (texto.length == 0){ 
	       msgaux+='\n- Preencha o CNPJ da Empresa'; 
	       erro=true;
	   }else{
		   if ( (valida_cnpj(document.frm_orc.CPF_CNPJ.value)) == false ){
		       msgaux+='\n- O Número do CNPJ não é valido'; 
		       erro=true;
	       }
       }
	   
	   texto = document.frm_orc.NOME.value; 
	   if (texto.length ==0){ 
		      msgaux+='\n- Preencha a Razão Social da Empresa'; 
		      erro=true;
	   } 
   } 	   
	    
   //Pessoa Fisica	    
   if (document.frm_orc.TP_PESSOA[1].checked == true ){   
	   texto = document.frm_orc.CPF_CNPJ.value; 
	   if (texto.length == 0){ 
	       msgaux+='\n- Preencha o CPF do Responsável por este cadastro'; 
	       erro=true;
	   }else{
	   	   if (valida_CPF(document.frm_orc.CPF_CNPJ.value) == 0 ) {
		       msgaux+='\n- O Número do CPF não é valido'; 
		       erro=true;
	       }
	   }

	   texto = document.frm_orc.NOME.value; 
	   if (texto.length ==0){ 
		      msgaux+='\n- Preencha o Nome da Pessoa'; 
		      erro=true;
	   } 
	   	   	     
   }
   //Restante do Formulário
   texto = document.frm_orc.ENDERECO_COM.value;
   if (texto.length ==0){
       msgaux+='\n- Preencha o Endereço'; 
       erro=true;
   } 

   texto = document.frm_orc.BAIRRO_COM.value; 
   if (texto.length ==0){ 
       msgaux+='\n- Preencha o Bairro ou Setor'; 
       erro=true;
   } 
   texto = document.frm_orc.MUNICIPIO_COM.value; 
   if (texto.length ==0){ 
       msgaux+='\n- Preencha o Municipio'; 
       erro=true;
   } 
    
   if (document.frm_orc.UF_COM.value == ""){ 
       msgaux+='\n- Escolha o Estado'; 
       erro=true;
   } 

   texto = document.frm_orc.DDD.value; 
   if (texto.length < 2){ 
       msgaux+='\n- Dígito DDD é inválido'; 
       erro=true;
   } 

   texto = document.frm_orc.TELEFONE1.value; 
   if (texto.length == 0){ 
       msgaux+='\n- Digite o número de Telefone'; 
       erro=true;
   } 
   
   texto = document.frm_orc.CEP_COM.value;
    if (texto.length == 0){ 
       msgaux+='\n- CEP informado é inválido. Veja o exemplo ao lado deste campo'; 
       erro=true;
   }else{
     if(!(valida_cep(texto))){
       msgaux+='\n- Formatação do CEP é incorreto'; 
       erro=true;
     }	 
   } 
  
   texto = document.frm_orc.CONTATO.value; 
   if (texto.length ==0){ 
       msgaux+='\n- Preencha o Responsável pelo Orçamento'; 
       erro=true;
   }	   
   //texto = document.frm_orc.EMAIL.value; 
   //if (texto.length ==0){ 
   //    msgaux+='\n- O Email deve ser informado para que possamos entrar em contato'; 
   //    erro=true;
   //} 
   texto = document.frm_orc.EMAIL.value; 
   if (texto.length ==0){ 
       //msgaux+='\n- Preencha o CEP'; 
       //erro=true;
	   alert("Você deveria informar um e-mail para Contato");
   } 

   //PEDIDO DE SERVICO
   if ( (document.frm_orc.COND_ENTREGA[0].checked == false) && (document.frm_orc.COND_ENTREGA[1].checked == false) ){ 
       msgaux+='\n- Marque a Condição de Entrega'; 
       erro=true;
   }    

   if (document.frm_orc.TP_PAPEL.value == ""){ 
       msgaux+='\n- Escolha o tipo de Papel'; 
       erro=true;
   } 
   if ( (document.frm_orc.NR_FACES[0].checked == false) && (document.frm_orc.NR_FACES[1].checked == false) ){ 
       msgaux+='\n- Marque o Número de Faces'; 
       erro=true;
   }    

   if (erro) alert(msgaux);
   return !(erro);
}

//function verfonte() {
//  if (event.button==2){
//      window.alert('Acesso Negado !')
//  }
//}

