
	

	var $w2n = jQuery.noConflict();
	
	$w2n(document).ready(function(){
		
		$w2n("#form-pesquisa #finalidade").change(function(){	

			if($w2n(this).val().length != 0 && $w2n(this).val() != '0' && $w2n(this).val() != ''){
			
				$w2n("#form-pesquisa #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-pesquisa #tipo_imovel").removeAttr("disabled");
						$w2n("#form-pesquisa #tipo_imovel").removeOption(/./);
						$w2n("#form-pesquisa #subtipo_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-pesquisa #tipo_imovel").addOption(arrlistaAjax[0], arrlistaAjax[1]);	
							
						}
						
						$w2n("#form-pesquisa #tipo_imovel").selectOptions('0');
	
					},
					complete: function(){
						
						$w2n("#load-ajax").fadeOut("fast");	
						
					},
					error: function(){ 
					
						alert('erro'); 
						
					}
				});
			
			}else{
				
				$w2n("#form-pesquisa #tipo_imovel").removeOption(/./);		
				$w2n("#form-pesquisa #subtipo_imovel").removeOption(/./);		
				
			}
																 
		}); 		
		
		$w2n("#form-pesquisa #tipo_imovel").change(function(){	

			if($w2n(this).val().length != 0 && $w2n(this).val() != '0' && $w2n(this).val() != ''){
			
				$w2n("#form-pesquisa #subtipo_imovel").attr("disabled", true);	
				
				$w2n.ajax({
					type: "POST",
					url: "/ajax/lista-subtipo-imovel.asp",
					data: { id_tipo : $w2n(this).val() },
					async: true,
					cache: true,					
					beforeSend: function(){
						
						$w2n("#load-ajax").fadeIn("slow");
						
					},
					success: function(resposta){
						
						$w2n("#form-pesquisa #subtipo_imovel").removeAttr("disabled");
						$w2n("#form-pesquisa #subtipo_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-pesquisa #subtipo_imovel").addOption(arrlistaAjax[0], arrlistaAjax[1]);	
							
						}
						
						$w2n("#form-pesquisa #subtipo_imovel").selectOptions('0');
	
					},
					complete: function(){
						
						$w2n("#load-ajax").fadeOut("fast");	
						
					},
					error: function(){ 
					
						alert('erro'); 
						
					}
				});
			
			}else{
				
				$w2n("#form-pesquisa #subtipo_imovel").removeOption(/./);				
				
			}
																 
		}); 
		
		$w2n("#form-pesquisa #cidade").change(function(){	

			if($w2n(this).val().length != 0 && $w2n(this).val() != '0' && $w2n(this).val() != ''){
			
				if($w2n("#form-pesquisa #filtrar-bairro:checked").length==1){	
					
					$w2n("#form-pesquisa #lista-filtro-bairros").empty();
					
					$w2n.ajax({
						type: "POST",
						url: "/ajax/lista-bairro.asp",
						data: { cidade : $w2n("#form-pesquisa #cidade").val() },
						async: true,
						cache: true,					
						beforeSend: function(){
							
							$w2n("#load-ajax").fadeIn("slow");
							
						},
						success: function(resposta){							
							
							$w2n("#form-pesquisa #lista-filtro-bairros").append(resposta);
						
						},
						complete: function(){
							
							$w2n("#load-ajax").fadeOut("fast");	
							
						},
						error: function(){ 
						
							alert('erro'); 
							
						}
					});

				}				
			
			}else{
				
				$w2n("#form-pesquisa #filtrar-bairro:checked").attr("checked", false);
				$w2n("#form-pesquisa #lista-filtro-bairros").empty();
				$w2n("#form-pesquisa #lista-filtro-bairros").slideUp('slow');		
				
			}
																 
		}); 
		
		$w2n("#form-pesquisa #preco_min").maskMoney();
		$w2n("#form-pesquisa #preco_max").maskMoney();
		
		$w2n("#form-pesquisa #filtrar-bairro").click(function(){
					
			if($w2n("#form-pesquisa #filtrar-bairro:checked").length==1){
				
				if($w2n("#form-pesquisa #cidade").val().length == 0 || $w2n("#form-pesquisa #cidade").val() == '0' || $w2n("#form-pesquisa #cidade").val() == ''){
					
					alert('Selecione a Cidade');
					$w2n("#form-pesquisa #filtrar-bairro:checked").attr("checked", false);
					
				
				}else{
					
				$w2n.ajax({
					type: "POST",
					url: "/ajax/lista-bairro.asp",
					data: { cidade : $w2n("#form-pesquisa #cidade").val() },
					async: true,
					cache: true,					
					beforeSend: function(){
						
						$w2n("#load-ajax").fadeIn("slow");
						
					},
					success: function(resposta){							
						
						$w2n("#form-pesquisa #lista-filtro-bairros").append(resposta);
					
					},
					complete: function(){
						
						$w2n("#load-ajax").fadeOut("fast");	
						
					},
					error: function(){ 
					
						alert('erro'); 
						
					}
				});
			
				$w2n("#form-pesquisa #lista-filtro-bairros").slideDown('slow');
					
				}

			}else{
				
				$w2n("#form-pesquisa #lista-filtro-bairros").empty();
				$w2n("#form-pesquisa #lista-filtro-bairros").slideUp('slow');				
				
			}
								
		});

	});
	
	