function buscaPais()
	{
		
	$("#selPais").html("<option value=\"\">" + SITE_FORMULARIO_OPCOES_AGUARDE + "</option>"); 
	$("#selPaisLoading").html("<img src='comum/img/loading-ajax.gif' alt='' />"); 

	$.ajax(
		{
		type: "POST",
		data: "acao=carregarpais",
		url: "_form_enviar.php",
		success: function(retorno)
			{

				$("#selPais").html(retorno);
				$("#selPaisLoading").html(""); 
				
			}
		});           
	}
function buscaUnidadeFederativa(paisID)
	{
	$("#selEstado").html("<option value=\"\">" + SITE_FORMULARIO_OPCOES_AGUARDE + "</option>"); 
	$("#selEstadoLoading").html("<img src='comum/img/loading-ajax.gif' alt='' />");
	$("#selEstado").show();
	$("#selCidade").show();
	$.ajax(
		{
		type: "POST",
		data: "acao=carregarestado&selPais="+paisID,
		url: "_form_enviar.php",
		success: function(retorno)
			{
				$("#selEstado").html(retorno);
				$("#selEstadoLoading").html(""); 
			}
		});           
	}
function buscaCidade(EstadoID)
	{

	$("#selCidade").html("<option value=\"\">" + SITE_FORMULARIO_OPCOES_AGUARDE + "</option>"); 
	$("#selCidadeLoading").html("<img src='comum/img/loading-ajax.gif' alt='' />"); 
	$.ajax(
		{
		type: "POST",
		data: "acao=carregarcidade&selEstado="+EstadoID,
		url: "_form_enviar.php",
		success: function(retorno)
			{
				$("#selCidade").html(retorno);
				$("#selCidadeLoading").html(""); 
			}
		});           
	}

function cadastro()
{	
	var FormCadastroUsuario = "#frmCadastroUsuario";

	// Mostra form(s) ao carregar a página completamente //
	$(FormCadastroUsuario).show();

	// verifica se existe o formulario
	if ($(FormCadastroUsuario).length > 0)
	{
		buscaPais();
		
		$("#selEstado").hide();
		$("#selCidade").hide();
		
		$("#selPais").change( function() 
		{
					
			if($(this).val() == '1')
			{
				$("#txtEstado").hide();
				$("#txtCidade").hide();
				$("#txtEstado").val('');
				$("#txtCidade").val('');			
				$("#selEstado").show();
				buscaUnidadeFederativa($(this).val());	
			}
			else
			{	
			
				$("#selEstado").hide();
				$("#selCidade").hide();
				$("#selEstado").val('');
				$("#selCidade").val('');	
				$("#txtEstado").show();
				$("#txtCidade").show();
			}
		});
		
		$("#selEstado").change( function() 
		{
			buscaCidade($(this).val());
		});
		
		$("#txtFone").mask("(99) 9999-9999");	
		$("#txtCep").mask("99999-999");
		$("#txtCpf").mask("999.999.999/99");
			
		        	$(FormCadastroUsuario).validate({
			                errorPlacement: function(error, element) 
			                {
			                    error.appendTo( $("#errotxt") );
								//error.appendTo( $("#errotxt" + element.attr("id")) );
			                },	
							errorClass:"erro",
							errorElement:"span",
							rules:
			                {
			                    txtNome: 
			                    {
			                        required: true
			                    },								
								txtEmail: 
			                    {
			                        required: true,
			                        email: true //Valida o email
			                    },
								txtFone: 
			                    {
			                        required: true
			                    },								
								txtEndereco: 
			                    {
			                        required: true
			                    },
								txtNumero: 
			                    {
			                        required: true
			                    },								
			                    txtBairro:
			                    {
			                        required: true
			                    },
								txtCep:
								{
									required: true
								},
								selPais:
								{
									required: true
								},
								selEstado:
								{
									required: function(element) 
									{
										return $("#selPais").val() == '1';
									}
								},
								selCidade:
								{
									required: function(element) 
									{
										return $("#selPais").val() == '1';
									}
								}
			                },	
			                messages: 
			                {
			                    txtNome: 
			                    {
			                        required: SITE_CONTATO_NOME_OBRIGATORIO
			                    },	
								txtEmail: 
			                    {
			                        required: SITE_CONTATO_EMAIL_OBRIGATORIO,
			                        email: SITE_CONTATO_EMAIL_INVALIDO
			                    },
								txtFone:
			                    {
			                        required: SITE_CONTATO_TELEFONE_OBRIGATORIO
			                    },
								txtEndereco:
			                    {
			                        required: SITE_CADASTRO_ENDERECO_OBRIGATORIO
			                    },
								txtNumero:
			                    {
			                        required: SITE_CADASTRO_NUMERO_OBRIGATORIO
			                    },
			                    txtBairro:
			                    {
			                        required: SITE_CADASTRO_BAIRRO_OBRIGATORIO
			                    },
								txtCep:
								{
									required: SITE_CADASTRO_CEP_OBRIGATORIO
								},
								selPais:
								{
									required: SITE_CADASTRO_PAIS_OBRIGATORIO
								},
								selEstado:
								{
									required: SITE_CONTATO_ESTADO_OBRIGATORIO
								},
								selCidade:
								{
									required: SITE_CONTATO_MUNICIPIO_OBRIGATORIO
								}
			                }
			            });

	}
}