function vardump( a ){
	aux = "";
	if( typeof a == "object" ){
		var espaco = ( typeof arguments[1] != "undefined" )?arguments[1]:"..";
		if( typeof a.nodeType != "undefined"){
			return "[NODE] = ( '"+ a.innerHTML.substr( 0, 15 ) +"...' )\n";
		}
		aux += typeof a + " {\n";
		for( i in a ){
			aux += espaco + "["+i+"]" + " = " + vardump( a[i], espaco + ".." );
		}
		aux += espaco + "}\n";
	}else{
		aux += typeof a + " '" + a + "'\n"
	}
	return aux;
}
$(document).ready(function(){
	
	$("select.frm_busca_drop").change(function(){
	
		var busca = new Array();
		var selects = new Array();
		var index = $("select.frm_busca_drop").index(this);		
		var next_index = index+1;
			
		$("select option:selected").each(function(i){
			if($(this).val() != "")
			{
				//alert(i+"<"+index);
				if(i<=index)
				{
					busca[i]=$(this).parent().attr("id")+"="+$(this).val();
					selects[$(this).parent().attr("id")] = $(this).val();
				}
			}
		});
		
		if(busca[0]=="tipo=2" || busca[0]=="tipo=4")
		{
			$("#dormit").attr("disabled", "disabled");
		}
		
		var next_combo = $("select.frm_busca_drop:eq("+next_index+")").attr("id");
		
		$.ajax({
			type:"POST",
			url:"pesquisa_inteligente.php",
			data:busca.join('&'),
			dataType:"xml",
			success: function(xml)
			{
				$("select.frm_busca_drop:gt("+index+")").each(function(){
					var combos = new Array();
					var id_atual = $(this).attr("id");
					$(id_atual,xml).children().each(function(){
						combos[$(this).attr("val")] = $(this).text();
					})
					//alert($(id_atual,xml).text());
					if($(id_atual,xml).text() != null)
					{
						$(this).html("");
						$(this).removeAttr("disabled");
						$(this).addOption(combos, false);
					}
					else
					{
						$(this).attr("disabled", "disabled");
						//next_index++;
						//alert($("select.frm_busca_drop:eq("+next_index+")").attr("id"));
					}
				}).val(99);
			},
			error:function(a,b,c){
				//alert(b)
				//alert(vardump(c));
			}
			
		})
 	})
})