
function tohtml(editeurId,divHtmlId,txtHtmlId) {
	editeurhtml=document.getElementById(editeurId+'_html');
	editeurtxt=document.getElementById(editeurId+'_txt');
	divHtml=document.getElementById(divHtmlId);
	txtHtml=document.getElementById(txtHtmlId);
	
	editeurhtml.style.display="none";
	editeurtxt.style.display="block";
	txtHtml.value=divHtml.innerHTML;
	return false;
}

function towysiwyg(editeurId,divHtmlId,txtHtmlId) {
	editeurhtml=document.getElementById(editeurId+'_html');
	editeurtxt=document.getElementById(editeurId+'_txt');
	divHtml=document.getElementById(divHtmlId);
	txtHtml=document.getElementById(txtHtmlId);
	
	editeurhtml.style.display="block";
	editeurtxt.style.display="none";
	divHtml.innerHTML=txtHtml.value;
	return false;
}

function convertLayer(editeurId,divHtmlId,txtHtmlId) {
	editeurhtml=document.getElementById(editeurId+'_html');
	editeurtxt=document.getElementById(editeurId+'_txt');
	divHtml=document.getElementById(divHtmlId);
	txtHtml=document.getElementById(txtHtmlId);

	if (editeurhtml.style.display=="none") 	divHtml.innerHTML=txtHtml.value;
	txtHtml.value=divHtml.innerHTML;
}


function switchDiv(noCat){
	imgsec=document.getElementById('img'+noCat);
	divsec=document.getElementById(noCat);
	if (divsec.style.display=="none"){
		divsec.style.display="block";
		
		if (imgsec){
			imgsec.src='images/deplierbas.gif';
	   	}
	} else {
		if ( (divsec.style.display=="block") || (divsec.style.display=="") ){
	   		divsec.style.display="none";
			if (imgsec){
				imgsec.src='images/deplierhaut.gif';
			}
		}
	}
	return false;
	
}

function switchTreeDiv(div,imagepath) {
	imgsec=document.getElementById('img'+div);
	divsec=document.getElementById(div);
	if (divsec.style.display=="none") {
		divsec.style.display="";
		if (imgsec)
		{
			imgsec.src=imagepath+'/tree_collapse.gif';
		}
   	}else {
   		divsec.style.display="none";
		if (imgsec)
		{
			imgsec.src=imagepath+'/tree_expand.gif';
		}
   	}
	return false;
}

function is_mozilla()
{
	var ua=navigator.userAgent.toLowerCase();
	return (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
}

function getElementsByTagAndName(tagname, name)
{
	if (is_mozilla()) return document.getElementsByName(name);
	var elems = document.getElementsByTagName(tagname);
	var result=new Array();
	for (i=0; i<elems.length; i++)
	{
		var elem = elems[i];
		if (elem.name == name) result.push (elem);
	}
	return result;
}

function menu_admin_switch(id, url_root)
{
  var tr_list = getElementsByTagAndName('tr', id);		
  var show = (tr_list[0].style.display=='none');
  do_menu_admin_switch(id, url_root, tr_list, show);  
}

function do_menu_admin_switch(id, url_root, tr_list, show) 
{
  var img = document.getElementById(id+"_img");
  var i;
  for (i=0; i<tr_list.length; i++)
  {
    tr = tr_list[i];
    if (show) {
	  tr.style.display = '';
	  img.src = url_root+'images/treemenu2/tree_collapse.gif';
    } else {
      tr.style.display = 'none';
	  img.src = url_root+'images/treemenu2/tree_expand.gif';
	}

	var children = getElementsByTagAndName('tr', tr.id);
	if (!show && (0<children.length)) do_menu_admin_switch(tr.id, url_root, children, show)
  }
}

function writeEmailingField(modid, tabfield, selectionObj){
    // Zone d'affichage de la liste des champs personnalisables disponible
    var field = document.getElementById(modid+"_listfield");    

    // Si la zone existe, on remplit avec la liste des champs personnalisables
    if( field != undefined ){
        selectionIndex=selectionObj.selectedIndex;
        field.innerHTML = tabfield[selectionIndex];
    }
}

function swf_object(name, variables, width, height, menu, quality, wmode, bgcolor)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="'+name+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="./flash/'+name+'.swf'+variables+'" />');
	document.write('<param name="menu" value="'+menu+'" />');
	document.write('<param name="quality" value="'+quality+'" />');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="bgcolor" value="'+bgcolor+'"/>');
	document.write('<embed src="./flash/'+name+'.swf'+variables+'" menu="'+menu+'" quality="'+quality+'" wmode="'+wmode+'" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+name+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

/*function swf_object_maquette(name, variables, width, height, menu, quality, wmode, bgcolor)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="'+name+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="../../flash/'+name+'.swf'+variables+'" />');
	document.write('<param name="menu" value="'+menu+'" />');
	document.write('<param name="quality" value="'+quality+'" />');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="bgcolor" value="'+bgcolor+'"/>');
	document.write('<embed src="../../flash/'+name+'.swf'+variables+'" menu="'+menu+'" quality="'+quality+'" wmode="'+wmode+'" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+name+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}*/

String.prototype.trim = function () 
{
   return this.replace(/^\s*|\s*$/,"");
}

function Selectionner_tout(l1) 
{
	var total=l1.length;
	for (var n=0;n<total;n++)
	{
		l1.options[n].selected=true;
	}
}

function Deplacer(l1,l2) 
{
	var no_code=0;
	for (var n=0;n<l1.length;n++)
	{
		if (l1.options.selectedIndex>=0) 
		{
				o=new Option(l1.options[l1.options.selectedIndex].text,l1.options[l1.options.selectedIndex].value);
				l2.options[l2.options.length]=o;
				l1.options[l1.options.selectedIndex]=null;
				n--;
				no_code=1;
		}
	}
	if(no_code==0)
	{
		alert("Aucun ref choisie(s)");
	}
}

function preload_img()
{
	var long=preload_img.arguments.length;
	if(long>0)
	{
		var che="./themes/orest/images/";
		var tab_img=new Array();
		
		for(var i=0;i<long;i++)
		{
			var nomimg=preload_img.arguments[i];
			tab_img[i+1]=new Image();
			tab_img[i+1].src=che+nomimg;
		}
	}
}

function PopupCentrer(page,nom,largeur,hauteur,options) 
{
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}