// JavaScript Document	

function maskCampo(campo, tipo) { 

	var dot = ".-,:;/";
	var key = window.event.keyCode;
	var char = String.fromCharCode(key);
	var Msk = tipo.substring(campo.value.length,campo.value.length+1);
	var Prx = tipo.substring(campo.value.length+1,campo.value.length+2);

	cont = false;
	if (key == 8 || key == 9 || window.event.ctrlKey == true) return true;
	else if (key > 47 && key < 58 && (Msk == "0" || Msk == "?")) cont = true;	
	else if (key > 64 && key < 91 && (Msk == "Z" || Msk == "?")) cont = true;
	else if (key > 96 && key < 123 && (Msk == "z" || Msk == "?")) cont = true;
	else if (char == Msk && dot.indexOf(char) != -1 && dot.indexOf(Msk) != -1) cont = true;
	else if (Msk == "*") cont = true;

	if (cont == true) {
		campo.value = campo.value + char; 
		if (dot.indexOf(Prx) != -1) {
			campo.value = campo.value + Prx;
		}
	}

	return false;
}

	 

		function Validar_Email(email)
		{
			if(email.length < 6) {
				return false;
			}
			var x = 0;
			for (var c=0;c<email.length;c++) {
				if (email.substring(c,c+1) == '@') {
					x = c;
				}
			}
			var y = 0;
			if (x > 0) {
				for (c=x;c<email.length;c++) {
					if (email.substring(c,c+1)=='.') {
						y = c;
						var valida = 1;
					}
				}
				if (y > 0) {
					var dominio = '';
					for (c=x;c<y;c++) {
						dominio = dominio + email.substring(1,c);
					}
				}
			}
			else {
				return false;
			}					
			if (y <= x+2){
				return false;
			}				
			if (valida == 1){
				return true;
			}
		}
		
		function ValidarCadastro()
		{
			if (document.form.nome.value == "") {
				document.form.nome.focus();
				alert("Preencha todos os campos!");
				return;
			}
			
			if (document.form.email.value == "") {
				document.form.email.focus();
				alert("Preencha todos os campos!");
				return;
			}
			
			if (document.form.profissao.value == "") {
				document.form.profissao.focus();
				alert("Preencha todos os campos!");
				return;
			}
			
			if (document.form.nascimento.value == "") {
				document.form.nascimento.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.celular.value == "") {
				document.form.celular.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.civil.value == "") {
				document.form.civil.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.telefone.value == "") {
				document.form.telefone.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.cidade.value == "") {
				document.form.cidade.focus();
				alert("Preencha todos os campo!");
				return;
			}

			
			if (document.form.conhecimento.value == "") {
				document.form.conhecimento.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.local.value == "") {
				document.form.local.focus();
				alert("Preencha todos os campo!");
				return;
			}


			
			if (document.form.email.value != "") {
						if (!Validar_Email(document.form.email.value)) {
						document.form.email.focus();
						alert("E-mail inválido!");
						return; return; }
			}	

			document.form.submit();
			
		}
		
		function ValidarContato()
		{
			if (document.form.nome.value == "") {
				document.form.nome.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.email.value == "") {
				document.form.email.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			if (document.form.mensagem.value == "") {
				document.form.mensagem.focus();
				alert("Preencha todos os campo!");
				return;
			}
			
			document.form.submit();
			//alert("Seus dados foram enviados com sucesso, Aguarde o retorno!");
		}


