/* !!! Utilisation de Mootools */
function toggleForm(idForm, disabled)
{
	// Récuération des champs du formulaire
	var elements = $$('#' + idForm + ' input', '#' + idForm + ' select', '#' + idForm + ' textarea');
	
	elements.each(
		function(item, index, array)
		{
			if( item.getProperty('disabled') == '' || disabled )
			{ item.setProperty('disabled', 'disabled'); }
			else
			{ item.removeProperty('disabled'); }
		}
	);
}

function toggleAdvertising(id)
{
	var image = document.getElementById('advertising123');
	image.src = image.src.substring(0, image.src.lastIndexOf('/')+1) + id+'.gif';
}

function toggleDisplay(me, forceMode)
{
	oObj = document.getElementById(me);
	if (oObj)
	{
		if(forceMode != null)
		{
			oObj.style.display=forceMode;
		}
		else if (oObj.style.display == "block")
		{
			oObj.style.display="none";
		}
		else
		{
			oObj.style.display="block";
		}
	}
}

function showLegends(toShow) {
	if(toShow == 'f_') toShow = 'f_main';
	if(toShow == 'm_') toShow = 'm_main';
	if(toShow == 'l_') toShow = 'l_main';
	if(toShow != null) {
		var elem = document.getElementById('legends').getElementsByTagName('p');
		for (var i = 0; i < elem.length; i++) {
			elem[i].style.display = "none";
		}	
		document.getElementById(toShow).style.display = 'block';
	}
}

function activeCat(selId)
{
	switch(selId)
	{
		case 'flt_fixed' :
			toggleDisplay(selId, 'block');
			document.formMapFilter.only_by_fixed.selectedIndex = 0;
			showLegends('f_main');
			toggleDisplay('flt_mobile', 'none');
			toggleDisplay('flt_light', 'none');
			break;
		case 'flt_mobile' :
			toggleDisplay(selId, 'block');
			document.formMapFilter.only_by_mobile.selectedIndex = 0;
			showLegends('m_main');
			toggleDisplay('flt_fixed', 'none');
			toggleDisplay('flt_light', 'none');
			break;
		case 'flt_light' :
			toggleDisplay(selId, 'block');
			document.formMapFilter.only_by_light.selectedIndex = 0;
			showLegends('l_main');
			toggleDisplay('flt_fixed', 'none');
			toggleDisplay('flt_mobile', 'none');
			break;
	}
}

function showSpotLight(divObj, mode)
{
	var txtObj = document.getElementById(divObj.id + '_text').getParent();

	if(mode == 'show')
	{
		if(divObj.fxTween)
		{
			divObj.fxTween.cancel();
			txtObj.fxTween.cancel();
		}
		
		divObj.fxTween = new Fx.Tween(divObj, {'duration':250});
		txtObj.fxTween = new Fx.Tween(txtObj, {'duration':250});
			
		divObj.fxTween.start('margin-top', divObj.style.marginTop, '-101px');
		txtObj.fxTween.start('height', txtObj.style.height, '101px');
	}
	else if(mode == 'hide')
	{
		divObj.fxTween.cancel();
		txtObj.fxTween.cancel();
		
		divObj.fxTween = new Fx.Tween(divObj, {'duration':250});
		txtObj.fxTween = new Fx.Tween(txtObj, {'duration':250});
		
		divObj.fxTween.start('margin-top', divObj.style.marginTop, '0px');
		txtObj.fxTween.start('height', txtObj.style.height, '0px');
	}
}

function initSpotLights(_divIDs_)
{
	for(var i=0; i<arguments.length; i++)
	{
		var divObj = $(arguments[i]);
		var txtObj = $(arguments[i] + '_text');
		var titleObj = divObj.getElements('span')[0];
		while(titleObj.getSize().y > 20)
		{
			var txt = titleObj.firstChild.nodeValue;
			titleObj.firstChild.nodeValue = txt.substring(0, txt.lastIndexOf(' ')) + '...';
		}

		while($(txtObj).getElements('a')[0].getPosition($(txtObj)).y > 60)
		{
			var txt = txtObj.firstChild.nodeValue;
			txtObj.firstChild.nodeValue = txt.substring(0, txt.lastIndexOf(' ')) + '...';
		}
		
		divObj.style.marginTop = '0px';
		txtObj.getParent().style.display = 'block';
		txtObj.getParent().style.height = '0px';
		
		divObj.addEvents(
			 {
				'mouseenter': function()
				{
					showSpotLight(this, 'show');
				},
				'mouseleave': function()
				{
					showSpotLight(this, 'hide');
				}
			}
		);
	}
}

function clickSpotlight(spotlight)
{
	var divObj = document.getElementById(spotlight);
	window.location = ($(divObj).getElements('a')[0].href);
}

function iFrameHeight() 
{
	var hauteur; 
	var monFrm = document.getElementById('ifrm'); 
	if(document.all)
	{ 
		hauteur = monFrm.contentWindow.document.body.scrollHeight; 
	} 
	else 
	{ 
		hauteur = monFrm.contentWindow.document.body.offsetHeight; 
	} 
	monFrm.setAttribute('height', (hauteur+20));
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function popup(url, w, h) {
	window.open(url, 'popup', 'width='+w+', height='+h+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}

var debug_line = 1;
function trace(text_content)
{
	debug_line += 1;

	var oObj = document.getElementById('debug_console');
	oObj.innerHTML += "<span style='color:#ccc'>" + debug_line + ".</span> " + text_content + "<br>\n";
	oObj.scrollTop += oObj.scrollHeight;
}

function extractGetVariables()
{
	var t = location.search.substring(1).split('&');
	var f = [];
	for (var i=0; i<t.length; i++)
	{
		var x = t[i].split('=');
		f[x[0]] = x[1];
	}
	return f;
}