$(document).ready(function(){		
	$("#chkconcordo").click(function() {
		if ($("#chkconcordo").is(":checked")) {
			$("#btn-cadastrar").attr("disabled", false);
		}else{
			$("#btn-cadastrar").attr("disabled", true);
		}
	});			
	$("#frmcadastro").submit(function(){
		// VERIFICA SE CAMPOS OBRIGATORIOS FORAM PREENCHIDOS
		$(".campoobrigatorio").css("border","1px solid #CCCCCC");
		if ($(".campoobrigatorio[value=]").css("border","2px solid red").size() > 0) {
			alert("Digite todos os campos obrigatórios!");
		} else {
			$.post("http://www.granadaimoveis.com.br/imoveis/cadastrar", $("#frmcadastro").serialize(),
				function(response) {
					if (response == '1') {
						alert ("Cadastro efetuado com sucesso! Em breve entraremos em contato.");
						$("input[type='text']").val('');
					} else {
						alert ("Ocorreu um erro no cadastro. Tente novamente ou entre em contato conosco!");
					}
				}
			);
		}
		return false;
	});
	// BUSCA O CEP
	$("#txtimov_cepprop").blur( function (event) {
		// TRATA O COMPORTAMENTO DA PÁGINA NAS REQUISIÇÕES AJAX
		$.ajax ({
			type: 'GET',
			cache: false,
			url: 'includes/buscacep.php?cep=' + $("#txtimov_cepprop").val(),
			dataType: 'xml',
			success: function(response) {
				$("#txtimov_enderecoprop").val($("webservicecep",response).children('retorno').children('tipo_logradouro').text()  + " " + $("webservicecep",response).children('retorno').children('logradouro').text());
				$("#txtimov_bairroprop").val($("webservicecep",response).children('retorno').children('bairro').text());				
				$("#txtimov_cidadeprop").val($("webservicecep",response).children('retorno').children('cidade').text());								
				$("#cboimov_estadoprop").val($("webservicecep",response).children('retorno').children('uf').text());
				$("#txtimov_numeroprop").focus();
			}
		});								
	});	
	$("#txtimov_cep").blur( function (event) {
		// TRATA O COMPORTAMENTO DA PÁGINA NAS REQUISIÇÕES AJAX
		$.ajax ({
			type: 'GET',
			cache: false,
			url: 'includes/buscacep.php?cep=' + $("#txtimov_cep").val(),
			dataType: 'xml',
			success: function(response) {
				$("#txtimov_endereco").val($("retorno",response).children('tipo_logradouro').text()  + " " + $("retorno",response).children('logradouro').text());
				$("#txtimov_bairro").val($("retorno",response).children('bairro').text());				
				$("#txtimov_cidade").val($("retorno",response).children('cidade').text());								
				$("#cboimov_estado").val($("retorno",response).children('uf').text());
				$("#txtimov_numero").focus();
			}
		});								
	});	
});

