Menus = new Array ( 
	new Array ( 
		new Array ( 'Cut'     		, 'Cut'     		, 'cut'   		),
		new Array ( 'Copy'     		, 'Copy'     		, 'copy'   		),
		new Array ( 'Paste' 			, 'Paste'   		, 'paste'		)
	),
	new Array ( 
		new Array ( 'Gras'     		, 'Bold'     		, 'bold'   		),
		new Array ( 'Italique' 		, 'Italic'   		, 'italic'		),
		new Array ( 'Underline'		, 'Underline'		, 'underline'	)
	),
	new Array ( 
		new Array ( 'Indent'			, 'Indent'			, 'indent'		),
		new Array ( 'Outdent'		, 'Outdent'			, 'outdent'		)
	),
	new Array ( 
		new Array ( 'JustifyCenter', 'JustifyCenter'	, 'justify'		),
		new Array ( 'JustifyLeft'	, 'JustifyLeft'	, 'left'			),
		new Array ( 'JustifyRight'	, 'JustifyRight'	, 'right'		)
	),
	new Array ( 
		new Array ( 'Couleur 1'		, 'ForeColor'		, 'fgcolor'		),
		new Array ( 'Couleur 2'		, 'BackColor'		, 'bgcolor'		),
		new Array ( 'RemoveFormat'	, 'RemoveFormat'	, 'rem_format'	)
	),
	new Array ( 
		new Array ( 'Lien'		   , 'CreateLink'		 , 'lien'		),
		new Array ( 'Image'		   , 'InsertImage'	 , 'image'		),
		new Array ( 'Lien fichier' , 'CreateLinkFile', 'lienfichier'	)
	),
	new Array ( 
		new Array ( 'FormatBlock1'	, 'FormatBlock1'	, 'formatblock1'),
		new Array ( 'FormatBlock2'	, 'FormatBlock2'	, 'formatblock2'),
		new Array ( 'FormatBlock3'	, 'FormatBlock3'	, 'formatblock3')
	)
	
//	new Array ( 'SelectAll','SelectAll','newfolder')
);
function isArray(obj)
{
	return (typeof(obj.length)=="undefined") ? false : true;
}

function pick_color()
{
	return showModalDialog ( "/forms/pick_color.php", "", "dialogWidth:445px; dialogHeight:140px; status:no; scroll:no; help:no");
}

function pick_link()
{
	return showModalDialog ( "/forms/pick_link.php", "", "dialogWidth:445px; dialogHeight:140px; status:no; scroll:no; help:no");
}

function pick_image()
{
	var parameters = showModalDialog ( "/forms/form_files.php5?withaction=2&withmenu=0", "", "dialogWidth:450px; dialogHeight:300px; status:no; scroll:yes; help:no");	
	return 'photo.php5?id='+parameters[3];
}
/*
function pick_image1()
{
	GALpopup.init( 
		function (e)
		{
			if (Active_Div!=0)
			{
				var div = document.getElementById('DIV_'+Active_Div);
				div.focus();
			}
			document.execCommand( 'InsertImage',false,'photo.php5?id='+e);		
		}
	);
}*/

function pick_file()
{
	var parameter = showModalDialog ( "/forms/form_file.php5", "", "dialogWidth:450px; dialogHeight:140px; status:no; scroll:yes; help:no");	
	var reg=new RegExp("[|]", "gi");
	var parameters=parameter.split(reg);
	return 'popup_.php5?&name='+parameters[0]+'&gadget=oGetFile';
}
/*
function ClickEdtChk(chk,qui)
{
	var div = document.getElementById('DIV_'+qui);
	var txt = document.getElementById('TEXT_DIV_'+qui);
	eval ( 'var inp = document.forms.cbconseil.DATA_DIV_'+qui+';');
	eval ( 'var edt = document.forms.cbconseil.EDIT_DIV_'+qui+';');
	if (chk.checked)
	{
		edt.value=inp.value;
		div.style.display = 'none';
		txt.style.display = 'block';
	}
	else
	{
		inp.value = edt.value;
		div.style.display = 'block';
		txt.style.display = 'none';
		div.innerHTML=inp.value;
	}
}
*/
function ClickEdtChk(chk,qui)
{
	var div = document.getElementById('DIV_'+qui);
	var txt = document.getElementById('TEXT_DIV_'+qui);
	eval ( 'var inp = document.forms.cbconseil.DATA_DIV_'+qui+';');
	eval ( 'var edt = document.forms.cbconseil.EDIT_DIV_'+qui+';');
	if (chk.value==1)
	{
		edt.value=inp.value;
		div.style.display = 'none';
		txt.style.display = 'block';
	}
	else
	{
		inp.value = edt.value;
		div.style.display = 'block';
		txt.style.display = 'none';
		div.innerHTML=inp.value;
	}
}

function noHtml (txt) 
{
	a = txt.indexOf('<');
	b = txt.indexOf('>');
	len = txt.length;
	c = txt.substring(0, a);
	if(b == -1) 
		b = a;
	d = txt.substring((b + 1), len);
	txt = c + d;
	cont = txt.indexOf('<');
	if (cont != -1) 
		txt = noHtml(txt);
	return txt;
}

function FocusEdtOut (qui)
{
	if (qui!='')
	{
		eval ( 'var inp = document.forms.cbconseil.DATA_DIV_'+qui+';');
		eval ( 'var edt = document.forms.cbconseil.EDIT_DIV_'+qui+';');
		inp.value = edt.value;
	}
	else if (Active_Id!=0)
	{
		var div = document.getElementById('DIV_'+Active_Id);
		eval ( 'var inp = document.forms.cbconseil.DATA_DIV_'+Active_Id+';');
		inp.value=div.innerHTML;
	}
	Active_Id=0;
}

function FocusEdtIn(qui)
{
	Active_Id=qui;
}

var popup_menu_open=false;
var popup_dialog_open=false;

var popup_menu = null;
if (window.createPopup)
	popup_menu = window.createPopup();

function do_action(action)
{
	switch(action)
	{
		case 'ForeColor'			: return document.execCommand( action,false,pick_color());
		case 'BackColor'			: return document.execCommand( action,false,pick_color());
		case 'CreateLink'			: return document.execCommand( action,true);
		case 'InsertImage' 		: return document.execCommand( action,false,pick_image());
//		case 'InsertImage' 		: return pick_image1();
		case 'CreateLinkFile'	: return document.execCommand( 'CreateLink',false,pick_file());
		case 'FormatBlock1'		: return document.execCommand( 'FormatBlock',false,'<H1>');
		case 'FormatBlock2'		: return document.execCommand( 'FormatBlock',false,'<H2>');
		case 'FormatBlock3'		: return document.execCommand( 'FormatBlock',false,'<H3>');
		case 'RemoveFormat'		:
			if (Active_Id!=0)
			{
				var div = document.getElementById('DIV_'+Active_Id);
//				eval ( 'var inp = document.forms.cbconseil.DATA_DIV_'+Active_Id+';');
				div.innerHTML = noHtml ( div.innerHTML);
			}
		return 1;
	}
	
	var sText = document.selection.createRange();
	if (!sText=="")
	{
		return document.execCommand(action);
   }
   return 0;
}

function popup_menu_over(obj, over)
{
	if(over)
	{
		obj.style.backgroundColor = 'Highlight';
		obj.style.color = 'HighlightText';
	}
	else
	{
		obj.style.backgroundColor = '';
		obj.style.color = '';
	}
}

function make_popup_menu_item ( menus)
{
	var code = '';

	name 		= menus[0];
	action 	= menus[1];
	img_name = menus[2];
	
	code += '<tr>';
	if(name != '<HR>')
	{
		code += '<td onclick="parent.do_action(\''+action+'\'';
		code += '); parent.popup_dialog_open=true; parent.popup_menu_open=false; parent.popup_menu.hide();';
		code += '" style="cursor:hand; font-family:Verdana; font-size:10px;"';
		code += ' onmouseover="parent.popup_menu_over(this, true);"';
		code += ' onmouseout="parent.popup_menu_over(this);">';
	}
	else
	{
		code += '<td>';
	}

	code += '<nobr>';
	if(img_name)
	{
		code += '<img src="../images/icones/'+img_name+'.gif" width="20" height="20" alt="'+name+'" align="absmiddle" hspace="4">';
	}
	else
	{
		code += '<img src="../images/icones/vide.gif" width="20" height="20" hspace="4">';
	}

	if(name != '<HR>')
	{
		code += name;
	}
	else
	{
		code += '<br><img src="../images/icones/vide.gif" width="100%" height="1" style="BACKGROUND-COLOR: buttonshadow"><br>';
		code += '<img src="../images/icones/vide.gif" width="100%" height="1" style="BACKGROUND-COLOR: buttonhighlight"><br>';
	}

	code += '<img src="../images/icones/vide.gif" width="8" height="1"></nobr>';
	code += '</td></tr>';

	return code;
}

function make_popup_menu_button_item ( menus)
{
	var i;
	var code = '';

	code += '<tr><td><table align=left cellspacing=0 cellpadding=0 border=0><tr>';
	for (i=0; i<menus.length; i++)
	{
		code += '<td onclick="parent.do_action(\''+menus[i][1]+'\'';
		code += '); parent.popup_dialog_open=true; parent.popup_menu_open=false; parent.popup_menu.hide();';
		code += '" style="cursor:hand; font-family:Verdana; font-size:10px;"';
		code += ' onmouseover="parent.popup_menu_over(this, true);"';
		code += ' onmouseout="parent.popup_menu_over(this);">';
	
		code += '<img src="../images/icones/'+menus[i][2]+'.gif" width="20" height="20" alt="'+menus[i][0]+'" align="absmiddle" hspace="2">';
		code += '</td>';
	}
	code += '</tr></table></td></tr>';

	return code;
}

function make_popup_menu_body(datainnerHTML)
{
	var code = '';

	code += '<table cellspacing=1 cellpadding=0 border=0 bgcolor=black width=100% height=100%>';
	code += '<tr><td>';
	code += '<table cellspacing="0" cellpadding="0" border="0" bgcolor="buttonface" width="100%" height="100%">';
	code += '<tr bgcolor=#339933><td style="font-family:Verdana; font-size:10px; color=#FFFFFF; font-weight: bold" align=center>Menu</td></tr>';
	code += datainnerHTML;
	code += '</table>';
	code += '</td></tr>';
	code += '</table>';

	return code;
}

function close_popup_menu ()
{
	if (popup_menu_open)
	{
		popup_menu_open=false;
	}
}

function make_popup_menu ()
{
	if(!popup_menu || !Active_Id || popup_menu_open) return false;
	Active_Div = Active_Id;
	popup_menu_open=true;

	var td_height = 20;
	var hr_height = 4;

	var width = 0;
	var height = 4;

	var char_width = 8;//13
	var max_chars = 0;

	var datainnerHTML = '';
	
	var i;
	
	for (i=0; i<Menus.length; i++)
	{
//		! instanceof ne fonctionne pas sur IEmac
//		if (Menus[i][0] instanceof Array)			// make_popup_menu_button_item
		if (isArray(Menus[i][0]))
		{
			datainnerHTML += make_popup_menu_button_item ( Menus[i]); 
			height += td_height;
		}
		else 													// make_popup_menu_item
		{
			datainnerHTML += make_popup_menu_item ( Menus[i]); 
			height += td_height;
		}
	}
	
	max_chars = Math.max(max_chars, 10);
//	width     = max_chars*char_width+40;
	width     = 3*25;
		
	popup_menu.document.body.innerHTML = make_popup_menu_body ( datainnerHTML); height += td_height;
	popup_menu.document.body.onunload = close_popup_menu;
	popup_menu.show ( event.clientX, event.clientY, width, height, document.body);
	return false;
}

document.oncontextmenu = make_popup_menu;

var Active_Id=0;
var Active_Div=0;
FocusEdtOut ('');

