// sets the paths appropriately according to the current position of the file.
var fullDir = '';
var pathToRoot = '';
var pathToDomains = 'domains/';
var dirSplit = directory.split('/'); //find out if there is any directory for the current file.
var emptyDir = 0;
//TESTING Environement
for (var i in dirSplit) {
	if ((dirSplit[i] == 'Users') || (dirSplit[i] == 'lionelmochamps') || (dirSplit[i] == 'Sites')) {
		dirSplit[i] = '';
	}
}
//END Testing Env.
for (var i in dirSplit) {
	if (dirSplit[i] != '') {
		if (dirSplit[i] == 'domains') {
			pathToDomains = '';
			pathToRoot = '../';
			fullDir = dirSplit[i] + '/'; // not in use for the moment
		} else if (dirSplit[++i] != undefined) {
			i = --i;
			if (fullDir == "") {
				pathToDomains = '../domains/';
				pathToRoot = '../';
				fullDir = dirSplit[i] + '/';
			} else {
				pathToDomains = '../' + pathToDomains;
				pathToRoot = pathToRoot + '../';
				fullDir = fullDir + dirSplit[i] + '/';
			}
		} else if (fullDir == "") {
			i = --i;
			pathToDomains = 'domains/';
			fullDir = fullDir + dirSplit[i];
		} else {
			i = --i;
			fullDir = fullDir + dirSplit[i];
		}
	}
}
for (var i in dirSplit) {
if (dirSplit[i] == '') {
emptyDir = ++emptyDir;
}
}
//window.alert('fullDir: ' + fullDir + '\rpathToRoot: ' + pathToRoot + '\rpathToDomains: ' + pathToDomains + '\rdirSplit: ' + dirSplit);
// **************************** fileName ****************************
var fileName;
if (dirSplit.length == emptyDir) {
fileName = 'index';
} else if (dirSplit.length > emptyDir + 2) {
fileName = dirSplit[emptyDir + 1];
} else {
fileName = dirSplit[dirSplit.length -1];
}
var fileNameArray = fileName.split('.');
fileName = fileNameArray[0];
// **************************** submenu domain ****************************
function submenuDomain() {
if (document.getElementById('domains')) {
var myMenuTarget = document.getElementById('domains');
var myItems = myMenuTarget.getElementsByTagName('li');
var mySubDomLink = new Array();
for (var i = 0; i < myItems.length; i++) {
//window.alert(myItems[i].getAttribute('class'));
if ((myItems[i].getAttribute('class') == 'current') && (fileName == domfileName[i])) {
//window.alert(myItems[i]);
for (var y in subDomLink) {
mySubDomLink[y] = pathToDomains + fileName + '/' + subDomLink[y];
}
theNewList('mySubDom', '', subDomName, mySubDomLink, '', '', myItems[i]);
var theSubMenu = document.getElementById('mySubDom');
//window.alert(theSubMenu);
var z = i + 1;
if (myItems[i]) {
//window.alert(myItems[z]);
myMenuTarget.insertBefore(theSubMenu, myItems[i].nextSibling);
} else {
myMenuTarget.appendChild(theSubMenu);
}
}
}
}
}
// **************************** navbarUpdate ****************************
function navbarUpdate() {
submenuDomain(); // subdomain setup
//Testing class of doc_content for display in navbar
var getPageWidth = document.getElementById('doc_content');
var myClass = getPageWidth.getAttribute('class');
var myTarget = document.getElementById('navbar');
//window.alert(myTarget);
var thePath = '';
if (dirSplit.length == emptyDir) {
thePath = ' » index.html';
} else {
for (var i = emptyDir; i < dirSplit.length; i++) {
thePath = thePath + ' » ' + dirSplit[i];
}
}
//window.alert('thePath: ' + thePath + '\remptyDir: ' + emptyDir + '\rdirSplit.length: ' + dirSplit.length);
var mySpanTag = myTarget.getElementsByTagName('span');
mySpanTag[0].firstChild.nodeValue = 'e-materials v.1.2' + thePath; // + ' - Class: ' + myClass + ' - fileName: ' + fileName + ' - emptyDir: ' + emptyDir + ' - dirSplit[last]: ' + dirSplit[dirSplit.length -1]
}
//<span class="path"> <a href="index.html">home</a> &raquo; site map &raquo; </span> 
// **************************** encodeMyText ****************************
function encodeMyText(myCourrierAdd) {
return myCourrierAdd.replace(/[a-zA-Z]/g, function(c) {
return String.fromCharCode((c<="Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c-26);
});
}
// **************************** reportBrokenLinks ****************************
// to be used with <input type="button" value="Report Broken Link" onclick="reportBrokenLinks('#targetID')" id="showreport" />
function reportBrokenLinks(theTargetId) {
var myButton = document.getElementById('showreport');
var myValueShow = 'Report Broken Link';
var myValueHide = 'Hide [Broken?] Links'
var myClass = 'report';
if (myButton.getAttribute('value') == myValueShow) {
var myTarget = document.getElementById(theTargetId);
var myListOfTags = myTarget.getElementsByTagName('a');
var theBrokenLink = new Array(myListOfTags.length);
var theBrokenLinkText = new Array(myListOfTags.length); // Just added for the text of the anchor
for (var i = 0; i < myListOfTags.length; i++) {
//window.alert(myListOfTags[i].getAttribute('href'));
theBrokenLink[i] = myListOfTags[i].getAttribute('href');
theBrokenLinkText[i] = myListOfTags[i].firstChild.nodeValue; // Just added for the text of the anchor
var myId = myClass + i + '';
var theSpanNode = document.createElement('span');
theSpanNode.setAttribute('id', myId);
if (myListOfTags[i].getAttribute('class') == 'local') { // test for local links
theSpanNode.setAttribute('class', 'local');
}
myListOfTags[i].parentNode.insertBefore(theSpanNode, myListOfTags[i].nextSibling);
}
for (var i in theBrokenLink) {
var myReportSubject = escape('Report of a broken link.');
var myReportBody = escape('This link seems broken, please check:\r\r');
var inPage = escape('\r\rFrom the page: ');
var lineFeed = escape('\r');
var myReport = 'mailto:support.ematerials.web@ensiacet.fr?subject=' + myReportSubject + '&body=' + myReportBody + theBrokenLinkText[i] + lineFeed + theBrokenLink[i] + inPage + directory;
var theWarningText = document.createTextNode('[Broken?]');
var theWarningAnchor = document.createElement('a');
theWarningAnchor.setAttribute('href', myReport);
theWarningAnchor.setAttribute('class', myClass);
theWarningAnchor.setAttribute('title', 'Report broken links and help us keep this site functional.');
theWarningAnchor.appendChild(theWarningText);
var myId = myClass + i + '';
var theSpanNode = document.getElementById(myId);
if (theSpanNode.getAttribute('class') != 'local') { // test for local links
theSpanNode.parentNode.insertBefore(theWarningAnchor, theSpanNode.nextSibling);
}
theSpanNode.parentNode.removeChild(theSpanNode);
}
myButton.setAttribute('value', myValueHide);
} else if (myButton.getAttribute('value') == myValueHide) {

var myTarget = document.getElementById(theTargetId);
var myListOfTags = myTarget.getElementsByTagName('a');
for (var i = 0; i < myListOfTags.length; i++) {
if (myListOfTags[i].getAttribute('class') == myClass) {
myListOfTags[i].parentNode.removeChild(myListOfTags[i]);
}
}
myButton.setAttribute('value', myValueShow)
}
}
// **************************** setupReportBox ****************************
function setupReportBox(insertionPointId, theTargetId) {
var changePageWidth = document.getElementById('doc_content');
var myClass = changePageWidth.getAttribute('class');
if (myClass == 'no_sidebox') { myClass = 'sides'} else if (myClass == 'no_sides') { myClass = 'no_menu'}
changePageWidth.setAttribute('class', myClass);
var theDivElement = document.createElement('div');
theDivElement.setAttribute('id', 'report');
theDivElement.setAttribute('class', 'side_box');
var theInputButton = document.createElement('input');
theInputButton.setAttribute('type', 'button');
theInputButton.setAttribute('value', 'Report Broken Link');
theInputButton.setAttribute('onclick', 'reportBrokenLinks(\'' + theTargetId + '\');');
theInputButton.setAttribute('id', 'showreport');
var theReportBoxH = document.createElement('h4');
var theReportBoxP = document.createElement('p');
var theReportBoxTitle = document.createTextNode('Any broken link?');
var theReportBoxText = document.createTextNode('Report the broken links you come across and help us keep this site functional and tidy.');
theReportBoxH.appendChild(theReportBoxTitle);
theReportBoxP.appendChild(theReportBoxText);
var insertionPoint = document.getElementById(insertionPointId);
//window.alert('insertionPoint: ' + insertionPoint + '\rinsertionPointId: ' + insertionPointId);
theDivElement.appendChild(theReportBoxH);
theDivElement.appendChild(theReportBoxP);
theDivElement.appendChild(theInputButton);
insertionPoint.appendChild(theDivElement);
}
// **************************** contactVar ****************************
var contactVar = ['Lionel Mochamps,yvbary\056zbpunzcf\100znp\056pbz,Technical Editor & Site Design.', 'Daniel Monceau,qnavry\056zbaprnh\100rafvnprg\056se,', 'Lachlan Cranswick,y\056z\056q\056penafjvpx\100qy\056np\056hx,', 'S. Coste,fpbfgr\100rafpg\056se,', 'M.I. Mendelev,zraqryri\100cevaprgba\056rqh,', 'Andrei Gusak,thfnx\100havire\056purexnffl\056hn,', 'Prof. S.E.Mohney,zbuarl\100rzf\056cfh\056rqh,', 'Jean-Paul Baïlon,wonvyba\100rznvy\056culf\056cbylzgy\056pn,', 'Prof. Gary Purdy,cheqlt\100zpznvy\056pvf\056ZpZnfgre\056PN,', 'Benoit Devincre,qrivaper\100mvt\056baren\056se,', 'Feedback,srrqonpx\056rzngrevnyf\056jro\100rafvnprg\056se,Comments about Yves Br&eacute;chet&sbquo;s document.', 'email us your thoughts,srrqonpx\056rzngrevnyf\056jro\100rafvnprg\056se,Survey Feedback.'];
var contactVarAlt = ['rzngrevnyf\056jro\100rafvnprg\056se,General.', 'fhccbeg\056rzngrevnyf\056jro\100rafvnprg\056se,Technical Support.', 'srrqonpx\056rzngrevnyf\056jro\100rafvnprg\056se,Feedback.', 'fcbafbevat\056rzngrevnyf\056jro\100rafvnprg\056se,Sponsoring.', 'npgh-erdhrfg\100cernh\056nffb\056se,', 'obxfg\100cupu\056zvfn\056np\056eh,', 'lirf\056yvzbtr\100prn\056se,','byvivre\056cbyvgnab\100h-obhetbtar\056se,'];
var myContact = [];
var myAddress = [];
var myContactSubject = [];
// **************************** makeContactVar ****************************
function makeContactVar() {
for (i in contactVar) {
var temRecord = contactVar[i].split(',');
myContact.push(temRecord[0]);
myAddress.push(temRecord[1]);
myContactSubject.push(temRecord[2]);
}
for (i in contactVarAlt) {
var temRecord = contactVarAlt[i].split(',');
myContact.push(encodeMyText(temRecord[0]));
myAddress.push(temRecord[0]);
myContactSubject.push(temRecord[1]);
}
}
// **************************** doTheMagic ****************************
function doTheMagic(theTargetId) {
makeContactVar();
var myTarget = document.getElementById(theTargetId);
var myListOfTags = myTarget.getElementsByTagName('span');
for (var i = 0; i < myListOfTags.length; i++) {
if (myListOfTags[i].getAttribute('class') == 'f_off') {
var myAnchorText = myListOfTags[i].firstChild;
var insertHere = myListOfTags[i];
var myMatch = '';
var z = 0;
do {
if (myContact[z]) {
if (myContact[z] == myAnchorText.nodeValue) {
myAnchor = document.createElement('a');
myAnchorHref = encodeMyText(myAddress[z]);
if (myContactSubject[z]) {
myAnchor.setAttribute('href', 'mailto:' + myAnchorHref + '?subject=' + escape('E-Materials: ' + myContactSubject[z]));
} else {
myAnchor.setAttribute('href', 'mailto:' + myAnchorHref + '?subject=' + escape('E-Materials: Contact from a website visitor.'));
}
myAnchor.appendChild(myAnchorText);
insertHere.appendChild(myAnchor);
myMatch = 'exit';
}
z++;
} else {
myMatch = 'exit';
}
} while (myMatch != 'exit');
}
}
}
// **************************** theNewElement ****************************
/*
elementType = string
elementText = string
elementId = string
elementClass = string
insertionPointId = string
*/
function theNewElement(elementType, elementText, elementId, elementClass, theTargetId) {
var myNewElement = document.createElement(elementType);
if (elementText) {
var myElementText = document.createTextNode(elementText);
myNewElement.appendChild(myElementText);
}
if (elementId) {
myNewElement.setAttribute('id', elementId);
}
if (elementClass) {
myNewElement.setAttribute('class', elementClass);
}
//window.alert(myElementText.nodeValue);
//var insertHere = document.getElementById(theTargetId);
//window.alert(insertHere + '\rtheTargetId: ' + theTargetId);
//insertHere.appendChild(myNewElement);
document.getElementById(theTargetId).appendChild(myNewElement);
}

// **************************** theNewList ****************************
/*
listId = string
listClass = string
listOfItems = array
anchorsHref = array
anchorsClass = string
anchorsTitle = array
insertionPointId = string
*/
function theNewList(listId, listClass, listOfItems, anchorsHref, anchorsClass, anchorsTitle, insertionPointId) {
/*if (fileName == "index") {
fileName = "home";
}*/
// prepare the ul and arrays for li, a and text nodes
var myNewList = document.createElement('ul');
var myNewListItem = new Array(listOfItems.length);
var myNewAnchor = new Array(listOfItems.length);
var myNewItemText = new Array(listOfItems.length);
// prepare the li, a and texte nodes for each tab
for (var i in listOfItems) {
myNewListItem[i] = document.createElement('li');
myNewAnchor[i] = document.createElement('a');
myNewItemText[i] = document.createTextNode(listOfItems[i]);
}
// put together the a items
for (var i in listOfItems) {
myNewAnchor[i].appendChild(myNewItemText[i]);
myNewAnchor[i].setAttribute('href', anchorsHref[i]);
if (anchorsClass) {
myNewAnchor[i].setAttribute('class', anchorsClass);
}
if (anchorsTitle) {
myNewAnchor[i].setAttribute('title', anchorsTitle[i]);
}
}
// put together the li items
for (var i in listOfItems) {
myNewListItem[i].appendChild(myNewAnchor[i]);
if ((fileName == domfileName[i]) && (listOfItems[i] == domName[i])) { // current selection
myNewListItem[i].setAttribute('id', 'subinsert');
myNewListItem[i].setAttribute('class', 'current');
}
if (subDomLink[i]) { // current sub domain selection
//window.alert(subDomLink[z]);
if (dirSplit[dirSplit.length -1] == subDomLink[i]) {
myNewListItem[i].setAttribute('class', 'current');
}
}
}
// put together the ul item
for (var i in listOfItems) {
myNewList.appendChild(myNewListItem[i]);
}
if (listId) {
//window.alert(listId);
myNewList.setAttribute('id', listId);
//window.alert(myNewList.getAttribute('id'));
}
if (listClass) {
//window.alert(listClass);
myNewList.setAttribute('class', listClass);
}
//insert ul to the document
if (insertionPointId != null) { // in case no insertion specified
if (document.getElementById(insertionPointId)) { // in case not an id but object itself
//window.alert('document.getElementById(insertionPointId): ' + document.getElementById(insertionPointId));
var insertionPoint = document.getElementById(insertionPointId);
//window.alert('1. insertionPoint: ' + insertionPoint);
} else {
//window.alert('2. insertionPointId: ' + insertionPointId);
var insertionPoint = insertionPointId; // in case object itself
}
//window.alert('3. insertionPoint: ' + insertionPoint);
insertionPoint.appendChild(myNewList); // do the insertion
}
}
// **************************** getEditors ****************************
function getEditors (fileName) {
makeEditorsVar();
var defaultAddress = 'rzngrevnyf\056jro\100rafvnprg\056se';
var pageEditors = 0;
var pagePrincipEditors = 0;
var pagePrincipEditorsCount = 0;
var pageEditorsCount = 0;
var pagePrincipEditorsNames = new Array();
var pagePrincipEditorsAdd = new Array();
var pageEditorsNames = new Array();
var pageEditorsAdd = new Array();
var myDomainApplication = '';
for (var i in domfileName) {
if (fileName == domfileName[i]) {
var myVar = ++i; // var declaration added - Today is 3/11/07. It is now 5:45 PM
--i;
pageEditors = 200 + myVar;
pagePrincipEditors = 100 + myVar;
myDomainApplication = domName[i];
} /*else if (fileName == 'home') {
pagePrincipEditors = 120;
} else if (fileName == 'e-learning') {
pagePrincipEditors = 116;
}*/
}
for (var i in editorsDomain) {
var editorSplit = editorsDomain[i].split('/');
for (var n in editorSplit) {
if (editorSplit[n] == pagePrincipEditors) {
pagePrincipEditorsCount ++;
pagePrincipEditorsNames.push(editorsName[i]);
pagePrincipEditorsAdd.push('mailto:' + encodeMyText(editorsAddress[i]));
} else if  (editorSplit[n] == pageEditors) {
pageEditorsCount ++;
pageEditorsNames.push(editorsName[i]);
pageEditorsAdd.push('mailto:' + encodeMyText(editorsAddress[i]));
} //window.alert('editorSplit[n]: ' + editorSplit[n] + '\rpageEditors: ' + 10 + pageEditors);
}
}
// Setup the email options and default links (join, apply...)
if (pagePrincipEditorsCount < 1) { // Set a default link if no principal editor
pagePrincipEditorsNames.push('Position Available');
var myReportSubject = escape('Application to join as Principal Editor in the domain: ');
pagePrincipEditorsAdd.push('mailto:' + encodeMyText(defaultAddress) + '?subject=' + myReportSubject + escape(myDomainApplication.toUpperCase()));
}
if (pageEditorsCount < 20) {
if (pageEditorsCount < 1) {
pageEditorsNames.push('*Apply for Position*');
} else {
pageEditorsNames.push('Join the team...');
}
var myReportSubject = escape('Application to join as Editorial Committee member in the domain: ');
pageEditorsAdd.push('mailto:' + encodeMyText(defaultAddress) + '?subject=' + myReportSubject + escape(myDomainApplication.toUpperCase()));
}
// End default links
var changePageWidth = document.getElementById('doc_content');
var myClass = changePageWidth.getAttribute('class');
if (myClass == 'no_sidebox') { myClass = 'sides'} else if (myClass == 'no_sides') { myClass = 'no_menu'}
changePageWidth.setAttribute('class', myClass); //make room on the side
theNewElement('div', '', 'editorbox', 'side_box', 'side');
theNewElement('h4', ' Editors: ', '', '', 'editorbox');
if (fileName == 'index') {
theNewElement('span', ' Site Editor: ', '', 'editortype', 'editorbox');
theNewList('' , 'editors', pagePrincipEditorsNames, pagePrincipEditorsAdd, 'editors', '', 'editorbox');
} else {
theNewElement('span', ' Principal Editor: ', '', 'editortype', 'editorbox');
theNewList('' , 'editors', pagePrincipEditorsNames, pagePrincipEditorsAdd, 'editors', '', 'editorbox');
//
theNewElement('span', ' Editorial Committee: ', '', 'editortype', 'editorbox');
theNewList('' , 'editors', pageEditorsNames, pageEditorsAdd, 'editors', '', 'editorbox');
}
}
// **************************** makeEditorsVar ****************************
function makeEditorsVar() {
for (i in editorsData) {
var temRecord = editorsData[i].split(',');
editorsName.push(temRecord[0]);
editorsAddress.push(temRecord[1]);
editorsDomain.push(temRecord[2]);
}
}
// **************************** editorsDataArray ****************************
//TESTING ONLY
function editorsDataArray(editorsData) {
var myNewArray = '';
for (i in editorsData) {
var dataSplit = editorsData[i].split(',');
//var dataDomainSplit = dataSplit[x]('/');
var address = encodeMyText(dataSplit[1]);
var changeChar = address.split('.');
var newAddress;
for (i in changeChar) {
if (i == 0) {
newAddress = changeChar[i];
} else {
newAddress = newAddress + '\\056' + changeChar[i];
}
}
var changeAt = newAddress.split('@');
for (i in changeAt) {
if (i == 0) {
newAddress = changeAt[i];
} else {
newAddress = newAddress + '\\100' + changeAt[i];
}
}
myNewArray = myNewArray + "'" + dataSplit[0] + ',' + newAddress + ',' + dataSplit[2] + "',";
}
//window.alert(myNewArray);
//document.write(myNewArray);
}
/*
THE END
*/