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 clear_info_text(element, check_text)
{ 
	if (check_text == null || check_text == element.value)
	{ 
		element.value = ''; 
	} 
}

function set_info_text(element, info_text)
{
	if (element.value == '')
	{
		element.value = info_text;
	}
}

function plie_plan()
{
	transition_plan("panelplan", '1', 500, '500', 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", '500', 500, '500');
}

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'));
			   txt=item_text.substring(0, (item_text.length - 1))
			   control_item.set('html', txt);
			   if ((item_text.length - 1) == 0) { break; }
			}
			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 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(); }
	}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

