document.write('<script type="text/javascript" language="javascript" src="../js/fckeditor/fckeditor.js"></script>');

//##################
// Masking Script
//##################
$(document).ready(function() {
	$("#cpfDocumento").mask("999.999.999-99");
	$("#cnpjDocumento").mask("99.999.999/9999-99");
});
//##################
//##################


//##################
// Validation Script
//##################
$(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = $("#frmRecuperarSenha").validate({
			onkeyup: false,
			onfocusout: false,
			onfocus: false,
			
			rules: {
				emlCliente: { required: true },
				
				cpfDocumento: { required: function() {
						if ($("#cnpjDocumento").val().length > 0) {
							return false;
						}
						else {
							return true;
						}
					}
				},
				
				cnpjDocumento: { required: function() {
						if ($("#cpfDocumento").val().length > 0) {
							return false;
						}
						else {
							return true;
						}
					}
				}
			},
			
			//Error messages
			messages: {
				emlCliente: { required: "Informe o seu e-mail" },
				cpfDocumento: { required: "Informe seu CPF" },
				cnpjDocumento: { required: "Informe seu CNPJ" }
			},
			
			//Where the errors are going to be placed
			//in the html
			errorPlacement: function(error, element) {
				
			},
			
			highlight: function(element, errorClass) {
				var aErrorMessage = validator.customMessage(element.name, "required");

				$(element).attr("title", aErrorMessage);
				setTooltip(element);
				
				$(element).addClass(errorClass);
			},
			
			unhighlight: function(element, errorClass) {
				$(element).attr("title", "");
				setTooltip(element);
				
				$(element).removeClass(errorClass);
			},

			
			//Before submiting, check the non-standard rules
			submitHandler: function(form) {
				//Pega as informações
				var aVars = new Object();
				
				aVars.emlCliente = $("#emlCliente").val();
				aVars.cpfDocumento = $("#cpfDocumento").val();
				aVars.cnpjDocumento = $("#cnpjDocumento").val();
				
				//Faz POST via Ajax
				showLoading("boxBtSolicitarNovaSenha", "boxNovaSenhaLoading", false);
				
				$.post(
					"../lib/ajax/action.gcl_clientes.recuperar_senha.php",
					aVars,
					function(data) {
						
						restoreLoading();
						
						switch (data["retorno"]) {
							case 0: alert("Ocorreu um erro desconhecido!");
											break;
							
							case 1: window.location.href = "cliente.recuperar_senha.php?a=1";
											break;
							
							case 2: alert("E-mail informado não encontrado!");
											break;
											
							case 3: alert("CPF não corresponde ao cadastro!");
											break;
											
							case 4: alert("CNPJ não corresponde ao cadastro!");
											break;
						}
					},
					"json"
				);
				
				return false;
			}
	});
	
	$("#frmCadastroImovel").bind("invalid-form.validate", function() {
		alert("Existem campos inválidos no formulário!");
	});
});
//##################
//##################
