function fn_set_main_tabs()
{
	var output = '<div id="tb31"></div>';
	var obj = getObject('tb3');
	
	
	var mm_help_arr = new Array(1,2,4,5,3);
	
	for(var k in mm_help_arr)
	{
		var i = mm_help_arr[k];

		if(port_mode)
		{
			if(i == 2 || i == 4 || i == 5)
			{
				continue;
			}
			else
			{
				if(i == 1)
				{
					main_modes[i][0] = 'Anuario';
					main_modes[i][1] = 'annu_port';
				}
				if(i == 3)
				{
					main_modes[i][0] = 'Legenda';
				}
			}
		}
		
		if(typeof i != 'function')
		{
			// set buttons inactive
			var inact_add = '';
			if(i != main_mode)
			{
				inact_add = 'in';
			}
		
			// If main mode is Legende
			var style_add = '';
			if(main_mode == 3 && i == 3)
			{
				style_add = ' style="color:#000;"';
			}
			
			var tab_text 	= main_modes[i][0];
			var tab_img		= '';
			
			if(i == 2 || i == 4 || i == 5)
			{
				tab_img = '<img style="height:12px;width:16px;" src="/_res/tab_' + i + '.png" />';
				if(main_mode == 1 || main_mode == 3)
				{
					tab_text = '';
				}
				else
				{
					tab_text = '&nbsp;' + tab_text;
				}
			}
			
			// build output
			output += '<div title="' + main_modes[i][0] + '" class="' + inact_add + 'act_tab_l" id="tab_' + main_modes[i][1] + '" onclick="fn_sw_mm(' + i +')" ' + style_add + '>' + tab_img + '<span>' + tab_text + '</span></div>\n' + 
								'<div class="' + inact_add + 'act_tab_r"></div>\n';			
		}
	}
	// output into obj
	obj.innerHTML = output;	
}

function fn_sw_mm(id, sw)
{
	ai.itype =	id;
	var old_mm = main_mode;
	
	if(sw === undefined)
	{
		sw = true;
	}
	
	
	fn_set_mm(id);
	
	if((!main_mode_used[id] || id == old_mm) && sw)
	{
		switch(id)
		{
			// ANNUAIRE
			case 1: ai = new Active_Item();
							main_mode_used[1] = true;
							br_history[1].ids = new Array(0);
							searchmode = false;
							getObject('tb411').style.display = 'none';
							fn_load_browser(); 
							break;
			
			// IMMO
			case 2: main_mode_used[id] = true;
							fn_init_list_filter(id);
							fn_load_list_browser(id);
							break;
			
			// LEGEND
			case 3: main_mode_used[3] = true;
							getObject('tb431').style.display = 'none';
							fn_load_browser(); 
							break;
			
			// HOTEL/RESTO
			case 4: main_mode_used[id] = true;
							fn_init_list_filter(id);
							fn_load_list_browser(id);
							break;
			
			// AUTO/MOTO
			case 5: main_mode_used[id] = true;
							fn_init_list_filter(id);
							fn_load_list_browser(id);
							break;

			default:break;
		}
	}
	fn_heights();
}

function fn_set_mm(id)
{
	main_mode = id;
	pack3_active = false;
	fn_set_ui();
	fn_set_main_tabs();
}

function fn_set_ui()
{
	var def_width = '320px';
	var xl_width	= '540px';
	
	var tb0 = getObject('tb0');
	var tb1 = getObject('tb1');
	var tb2 = getObject('tb2');
	var tb3 = getObject('tb3');
	var tb4 = getObject('tb4');
	var tb5 = getObject('tb5');
	var tb6 = getObject('tb6');
	var tb7 = getObject('tb7');
	var tb8 = getObject('tb8');
	
	// special
	var tb11 	= getObject('tb11');
	var tb12 	= getObject('tb12');
	var tb4111 	= getObject('tb4111');
	var tb4112 	= getObject('tb4112');
	var tb412 	= getObject('tb412');
	
	// hide containers
	for(var i = 1; i <= 5; i++)
	{
		getObject('tb4' + i).style.display = 'none';
	}
	
	getObject('tb4' + main_mode).style.display = 'block';

	if((main_mode == 1 && pack3_active) || main_mode == 2 || main_mode == 4 || main_mode == 5)
	{
		var path = 'xl/'; 
		hvo_active = 1;
		tb0.style.width = xl_width;
		tb11.style.width = '470px';
	}
	else
	{
		var path = ''; 
		tb0.style.width = def_width;
		tb11.style.width = '250px';
		hvo_active = 0;
	}
	
	if(zoom_level == 1)
	{
		center_view_port();
	}
	
	var tmp_browser = navigator.userAgent;
	var trans_file = 'png';
	if(tmp_browser.match(/MSIE\s6.0/))
	{
		trans_file = 'gif';
	}
	
	// CHECK FOR PORT MODE
	if(port_mode)
	{
		tb11.style.backgroundImage = 'url(/_res/tb/bg_tb11_port.png)';
	 	tb12.style.backgroundImage = 'url(/_res/tb/bg_tb12_port.png)';
	}
	else
	{
		tb11.style.backgroundImage = 'url(/_res/tb/bg_tb11.png)';
	 	tb12.style.backgroundImage = 'url(/_res/tb/bg_tb12.png)';
	}
	
	//tb1.style.backgroundImage = 'url(/_res/tb/' + path +'bg_viaah_logo.' + trans_file + ')';
	tb2.style.backgroundImage = 'url(/_res/tb/' + path +'bg_search.' + trans_file + ')';
	tb3.style.backgroundImage = 'url(/_res/tb/' + path +'bg_main_tabs.' + trans_file + ')';
	tb5.style.backgroundImage = 'url(/_res/tb/' + path +'bg_close_cont.' + trans_file + ')';
	tb7.style.backgroundImage = 'url(/_res/tb/' + path +'bg_trans_3.' + trans_file + ')';
	tb8.style.backgroundImage = 'url(/_res/tb/' + path +'bg_close_trans.' + trans_file + ')';

	if(tb4111)tb4111.style.backgroundImage = 'url(/_res/tb/' + path +'bg_cat_cont.' + trans_file + ')';
	if(tb4112)tb4112.style.backgroundImage = 'url(/_res/tb/' + path +'bg_tabs.' + trans_file + ')';
	if(tb412)tb412.style.backgroundImage = 'url(/_res/tb/' + path +'bg_cat_cont.' + trans_file + ')';

	getObject('tb61').style.backgroundImage = 'url(/_res/tb/' + path +'bg_tab_vis_items.' + trans_file + ')';
	getObject('tb62').style.backgroundImage = 'url(/_res/tb/' + path +'bg_cat_cont.' + trans_file + ')';
	getObject('tb63').style.backgroundImage = 'url(/_res/tb/' + path +'bg_close_cont.' + trans_file + ')';
	
	load_banners(main_mode);
}

function fn_heights()
{
	var min_height = 150;
	
	// top height
	var top_height = fn_get_height('tb1') + fn_get_height('tb2') + fn_get_height('tb3');
	// bottom height
	var bottom_height = fn_get_height('tb5') + fn_get_height('tb7') + fn_get_height('tb8');
	// vis items height
	var vis_items_height = fn_get_height('tb6');
	
	var win_size = fn_get_win_height();
	var win_height = win_size[1];
	
	// annuaire and legend
	if(main_mode == 1 || main_mode == 3)
	{
		var free_contx = getObject('cont_' + main_mode + '_0');
		if(pack3_active)
		{
			var free_contx = getObject('tb4121');
		}
		
		var history_height = fn_get_height('tb4' + main_mode + '1');
		if(isNaN(history_height))
		{
			history_height = 0;
		}
		if(isNaN(vis_items_height))
		{
			vis_items_height = 0;
		}
		
		max_height = win_height - top_height - history_height - vis_items_height - bottom_height - 10;
		cont_height = 0;
		if(free_contx)
		{
			cont_height = free_contx.scrollHeight;
		}
		
		if(cont_height <= min_height)
		{
			height = min_height + 'px';
		}
		else if(cont_height < max_height)
		{
			height = cont_height + 'px';
		}
		else
		{
			height = max_height + 'px';
		}
		
		fn_remove_style_att('height', 'cont_' + main_mode + '_0');
		
		getObject('tb4' + main_mode + '21').style.height = height;
		if(free_contx)
		{
			free_contx.style.height = height;
			free_contx.style.overflow = 'auto';
		}
	}	
	// immo, hore, aumo
	if(main_mode == 2 || main_mode == 4 || main_mode == 5)
	{
		var filter_height = 35;
		if(main_mode == 2)
		{
			filter_height = 85;
		}
		
		if(isNaN(vis_items_height))
		{
			vis_items_height = 0;
		}
		
		max_height = win_height - top_height - filter_height - vis_items_height - bottom_height;
		cont = getObject('tb4' + main_mode + '2');
		
		cont_height = fn_get_scroll_height('tb4' + main_mode + '2');
		if(cont_height < max_height)
		{
			height = cont_height + 'px';
		}
		else
		{
			height = max_height + 'px';
		}
		if(cont)
		{
			cont.style.height = height;
		}
	}	
}

function fn_get_height(obj)
{
	if(getObject(obj))
	{
		return parseInt(getObject(obj).offsetHeight);
	}
	else
	{
		return 0;
	}
}

function fn_get_scroll_height(obj)
{
	if(getObject(obj))
	{
		return parseInt(getObject(obj).scrollHeight);
	}
	else
	{
		return 0;
	}
}

function fn_adjust_min_max_select(id_act, id_min, id_max)
{
	min = getObject(id_min);
	max = getObject(id_max);
	
	if(id_act == id_min)
	{
		if(min.value == 'unlim' || parseInt(max.value) < parseInt(min.value))
		{
			max.value = min.value;
		}
	}
	else if(id_act == id_max)
	{
		if(min.value == 'unlim' || parseInt(min.value) > parseInt(max.value))
		{
			min.value = max.value;
		}
	}
}

/* ------------------------------------------------------------------------------------------------------------------*/
/* --------------------------------------------- Banner functions ---------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/
// CONSTRUCTOR FOR BANNERS
function Banner(file_name, url)
{
	this.file_name 	= file_name;
	this.url 				= url;
}

function load_banners(mm, town_id)
{
	var query_str = '';
	
	if(mm && (mm == 2 || mm == 4 || mm == 5))
	{
		if(town_id != undefined && town_id > 0)
		{
			query_str = '&mm=' + main_mode + '&env=loc&town_id=' + town_id;
			var env = 'loc';
		}
		else
		{
			query_str = 'env=nat&mm=' + mm;
			var env = 'nat';
			banners['loc'] = new Array();
		}
	}
	else
	{
		fn_remove_banner();
	}

	if(query_str != '')
	{
		var url = '/_inc/php/get_banners.php?' + query_str;
		jah_back(url, 'set_banners(result, "' + env + '");');			
	}
}

function set_banners(str, env)
{
	banners[env] = new Array();
	
	if(str != '')
	{
		var bs_arr = str.split('??');
		
		for(var i = 0; i < bs_arr.length; i++)
		{
			var b_arr = bs_arr[i].split('!!');
			banners[env].push(new Banner(b_arr[0], b_arr[1]));			
		}
	}
	
	fn_set_banners();
}

function fn_set_banners()
{
	fn_remove_banner();
		
	// MIX BUTTONS
	banners['mix']['items'] = banners['nat'].concat(banners['loc']);
	
	// SHUFFLE THEM
	banners['mix']['items'].fn_array_shuffle();
	
	if(banners['mix']['running'])
	{
		banners['mix']['running']		= false;
		clearTimeout(banners['mix']['timer_id']);
		banners['mix']['timer_id'] 	= false;
	}	
	
	if(banners['mix']['items'].length > 0 && !banners['mix']['running'])
	{
		banners['mix']['running'] = true;

		// SET BANNER
		var b_cont = document.createElement('div');
		b_cont.id = 'head_banner';
	
		getObject('tb1').appendChild(b_cont);

		loop_banners();
	}
}

function loop_banners(i)
{
	if(i === undefined || i >= (banners['mix']['items'].length-1))
	{
		i = 0;
	}
	else
	{
		i++
	}
	
	if(getObject('head_banner'))
	{
		var path = '/_img/banners/' + banners['mix']['items'][i]['file_name'];
		var image = '<img src="' + path + '"/>';
		
		preloaded_banners[i] = document.createElement('img');
    preloaded_banners[i].setAttribute('src', path);

		if(banners['mix']['items'][i]['url'] != '')
		{
			image = '<a target="_blank" href="http:\/\/' + banners['mix']['items'][i]['url'] + '">' + image + '</a>';
		}
		
		if((i+1) < banners['mix']['items'].length)
		{
			var path = '/_img/banners/' + banners['mix']['items'][i+1]['file_name'];
			preloaded_banners[i+1] = document.createElement('img');
	    preloaded_banners[i+1].setAttribute('src', path);
		}

		getObject('head_banner').innerHTML = image;
	}
	else
	{
		return false;
	}
	
	if(banners['mix']['items'].length > 1)
	{
		banners['mix']['timer_id'] = setTimeout('loop_banners(\'' + i + '\')', 8000);
	}
	return true;
}

function fn_remove_banner()
{
	if(getObject('head_banner'))
	{
		getObject('head_banner').parentNode.removeChild(getObject('head_banner'));
	}
}

/* ------------------------------------------------------------------------------------------------------------------*/
/* --------------------------------------------- Immo functions -----------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/
function fn_set_main_photo(id, img)
{
	target = getObject('immo_main_photo');
	if(target)
	{
		var main_photo = target.getElementsByTagName('img');
		if(main_photo[0])
		{
			main_photo[0].src = '/_img/advert_photos/medium/' + img;
			main_photo[0].onclick = function(){fn_set_immo_photos(id, img);};
		}
	}
	fn_heights();
}

function fn_set_immo_photos(id, img)
{
	fn_save_list_detail(2);
	getObject('tb421').innerHTML = fn_set_list_back('fn_load_list_detail(2);', 2, 'Retour');
	var url = '/_inc/php/set_immo_photos.php?id=' + id + '&img=' + img;
	jah(url, 'tb422', 'fn_heights();');
}

/* ------------------------------------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/


/* ------------------------------------------------------------------------------------------------------------------*/
/* ------------------------------------------ Hotel/Resto functions -------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/



/* ------------------------------------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------------------------------------*/

function fn_set_list_order()
{
	fn_loader(1);
	mm = fn_set_list_order.arguments[0];
	for(var i = 0; i < list_order[mm].length; i++)
	{
		list_order[mm][i] = '';
	}

	var first_ord = 'ASC';
	var secon_ord = 'DESC';
	
	if(fn_set_list_order.arguments[1] == 4)
	{
		first_ord = 'DESC';
		secon_ord = 'ASC';
	}
	
	var set_to = first_ord;
	if(fn_set_list_order.arguments[2] == first_ord)
	{
		set_to = secon_ord;
	}
	list_order[mm][fn_set_list_order.arguments[1]] = set_to;
	list_count[mm] = 0;
	fn_load_list(false, mm);	
}

function fn_load_list_browser(mm)
{
	fn_loader(1);
	list_count[mm] = 0;
	fn_load_list_filter(mm);
	fn_load_list(false, mm);
}

function fn_load_list(ids, mm, cc)
{	
	
	// load immo list
	var url = '/_inc/php/set_list.php';
	
	
	var order_str = fn_get_list_order_str(mm);
	if(!ids && !cc)
	{
		// build filter str
		var filter_str = fn_get_list_filter_str(mm);

		// build order str
		var query_str = filter_str + order_str + '&mm=' + mm + '&lm=' + list_count[mm];
		cc = false;
	}
	else
	{
		var query_str = '?' + order_str + '&ids=' + ids+ '&mm=' + mm + '&lm=' + 0;
		cc = true;
	}
	url = url + query_str;
	
	jah_back(url, 'fn_set_list(result, ' + mm + ', ' + cc + ');fn_heights();');	
}

function fn_set_list(str, mm, cc)
{
	if(str != '')
	{	
		if(str.match(/!!/))
		{
			var tmp_arr = str.split('!!');
			str 					= tmp_arr[0];
			cluster_click = parseInt(tmp_arr[1]);
			num_list 			= parseInt(tmp_arr[2]);
		}
		// set_icons ====>
		if(!cluster_click && list_count[mm] == 0)
		{
			if(mm == 2)
			{
				fn_set_immo_icons(2, 2);
			}
			else if(mm == 4 || mm == 5)
			{
				fn_set_icons (1, 2, list_filter[mm][0]);
			}
		}
		else
		{
			fn_loader();
		}
		/*
		// if first load build table
		if(!getObject('list_mm_' + mm))
		{
			getObject('tb4' + mm + '2').innerHTML = '<table></table>';
			//var tb = document.createElement('tbody');
			//tb.id = 'list_body_mm' + mm;
			//getObject('list_mm_' + mm).appendChild(tb);
		}
		*/

		var pattern = /\<tr\>\s*\<td\>\s*___\s*\<\/td\>\s*\<\/tr\>/ig;


		if(list_count[mm] == 0)
		{
			fn_loader(1);
			// process str
			getObject('tb4' + mm + '2').innerHTML = str;
			if(num_list <= 40)
			{
				getObject('tb4' + mm + '2').innerHTML = getObject('tb4' + mm + '2').innerHTML.replace(pattern, '');
				
				fn_loader();
			}
			
		}
		else
		{		
			fn_loader(1);
			
			var old_cont = getObject('tb4' + mm + '2');
			var old_cont_inner = old_cont.innerHTML;
			if(old_cont_inner.match(/___/))
			{
				var new_cont_inner = old_cont_inner.replace(pattern, str);
				old_cont.innerHTML = new_cont_inner;
			}
			fn_loader();
		}
		if(list_count[mm] == 0 && num_list > 40 && !cc)
		{
			list_count[mm] ++;
			fn_load_list(false, mm);
		}
	}
}

function fn_init_list_filter(mm)
{
	if(mm == 2)
	{
		// immo
		list_filter[2] 	= new Array();
		list_filter[2][0]		= 1;							// category
		list_filter[2][1]		= 0;							// type
		list_filter[2][2]		= 0;							// agency
		list_filter[2][3]		= '';							// location
		list_filter[2][4]		= '0';						// price_min
		list_filter[2][5]		= 'unlim';				// price_max
		list_filter[2][6]		= '0';						// room_min
		list_filter[2][7]		= 'unlim';				// room_max
		list_filter[2][8]		= '';							// ids/clusterclick		
	}
	else if(mm == 4)
	{
		// hotels / resto
		list_filter[4] 	= new Array();
		list_filter[4][0]		= 25;							// category 25 -> Restaurants
		list_filter[4][1]		= 16;							// town/location		
		list_filter[4][2]		= '';							// ids/clusterclick		
	}
	else if(mm == 5)
	{
		// auto / moto
		list_filter[5] 	= new Array();
		list_filter[5][0]		= 2502; 					// category 2502 -> Concessionnaires Auto
		list_filter[5][1]		= '';							// town/location
		list_filter[5][2]		= '';							// ids/clusterclick
	}
}

function fn_set_list_filter()
{
	var mm = fn_set_list_filter.arguments[0];

	// LOCATION FILTER IS SET ZOOM MAP TO TOWN
	// CHECK ALSO IF THERE ARE SOME LOCATION BANNERS
	if(
			(mm == 2 && fn_set_list_filter.arguments[1] == 3) ||
			(mm == 4 && fn_set_list_filter.arguments[1] == 1) || 
			(mm == 5 && fn_set_list_filter.arguments[1] == 1)
		)
	{
		var town_id = fn_set_list_filter.arguments[2];
		if(town_id.match(/^[0-9]+$/))
		{
			load_banners(mm, town_id);
	
			var url = '/_inc/php/get_coord.php?type=4&id=' + town_id;
			jah_back(url, 'zoomToPoint(result, 10, 4);');			
		}
		else
		{
			load_banners(mm, false);
			setZoomLevel(1);
			center_view_port();
			setZoomLevel(1);
		}
	}

	for(var i = 1; i < fn_set_list_filter.arguments.length; i = i + 2)
	{		
		if(fn_set_list_filter.arguments[i] == 0 && mm == 2)
		{
			// reset filter when category is switched
			list_filter[mm][1]	= 0;							// type
			list_filter[mm][4]	= '0';						// price_min
			list_filter[mm][5]	= 'unlim';				// price_max
		}
		
		if(fn_set_list_filter.arguments[i] == 0 && fn_set_list_filter.arguments[i+1] == '' && mm == 4)
		{
			// reset filter when category is empty
			fn_set_list_filter.arguments[i+1]	= 31;							// type
		}
		
		list_filter[mm][fn_set_list_filter.arguments[i]] = fn_set_list_filter.arguments[i+1];

		// if not cluster filter set, reset cluster filter
		if(fn_set_list_filter.arguments[i] != 8 && mm == 2)
		{
			list_filter[mm][8]	= '';
		}
		
		if(fn_set_list_filter.arguments[i] != 2 && (mm == 4 || mm == 5))
		{
			list_filter[mm][2]	= '';
		}
		
	}
	
	fn_load_list_browser(mm);
}

function fn_load_list_filter(mm)
{
	// set url
	var url = '/_inc/php/set_list_filter.php';
	
	// build filter str
	var filter_str = fn_get_list_filter_str(mm);
	
	// build order str
	var order_str = fn_get_list_order_str(mm);
	
	url = url + filter_str + order_str + '&mm=' + mm;

	getObject('tb4' + mm + '1').style.display = 'block';
	jah(url, 'tb4' + mm + '1', 'if(' + mm + '==2){fn_set_nouv_rech(2);}');
}

function fn_get_list_filter_str(mm)
{
	var str = '?';
	for(var i = 0; i < list_filter[mm].length; i++)
	{
		var filter_val = list_filter[mm][i];
		if(filter_val == 'tout')
		{
			filter_val = '';
		}
		str += 'lf_' + i + '=' + filter_val + '&';		
	}
	str = str.substr(0, str.length - 1);
	
	return str;	
}

function fn_get_list_order_str(mm)
{
	var str = '&';
	for(var i = 0; i < list_order[mm].length; i++)
	{
		if(list_order[mm][i] != '')
		{
			str += 'lo_' + i + '=' + list_order[mm][i] + '&';		
		}
	}
	str = str.substr(0, str.length - 1);
	
	return str;	
}

function list_hv(obj, on, mm)
{
	if(obj)
	{
		var arr = obj.getElementsByTagName('td'); 
	
		if(on)
		{	
			for(var i = 0; i < arr.length; i++)
			{
				if(mm == 2)
				{
					arr[i].className = 'immo_list_hover';					
				}
				else if(mm == 4)
				{
					arr[i].className = 'hore_list_hover';
				}
				else if(mm == 5)
				{
					arr[i].className = 'aumo_list_hover';
				}
			}
			arr[arr.length-1].style.backgroundPosition = 'bottom right';
		}
		else
		{
			for(var i = 0; i < arr.length; i++)
			{
				arr[i].className = '';
			}
		}	
	}
}

function fn_set_list_back(func, mm, text)
{
	if(func != '' && text != '')
	{
		var output = '<ul id="hist_list"><li class="list_browser_retour" onmouseout="this.className=\'list_browser_retour\'" onmouseover="this.className=\'list_browser_retour_sel\'" onclick="' + func + '"><p class="cat_name">' + text + '</p></li></ul>';
		return output;		
	}
	return true;
}

function list_det(id, mm, town_id)
{
	id = String(id);
	if(id.match(/^[0-9,]+$/))
	{
		main_mode = mm;
		fn_set_ui();
		// if there are more than one id (cluster)
		if(id.match(/[,]+/))
		{
			if(!getObject('hist_list'))
			{
				fn_set_nouv_rech(mm);
			}
			list_count[mm] = 0;
			fn_load_list(id, mm, true);
		}
		else
		{
			fn_save_list_cont(mm);
			if(mm == 2)
			{
				fn_set_active(id, 2, 1);
				sip();
				//fn_set_icons (2, 1, id);
				fn_set_immo_icons(2, 1, id, true);				
				var url = '/_inc/php/get_item_details.php?id=' + ai.id + '&type=' + ai.itype + '&mode=' + ai.mode;
			}
			else
			{
				fn_set_icons(1, 1, id);
				sip();
				var url = '/_inc/php/get_item_details.php?id=' + id + '&type=' + 1 + '&mm=' + mm;
				
			}
			getObject('tb4' + mm + '1').innerHTML = fn_set_list_back('fn_load_list_cont(' + mm + ');', mm, 'Retour');
			jah(url, 'tb4' + mm + '2', 'fn_heights();');
			
			if(town_id != undefined && town_id.match(/^[0-9]+$/) && town_id > 0)
			{
				load_banners(mm, town_id);
			}
		}
	}
}

function fn_set_nouv_rech(mm)
{
	getObject('tb4' + mm + '1').innerHTML += fn_set_list_back('fn_init_list_filter(' + mm + ');fn_load_list_browser(' + mm + ');', mm, 'Nouvelle recherche');
}

function scroll_icons(ico_id, cats)
{
	if(cats != undefined)
	{
		looping_icons[ico_id] = new Array(false, 0);
		looping_icons[ico_id][0] = setInterval('loop_icon(\'' + ico_id + '\', \'' + cats + '\')', 800);
		
	}
	else
	{
		clearInterval(looping_icons[ico_id][0]);
		looping_icons[ico_id] = new Array(false, 0);
	}
}

function loop_icon(ico_id, cats)
{
	var cat_arr = cats.split(',');
	

	if(looping_icons[ico_id][1] == (cat_arr.length - 1))
	{
		looping_icons[ico_id][1] = 0;
	}
	else
	{
		looping_icons[ico_id][1]++;
	}
	
	if(getObject(ico_id))
	{
		getObject(ico_id).src = '/_img/categories/' + cat_arr[looping_icons[ico_id][1]] + '.png';	
	}
}


// function set_image_preview
function sip(event, img)
{
	var id = 'list_image_preview';

	if(getObject(id))
	{
		getObject(id).parentNode.removeChild(getObject(id));
	}

	if(img)
	{
		var pos_arr = fn_get_cursor_position(event);
		var win_size = fn_get_win_height();
		var win_height = win_size[1];
		
		if(pos_arr[1] > win_height/2)
		{
			var top = pos_arr[1] - 300; 
			var bot_align = 'bottom:0;';
		}
		else
		{
			var top = pos_arr[1];
			var bot_align = '';
		}
		var left = pos_arr[0] - 320;
	
		var immo_pre = document.createElement('div');
		immo_pre.className = 'list_image_pre_par';
		immo_pre.style.top 	= top + 'px';
		immo_pre.id = id;
		immo_pre.style.left = left + 'px';
	
		immo_pre.innerHTML = '<div class="list_image_pre_chld" style="' + bot_align + ';right: 0;"><img src="' + img + '" /></div>';
		getObject('tb0').appendChild(immo_pre);
	}
}

function fn_save_list_cont(mm)
{
	if(window.saved_list_cont === undefined)
	{
		saved_list_cont = new Array();
	}
	if(window.saved_list_cont[mm] === undefined)
	{
		saved_list_cont[mm] = new Array();
	}
	
	saved_list_cont[mm].push(new Array());
	saved_list_cont[mm][saved_list_cont[mm].length-1][0] = getObject('tb4' + mm + '1').innerHTML;
	saved_list_cont[mm][saved_list_cont[mm].length-1][1] = getObject('tb4' + mm + '2').innerHTML;
	saved_list_cont[mm][saved_list_cont[mm].length-1][2] = getObject('tb4' + mm + '2').scrollTop;
}

function fn_load_list_cont(mm)
{
	getObject('tb4' + mm + '1').innerHTML = saved_list_cont[mm][saved_list_cont[mm].length-1][0];
	getObject('tb4' + mm + '2').innerHTML = saved_list_cont[mm][saved_list_cont[mm].length-1][1];
	
	// scroll to old position 
	if(!isNaN(saved_list_cont[mm][saved_list_cont[mm].length-1][2]))
	{
		getObject('tb4' + mm + '2').scrollTop = saved_list_cont[mm][saved_list_cont[mm].length-1][2];
	}
		
	saved_list_cont[mm].pop();
	setZoomLevel(1);
	center_view_port();
	setZoomLevel(1);
	fn_heights();
}

function fn_save_list_detail(mm)
{
	if(window.saved_list_detail === undefined)
	{
		saved_list_detail = new Array();
	}
	if(window.saved_list_detail[mm] === undefined)
	{
		saved_list_detail[mm] = new Array();
	}
	
	saved_list_detail[mm].push(new Array());
	saved_list_detail[mm][saved_list_detail[mm].length-1][0] = getObject('tb4' + mm + '1').innerHTML;
	saved_list_detail[mm][saved_list_detail[mm].length-1][1] = getObject('tb4' + mm + '2').innerHTML;
}

function fn_load_list_detail(mm)
{
	getObject('tb4' + mm + '1').innerHTML = saved_list_detail[mm][saved_list_detail[mm].length-1][0];
	getObject('tb4' + mm + '2').innerHTML = saved_list_detail[mm][saved_list_detail[mm].length-1][1];
	saved_list_detail[mm].pop();
	fn_heights();	
}

function fn_set_info(itype)
{
	if(main_mode != 1)
	{
		fn_sw_mm(1);
	}
	
	getObject('tb411').innerHTML = '';
	url = '/_inc/php/home.php?a=' + itype;
	jah(url, 'cont_1_0', 'fn_heights();');
}

function fn_hover_tr(obj, class_name)
{
	if(obj)
	{
		var tds = obj.getElementsByTagName('td');
		for(var i = 0; i < tds.length; i++)
		{
			tds[i].className = class_name;
			if(tds.length > 1 && i == 0)
			{
				tds[i].style.backgroundPosition = 'bottom left';
			}
		}
	}
}

function fn_check_parent_ckbx(ckbx_id)
{
	var ckbx = getObject(ckbx_id);
	
	if(ckbx)
	{
		if(ckbx.checked)
		{
			ckbx.checked = false;
		}
		else
		{
			ckbx.checked = true;
		}
	}
}

function show_pack3(id, company_id, init)
{
	pack3_active = true;
	fn_set_ui();
	
	cont 		= getObject('cont_' + main_mode + '_0');
	tb4121 	= getObject('tb4121');
	
	// cache old tb4121/cont content
	if(tb4121 && init)
	{
		pack3_cache[1] = cont.innerHTML;
		pack3_cache[0] = tb4121.innerHTML;
	}
	var url = '/_inc/php/set_pack3_content.php?id=' + id + '&company_id=' + company_id;
	jah(url, 'tb4121', 'fn_heights();');		
}

function hide_pack3()
{
	if(pack3_active)
	{
		tb4121 = getObject('tb4121');
		if(tb4121)
		{
			tb4121.innerHTML = pack3_cache[0];
		}
		tb4121.style.overflow = 'hidden';
		pack3_active = false;
		fn_set_ui();
		fn_heights();
	}
}

function show_comp_photos(company_id)
{
	// CACHE OLD CONT
	var cont = getObject('cont_' + main_mode + '_0');
	
	if(cont)
	{
		comp_photo_cache = cont.innerHTML;
	}
	var url = '/_inc/php/set_comp_photos.php?company_id=' + company_id + '&port_mode=' + port_mode;
	jah(url, cont.id, 'fn_heights();');		
}	

function hide_comp_photos()
{
	cont = getObject('cont_' + main_mode + '_0');
	if(cont)
	{
		cont.innerHTML = comp_photo_cache;
	}
	fn_heights();		
}	


function fn_hover_btn(obj,init)
{
	var divs_in_div = obj.getElementsByTagName("div");

	if(init)
	{
		var pos = 'bottom';
	}
	else
	{
		var pos = 'top';
	}

	divs_in_div[0].style.backgroundPosition = pos + ' left';
	divs_in_div[1].style.backgroundPosition = pos + ' right';
}

