	
	var $w2n = jQuery.noConflict();
	
	$w2n(document).ready(function(){

		$w2n("#form-imovel #telefone").mask("(99) 9999-9999");
		$w2n("#form-imovel #codigo").mask("99999");
		
		$w2n("#form-imovel select[@id='finalidade']").change(function(){	
																	 
			if($w2n(this).val().length != 0 && $w2n(this).val() != '0' && $w2n(this).val() != ''){
			
				$w2n("#form-imovel select[@id='tipo_imovel']").attr("disabled", true);
				
				$w2n.ajax({
					type: "POST",
					url: "/ajax/lista-tipo-imovel.asp",
					data: { finalidade : $w2n(this).val() },
					async: true,
					cache: true,					
					beforeSend: function(){
						
						$w2n("#load-ajax").fadeIn("slow");
						
					},
					success: function(resposta){
						
						$w2n("#form-imovel select[@id='tipo_imovel']").removeAttr("disabled");
						$w2n("#form-imovel select[@id='tipo_imovel']").removeOption(/./);
						
						var listaAjax = eval(resposta);					
	
						for(var i=0; i < listaAjax.length; i++){
							
							listaAjax[i] = unescape(listaAjax[i]);
							
							arrlistaAjax = listaAjax[i].split( "|" );
							
							$w2n("#form-imovel select[@id='tipo_imovel']").addOption(arrlistaAjax[0], arrlistaAjax[1]);	
							
						}
						
						$w2n("#form-imovel select[@id='tipo_imovel']").selectOptions('0');
					
					},
					complete: function(){
						
						$w2n("#load-ajax").fadeOut("fast");	
						
					},
					error: function(){ 
					
						alert('erro'); 
						
					}
				});
			
			}else{
				
				$w2n("#form-imovel select[@id='tipo_imovel']").removeOption(/./);			
				
			}
																 
		}); 
		
		$w2n("#form-imovel").validate({
			rules: {
				nome: "required",
				email: {
					required: true,
					email: true
				},
				telefone: "required",
				cidade: "required",
				deseja_contato: "required",
				melhor_horario: "required",
				transacao: "required",
				finalidade: "required",
				tipo_imovel: "required",
				detalhes: "required"
			},
			messages: {
				nome: "Informe o Nome",
				email: "Informe o E-mail",
				telefone: "Informe o Telefone",
				cidade: "Informe a Cidade",
				deseja_contato: "Informe por onde Deseja Contato",
				melhor_horario: "Informe o Melhor Horário",
				transacao: "Informe a Transação",
				finalidade: "Informe a Finalidade",
				tipo_imovel: "Informe o Tipo de Imóvel",				
				detalhes: "Informe os Detalhes do Imóvel"
			}
		});	
		
	});