$(document).ready(function() {

	Mudadestaque = function(url,width,height){
		content = "<img src='" + url + "' width='" + width +"' height='" + height +"'>";
		$('#fotodestaque').html(content);
	}
	
	//$('#gallery a').lightBox({fixedNavigation:true});
	
	MudaCategoria = function(negocio,url){
		$('#categoria').load(url + '/busca/index/?tipo=negocio&tiponegocio=' + negocio);	
	}	
	
	MudaTipo = function(idCategoria,negocio,url){
		$('#tipo').load(url + '/busca/index/?tipo=categoria&id=' + idCategoria + '&tiponegocio=' + negocio);	
	}
	

	MudaDormitorio = function(idCategoria,idSubCategoria,valor,tiponegocio,campo,url){	

		 if(tiponegocio == 2){
			if(campo == 'valormax' && document.formBusca.valormin_aluguel.value != ''){
				$('#dormitorios').load(url + '/busca/index/?tipo=dormitorio&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel');	
			} else {
				$('#dormitorios').load(url + '/busca/index/?tipo=dormitorio&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + valor + '&tiponegocio=valorimovelaluguel');					
			}
		} else {
			if(campo == 'valormax' && document.formBusca.valormin.value != ''){
				$('#dormitorios').load(url + '/busca/index/?tipo=dormitorio&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel');	
			} else {
				$('#dormitorios').load(url + '/busca/index/?tipo=dormitorio&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + valor + '&tiponegocio=valorimovel');					
			}
		}
		
	}
	
	MudaSuite = function(idCategoria,idSubCategoria,dormitorio,url){
		var tiponegocio = document.formBusca.tiponegocio.value;

		if(tiponegocio == 2){
		 	
		 	var valor = document.formBusca.valormax_aluguel.value;
		 	if(document.formBusca.valormax_aluguel.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
		
			if((campo == 'valormax') && (document.formBusca.valormin_aluguel.value != '')){
				$('#qtdesuites').load(url + '/busca/index/?tipo=suites&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio);	
			} else {
				$('#qtdesuites').load(url + '/busca/index/?tipo=suites&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio);	
			}
			
		} else {
		 	var valor;
		 	valor = document.formBusca.valormax.value;
		 	if(document.formBusca.valormax.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
					
			if(campo == 'valormax' && document.formBusca.valormin.value != ''){
				$('#qtdesuites').load(url + '/busca/index/?tipo=suites&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio);	

			} else {
				$('#qtdesuites').load(url + '/busca/index/?tipo=suites&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio);	
			}

			
		}
		
	}
	
	
	MudaVaga = function(idCategoria,idSubCategoria,dormitorio,suite,url){
		var tiponegocio = document.formBusca.tiponegocio.value;

		if(tiponegocio == 2){
		 	
		 	var valor = document.formBusca.valormax_aluguel.value;
		 	if(document.formBusca.valormax_aluguel.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
		
			if((campo == 'valormax') && (document.formBusca.valormin_aluguel.value != '')){
				$('#qtdevagas').load(url + '/busca/index/?tipo=vaga&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite);	
			} else {
				$('#qtdevagas').load(url + '/busca/index/?tipo=vaga&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite);	
			}
			 
		} else {
		 	var valor;
		 	valor = document.formBusca.valormax.value;
		 	if(document.formBusca.valormax.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
					
			if(campo == 'valormax' && document.formBusca.valormin.value != ''){
				$('#qtdevagas').load(url + '/busca/index/?tipo=vaga&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite);	

			} else {
				$('#qtdevagas').load(url + '/busca/index/?tipo=vaga&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite);	
			}
	
			
		}
		
	}
	
	ExibeBairros = function(idCategoria,idSubCategoria,dormitorio,suite,vagas,area,tipoarea,parametro,url){
		var tiponegocio = document.formBusca.tiponegocio.value;
		if(tiponegocio == 2){
		 	
		 	var valor = document.formBusca.valormax_aluguel.value;
		 	if(document.formBusca.valormax_aluguel.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
		
			if((campo == 'valormax') && (document.formBusca.valormin_aluguel.value != '')){
				$('#bairros').load(url + '/busca/index/?tipo=bairros&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas + '&area=' + area + '&tipoarea=' + tipoarea + '&parametro=' + parametro);	
			} else {
				$('#bairros').load(url + '/busca/index/?tipo=bairros&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas + '&area=' + area + '&tipoarea=' + tipoarea + '&parametro=' + parametro);	
			}
			 
		} else {
		 	var valor;
		 	valor = document.formBusca.valormax.value;
		 	if(document.formBusca.valormax.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
					
			if(campo == 'valormax' && document.formBusca.valormin.value != ''){
				$('#bairros').load(url + '/busca/index/?tipo=bairros&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas + '&area=' + area + '&tipoarea=' + tipoarea + '&parametro=' + parametro);	

			} else {
				$('#bairros').load(url + '/busca/index/?tipo=bairros&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas + '&area=' + area + '&tipoarea=' + tipoarea + '&parametro=' + parametro);	
			}
		}		
	}	
	
	exibeBairro = function (){
		$('#bairros').fadeIn();		
	}

	MudaArea = function(idCategoria,idSubCategoria,dormitorio,suite,vagas,url){
		var tiponegocio = document.formBusca.tiponegocio.value;

		if(tiponegocio == 2){
		 	
		 	var valor = document.formBusca.valormax_aluguel.value;
		 	if(document.formBusca.valormax_aluguel.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
		
			if((campo == 'valormax') && (document.formBusca.valormin_aluguel.value != '')){
				$('#areautil').load(url + '/busca/index/?tipo=areautil&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
				$('#areaconstruida').load(url + '/busca/index/?tipo=areaconstruida&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
			} else {
				$('#areautil').load(url + '/busca/index/?tipo=areautil&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
				$('#areaconstruida').load(url + '/busca/index/?tipo=areaconstruida&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin_aluguel.value + '&valormax=' + valor + '&tiponegocio=valorimovelaluguel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
			}
			 
		} else {
		 	var valor;
		 	valor = document.formBusca.valormax.value;
		 	if(document.formBusca.valormax.value){
				campo = 'valormax';
			} else {
				campo = 'valormin';	
			}
					
			if(campo == 'valormax' && document.formBusca.valormin.value != ''){
				$('#areautil').load(url + '/busca/index/?tipo=areautil&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
				$('#areaconstruida').load(url + '/busca/index/?tipo=areaconstruida&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	

			} else {
				$('#areautil').load(url + '/busca/index/?tipo=areautil&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
				$('#areaconstruida').load(url + '/busca/index/?tipo=areaconstruida&id=' + idCategoria + '&idsubcategoria=' + idSubCategoria + '&valormin=' + document.formBusca.valormin.value + '&valormax=' + valor + '&tiponegocio=valorimovel&dormitorio=' + dormitorio + '&suite=' + suite + '&vagas=' + vagas);	
			}
		}	
		
	}
	
	TodosBairros = function(){
		var todos_bairros = new Array() 
		var i = 0;
		for(cont = 0;cont <= document.formBusca.bairros.length; cont++){
			if((document.formBusca.bairros[cont]) && (document.formBusca.bairros[cont].checked == 1)){
				todos_bairros[i] = document.formBusca.bairros[cont].value;
				i++;
			}
		}
		document.formBusca.todos_bairros.value = todos_bairros;

	}
	
	Valormax = function(valor,url){
		$('#valormax').load(url + '/busca/index/?tipo=valormax&valor=' + valor);
	}

	ValormaxAluguel = function(valor,url){
		$('#aluguelmax').load(url + '/busca/index/?tipo=valormax_aluguel&valor=' + valor);
	}
	

	
});


