	function Pessoa()
{

	var frmPessoaQuemEuSou		= "#frmPessoaQuemEuSou";
	var frmPessoaSobreVoce 		= "#frmPessoaSobreVoce";
	var frmPessoaMeuPerfil 		= "#frmPessoaMeuPerfil";
	var frmPessoaAutenticar 	= "#frmPessoaAutenticar";
	var frmPessoaImagemPerfil 	= "#frmPessoaImagemPerfil";
	var frmPessoaBuscarPerfil 	= "#frmPessoaBuscarPerfil";
	var frmSenha 				= "#frmSenha";
	
	/**
	 * EF Buscar Perfil - IN1
	 */
	if ($j(frmPessoaBuscarPerfil).length > 0)
	{
		$j("#selUnidadeFederativa").change(function()
		{
			carregarMunicipio($j(this));
		});	
	
		$j(frmPessoaBuscarPerfil).validate
		(
			{
		 		submitHandler: function()
		 		{
		 			$j(frmPessoaBuscarPerfil)[0].submit();
		 		},	
		 		errorPlacement: function(error, element) 
				{
					element.next().html(error);
				},
				rules:
				{
					txtNome:
					{
						required: true
					}
				},
				messages:
				{
					txtNome:
					{
						required: MSG18.replace("{CAMPO}","Nome")
					}
				}
			}
		);
		
	}

	/**
	 * EF Manter Home - IN1.1
	 */
	if ($j(frmPessoaAutenticar).length > 0)
	{
		$j(frmPessoaAutenticar).validate
		(
		 	{
		 		submitHandler: function()
		 		{
		 			$j(frmPessoaAutenticar)[0].submit();
		 		},	
		 		errorPlacement: function(error, element) 
				{
					element.parent().next().html(error);
				},
				rules:
				{
					txtLoginEmail: 
					{
						required: true,
						email: true
					},
					txtLoginSenha:
					{
						required: true
					}
				},
				messages:
				{
					txtLoginEmail: 
					{
						required: "E-mail obrigatório",
						email: "E-mail inválido"
					},
					txtLoginSenha: 
					{
						required: "Senha obrigatória"
					}
				}
			}
		);
	}	

	/**
	 * EF Manter Perfil - IN3
	 */
	if ($j(frmPessoaMeuPerfil).length > 0)
	{
		// evento de voltar
		$j('#btnVoltar').click(function() {
			location.href = 'participar-sobre-voce.php';
		});	
	}
	
	/**
	 * EF Manter Perfil - IN3.1
	 */
	if ($j(frmPessoaImagemPerfil).length > 0)
	{
		
		$j(frmPessoaImagemPerfil).validate
		(
			{
				errorPlacement:function(error,element)
				{					
					if(error.html() != $j("span.msg").html()) $j("span.msg").html("<span>"+error.html()+"</span>");					
				},
				highlight: function(element, errorClass)
				{
					$j(element).addClass(errorClass);
				},		
				unhighlight: function(element, errorClass)
				{
					$j(element).removeClass(errorClass);
					
					if($j(".erro",frmContato).length == 0) $j("span.msg").html("");
				},
				errorClass: "erro",
				errorElement:"span",
				rules:
				{
					uplFoto:
					{
						required: true,
						accept: "png|jpe?g|gif"
					}
				},
				messages:
				{
					uplFoto:
					{
						required: "Verifique o formato ou o tamanho do aquivo selecionado",
						accept: "Verifique o formato ou o tamanho do aquivo selecionado"
					}
				}
			}
		)
	}

	/**
	 * EF Manter Perfil - IN2
	 */
	if ($j(frmPessoaSobreVoce).length > 0)
	{	
		// evento de voltar
		$j('#btnVoltar').click(function() {
			location.href = 'participar.php';
		});
				
	}
	
	/**
	 * EF Manter Perfil - IN1
	 */
	if ($j(frmPessoaQuemEuSou).length > 0)
	{
		
		// controla os campos de canais de contato
		// celular
		$j("#txtCelular").blur(function() {
			if (($j(this).val() != '') && ($j(this).val().indexOf("_") == -1))
			{
				$j('.sms').attr({"disabled":false});
			}
			else
			{
				$j('.sms').attr({"disabled":true});
				$j('.sms').attr({"checked":false});
			}
		});
		
		// orkut
		$j('input[@name="radOrkut"]').click(function() {
			if($j(this).val() == "1")
			{
				$j('.orkut').attr({"disabled":false});
			}
			else
			{
				$j('.orkut').attr({"disabled":true});
				$j('.orkut').attr({"checked":false});
			}
			controlarExibicaoCampo($j(this).val(), $j("#txtOrkut"));
		});
		
		// msn
		$j('input[@name="radMSN"]').click(function() {
			if($j(this).val() == "1")
			{
				$j('.msn').attr({"disabled":false});
			}
			else
			{
				$j('.msn').attr({"disabled":true});
				$j('.msn').attr({"checked":false});
			}
			controlarExibicaoCampo($j(this).val(), $j("#txtMsn"));
		});
		
		// twitter
		$j('input[@name="radTwitter"]').click(function() {
			if($j(this).val() == "1")
			{
				$j('.twitter').attr({"disabled":false});
			}
			else
			{
				$j('.twitter').attr({"disabled":true});
				$j('.twitter').attr({"checked":false});
			}
			controlarExibicaoCampo($j(this).val(), $j("#txtTwitter"));
		});
		
		// blog
		$j('input[@name="radBlog"]').click(function() {
			if($j(this).val() == "1")
			{
				$j('.blog').attr({"disabled":false});
			}
			else
			{
				$j('.blog').attr({"disabled":true});
				$j('.blog').attr({"checked":false});
			}
			controlarExibicaoCampo($j(this).val(), $j("#txtBlog"));
		});
		
		// campos numéricos e com máscara
		$j("#txtDataNascimento").mask("99/99/9999");
		$j("#txtCpf").mask("999.999.999-99");
		$j("#txtNumero").numeric();
		$j("#txtCep").mask("99.999-999");
		$j("#txtTelefone").mask("(99)9999-9999");
		$j("#txtCelular").mask("(99)9999-9999");
		
		// pais
		$j('#selPais').change(function() {
			controlarExibicaoEstado($j(this));
		});
		
		// uf
		$j('#selUnidadeFederativa').change(function() {
			carregarMunicipio($j(this));
		});
				
		$j(frmPessoaQuemEuSou).validate
		(
		 	{
		 		invalidHandler: function(form, validator)
		 		{
		 			var qtdErros = validator.numberOfInvalids();
					if (qtdErros > 0)
					{
						$j('.msg-obrigatorio').show();
					}
					else
					{
						$j('.msg-obrigatorio').hide();
					}
		 		},
		 		errorLabelContainer: "#erro",
   				wrapper: "div",
				errorElement: "label",
				rules:
				{
					txtNome: 
					{
						required: true
					},
					txtDataNascimento:
					{
						required: true,
						diferente: "__/__/____",
						data: true
					},
					txtCpf:
					{
						required: true,
						cnpf: true
					},
					txtEmail:
					{
						required: true,
						email: true,
						remote: "acao/Pessoa.php?hdnAcao=verificarEmail&hdnPessoaID="+$j("#hdnPessoaID").val()
					},
					txtSenha:
					{
						required: function()
						{
							if ($j('#hdnPessoaID').val() == '')
							{
								return true;
							}
							else
							{
								return false;
							}
						}
					},
					txtRepetirSenha:
					{
						required: function()
						{
							if ($j('#hdnPessoaID').val() == '')
							{
								return true;
							}
							else
							{
								return false;
							}
						},
						equalTo: "#txtSenha"
					},
					selEstadoCivil:
					{
						required: true
					},
					txtEndereco:
					{
						required: true
					},
					txtNumero:
					{
						required: true
					},
					txtBairro:
					{
						required: true
					},
					selPais:
					{				
						required: true
					},
					selUnidadeFederativa:
					{
						required: function()
						{
							if ($j('#selPais').find("option:selected").attr("class") == 'padrao')
							{
								return true;
							}
							else
							{
								return false;
			
							}
						}
					},
					selMunicipio:
					{
						required: function()
						{
							if ($j('#selPais').find("option:selected").attr("class") == 'padrao')
							{
								return true;
							}
							else
							{
								return false;
			
							}
						}
					},
					txtMunicipioExterior:
					{
						required: function()
						{
							if ($j('#selPais').val() != '')
							{
								if ($j('#selPais').find("option:selected").attr("class") == 'padrao')
								{
									return false;
								}
								else
								{
									return true;
								}
							}
							else
							{
								return false;
							}
						}
					},
					txtCep:
					{				
						required: true
					},
					txtOrkut:
					{
						required: function()
						{
							if ($j('#txtOrkut').hasClass('validar'))
							{
								return true;
							}
							else
							{
								return false;
							}
						}
					},
					txtMsn:
					{
						required: function()
						{
							if ($j('#txtMsn').hasClass('validar'))
							{
								return true;
							}
							else
							{
								return false;
							}
						}
					},
					txtTwitter:
					{
						required: function()
						{
							if ($j('#txtTwitter').hasClass('validar'))
							{
								return true;
							}
							else
							{
								return false;
							}
						}
					},
					txtBlog:
					{
						required: function()
						{
							if ($j('#txtBlog').hasClass('validar'))
							{
								return true;
							}
							else
							{
								return false;
							}
						}
					}
				},
				messages:
				{
					txtNome: 
					{
						required: "Nome obrigatório."
					},
					txtDataNascimento: 
					{
						required: "Data de nascimento obrigatória.",
						diferente: "Data de nascimento obrigatória.",
						data: "Data de nascimento inválida."
					},
					txtCpf: 
					{
						required: "CPF obrigatório.",
						cnpf: "CPF inválido."
					},
					txtEmail: 
					{
						required: "E-mail obrigatório.",
						email: "E-mail inválido.",
						remote: "E-mail já existe."
					},
					txtSenha: 
					{
						required: "Senha obrigatória."
					},
					txtRepetirSenha: 
					{
						required: "Repetir senha obrigatório.",
						equalTo: "Senhas estão diferentes."
					},
					selEstadoCivil:
					{
						required: "Estado Civil obrigatório."
					},
					txtEndereco:
					{
						required: "Endereço obrigatório."
					},
					txtNumero:
					{
						required: "Número obrigatório."
					},
					txtBairro:
					{
						required: "Bairro obrigatório."
					},
					selPais:
					{
						required: "País obrigatório."
					},
					selUnidadeFederativa:
					{
						required: "UF obrigatório."
					},
					selMunicipio:
					{
						required: "Municipio obrigatório."
					},
					txtMunicipioExterior:
					{
						required: "Municipio obrigatório."
					},
					txtCep:
					{
						required: "CEP obrigatório."
					},
					txtOrkut:
					{
						required: "Orkut obrigatório."
					},
					txtMsn:
					{
						required: "MSN obrigatório."
					},
					txtTwitter:
					{
						required: "Twitter obrigatório."
					},
					txtBlog:
					{
						required: "Blog obrigatório."
					}
				}
			}
		);
	}
	
	/**
	 * Controla a exibição dos estados
	 *  
 	 * @author Mauricio Brentano (mauricio@gadbrivia.com.br)
	 */	
	function controlarExibicaoEstado(selPais)
	{
		if (selPais.val() != '')
		{
			if (selPais.find('option:selected').attr('class') == 'padrao')
			{	
				$j('.item-UF').show();
				$j('#selMunicipio').attr({"disabled":false});
				$j('.item-Cidade').show();
				$j('#selUnidadeFederativa').attr({"disabled":false});
				$j('.item-OutroCidade').hide();
				$j('#txtMunicipioExterior').val('');
			}
			else
			{		
				$j('.item-UF').hide();
				$j('#selUnidadeFederativa').val('');
				$j('.item-Cidade').hide();
				$j('#selMunicipio').html('<option value="">Selecione</option>');
				$j('#selMunicipio').attr({"disabled":true});
				$j('.item-OutroCidade').show();
				$j('.item-OutroCidade').val('');
			}
		}
		else
		{
				$j('.item-UF').hide();
				$j('#selUnidadeFederativa').val('');
				$j('.item-Cidade').hide();
				$j('#selMunicipio').html('<option value="">Selecione</option>');
				$j('#selMunicipio').attr({"disabled":true});
				$j('.item-OutroCidade').hide();
				$j('.item-OutroCidade').val('');
		}
	}
	
	/**
	 * Carrega os municipios e os coloca em um combobox
	 *  
 	 * @author Mauricio Brentano (mauricio@gadbrivia.com.br)
	 */	
	function carregarMunicipio(selUnidadeFederativa)
	{
		if (selUnidadeFederativa.val() != '')
		{
			$j('#selMunicipio').attr({"disabled":true});
			$j('#selMunicipio').html('<option value="">Carregando...</option>');
		
			$j.getJSON("acao/Municipio.php?hdnAcao=pesquisar&selUnidadeFederativa="+selUnidadeFederativa.val(), function(json){
				var colecaoMunicipio = json;
				var totalColecaoMunicipio = colecaoMunicipio.length;					
				if (totalColecaoMunicipio > 0)
				{
					var opcoesMunicipio = '<option value="">Selecione</option>';
					for (var contador = 0; contador < totalColecaoMunicipio; contador++)
					{
						opcoesMunicipio += '<option value="' + colecaoMunicipio[contador].MunicipioID + '">' + colecaoMunicipio[contador].Nome + '</option>';
					}
					$j('#selMunicipio').html(opcoesMunicipio);
					$j('#selMunicipio').attr({"disabled":false});
				}
			});
		}
	}
	
	/**
	 * Controla a exibição de um campo.
	 *  
 	 * @author Mauricio Brentano (mauricio@gadbrivia.com.br)
	 */	
	function controlarExibicaoCampo(valor, campo)
	{
		if (valor == "1")
		{
			campo.parent().show();
			campo.addClass('validar');
		}
		else
		{
			campo.parent().hide();
			campo.removeClass('validar');
			campo.val('');
		}
	}
	
	if ($j(frmSenha).length > 0)
	{
		$j(frmSenha).validate
		(
			{
				errorPlacement:function(error,element)
				{					
					if(error.html() != $j("span.msg").html()) $j("span.msg").html("<span>"+error.html()+"</span>");					
				},
				highlight: function(element, errorClass)
				{
					$j(element).addClass(errorClass);
				},		
				unhighlight: function(element, errorClass)
				{
					$j(element).removeClass(errorClass);
					
					if($j(".erro",frmSenha).length == 0) $j("span.msg").html("");
				},
				errorClass: "erro",
				errorElement:"span",
				rules:
				{
					txtEmail:
					{
						required: true,
						email: true,
						remote: "acao/Pessoa.php?hdnAcao=verificarEmail&recuperarSenha=true&txtEmail="+$j("#txtEmail").val()
							
					}
				},
				messages:
				{
					txtEmail:
					{
						required: "E-mail obrigatório.",
						email: "E-mail inválido.",
						remote: "E-mail não existe."
					}
				}
			}
		);
	}
	
}