var IE6 = false, IE7 = false,
FIREFOX2 = false, FIREFOX = false,
NETSCAPE7 = false, NETSCAPE = false,
OPERA9 = false, OPERA = false,
AUTRE = false;
var strChUserAgent = navigator.userAgent;
var intSplitStart = strChUserAgent.indexOf("(",0);
var intSplitEnd = strChUserAgent.indexOf(")",0);
var strChStart = strChUserAgent.substring(0,intSplitStart);
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
var strChEnd = strChUserAgent.substring(strChEnd);

if(strChMid.indexOf("MSIE 7") != -1)
IE7 = true;
else if(strChMid.indexOf("MSIE 6") != -1)
IE6 = true;
else if(strChEnd.indexOf("Firefox/2") != -1)
FIREFOX2 = true;
else if(strChEnd.indexOf("Firefox") != -1)
FIREFOX = true;
else if(strChEnd.indexOf("Netscape/7") != -1)
NETSCAPE7 = true;
else if(strChEnd.indexOf("Netscape") != -1)
NETSCAPE = true;
else if(strChStart.indexOf("Opera/9") != -1)
OPERA9 = true;
else if(strChStart.indexOf("Opera") != -1)
OPERA = true;
else
AUTRE = true;

window.addEvent('domready', function()
{
	$$(".btnsp").addEvent('click', 
		function()
		{
			if($("panelplan").getStyle('height') == '1px') { deplie_plan(); }
			else { plie_plan(); }
			return false;
		}
	);
});

function affiche_tarificateur_amt()
{
	window.addEvent('domready', function()
	{
		openSqueezeBox('http://souscriptions.amt.tm.fr/quad/quad.php?User=400071', 530, 1000);
	});
}

function plie_plan()
{
	transition_plan("panelplan", '1', 600, '600', function () { $("panelplan").setStyle('display', 'none'); if (IE6) { $$("select").setStyle('visibility', 'visible'); } })
}

function deplie_plan()
{
	if (IE6)
	{
		$$("select").setStyle('visibility', 'hidden'); 
	}
	$("panelplan").setStyle('display', 'block');
	transition_plan("panelplan", '600', 600, '600');
}

function resume_class_element_width(element_class_name, max_height, setCssHeight)
{ 
	var item_orig_text, item_text, chomped_height, compl, txt;
 		
	$$("." + element_class_name).each(function (item, i)
	{	
		item_orig_text = item.get('html');
		
		compl = '';
		chomped_height = false;
		
		control_item_name = item.getProperty('id') + '_ctrl';
		overflow_item_name = item.getProperty('id') + '_ovfl';
		
		if (max_height != null && setCssHeight != null) { compl = ' height: ' + max_height + 'px; ';  }
		
		item.set('html', '<div style="overflow: hidden; ' + compl + '" id="' + overflow_item_name + '"><div style="display: block;" id="' + control_item_name + '">' + item_orig_text + '</div></div>'); 
		control_item = $(control_item_name);
		overflow_item = $(overflow_item_name);
		
		if (max_height != null)
		{
			while (control_item.offsetHeight >= max_height) 
			{
			   chomped_height = true;
			   item_text = String(control_item.get('text'));
			   if ((item_text.length - 10) <= 0) { break; }
			   txt=item_text.substring(0, (item_text.length - 10))
			   control_item.set('html', txt);
			}
			if (chomped_height)
			{
			   item_text = control_item.get('text');
			   item_text = item_text.substring(0, item_text.length - 3);
			   item_text = item_text.replace(/\s+[^\s]+\s*$/, '...');
			   control_item.set('html', item_text);
			}
		}
   });
}

function go_url(url)
{
	document.location.href = url;	
}

function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}


function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}


function transition_plan(element, target_height, time, real_height, callback, interval)
{
	cur_height = $(element).getStyle('height');
	unit_pos = cur_height.indexOf('px');
	cur_height_val = parseInt(cur_height.substring(0, unit_pos));
	
	//nombre de pixels ajoutes ou soustraits a chaque etape
	stepPlan = 20;
	
	//calcul de l'interval
	if (interval == null) { interval = Math.floor(time / (Math.abs(cur_height_val - target_height) / stepPlan)); }
	
	new_height = null;
	
	//calcul de la nouvelle taille
	//plie
	if (cur_height_val > target_height)
	{
		if((cur_height_val - stepPlan) >= target_height)
		{
			new_height = (cur_height_val - stepPlan);
		}
		else if ((cur_height_val - stepPlan) < target_height)
		{
			new_height = target_height;
		}
	}
	//deplie
	else if (cur_height_val < target_height)
	{
		if((cur_height_val + stepPlan) <= target_height)
		{
			new_height = (cur_height_val + stepPlan);
		}
		else if ((cur_height_val + stepPlan) > target_height)
		{
			new_height = target_height;
		}
	}
	
	if(new_height != null)
	{
		 $(element).setStyle('height', new_height + 'px');
		 window.setTimeout(function () { transition_plan(element, target_height, time, real_height, callback, interval); }, interval);
	}
	else
	{
		if(callback != null) { callback.call(); }
	}
}