// &amp; OK
//	Rosette-scripts.js : Rosette basic functions in JavaScript.
//	Leader : C.Roy
//	Rosette versions : 2.1 and 3.0

// Copyright (c) 2006-2009 Rosette - by Vincent Euverte - August 2006 - extended October 2007

var newwindow = ''; var editorPalette = '';

//  test AJAX -------------------------------------------------------------

//
function ajaxEditorEnvrt( )
	{
	var Text, fontbase0, Font, orientation, direction,widthOrHeightMax,withPositionNbr,analysis,sample,option;
	
	Text = encodeURIComponent( ( document.chain_input.Text.value ) );
	fontbase0 = document.chain_input.fontbase0.value;
	Font = document.getElementById('parameter' ).Font.value;
	orientation = (document.getElementById('ori2').checked)?'V':'H';
	direction = (document.getElementById('dirdir2').checked)?1:0;
	var pureTextCoef = document.chain_input.pureTextCoef.value;
	widthOrHeightMax = document.chain_input.widthOrHeightMax.value;
	withPositionNbr = (document.chain_input.pos_num.checked)?1:0;
	analysis = (document.chain_input.analysis.checked)?1:0;
	sample = document.chain_input.sample.value;
	document.chain_input.currentSample.value = sample;
	option = document.getElementById( 'ongletActif' ).value;
	//option = document.chain_input.option.value;
	return 'Text=' + Text + '&fontbase0=' + fontbase0
		+ '&Font=' + Font + '&orientation=' + orientation + '&direction=' + direction
		+ '&pureTextCoef=' + pureTextCoef + '&widthOrHeightMax=' + widthOrHeightMax + '&withPositionNbr=' + withPositionNbr
		+ '&analysis=' + analysis + '&sample=' + sample + '&option=' + option;
	}
//
function ajaxEditorLaunch(  )
	{
	ajaxEditor( ajaxEditorEnvrt() );
	document.getElementById( 'hieros' ).innerHTML = _ajaxAnswer;
	document.getElementById('hieros').style.width = "auto";	//document.getElementById( 'content' ).style.width;
	document.getElementById('hieros').style.height = "auto";
	positionneImages( 'hieros' );
//alert('fin ajaxEditorLaunch');
	}

function ajaxEditorLaunchCorpus( sourceName, targetName )
	{
if( targetName == 'hieros' )
	Text = encodeURIComponent( document.getElementsByName( sourceName )[0].value );
else
	Text = '"' + encodeURIComponent( document.getElementsByName( sourceName )[0].value ) + '"/zt/s125';
Font = document.getElementById('parameter' ).Font.value;
params = 'Text=' + Text + '&fontbase0=25'
		+ '&Font=' + Font + '&orientation=H&direction=0'
		+ '&pureTextCoef=0.5&widthOrHeightMax=-1&withPositionNbr=0'
		+ '&analysis=0&sample=0&option=0';
	ajaxEditor( params );
	document.getElementById( targetName ).innerHTML = _ajaxAnswer;
	}

//	appel depuis corpus (corpus.php)
//	
//	le MdC à traiter est transmis par la variable de session 'corpusText' (pour ne pas dépasser la longuer max d'URI)
function ajaxEditorLaunchCorpus2( textId, ancesters, lineIndex, optSize, mode, orientation, direction, grid, widthOrHeightMax )
	{
	var Font = document.getElementById('parameter' ).Font.value;
	var params = 'Text=session' + lineIndex + '&fontbase0=' + optSize
			+ '&textId=' + textId + '&ancesters=' + ancesters
			+ '&Font=' + Font + '&orientation=' + orientation + '&direction=' + direction
//			+ '&pureTextCoef=0.5&widthOrHeightMax=-1&withPositionNbr=0'
			+ '&pureTextCoef=0.5&widthOrHeightMax=' + widthOrHeightMax + '&withPositionNbr=0'
			+ '&analysis=0&sample=0&option=0'
			+ '&corpusMode=' + mode;
	if( grid )
		params = params + '&corpusGrid';
	ajaxEditor( params );
	var targetDiv = 'hieros' + lineIndex;
	document.getElementById( targetDiv ).innerHTML = _ajaxAnswer;
	positionneImages( targetDiv );
	}

function dimensionnePhoto( lineIndex )
	{
	var targetDiv = 'hieros' + lineIndex;
	var imageId = 'photo' + lineIndex;
	document.getElementById( imageId ).style.height = document.getElementById( targetDiv ).style.height;
	}

//	appel depuis éditeur lignes corpus (admin_Text_line.php)
//	
//	le MdC à traiter est transmis par la variable de session 'corpusText' (pour ne pas dépasser la longuer max d'URI)
function ajaxEditorLaunchCorpus3( textAreaId, targetDiv )
	{
	var theText = encodeURIComponent( document.getElementById( textAreaId ).value );
	if( textAreaId == 'Translit' )
		theText = '"' + theText + '"/zt';
	var params = 'Text=' + theText + '&fontbase0=35'
			+ '&Font=1&orientation=H&direction=0'
			+ '&pureTextCoef=0.5&widthOrHeightMax=-1&withPositionNbr=0'
			+ '&analysis=0&sample=0&option=0';
	ajaxEditor( params );
	document.getElementById( targetDiv ).innerHTML = _ajaxAnswer;
	//positionneImages( targetDiv );
	}

//	appel depuis depuis corpus pour initialisation des variables
//	
//	le MdC à traiter est transmis par la variable de session 'corpusText' (pour ne pas dépasser la longuer max d'URI)
function ajaxEditorLaunchCorpus4( textId, optSize )
	{
	//alert( 'ajaxEditorLaunchCorpus4');
	var params = 'Text=session0' + '&fontbase0=' + optSize
			+ '&textId=' + textId
			+ '&Font=1&orientation=H&direction=0'
			+ '&pureTextCoef=0.5&widthOrHeightMax=-1&withPositionNbr=0'
			+ '&analysis=0&sample=0&option=0&ancesters';
	ajaxEditor( params );
	}

function ajaxEditorCheck( langue, mdc, displayCode )
	{
	document.getElementById('hieros').innerHTML = '';
	var lesParams= 'Lang=' + langue
		+'&Text=' + encodeURIComponent( document.getElementsByName(mdc)[0].value );
	//alert(lesParams );
	ajaxCheck( lesParams );
	
	var errorMet, resultat, reponse;

var i = _ajaxAnswer.indexOf( '---NOK---', 0 );
//	if( _ajaxAnswer.substring( 0, 2 ) == 'OK' )
	if( i == -1 )
		{	//	validation OK
		show = displayCode;
		errorMet = false;
		reponse = _ajaxAnswer.replace( '---OK---', 'Code normalisé :<div style="margin-left:20px;">' );	//, _ajaxAnswer.length-2 );
		}
	else
		{
		show = true;
		errorMet = true;
		reponse = _ajaxAnswer.replace( '---NOK---', '' );	//, _ajaxAnswer.length-2 );
		}
	if( show )
		{
		if( errorMet )
			resultat = '<div style="margin-left:20px;color:red;">';
		else
			resultat = '';
		resultat += reponse + '</div>';
		}
	else
		resultat = 'OK';
	document.getElementById('hieros').style.width = "auto";	//document.getElementById( 'content' ).style.width;
	document.getElementById('hieros').style.height = "auto";
	document.getElementById('hieros').innerHTML = resultat.replace(/\n/g, '<br/>');
	}

// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)
function getXMLHTTP()
	{
	var xhr=null;
if( true )
	{
	try
		{
		xhr = new XMLHttpRequest(); 
		}
	catch(e)
		{ 
		try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e2)
			{ 
			try
				{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); } 
			catch (e)
				{ alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); }
			}
		}
	}
else
	{
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
		{ // Internet Explorer
		try
			{xhr = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e)
			{
			try
				{xhr = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e1)
				{xhr = null;}
			}
		}
	else // XMLHttpRequest non support¬é par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}
	return xhr;
	}

var _xmlHttp = null; //l'objet xmlHttpRequest utilis¬é pour contacter le serveur
var	_ajaxAnswer='';

function ajaxTraiteXmlAnswer( xmlDoc )
	{
	var options = xmlDoc.getElementsByTagName('option');
	var optionsListe = new Array();
	for( var i=0; i < options.length; ++i )
		optionsListe.push(options[i].firstChild.data);
	return optionsListe;
	}

function ajaxPopup( popupId, action )
	{
	var _adresseCible = "scripts/ajax.php" //l'adresse ¬à interroger pour trouver les suggestions
	if(_xmlHttp&&_xmlHttp.readyState!=0)
		_xmlHttp.abort();
	_xmlHttp = getXMLHTTP();
	if(_xmlHttp)
		{	//appel SYNCHRONE ¬à l'url distante
		_xmlHttp.open( 'GET', _adresseCible + '?popupId=' + popupId + '&action=' + action, false );
		// envoi de la requête
		_xmlHttp.send( null );
		liste = ajaxTraiteXmlAnswer( _xmlHttp.responseXML );
		_ajaxAnswer = liste[0];
		}
	}

function ajaxEditor( params )
	{
	var _adresseCible = 'scripts/ajaxEditor.php';
	if( _xmlHttp && _xmlHttp.readyState!=0)
		_xmlHttp.abort();
	_xmlHttp = getXMLHTTP();
	if(_xmlHttp)
		{	//appel SYNCHRONE ¬à l'url distante
		_xmlHttp.open( 'GET', _adresseCible + '?' + params, false );
		// envoi de la requ¬ête
		_xmlHttp.send( null );
		if( _xmlHttp.status == 200 )
			_ajaxAnswer = _xmlHttp.responseText;
		else
			{
			alert( '_xmlHttp.status : ' + _xmlHttp.status );
			_ajaxAnswer = '';
			}
		}
	}

function ajaxLoadSample( withRendering )
	{
	var _adresseCible = 'scripts/ajaxEditorLoad.php' //l'adresse ¬à interroger pour charger le sample

	var sample = document.chain_input.sample.value;
	var params = ajaxEditorEnvrt();
	if(_xmlHttp&&_xmlHttp.readyState!=0)
		_xmlHttp.abort();
	_xmlHttp = getXMLHTTP();
	if(_xmlHttp)
		{	//appel SYNCHRONE ¬à l'url distante
		_xmlHttp.open( 'GET', _adresseCible + '?' + params, false );
		// envoi de la requ¬ête
		_xmlHttp.send( null );
		_ajaxAnswer = _xmlHttp.responseText;
		document.chain_input.Text.value = _ajaxAnswer;
		if( withRendering )
			ajaxEditorLaunch( );
		}
	}

function ajaxCheck( params )
	{
	var _adresseCible = "scripts/ajaxCheck.php" //l'adresse ¬à interroger pour trouver les suggestions
	if(_xmlHttp&&_xmlHttp.readyState!=0)
		_xmlHttp.abort();
	_xmlHttp = getXMLHTTP();
	if(_xmlHttp)
		{	//appel SYNCHRONE ¬à l'url distante
		_xmlHttp.open( 'GET', _adresseCible + '?' + params, false );
		// envoi de la requ¬ête
		_xmlHttp.send( null );
		_ajaxAnswer = _xmlHttp.responseText;
		}
	}

//	positionne les images et les textes contenues dans une div
//
//	La position de chaque image est déterminée par l'attribut "position" de la balise <img correspondante
//	Cet attribut contient une (left et top) ou deux (left puis top) valeurs numériques séparées par une virgule.
//	Ces deux valeurs définissent la distance en pixels du coin sup./gauche de l'image par rapport au 
//	coin sup. gauche de la div.
//	Les paddings de la div sont pris en compte.
//
//	L'élément DOM juste au dessus de la div doit contenir position:relative dans son style
function positionneImages( divName )
	{
//alert( 'entrée positionneImages' );
	var m = document.getElementById( divName );
	//	paddings de la div --> paddings[]
	var paddings
if( false )
	{	// affiche hiérarchie de positionnement DOM
	n=m;
	mes=m.id + ' offsetTop ' + m.offsetTop + String.fromCharCode(10);
	while( n.offsetParent != null )
		{
		mes += '<' + n.offsetParent.id +'-'+ n.offsetParent.nodeName+'-'+n.offsetParent.nodeType+'-'+n.offsetParent.hasLayout;
		n = n.offsetParent;
		}
	alert( mes );
	}
	if( m.style.padding != '' )
		paddings = m.style.padding.split(' ');
	else
		paddings = Array( 0, 0, 0, 0 );
	var offsetLeftDiv = m.offsetLeft;
	var offsetTopDiv = m.offsetTop;
	var i = 0;
	for( ; i<4; i++ )		//	for each pas dispo avec Safari
		paddings[i] = parseInt(paddings[i]);

	var maxY = 0;
	var maxX = 0;
	var img;
	var dimensions;
	var message='';
	var img;
	var idxChild = 0;
	var imageDiv = false;
	var textDiv = false;
	while( (img = m.childNodes[ idxChild ] ) )		//	for each pas dispo avec Safari
		{	//	loop on nodes in container div
		if( img.nodeType != null && img.nodeType == 1 )
			{
			if( img.nodeName == 'IMG' )
				{	// repositionnement image
				var dimensions = img.getAttribute("dimensions");
				dimensions = dimensions.split( ',' );		// x,y,w,h
				for( i=0; i<4; i++ )
					dimensions[i] = parseInt( dimensions[i] );
				img.style.position = "absolute";
				img.style.left = ( offsetLeftDiv + paddings[3] + dimensions[0] ) + "px";
				img.style.top = ( offsetTopDiv + paddings[0] + dimensions[1] ) + "px";
				maxY = Math.max( maxY, ( dimensions[1] + dimensions[3] ) );
				maxX = Math.max( maxX, ( dimensions[0] + dimensions[2] ) );
				imageDiv = true;
				}
			else if( img.nodeName == 'DIV' )
				{	//	repositionnement texte
				var increment = textDiv?0:10;
				img.style.position = 'absolute';
				img.style.top = ( increment + offsetTopDiv + paddings[0] + maxY ) + "px";
				maxY = increment + maxY + img.offsetHeight;
				textDiv = true;
				}
			}
//if( img.nodeName == 'DIV' || img.nodeName == 'IMG' )
//	alert( 'fin bcle '+img.nodeType + '...'+img.nodeName+'...'+img.nodeValue+'...'+maxY);
		idxChild++;
		}
if( imageDiv || textDiv )
	{
	//alert( 'div height : ' + (maxY + paddings[2]) );
	m.style.height = ( maxY + paddings[2] ) + "px";
	m.style.width = ( maxX + paddings[1] ) + "px";
	}
	}

// functions for Rosette input palette
function putInEditor( laChaine, inputZoneName )
	{
	lObj = eval( 'window.opener.document.' + inputZoneName );
	if( laChaine == "return" ) laChaine = String.fromCharCode( 13 );
	insertAtCursor( lObj, laChaine );
	//var start = lObj.selectionStart;
	//var end = lObj.selectionEnd;
	//lObj.value = lObj.value.substr(0, start) + laChaine + lObj.value.substr(end);
	}

function insertAtCursor( myField, myValue) 
	{
	if ( window.opener.document.selection )
		{	//IE support
		//alert('IE');
		myField.focus();
		sel = window.opener.document.selection.createRange();
		var temp = sel.text.length;
		sel.text = myValue;
		if( myValue.length == 0 )
			{
			sel.moveStart( 'character', myValue.length );
			sel.moveEnd( 'character', myValue.length );
			}
		else
			sel.moveStart( 'character', -myValue.length + temp );
		}
	else if( myField.selectionStart || myField.selectionStart == '0' )
		{	//MOZILLA/NETSCAPE support
		//alert('mozilla');
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring( 0, startPos )
			+ myValue
			+ myField.value.substring( endPos, myField.value.length );
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
		//alert( startPos + '.' + myValue.length + '.' + myField.selectionStart );
		}
	else
		{
		//alert('else');
		myField.value += myValue;
		myField.focus();
		}
	}

//	function to confirm an operation
function confirmOperation( text, url )
	{
	if( confirm( text ) )
		window.location.href = url;
	}

//	functions checking an email address
function check_email( address )
	{
	if ( address.trim() == "")
		{
		alert("Vous avez oubli¬é de renseigner la rubrique ADRESSE ELECTRONIQUE.");
		document.formulaire.Email.focus();
		return false;
		}
	posAt = address.indexOf('@',0);
	posDot = address.indexOf('.',posAt+2);
	posPipe = address.indexOf('|',0);
	posStar = address.indexOf('*',0);		
	if( posStar != -1 || posPipe != -1 || posAt == -1 || posDot == -1 || (address.length - posDot < 3))
		{
		alert("L'ADRESSE ELECTRONIQUE que vous avez saisie n'est pas valide");
		document.formulaire.Email.focus();
		return false; 		
		}
	return true;
	}
	
//	function called from editor_menu
function askPdf( script, orientation )
	{
	params = '?text=' + document.getElementById("theText").value
				+ '&files=' + document.getElementById("tempFiles").value
				+ '&size=' + document.getElementById("optSize").value
				+ '&orientation=' + orientation;
	window.location = 'scripts/' + script + params;
	}
//

function popitup( url, fenetre, param, event, urlSpeciale )
	//	param est optionnel et peut ¬être 'pleinEcran'
	{
	if( event != null )
		// appel avec argt exlicite pour changer comportement du click si shift appuyé
		comportement = event.shiftKey?'nonStandard':'std';
	else
		comportement = 'std';

	if( comportement == 'std' )
		{
		if( fenetre == 'editorPalette' )
			{
			//	ask to server if popup open
			ajaxPopup( 1003, 'statut' );
			if( _ajaxAnswer == 'open' && window.editorPalette != '' )
				; // palette window active and opened by the current window
			else
				{
				if( arguments.length < 3 )
					param = 'top=10,left=10,width=580,height=540,scrollbars=yes';
				else if( param == 'pleinEcran' )
					param = 'fullsize,scrollbar,top=10,left=10,width=' + screen.width + ',height=' + screen.height;
				editorPalette=window.open( url, fenetre, param);
				//	pour voir barre adresse : ajouter location=yes
				if (!editorPalette.opener) editorPalette.opener = self;
				}
			if(window.focus) { editorPalette.focus() }
			}
		else
			{
			if( window.newwindow != '' && !newwindow.closed && newwindow.location )
				newwindow.location.href = url;
			else
				{
				if( arguments.length < 3 )
					param = 'top=0,left=0,width=580,height=540,scrollbars=yes';
				else if( param == 'pleinEcran' )
					param = 'fullsize,scrollbar,top=0,left=0,width=' + screen.width + ',height=' + screen.height;
				newwindow=window.open( url, fenetre, param);
				//	pour voir barre adresse : ajouter location=yes
				if (!newwindow.opener) newwindow.opener = self;
				}
			if(window.focus) { newwindow.focus() }
			}
		}
	else
		alert( 'comportement non std : ' + urlSpeciale + '>>>' + event.target );
	return false;
	}

function returnFromPopup( nbr )
	{
	theW = window.opener;
	
	theSel = "";
	for( i=0; i<nbr; i++ )
		{
		if( document.getElementById( "chk" + i ).checked )
			{
			theSel = theSel + i;
			if( i < nbr-1 ) theSel= theSel  + ",";
			}
		}
	if( theSel.length > 0 ) theSel = theSel.substring( 0, theSel.length-1 );

	theRef = theW.location.href;
	var i = (theRef+'').indexOf( "&colChooser", 0 );
	if( i != -1 )
		{
		var j = (theRef+'').indexOf( "&", i+1 );

		theRef2 = theRef.substring(0, i);
		if( j != -1 )
			theRef2 = theRef2+ theRef.substring( j, theRef.length );
		theRef = theRef2;
		}
	theW.location.href = theRef + "&colChooser=" + theSel;
	window.close();
	}

function TAinsr( mdc1, mdc2 )
	{		//insert text within the same window
	var TA = document.chain_input.Text;
	TAinsr0(mdc1,mdc2,TA);
	}

function TAinsr2( mdc1, mdc2 ) 
	{		//insert in Text area from a popup window
	var TA = window.opener.document.getElementsByName("Text")[0];
	TAinsr0( mdc1, mdc2, TA );
	}

function TASave( ) 
	{		//insert in Text area from a popup window
	var TA = document.getElementsByName("Text")[0];

	window.open( 'scripts/editor_download.php?text=' + encodeURIComponent( TA.value ) );
	}

function TAinsr1(mdc1,mdc2)
	{		//Rosette editor - management of the frame flags
	if (mdc1.substring(0,1) == "<") { // frame opening
		if(document.getElementById("bastion").checked) { // rounded bastion flag is set
			if (mdc1 == "<F") {mdc1 = "<F1";}
			if (mdc1 == "<G") {mdc1 = "<G1";}
			if (mdc2 == "F>") {mdc2 = "F1>";}
			if (mdc2 == "G>") {mdc2 = "G1>";}
			}
		if(document.getElementById("nobeg").checked) { // no beginning flag is set
			switch (mdc1.substr(1,1)) {
				case "F" : mdc1 = "<F0"; break;
				case "G" : mdc1 = "<G0"; break;
				case "H" : mdc1 = "<H0"; break;
				case "S" : mdc1 = "<S0"; break;
				default : mdc1 = "<0";
			}	}
		if(document.getElementById("noline").checked) {mdc1 += '/n';} // no line flag is set
		if(document.getElementById("noend").checked) { // no ending flag is set
			switch (mdc2.substr(0,1)) {
				case "F" : mdc2 = "F0>"; break; 
				case "G" : mdc2 = "G0>"; break;
				case "H" : mdc2 = "H0>"; break;
				case "S" : mdc2 = "S0>"; break;
				default : mdc2 = "0>";
			}	}
		for(i=0;i<3;i++){ // include the separator, acording tothe separator option
			if (document.chain_input.separator[i].checked) {
				mdc1 = mdc1 + document.chain_input.separator[i].value;
				mdc2 = document.chain_input.separator[i].value + mdc2 + document.chain_input.separator[i].value;
		}	}	}
	TAinsr(mdc1,mdc2);	
	} 
		
function TAinsr0( mdc1, mdc2, TA) 
	{		//main script, from Aceboard script to add a message
	if (document.selection)
		{
		if ((window.opener) && (window.opener.document))
			{
			TA.focus();
			var str=window.opener.document.selection.createRange().text;			
			var sel=window.opener.document.selection.createRange();
			}
		else
			{
			var str=document.selection.createRange().text;			
			TA.focus();
			var sel=document.selection.createRange();
			}
		if (mdc2!="")
			{
			if (str=="")
				sel.text=sel.text+mdc1+mdc2;
			else
				sel.text=mdc1+sel.text+mdc2;
			}
		else
			sel.text=sel.text+mdc1;
		}
	else if (TA.selectionStart | TA.selectionStart == 0)
		{
		if (TA.selectionEnd > TA.value.length)
			TA.selectionEnd = TA.value.length;
		var firstPos = TA.selectionStart;
		var secondPos = TA.selectionEnd+mdc1.length;
		TA.value=TA.value.slice(0,firstPos)+mdc1+TA.value.slice(firstPos);
		TA.value=TA.value.slice(0,secondPos)+mdc2+TA.value.slice(secondPos);
		TA.selectionStart = firstPos+mdc1.length;
		TA.selectionEnd = secondPos;
		TA.focus();
		}
	else
		{ // Opera
		var sel = document.chain_input.Text;
		var instances = countInstances(mdc1,mdc2);
		if (instances%2 != 0 && mdc2 != ""){
			sel.value = sel.value + mdc2;
		}else{
			sel.value = sel.value + mdc1;
		}
	}
}
		 
function size_adjust(delta)
	{
	document.chain_input.fontbase.value = document.chain_input.fontbase.value - (- delta); }

function go1()
	{
	if (document.chain_input.Section.options[document.chain_input.Section.selectedIndex].value != "none") {
			location = document.chain_input.Section.options[document.chain_input.Section.selectedIndex].value}
	}

function comment(com)
	{
	var descript = document.getElementById("descript");
	descript.expli.value = com;
	}

var w;

function ouvrir(page)
	{
	w=window.open(page, '', 
		'width=800, height=600, scrollbars=yes, left=10, top=10');
	}

function fermer() {if (w.document) w.close();}

function show( idOnglet, rangOnglet )
	{
	document.getElementById( idOnglet ).className = '';
	lObj = document.getElementById( 'option' );
	if( lObj != null ) lObj.value = rangOnglet;
	lObj = document.getElementById( 't' + idOnglet );
	if( lObj != null ) lObj.style.backgroundColor = '#bbbbbb';
	}

function hide( idOnglet )
	{
	document.getElementById( idOnglet ).className = 'cachediv';
	lObj = document.getElementById( 't' + idOnglet );
	if( lObj != null ) lObj.style.backgroundColor = '#ffffff';
	}

// pour afficher ou masquer les onglets de editor_menu
function afficheOnglet( rangOngletActif, refresh )
	{
	//	positionnement objets DOM concernés qui ont pour id :
	//		onglet même : ongletX
	//		dialogue de l'onglet : dialogueOngletX
	//	X étant le rang de l'onglet
	for( onglet = 0; onglet<7; onglet++ )
		{
		nomOnglet = 'onglet' + onglet;
		nomZoneOnglet = 'dialogueOnglet' + onglet;
		if( onglet == rangOngletActif )
			{
			document.getElementById( nomZoneOnglet ).className = '';
			//lObj = document.getElementById( 'option' );
			//if( lObj != null ) lObj.value = rangOngletActif;
			lObj = document.getElementById( nomOnglet );
			if( lObj != null ) lObj.style.backgroundColor = '#bbbbbb';
			}
		else
			{
			document.getElementById( nomZoneOnglet ).className = 'cachediv';
			lObj = document.getElementById( nomOnglet );
			if( lObj != null ) lObj.style.backgroundColor = '#ffffff';
			}
		}
	//	
	if( refresh )
		{
		var _adresseCible = 'scripts/ajaxEditorResetEnvrt.php'
		if(_xmlHttp&&_xmlHttp.readyState!=0)
			_xmlHttp.abort();
		_xmlHttp = getXMLHTTP();
		if(_xmlHttp)
			{	//appel SYNCHRONE ¬à l'url distante
			_xmlHttp.open( 'GET', _adresseCible + '?onglet=' + rangOngletActif + '&taille=300', false );
			// envoi de la requête
			_xmlHttp.send( null );
			}
		}
	}
function XXXshow( nom, optionRange )
	{
	document.getElementById(nom).className = '';
	lObj = document.getElementById('option');
	if( lObj != null ) lObj.value = optionRange;
	lObj = document.getElementById( 't' + nom );
	if( lObj != null ) lObj.style.backgroundColor = '#bbbbbb';
	}

function XXXhide( nom )
	{
	document.getElementById(nom).className = 'cachediv';
	lObj = document.getElementById( 't' + nom );
	if( lObj != null ) lObj.style.backgroundColor = '#ffffff';
	}

function size_adjust0(delta)
	{
	document.chain_input.fontbase0.value = document.chain_input.fontbase0.value - (- delta);
	}

// Corpus dynamic functions
//	these functions expect the following arrays to be predefined :
//	* nom : the filename of the image ("-r" will be added for the vignette, ".jpg" is assumed)
//	* desc : the label to be displayed either in the infobox or the sidelist
//	* map : center-x, center-y and ray of the circle for the mapping area
//	* loc : x/y coordinates to locate the vignette on the picture
//	* path : relative path where the images are stored (both high resolution and vignette)

function popimage(img)
	{ // concept simplifi√É¬© du site osirisnet.net
	// fonction am√É¬©liorable en limitant le resize selon les tailles de l'√É¬©cran et de l'image
	// les commandes directories=no, status=no, resizable=no ne fonctionnent pas sous FF
	w=open("","image","left=5,top=5,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=100,height=100");	
	w.document.writeln("<html><head><title>&copy;Projet Rosette</title>");
	w.document.writeln("<script language=javascript>function checksize() {	sw=document.images[0].width+50; sh=document.images[0].height+100; window.resizeTo(sw,sh); window.focus(); }");
    w.document.writeln("</script>");
    w.document.writeln("</head>");
	w.document.writeln("<body onload='checksize()'>");
	w.document.writeln("<a href='javascript:self.close();'><img src='"+img+"' title='fermer/close' alt='fermer/close' border=0></a>");
	w.document.writeln("</body></html>");
	w.document.close();
	}

function area(i)
	{	// creates the mapping for index "i" 
	document.write('<area shape="circle" coords="'+map[i]+'" href="javascript:popimage(\''+path+nom[i]+'.jpg\')" onmouseover="show(\'tab'+i+'\');" onmouseout="hide(\'tab'+i+'\');" title="'+desc[i]+'" alt="'+desc[i]+'" />');
	}

function cachtab(i)
	{	// creates the different <div> named "tabx" with automatic hide/show via class "cachediv"
	document.write('<div id="tab'+i+'" class="cachediv" style="position:absolute;'+loc[i]+'width:70px;" ><img src="'+path+nom[i]+'-r.jpg" alt="" style="position:absolute;left:0px;top:0px;border:3px double grey;" /></div>');
	}

function sidelist(i)
	{	// creates one line of the sidelist with link to the translated text
	document.write('<a href="page.php?Id=799&amp;TextId='+text+'&amp;line='+line[i]+'" onmouseover="show(\'tab'+i+'\');" onmouseout="hide(\'tab'+i+'\');" title="'+desc[i]+'">'+desc[i]+'</a>');
	}

function sidelist1(i)
	{	// OBSOLETE - creates one line of the sidelist with link to open the image
	// This should better go to the translated text ... need to identify the current text and to pass the first line to be displayed
	document.write('<a href="javascript:popimage(\''+path+nom[i]+'.jpg\')" onmouseover="show(\'tab'+i+'\');" onmouseout="hide(\'tab'+i+'\');" title="'+desc[i]+'">'+desc[i]+'</a>');
	}

// end of Rosette JS functions -->