$(document).ready(function(){
	$("#data_nascimento").mask("99/99/9999");	
	$("#cpf").mask("999.999.999-99");	
	$("#rg").mask("99999999-99");
	$("#cep").mask("99999-999");		
	$("#telefone").mask("(99) 9999.9999");	
	$("#celular").mask("(99) 9999.9999");	
	$("#tel_comercial").mask("(99) 9999.9999");	

	// Realiza o cadastro do usuário 
	$("#btnCadastrarUser").click(function(){
										  
		if ($("#nome").val().length == 0) {
			alert(VldCadAlertNome);
			$("#nome").focus();
			return false;
		}
		
		if (validar_data($("#data_nascimento").val()) == false) {
			alert(VldCadAlertData_Nasc_Inv);
			$("#data_nascimento").focus();
			return false;
		}
		
		if (validaCPF($("#cpf").val()) == false) {
			alert(VldCadAlertCPF_Inv);
			$("#cpf").focus();
			return false;
		}

		if ($("#telefone").val().length == 0) {
			alert(VldCadAlertTelefone);
			$("#telefone").focus();
			return false;
		}


		if (validar_email($("#email").val()) == false) {
			alert(VldCadAlertEmail_Inv);
			$("#email").focus();
			return false;
		}
		
		if ($("#senha").val().length == 0) {	
			alert(VldCadAlertSenha);
			$("#senha").focus();
			return false;
		}

		if ($("#conf_senha").val().length == 0) {	
			alert(VldCadAlertConfSenha);
			$("#conf_senha").focus();
			return false;
		}
		
		if ($("#senha").val().length > 0) {	
			if ($("#senha").val().length != $("#conf_senha").val().length) {	
				alert(VldCadAlertSenhaDif);
				$("#senha").focus();
				return false;
			}
		}
	
		if ($("#endereco").val().length == 0) {
			alert(VldCadAlertEndereco);
			$("#endereco").focus();
			return false;
		}

		if ($("#numero").val().length == 0) {
			alert(VldCadAlertNumero);
			$("#numero").focus();
			return false;
		}
	
		if ($("#bairro").val().length == 0) {
			alert(VldCadAlertBairro);
			$("#bairro").focus();
			return false;
		}
	
		if (valida_estado($("#estado").val()) == false) {
			alert(VldCadAlertEstado_Inv);
			$("#estado").focus();
			return false;
		}

		if ($("#cidade").val().length == 0) {
			alert(VldCadAlertCidade);
			$("#cidade").focus();
			return false;
		}
		$(this).hide();
		$("#ico-loader").show();
		$('form#frmCadastrarCliente').ajaxSubmit({
			url 			: 'e-commerce/actions/cadastrar_cliente.php',
			dataType 		: "xml",
			type	 		: "POST",
			success:function(xml) 
			{
				if ($(xml).find('erro').text() == 1)
				{
					alert("Seu cadastrado não foi preenchido corretamente.\nExistem campos em branco em formulário.");
					$("#email").focus();
				}
				if ($(xml).find('erro').text() == 2)
				{
					alert(AlertEmailJaCadastrado);
				}
				if ($(xml).find('erro').text() == 0)
				{
					alert("Cadastro realizado com sucesso!");
					location.reload();
				}
				$("#btnCadastrarUser").show();
				$("#ico-loader").hide();
			}
		}); // End Ajax 
		
	});
});

function mudaInfoGestante (opcao)
{
	if (opcao == 1) 
	{
		$(".tr_tempo_gestacao").show()
		$(".tr_idade_bebe").hide()
	}
	else 
	{
		$(".tr_tempo_gestacao").hide()
		$(".tr_idade_bebe").show()
	}
}
