function Pessoa()
{
	var FormCadastroPessoa = "#frmCadastro";
	var FormLogin = "#frmLogin";
	var FormRecuperarSenha = "#frmRecuperarSenha";
	
	if($(FormCadastroPessoa).length > 0)
	{	
		$(FormCadastroPessoa).validate
		(
		 	{
		 		errorPlacement: function(error, element) 
				{
					error.appendTo($("#alerta"));
				},
				errorClass: "erro",
				errorElement: "span",
				rules:
				{
					txtNome: 
					{
						required: true
					},
					radSexo:
					{
						required: true
					},
					txtNumeroPe:
					{
						required: true
					},
					txtDataNascimento:
					{
						required: true,
						data: true
					},
					txtTelefone:
					{
						required: true
					},
					txtCPF:
					{
						required: function()
						{
							if($("#selPais").val() == 1)
							{
								return true;
							}
							else
							{
								return false;
							}			
						},
						cnpf: function()
						{
								return $("#selPais").val() == 1
						},
						remote: SITE_CAMINHO_SITE_ABSOLUTO + "acao/Pessoa.php?acao=ValidarCpf"
					},
					txtEmail:
					{
						required: true,
						"email": true,
						remote: SITE_CAMINHO_SITE_ABSOLUTO + "acao/Pessoa.php?acao=ValidarEmail"
					},
					txtMSN:
					{
						required: false,
						"email": true
					},
					selOcupacao:
					{
						required: true
					},
					radFilhos:
					{
						required: true
					},
					txtEndereco:
					{
						required: true
					},
					txtNumero:
					{
						required: true
					},
					selPais:
					{
						required: true
					},
					selUnidadeFederativa:
					{
						required: function(){
							if($("#selPais").val() == "1") return true;
							else return false;
						}
					},
					selMunicipio:
					{
						required: function(){
							if($("#selPais").val() == "1") return true;
							else return false;
						}
					},
					txtUnidadeFederativa:
					{
						required: function(){
							if($("#selPais").val() != "1") return true;
							else return false;
						}
					},
					txtMunicipio:
					{
						required: function(){
							if($("#selPais").val() != "1") return true;
							else return false;
						}
					},
					txtCEP:
					{
						required: function()
						{
							if($("#selPais").val() == "1") return true;
							else return false;
						}
					},
					pwdSenha:
					{
						required: function(){
							if($("#hdnObrigatorio").val() != "") return true;
							else return false;
						}
					},
					pwdConfirmarSenha:
					{
						required: false,
						equalTo: "#pwdSenha"
					}
				},
				messages:
				{
					txtNome: 
					{
						required: MSG04
					},
					radSexo:
					{
						required: MSG04
					},
					txtNumeroPe:
					{
						required: MSG04
					},
					txtDataNascimento:
					{
						required: MSG04,
						data: MSG04
					},
					txtTelefone:
					{
						required: MSG04,
						maxlength: MSG48
					},
					txtCPF:
					{
						required: MSG04,
						maxlength: MSG49,
						remote: MSG42.replace("e-mail","e-mail ou CPF")
					},
					txtEmail:
					{
						required: MSG04,
						"email": MSG27.replace("{CAMPO}","E-mail"),
						remote: MSG42
					},
					txtMSN:
					{
						"email": MSG27.replace("{CAMPO}","MSN")
					},
					selOcupacao:
					{
						required: MSG04
					},
					radFilhos:
					{
						required: MSG04
					},
					txtEndereco:
					{
						required: MSG04
					},
					txtNumero:
					{
						required: MSG04
					},
					selPais:
					{
						required: MSG04
					},
					selUnidadeFederativa:
					{
						required: MSG04
					},
					selMunicipio:
					{
						required: MSG04
					},
					txtMunicipio:
					{
						required: MSG04
					},
					txtCEP:
					{
						required: MSG04,
						maxlength: MSG50
					},
					pwdSenha:
					{
						required: MSG04
					},
					pwdConfirmarSenha:
					{
						equalTo: MSG28.replace("{CAMPO}","Confirmar a senha").replace("{CAMPOANTERIOR}","Senha")
					}
				}
			}
		);

		$('.formulario-padrao ul li').next().hide();
		$('.formulario-padrao div').hide();
		
		$("#selPais").change(function()
		{	
			$('.formulario-padrao ul li').next().show();
			$('.formulario-padrao div').show();
			
			if ($(this).val() == '' || $(this).val() == null)
			{
				$('.formulario-padrao ul li').next().hide();
				$('.formulario-padrao div').hide();
			}
			else
			{
				if($("#selPais").val() == 1)
				{
					$("#txtUnidadeFederativa").hide();
					$("#selUnidadeFederativa").show();
					carregarComboUnidadeFederativa($("#selPais").val());
					$("#txtMunicipio").hide();
					$("#selMunicipio").show();
					$("#txtCEP").mask("99999-999").removeAttr("maxlength");
					$("#txtCPF").mask("999.999.999-99").removeAttr("maxlength");
					$("#txtTelefone").mask("(99) 9999-9999").removeAttr("maxlength");
					
				}
				else
				{
					$("#txtCEP").val($("#txtCEP").unmask().attr("maxlength", "8").val().replace(/\D/g,""));
					$("#txtCPF").val($("#txtCPF").unmask().attr("maxlength", "11").val().replace(/\D/g,""));
					$("#txtTelefone").val($("#txtTelefone").unmask().numeric().attr("maxlength", "15").val().replace(/\D/g,""));
					$("#selMunicipio").hide();
					$("#txtMunicipio").show();
					$("#selUnidadeFederativa").hide();
					$("#txtUnidadeFederativa").show();
				}
			}
		});
		
		if($("#selPais").val() == 1 && $("#PessoaID").val() == "")
		{
			carregarComboUnidadeFederativa($("#selPais").val());		
		}
		$("#txtNumeroPe").numeric();
		$("#txtNumero").numeric();
		$("#txtDataNascimento").mask("99/99/9999");		


		
		$("#txtCEP")
		.blur(function()
		{
			$(this).unmask();
		})
		.focus(function()
		{
			if ($(this).is(".PossuiMascara"))
			{
				$(this).unmask().mask("99999-999");
			}
		});
		
		$("#selUnidadeFederativa").change(function(){
			carregarComboMunicipio($(this).val());
		});
		
		$("#txtNumeroPe").keypress(function(e){
			e = $.event.fix(e || window.event);
			var digito = String.fromCharCode(e.charCode);

			if($("#txtNumeroPe").val().length == 2 && !isNaN(digito) && e.charCode != 32)
			{
				$("#txtNumeroPe").val($("#txtNumeroPe").val()+"."+digito);
			}
			else if(e.charCode == 46) return false;
			else if($("#txtNumeroPe").val().length > 2 && e.keyCode == 8)
			{
				 $("#txtNumeroPe").val($("#txtNumeroPe").val().substr(0,2));
				 return false;
			}
		});
	}

	function carregarComboUnidadeFederativa(PaisID)
	{
		if(PaisID.length > 0)
		{
			$("#selUnidadeFederativa").attr({"disabled":true});
			$("#selUnidadeFederativa").html('<option value="">'+SITE_CARREGANDO+'...</option>');
			
			$.ajax(
			{
				type: "POST",
				url: SITE_CAMINHO_SITE_ABSOLUTO + "acao/UnidadeFederativa.php",
				data: {acao:"Pesquisar",PaisID:PaisID},
				dataType: "json",
				success: function(ColecaoUnidadeFederativa)
				{
					if(ColecaoUnidadeFederativa.length > 0)
					{
						try
						{
							for(indice in ColecaoUnidadeFederativa)
							{
								$("#selUnidadeFederativa").append('<option value="'+unescape(ColecaoUnidadeFederativa[indice].ID)+'">'+unescape(ColecaoUnidadeFederativa[indice].Nome)+'</option>');
							}
							$("#selUnidadeFederativa").prepend('<option value="">'+SITE_SELECIONE+'</option>');
							$("#selUnidadeFederativa option:eq(1)").remove();
							$("#selUnidadeFederativa").attr({"disabled":false});					
						}
						catch(e)
						{
							$("#selUnidadeFederativa").html('<option value="">'+SITE_SELECIONE+'</option>');
							$("#selUnidadeFederativa").attr({"disabled":false});
						}
					}
					else
					{
						$("#selUnidadeFederativa").html('<option value="">'+SITE_SELECIONE+'</option>');
						$("#selUnidadeFederativa").attr({"disabled":false});
					}
				}
			});
		}
		else
		{
			$("#selUnidadeFederativa").html('<option value="">'+SITE_SELECIONE+'</option>');
		}
	}

	

	if($(FormLogin).length > 0)
	{
		var endereco = $("#hdnUrl").val();
		
		$(FormLogin).validate
		({
		 		submitHandler: function()
		 		{
		 			$.ajax
		 			({
						type: "POST",
						url: SITE_CAMINHO_SITE_ABSOLUTO + "acao/Pessoa.php",
						data: "acao=Login&txtEmail="+$("#txtEmail").val()+"&pwdSenha="+$("#pwdSenha").val(),
						dataType: "json",
						complete: function(resource,status)
						{
							var retorno = new Object();
							
							eval("retorno = "+resource.responseText+";");
							
							if(retorno.erro)
							{
								$("#alerta").prepend('<span class="erro">'+unescape(retorno.mensagem)+'</span>');
							}
							else
							{
								
								var ProdutoID = window.parent.$("#hdnProdutoSelecionado").val();
								var TextoBusca = window.parent.$("#hdnTextoBusca").val();
								
								var operadorConcatenacao = "?";
								
								if (ProdutoID != null && ProdutoID != "")
								{
									endereco += operadorConcatenacao + "ProdutoID="+ProdutoID;
									operadorConcatenacao = "&";
								}
								
								if (TextoBusca != null && TextoBusca != "")
								{
									endereco += operadorConcatenacao + "busca=" + TextoBusca;
								}
								if(retorno.alterado)
								{
									self.parent.location.href = endereco;
									self.parent.tb_remove();
								}
								else
								{
									self.parent.location.href = "cadastro.php";
									self.parent.tb_remove();
								}
								
							}
						}
					});
		 		},
				errorPlacement: function(error, element) 
				{
					error.appendTo( $("#alerta") );
				},			
				errorClass: "erro",
				errorElement: "span",
				rules:
				{
					txtEmail:
					{
						required: true,
						email: true
					},
					pwdSenha:
					{
						required: true
					}
				},
				messages:
				{
					txtEmail:
					{
						required: MSG11,
						"email": MSG27.replace("{CAMPO}","Usuário")
					},
					pwdSenha:
					{
						required: MSG11
					}
				}
			}
		);
	}
	
		
	if($(FormRecuperarSenha).length > 0)
	{
		$(FormRecuperarSenha).validate
		(
		 	{
		 		submitHandler: function()
		 		{
		 			$.ajax(
					{
						type: "POST",
						url: SITE_CAMINHO_SITE_ABSOLUTO + "acao/Pessoa.php",
						data: "acao=TrocarSenha&txtEmail="+$("#txtEmail").val(),
						dataType: "json",
						complete: function(resource,status)
						{
							var retorno = new Object();
							
							eval("retorno = "+resource.responseText+";");
							
							if(retorno.erro)
							{
								$("#alerta").prepend('<span class="erro">'+unescape(retorno.mensagem)+'</span>');
							}
							else
							{
								$("#alerta").prepend('<span class="sucesso">'+unescape(retorno.mensagem)+'</span>');
							}
						}
					});
		 		},
				errorPlacement: function(error, element) 
				{
					error.appendTo( $("#alerta") );
				},			
				errorClass: "erro",
				errorElement: "span",
				rules:
				{
					txtEmail:
					{
						required: true,
						email: true
					}
				},
				messages:
				{
					txtEmail:
					{
						required: MSG04,
						"email": MSG27.replace("{CAMPO}","Usuário")
					}
				}
			}
		);
	}
	
}
