var Ajax = false;

function AjaxRequest() {
				Ajax = false;
				
		        if (window.XMLHttpRequest) { // Mozilla, Safari,...
		            Ajax= new XMLHttpRequest();
					
		        } else if (window.ActiveXObject) { // IE
		            try {
		                Ajax = new ActiveXObject("Msxml2.XMLHTTP");
		            } catch (e) {
		                try {
		                    Ajax = new ActiveXObject("Microsoft.XMLHTTP");
		                } catch (e) {}
		            }
		        }		
			}

function validar() 
	{
		if( document.frmIdentificacao.cxnascimento.value == '')
		 {
			alert('Por favor, digite a data de nascimento');
			document.frmIdentificacao.cxnascimento.focus();
			return false;
		 }
		if( document.frmIdentificacao.cxnome.value == '')
		 {
			alert('Por favor, digite o nome do candidato');
			document.frmIdentificacao.cxnome.focus();
			return false;
		 }
		 //*
		 if( document.frmIdentificacao.cxsexo.value == '')
		 {
			alert('Por favor, escolha o sexo');
			document.frmIdentificacao.cxsexo.focus();
			return false;
		 }
		if( document.frmIdentificacao.cxuf.value == '')
		 {
			alert('Por favor, escolha a UF');
			document.frmIdentificacao.cxuf.focus();
			return false;
		 }
		 //*
		 if( document.frmIdentificacao.cxcep.value == '')
		 {
			alert('Por favor, digite o cep');
			document.frmIdentificacao.cxcep.focus();
			return false;
		 }
		if( document.frmIdentificacao.cxcidade.value == '')
		 {
			alert('Por favor, preencha o campo cidade');
			document.frmIdentificacao.cxcidade.focus();
			return false;
		 }
		 if( document.frmIdentificacao.cxbairro.value == '')
		 {
			alert('Por favor, preencha o campo bairro');
			document.frmIdentificacao.cxbairro.focus();
			return false;
		 }
		 if( document.frmIdentificacao.cxendereco.value == '')
		 {
			alert('Por favor, preencha o campo endereço');
			document.frmIdentificacao.cxendereco.focus();
			return false;
		 }
		/* if( document.frmIdentificacao.cxcomplemento.value == '')
		 {
			alert('Por favor, preencha o campo complemento');
			document.frmIdentificacao.cxcomplemento.focus();
			return false;
		 }*/
		if( document.frmIdentificacao.cxdddres.value == '')
		 {
			alert('Por favor, digite o ddd do telefone residencial');
			document.frmIdentificacao.cxdddres.focus();
			return false;
		 }
		 if( document.frmIdentificacao.cxfoneres.value == '' && document.frmIdentificacao.cxfonecel.value == '')
		 {
			alert('Por favor, digite um telefone para contato');
			document.frmIdentificacao.cxfoneres.focus();
			return false;
		 }
		  if( document.frmIdentificacao.cxfonecel.value != '' && document.frmIdentificacao.cxdddcel.value == '' )
		 {
			alert('Por favor, digite o ddd do telefone celular');
			document.frmIdentificacao.cxdddcel.focus();
			return false;
		 }
		if( document.frmIdentificacao.cxformacao.value == '')
		 {
			alert('Por favor, digite a formação escolar');
			document.frmIdentificacao.cxformacao.focus();
			return false;
		 }
		/* if( document.frmIdentificacao.cxformacaocurso.value == '')
		 {
			alert('Por favor, digite o nome do curso em que você se formou');
			document.frmIdentificacao.cxformacaocurso.focus();
			return false;
		 }*/
		return true;
	}

function selecionarCidade() { 
				var $co_uf = document.getElementById('cxuf').value;

				if($co_uf != "")
				 {
					AjaxRequest(); 
					if(!Ajax)
					 {
						alert('Não foi possível iniciar o AJAX');
						return;
					}
	        		Ajax.onreadystatechange = mostraCidade;
    	    		//Ajax.open('GET', 'lista_veiculos_cliente.php?num_cgc_cpf='+num_cgc_cpf, true);
					Ajax.open('GET', '/lista_cidade.php?co_uf='+$co_uf, true);
        			Ajax.send(null);
				}
				 else
				 {
					alert('favor selecionar a uf!');
				}
			} 
			
 function mostraCidade() 
{ 
				if (Ajax.readyState == 4)
				 {
            		if (Ajax.status == 200)
					{
						var xmldoc = Ajax.responseText.split("|"); 
						
						if(xmldoc == 0) 
						 {
						   return false;
						 }
						 else
						 {
							var selp = document.frmIdentificacao.cxcidade;
							selp.options.length = 0;
							//selp.options[0] = new Option('-- Selecione o Município --',"");
							//selp.options[1] = new Option('TODOS',0);
                             ii=1;
							for(var i=0;i < xmldoc.length-1;i+=2)
							 {
								var cod = xmldoc[i];
								var des = xmldoc[i+1];
								selp.options[ii++] = new Option(des,cod);
							}
						}
            		}
					else
					 {
						alert('Erro no Retorno do Servidor ' + Ajax.statusText);
            		}
        		}
}
function atualizaCombo(uf)
{
   document.getElementById("cxuf").value=uf;
}
function formataCPF(event, campo) {
		if (event.keyCode != 8) {
			if (event.keyCode != 46)
				if ((campo.value.length == 3) || (campo.value.length == 7))
					campo.value += '.';
			if (event.keyCode != 45)
				if (campo.value.length == 11)
					campo.value += '-';
		}	
	}

	function isCPF(txtField){ 
	  var i; 
	  s = txtField.value;  

	  if ( s.substr(3,1) != '.' || s.substr(7,1) != '.' || s.substr(11,1) != '-' ) {
		return false;
	  }	

	  s = s.substr(0,3) + s.substr(4,3) + s.substr(8,3) + s.substr(12,2);

	  if ( s == '11111111111' || s == '22222222222' || s == '33333333333' || s == '44444444444' || s == '55555555555' || s == '66666666666' || s == '77777777777' || s == '88888888888' || s == '99999999999' || s == '00000000000' ) {
		  return false;
	  }

	  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; 
	}		