function alterarLocalidade() {
		document.formCadastro.action = "cph_cadastre.php";
		document.formCadastro.submit();
}

function verifyMail(){
	email = document.formCadastro.strEmail.value;
	if (email == "") {
		return false;
	} else {
		if (email.indexOf("@") == -1) {
			return false;
		} else {
			return true;
		}
	}
}

function checkSexo()
{
	radio = document.formCadastro.strSexo;
	for (i=0;i<radio.length;i++){
	if (radio[i].checked==true)
		return true;
	}
	return false;
}

function checkInformativo()
{
	radio = document.formCadastro.strInformativo;
	for (i=0;i<radio.length;i++){
	if (radio[i].checked==true)
		return true;
	}
	return false;
}

function verifyDate()
{
	dataNascimento = document.formCadastro.strDataNascimento.value;
	
	if (dataNascimento == "") {
		return false;
	}
	
	var err = 0;
	var string = dataNascimento;
	var valid = "0123456789/";
	var ok = "yes";

	for (var i=0; i<string.length; i++)
	{
		var temp = "" + string.substring(i, i+1);

		if (valid.indexOf(temp) == "-1")
			return false;
	}

	if (string.length > 0 && string.length != 10)
		return false;

	if (string.length > 0) {
		dia = string.substring(0, 2);
		barra1 = string.substring(2, 3);
		mes = string.substring(3, 5);
		barra2 = string.substring(5, 6);
		ano = string.substring(6, 10);
		
		if ((dia < 1) || (dia > 31))
			return false;
		if (barra1 != '/')
			return false;
		
		if ((mes < 1) || (mes > 12))
			return false;
		
		if (barra2 != '/')
			return false;
		
		if (ano < 0)
			return false;
		
		if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
		{
			if (dia == 31)
				return false;
		}
		
		if (mes == 2)
		{
			var g = parseInt(ano/4);
	
			if (isNaN(g))
				return false;
	
			if (dia > 29)
				return false;
	
			if ((dia == 29) && (((ano/4) != parseInt(ano/4))))
				return false;
		}
	}
	return(true);
}

function submitForm(){
	var formulario = document.formCadastro;
	if (formulario.strNome.value == ""){
		alert('Favor preencher o campo nome');
		formulario.strNome.focus();
	} else if (verifyMail() == false){
		alert('Favor preencher um e-mail válido');
		formulario.strEmail.focus();
	} else if (verifyDate() == false){ 
		alert('Favor preencher uma data de nascimento válida');
		formulario.strDataNascimento.focus();
	} else if (checkSexo() == false){
		alert('Favor preencher o campo sexo');
	} else if (formulario.strPais.value == ""){
		alert('Favor preencher o campo país');
		formulario.strCidade.focus();
	} else if (formulario.strEstado.value == ""){
		alert('Favor preencher o campo estado');
		formulario.strEstado.focus();
	} else if (formulario.strCidade.value == ""){
		alert('Favor preencher o campo cidade');
		formulario.strCidade.focus();
	} else if (formulario.strSite.value == ""){
		alert('Favor preencher a pergunta sobre como conheceu o site');
		formulario.strSite.focus();
	} else if (checkInformativo() == false){
		alert('Favor preencher a pergunta se você tem interesse em receber nossos informativos sobre saúde corporativa');
	} else {
		formulario.submit();
	}
}

function dateFormat(fld, e) {
	var sep = 0;
  	var key = '';
  	var i = j = 0;
  	var len = len2 = 0;
  	var strCheck = '0123456789';
  	var aux = aux2 = '';
  	var whichCode = (window.Event) ? e.which : e.keyCode;
	 
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // Delete
	if (whichCode == 32) return false; // Space
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	aux = '';
	for(; i < len; i++)
  		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	 
	if (len>8) return false;
	
	for(i = 0; i < len; i++) {
		if (i == 1 || i == 3)
			aux2 += aux.charAt(i) + '/';
		else 
			aux2 +=	aux.charAt(i);
	}
	fld.value = aux2;
  	return false;
}