function validaCadastro(form){
	var f = document.forms[form];   
    var quant = f.elements.length;
	var frases=new Array();
	frases[0]="Opcional";
	frases[1]="Caso responda SIM, descreva qual defici\u00EAncia, suas caracter\u00EDsticas e restri\u00E7\u00F5es.";
	frases[2]="Sem abrevia\u00E7\u00F5es";
	frases[3]="Rua/avenida, n\u00FAmero , complemento.";
	frases[4]="Mais detalhes de sua forma\u00E7\u00E3o (curso, faculdade, conclus\u00E3o, previs\u00E3o de conclus\u00E3o, semestre).";
	frases[5]="Nome da empresa, data de entrada/sa\u00EDda, cargo, atividades exercidas, motivo de sa\u00EDda.";

    for(var i = 0; i < quant; i++){
      var ele = document.forms[form].elements[i];
	  var igual=false;

      if(ele.getAttribute('vazio') == 'false'){
		for(var j=0;j<=frases.length;j++){
			if(ele.value==frases[j]){
				igual=true;
				break;
			}
		}
        if(ele.value == ""||igual){
          var nom = ele.getAttribute('nome');
          alert('O campo ' + nom + ' n\u00E3o pode ficar vazio!');
          ele.focus();
          return false;
          break;
        }
      }else if(ele.getAttribute('email')){
        if(ele.value.indexOf("@") == -1){
          var nom = ele.getAttribute('nome');
          alert('O endere\u00E7o de e-mail digitado no campo ' + nom + ' n\u00E3o \u00E9 v\u00E1lido!');
          ele.focus();
          return false;
          break;
        }
		if(ele.value.indexOf(".") == -1){
          var nom = ele.getAttribute('nome');
          alert('O endere\u00E7o de e-mail digitado no campo ' + nom + ' n\u00E3o \u00E9 v\u00E1lido!');
          ele.focus();
          return false;
          break;
        }
      }else if(ele.getAttribute('emailvalida')){
        if(ele.value.length > 0){
			if(ele.value.indexOf("@") == -1){
			  var nom = ele.getAttribute('nome');
			  alert('O endere\u00E7o de e-mail digitado no campo ' + nom + ' n\u00E3o \u00E9 v\u00E1lido!');
			  ele.focus();
			  return false;
			  break;
			}
			if(ele.value.indexOf(".") == -1){
			  var nom = ele.getAttribute('nome');
			  alert('O endere\u00E7o de e-mail digitado no campo ' + nom + ' n\u00E3o \u00E9 v\u00E1lido!');
			  ele.focus();
			  return false;
			  break;
			}
		}		
      }else if(ele.getAttribute('cpf')){
		  var valor;
		  valor=desformata(ele);
		  if(!validacpf(valor)) {
			var nom = ele.getAttribute('nome');
          	alert('O n\u00FAmero do ' + nom + ' \u00E9 inv\u00E1lido!');
          	ele.focus();
			return false;
            break;
		  }
	  }else if(ele.getAttribute('data')){
		  if(!validaData(ele)) {
			var nom = ele.getAttribute('nome');
          	alert('O valor digitado no ' + nom + ' \u00E9 inv\u00E1lido!');
          	ele.focus();
			return false;
            break;
		  }
	  }/*else if(ele.getAttribute('confirmar') == 'true'){
			var answer = confirm("Clique em OK para enviar ou Cancelar se deseja imprimir antes.")
			if (!answer){
				return false;
				break;
			}
		}*/
    }
	
	d = document.cadastro;
	
	//VALIDA RADIO TIPO DE CONTATO
	controle = 0;
	for (i=0;i<d.tipo.length;i++){
		if (d.tipo[i].checked){
					controle++;
		}
	
	}
	
	if (controle <= 0) {
         alert("Voc\u00EA deve informar o Tipo de Contato.");
		 return false;
	}
	
	//VALIDA RADIO SÓCIO DA COOPERATIVA
	controle = 0;
	for (i=0;i<d.socio.length;i++){
		if (d.socio[i].checked){
					controle++;
		}
	}
	
	if (controle <= 0) {
         alert("Voc\u00EA deve informar se \u00E9 S\u00F3cio da Cooperativa.");
		 return false;
	}
	
	//VALIDA COMBO FAIXA SALARIAL
	 if (d.pretensaosalarial.selectedIndex==0){
		 alert("Voc\u00EA deve informar a sua Pretens\u00E3o Salarial!");
		 return false;
 	}
	
	//VALIDA COMBO ÁREA PROFISSIONAL
	 if (d.areaprofissional.selectedIndex==0){
		 alert("Voc\u00EA deve informar a sua \u00C1rea Profissional!");
		 return false;
 	}
			
	//VALIDA RADIO DEFICIENCIA
	var controle = 0;
	for (i=0;i<d.deficiencia.length;i++){
		if (d.deficiencia[i].checked){
			controle++;
		}
	}
	if (controle <= 0) {
         alert("Voc\u00EA deve informar se tem alguma Defici\u00EAncia F\u00EDsica!");
		 return false;
	}else{
		for (i=0;i<d.deficiencia.length;i++){ 
      	 	if (d.deficiencia[i].checked) 
         	 	break; 
   			}
			if(d.deficiencia[i].value==1){
				if (d.defeito.value.length == 0) {
					alert("Voc\u00EA deve informar a sua Defici\u00EAncia F\u00EDsica!");
					d.defeito.focus();
					return false;
				}else if (d.defeito.value == frases[1]) {
					alert("Voc\u00EA deve informar a sua Defici\u00EAncia F\u00EDsica!");
					d.defeito.focus();
					return false;
				}
			}else{
				d.defeito.value="";
			}
	}
	
	//VALIDA RADIO FILHOS
	controle = 0;
	for (i=0;i<d.filhos.length;i++){
		if (d.filhos[i].checked){
			controle++;
		}
	}
	if (controle <= 0) {
         alert("Voc\u00EA deve informar se tem Filhos!");
		 return false;
	}else{
		for (i=0;i<d.filhos.length;i++){ 
      	 	if (d.filhos[i].checked) 
         	 	break; 
   			}
			if(d.filhos[i].value==1){
				if (d.numfilhos.value.length == 0) {
					alert("Voc\u00EA deve informar Quantos Filhos possui");
					d.numfilhos.focus();
					return false;
				}
			}
	}
			
	//VALIDA RADIO SEXO
	controle = 0;
	for (i=0;i<d.sexo.length;i++){
		if (d.sexo[i].checked){
					controle++;
		}
	}
	
	if (controle <= 0) {
         alert("Voc\u00EA deve informar seu sexo!");
		 return false;
	}
	
	//VALIDA RADIO ESTADO CIVIL
	controle = 0;
	for (i=0;i<d.estcivil.length;i++){
		if (d.estcivil[i].checked){
					controle++;
		}
	}
	
	if (controle <= 0) {
         alert("Voc\u00EA deve informar seu Estado Civil!");
		 return false;
	}
	
	//VALIDA RADIO CARRO PRÓPRIO
	controle = 0;
	for (i=0;i<d.carroproprio.length;i++){
		if (d.carroproprio[i].checked){
					controle++;
		}
	}
	
	if (controle <= 0) {
         alert("Voc\u00EA deve informar se possui Carro Pr\u00F3prio!");
		 return false;
	}
	
	//VALIDA RADIO FORMAÇÃO
	controle = 0;
	for (i=0;i<d.ensinofundamental.length;i++){
		if (d.ensinofundamental[i].checked){
					controle++;
		}
	}
	/*if (controle <= 0) {
         alert("Voc\u00EA deve informar marcar todas as op\u00E7\u00F5es sobre a sua Forma\u00E7\u00E3o!");
		 return false;
	}
	controle = 0;*/
	for (i=0;i<d.ensinomedio.length;i++){
		if (d.ensinomedio[i].checked){
					controle++;
		}
	}

	for (i=0;i<d.ensinosuperior.length;i++){
		if (d.ensinosuperior[i].checked){
					controle++;
		}
	}
	
	for (i=0;i<d.ensinopos.length;i++){
		if (d.ensinopos[i].checked){
					controle++;
		}
	}
	
	if (controle <= 0) {
         alert("Voc\u00EA deve marcar a op\u00E7\u00E3o relativa a sua forma\u00E7\u00E3o");
		 return false;
	}
	
	
	
}

function formata(src, mask) {
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i);
  if (texto.substring(0,1) != saida){
	src.value += texto.substring(0,1);
  }
}

function desformata(src){
	var valor="";
	var digits="0123456789";
	for (var i=0;i<src.value.length;i++){
		campo_temp=src.value.substring(i,i+1);	
		if (digits.indexOf(campo_temp)!=-1){
			valor += src.value.substring(i,i+1);
		}
	}
	return valor;
}

function nu(campo,tipo){
	var digits;
	if(tipo==1){
		digits="0123456789";
	}else if(tipo==2){
		digits="0123456789.-";
	}else if(tipo==3){
		digits="01234567893/";
	}else if(tipo==4){
		digits="01234567893-";
	}else if(tipo==5){
		digits="01234567893 ";
	}
	var campo_temp ;
	for (var i=0;i<campo.value.length;i++){
		campo_temp=campo.value.substring(i,i+1) 
		if (digits.indexOf(campo_temp)==-1){
			campo.value = campo.value.substring(0,i);
			break;
		}
	}
}
function up(campo){
	var campo_temp ;
	var digits="0123456789";
	for (var i=0;i<campo.value.length;i++){
		campo_temp=campo.value.substring(i,i+1) 
		if (digits.indexOf(campo_temp)!=-1){
			campo.value = "";
			break;
		}
	}
	campo.value = campo.value.toUpperCase();
}

function validacpf(s){   
	var i; 
	var c = s.substr(0,9);   
	var dv = s.substr(9,2);   
	var d1 = 0; 

	if (s == "00000000000" || s == "11111111111" || s == "22222222222" || s ==
"33333333333" || s == "44444444444" || s == "55555555555" || s ==
"66666666666" || s == "77777777777" || s == "88888888888" || s ==
"99999999999"){   
		return false;  
	}
	
	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 validaRG(numero){
	var numero = numero.split("");
	tamanho = numero.length;
	vetor = new Array(tamanho);
	
	if(tamanho>=1){
	 vetor[0] = parseInt(numero[0]) * 2; 
	}
	if(tamanho>=2){
	 vetor[1] = parseInt(numero[1]) * 3; 
	}
	if(tamanho>=3){
	 vetor[2] = parseInt(numero[2]) * 4; 
	}
	if(tamanho>=4){
	 vetor[3] = parseInt(numero[3]) * 5; 
	}
	if(tamanho>=5){
	 vetor[4] = parseInt(numero[4]) * 6; 
	}
	if(tamanho>=6){
	 vetor[5] = parseInt(numero[5]) * 7; 
	}
	if(tamanho>=7){
	 vetor[6] = parseInt(numero[6]) * 8; 
	}
	if(tamanho>=8){
	 vetor[7] = parseInt(numero[7]) * 9; 
	}
	if(tamanho>=9){
	 vetor[8] = parseInt(numero[8]) * 100; 
	}
	
	 total = 0;
	
	if(tamanho>=1){
	 total += vetor[0];
	}
	if(tamanho>=2){
	 total += vetor[1]; 
	}
	if(tamanho>=3){
	 total += vetor[2]; 
	}
	if(tamanho>=4){
	 total += vetor[3]; 
	}
	if(tamanho>=5){
	 total += vetor[4]; 
	}
	if(tamanho>=6){
	 total += vetor[5]; 
	}
	if(tamanho>=7){
	 total += vetor[6];
	}
	if(tamanho>=8){
	 total += vetor[7]; 
	}
	if(tamanho>=9){
	 total += vetor[8]; 
	}
	
	resto = total % 11;
	
	if(resto!=0){
		return false;
	}

}
function validaData(pObj) {
  var expReg = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/(19|20)?\d{2}$/;
  var aRet = true;
  if ((pObj) && (pObj.value.match(expReg)) && (pObj.value != '')) {
        var dia = pObj.value.substring(0,2);
        var mes = pObj.value.substring(3,5);
        var ano = pObj.value.substring(6,10);
        if ((mes == 4 || mes == 6 || mes == 9 || mes == 11 ) && dia > 30) 
          aRet = false;
        else 
          if ((ano % 4) != 0 && mes == 2 && dia > 28) 
                aRet = false;
          else
                if ((ano%4) == 0 && mes == 2 && dia > 29)
                  aRet = false;
  }  else 
        aRet = false;  
  return aRet;
}
function limpaCampo(form,texto){
	var f = document.forms[form]; 
	alert(f.value);
	alert(texto);
	if(f.value == texto){
		f.value = '';
	}
}

function limpa_campo(campo,msg)
	{
	//alert($(campo).value);
	if($(campo).value == '')
		$(campo).value = msg;
	else if($(campo).value == msg)
		$(campo).value = '';
	}

function validarform(modulo)
	{
	 
	Exp = /(^[A-Za-z0-9_.-]+@([A-Za-z0-9_]+\.)+[A-Za-z]{2,4}$)/;
    var mensagem = '';
    switch(modulo)
		{
		case 'informativo':
		
		d = document.informativo
		
         if (d.nome.value.length == 0 || d.nome.value == 'Nome') mensagem += "- Nome\n"; 
             //if ($('email').value.length == 0) mensagem += "- E-mail\n";  
			if (!Exp.test(d.email.value)) mensagem += "- E-mail inv\u00e1lido\n";
        break;
		
		}
		
	if (modulo == 0 || modulo == 'Buscar Not\u00EDcias') mensagem += "- Buscar Not\u00EDcias\n";

    if (mensagem) 
		{
        alert('Campos de preenchimento obrigat\u00f3rio:\n'+mensagem);
        return false;
    	} 
	else 
		return true;
	}

//SOMENTE LETRAS
 
function SomenteLetras(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 SomenteNumeros(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 exportar_pdf() {
     window.open('pdf.php?'+$("form").serialize());
}
