function set_options(obj, arr){
	for(i=0;i<arr.length;i++)
		obj.options[i]=new Option(arr[i],i);
}
function sendQuery(param){
	$.getJSON('/ajax/main/quick_trip_finder.php', param, function(data){
		if(data.error==1){ 
			$('#info').hide();
			$('#nothing').show();
			alert(data.errorText);
		}
		else{
			newb=data.newb;
			newt=data.newt;
			render();
		}
	});
}
function getData(){
	var t='';
	$('input:checked').each(function(){t+='_'+$(this).val();});
	$('#info').hide();
	$('#progress').show();
	location.href='#progress';
	//, m:$('#finder-month').val()
	var param={
		d:days, 
		p:price, 
		a:t, 
		f:$('#finder-from').val(), 
		t:$('#finder-till').val(), 
		b:$('#finder-block').val(), 
		r:$('#finder-region').val()
	};
	sendQuery(param);
}
function setDateFrom(){
	getData();
}
function setDateTill(){
	getData();
}
function setPosition(t, id){
	if(t=='days')days=id; else price=id;
	if(action=='cruise') getCruise();
	else getData();
}
function render(){
	var count=0;
	$('#info').show();
	$('#nothing').hide();
	$('#progress').hide();
	
	for(i=0;i<allb.length;i++) $('#block'+allb[i]).hide();
	for(i=0;i<newb.length;i++){
		$('#block'+newb[i][0]).show();
		$('#count'+newb[i][0]).html(newb[i][1]);
	}
	for(i=0;i<allt.length;i++) $('#tour'+allt[i]).hide();
	for(i=0;i<newt.length;i++) 
		try{
			count++;
			$('#tour'+newt[i]).show();
		}catch(e){count--;}	
	if(count==0){
		$('#info').hide();
		$('#nothing').show();
	}
}

function quickTourCruise(){
	var url=$('#cruise-tour').val();
	if(url)location=url;
}
function getCruise(){
	$('#info').hide();
	$('#progress').show();
	location.href='#progress';
	var param={
		d:days, 
		p:price, 
		f:$('#finder-from').val(), 
		t:$('#finder-till').val(), 
		s:$('#finder-ship').val(), 
		r:rar[$('#finder-route').val()]
	};
	
	$.getJSON('/ajax/main/quick_cruise_finder.php', param, function(data){
		if(data.error==1){ 
			$('#info').hide();
			$('#nothing').show();
			alert(data.errorText);
		}
		else{
			$('#info').show();
			$('#nothing').hide();
			$('#progress').hide();
			$('.cruise-table tr[class!="cruise-table-title"]').hide();
			$('#count_tours').html(data.count);
			if(data.count==0){
				$('#info').hide();
				$('#nothing').show();
			}
			else{
				var show=data.show;
				for(i=0;i<show.length;i++) 
					try{$('#'+show[i]).show();}catch(e){}
			}
		}
	});
}