function onover(p) {

    if ( p.className == "submenu_entry" ||
	 p.className == "leftmenu_item" )
	p.style.background="#FF0000";
    else if ( p.className == "menu_entry" )
	//p.style.background="#FF8040";
	p.className = "menu_entry_over";

    expand(p);

}



function onout(p) {

    if ( p.className == "menu_entry_over" )
	p.className = "menu_entry";
    else if ( p.className == "submenu_entry" ||
	 p.className == "leftmenu_item" ||
	 p.className == "menu_entry" )
	p.style.background="";

    collapse(p);

}



function onoverselect(p) {

    if ( p.className == "menu_select" )
	p.className = "menu_select_over";

    //if ( p.className == "submenu_select" )

    //p.style.color="#000000";
    //p.style.background="#FF0000";

    expand(p);

}



function onoutselect(p) {

    if ( p.className == "menu_select_over" )
	p.className = "menu_select";

    //p.style.color="";
    //p.style.background="";

    collapse(p);

}



function expand(p) {

    for(var i=0;i<p.childNodes.length;i++) {
	if(p.childNodes[i].nodeName.toLowerCase()=="div")
	    p.childNodes[i].style.display="block";
    }

}



function collapse(p) {

    for(var i=0;i<p.childNodes.length;i++) {
	if(p.childNodes[i].nodeName.toLowerCase()=="div")
	    p.childNodes[i].style.display="none";
    }

}



var actualSubMenu = -1;

function showSubMenu(num, path) {

    actualSubMenu = num;

    //if ( document["menuImage" + num] )
    //document["menuImage" + num].src="" + path + "/" + menuImagesOver[num];

    layer = "sub_menu_layer_" + num;

    if ( document.getElementById ) {
	if ( document.getElementById(layer) )
	    //document.getElementById(layer).style.visibility = "visible";
	    document.getElementById(layer).style.display = "block";
    } else
	eval("document.layers["+layer+"].visibility = 'visible';");

}



function hideSubMenu(num, path) {

    actualSubMenu = -1;

    setTimeout("realHideSubMenu(" + num + ",\"" + path + "\")", 100);

}



function realHideSubMenu(num, path) {

    if ( actualSubMenu != num ) {

	//if ( document["menuImage" + num] )
	//document["menuImage" + num].src="" + path + "/" + menuImages[num];

	layer_name = "sub_menu_layer_" + num;

	if ( document.getElementById ) {
	    if ( document.getElementById(layer_name) )
		//document.getElementById(layer_name).style.visibility="hidden";
		document.getElementById(layer_name).style.display="none";
	} else
	    eval("document.layers["+layer_name+"].visibility = 'hidden';");

    }

}



function overSubMenu(layer) {

    if ( document.getElementById )
	document.getElementById(layer).style.background="#ff8000";
    else
	document.layers[layer].background="#ff8000";

}



function outSubMenu(layer) {

    if ( document.getElementById )
	document.getElementById(layer).style.background="none";
    else
	document.layers[layer].background="none";

}



function showLanguageMenu(path) {

    document["languageImg"].src = "" + path + "/" + languageImageOver;

}



function hideLanguageMenu(path) {

    document["languageImg"].src = "" + path + "/" + languageImage;

}



function removeLanguageMenu() {

    document["languageImg"].style.display="none";

}



function english_exists() {

    if ( (location.href.indexOf("/intra")              != -1) ||
	 (location.href.indexOf("/notes/")             != -1) ||
	 (location.href.indexOf("/enseignement/")      != -1) ||
	 (location.href.indexOf("/liens")             != -1) ||
	 (location.href.indexOf("/cours.html")         != -1) ||
	 (location.href.indexOf("/horaires.html")      != -1) ||
	 (location.href.indexOf("/consignes.html")     != -1) ||
	 (location.href.indexOf("/notes.html")         != -1) ||
	 (location.href.indexOf("/conferences.html")   != -1) ||
	 (location.href.indexOf("/projetI5/")          != -1) ||
	 (location.href.indexOf("/systeme/")           != -1) )
	return false;
    else
	return true;

}



function english() {

    if ( english_exists() ) {
        pos = location.href.lastIndexOf("/");
        location.href=location.href.substring(0,pos) + "/en" + location.href.substring(pos);
    } else {
        alert( "Sorry : This page doesn't exist in english." + '\n' +
	       "Désolé : Cette page n'existe pas en anglais." );
    }

}



function french() {

    pos = location.href.lastIndexOf("/");

    location.href=location.href.substring(0,pos - 3) + location.href.substring(pos);

}



function LocationPassGo() {
    document.LocationSecurityForm.action = "notes/" + document.LocationSecurityForm.LocationPassCode.value + "/index.html";
}



var actual_zoom = 4;

zoomplus = "maps/zoom_plus.gif";
zoommoins = "maps/zoom_moins.gif";

var map_array = new Array(6);
map_array[0] = "maps/world_map.gif";
map_array[1] = "maps/europe_map.gif";
map_array[2] = "maps/france_map.gif";
map_array[3] = "maps/mlv_map.gif";
map_array[4] = "maps/descartes_map.gif";
map_array[5] = "maps/esiee_anim_map.gif";

var scale_array = new Array(6);
scale_array[0] = "maps/scale_world.gif";
scale_array[1] = "maps/scale_europe.gif";
scale_array[2] = "maps/scale_france.gif";
scale_array[3] = "maps/scale_mlv.gif";
scale_array[4] = "maps/scale_descartes.gif";
scale_array[5] = "maps/scale_esiee.gif";

var selected_scale_array = new Array(6);
selected_scale_array[0] = "maps/scale_world_s.gif";
selected_scale_array[1] = "maps/scale_europe_s.gif";
selected_scale_array[2] = "maps/scale_france_s.gif";
selected_scale_array[3] = "maps/scale_mlv_s.gif";
selected_scale_array[4] = "maps/scale_descartes_s.gif";
selected_scale_array[5] = "maps/scale_esiee_s.gif";

function zoomin(path) {

    if ( actual_zoom + 1 < map_array.length )
	zoomto(actual_zoom + 1, path);

}


function zoomout(path) {

    if ( actual_zoom > 0 )
	zoomto(actual_zoom - 1, path);

}


function zoomto(value, path) {

    if ( value >= 0 && value < map_array.length ) {
	document['scaleImg'+actual_zoom].src = path + "/" + scale_array[actual_zoom];
	actual_zoom = value;
	document['mapImg'].src = path + "/" + map_array[actual_zoom];
	document["scaleImg"+actual_zoom].src = path + "/" + selected_scale_array[actual_zoom];
    }

}



function createmap(path) {

    // pre-chargement des images de plan
    for ( i = 0; i < map_array.length; i++ ) {
	mypix=new Image();
	mypix.src = "" + path + "/" + map_array[i];
    }

    // pre-chargement des images d'echelle
    for ( i = 0; i < scale_array.length; i++ ) {
	mypix=new Image();
	mypix.src = "" + path + "/" + scale_array[i];
    }

    // pre-chargement des images d'echelle selectionnees
    for ( i = 0; i < selected_scale_array.length; i++ ) {
	mypix=new Image();
	mypix.src = "" + path + "/" + selected_scale_array[i];
    }

    // Generation du code HTML de l'affichage des plans et de l'echelle

    document.writeln("<table border=0>");
    document.writeln("  <tr>");
    document.writeln("    <td><a href='javascript:zoomin(\""+path+"\")'><img name='mapImg' src='" + path + "/" + map_array[actual_zoom] + "' alt='map: clic to zoom' border=0></a></td>");
    document.writeln("    <td>");
    document.writeln("      <table border=0>");
    document.writeln("        <tr><td align=center><a href='javascript:zoomout(\""+path+"\")'><img src=" + path + "/" + zoommoins +" alt='zoom' border=0></a></td></tr>");
    for ( i = 0; i < map_array.length; i++ ) {
	document.writeln("        <tr><td align=center><a href='javascript:zoomto("+i+",\""+path+"\")'><img name='scaleImg" + i + "' src=" + path + "/" + scale_array[i] +" alt='zoom in' border=0></a></td></tr>");
    }
    document.writeln("        <tr><td align=center><a href='javascript:zoomin(\""+path+"\")'><img src=" + path + "/" + zoomplus +" alt='zoom in' border=0></a></td></tr>");
    document.writeln("      </table>");
    document.writeln("    </td>");
    document.writeln("  </tr>");
    document.writeln("</table>");
    if ( actual_zoom < 0 || actual_zoom >= map_array.length )
	actual_zoom = 0;
    document["scaleImg"+actual_zoom].src = path + "/" + selected_scale_array[actual_zoom];
    
}



function afficheImage_notes(filename) {
    document.images['graphe_notes'].src=filename;
    if ( filename.indexOf("lin", 0) == -1 ) {
	document.images['barre1'].src="../../images/barre_notes_v_vide.gif";
	document.images['barre2'].src="../../images/barre_notes.gif";
    } else {
	document.images['barre1'].src="../../images/barre_notes_v.gif";
	document.images['barre2'].src="../../images/barre_notes_vide.gif";
    }
}



function afficheImage_projet(filename) {
    afficheImage_notes(filename);
}



function loading(path) {
    document['menu_load_anim1'].src="" + path + "/sub_menu_top_load.gif";
    document['menu_load_anim2'].src="" + path + "/sub_menu_top_load.gif";
}



var stop_div_name;
var freeze_div_name;
var div_name_moves = 0;


function moveDiv(layer_id, moving_direction, min_x, max_x) {

    var layer;
    var width;
    var pos;


    if ( stop_div_name == layer_id )
	return;

    if ( window.innerWidth )
	width = window.innerWidth;
    else
	if ( document.body.offsetWidth )
	    width = document.body.offsetWidth;
	else
	    if ( document.body.clientHeight )
		width = document.body.clientHeight;

    if ( document.all )
	layer = document.all(layer_id).style;
    else
	if ( document.getElementById )
	    layer = document.getElementById(layer_id).style;
	else
	    layer = document.layers[layer_id];

    if ( freeze_div_name != layer_id ) {

	if ( layer.left == "" )
	    pos = min_x;
	else
	    pos = parseInt(layer.left) + moving_direction;

	if ( pos > width - max_x )
	    pos = width - max_x;
	else
	    if ( pos < min_x )
		pos = min_x;

	if (document.layers)
	    layer.left = pos;
	else
	    layer.left = pos + "px";
    }

    if ( ( moving_direction > 0 && parseInt(layer.left) < width - max_x ) ||
	 ( moving_direction < 0 && parseInt(layer.left) > min_x ) )
	setTimeout("moveDiv(\""+layer_id+"\", "+moving_direction+", "+min_x+", "+max_x+")", 100);
    else {
	div_name_moves--;
	if ( div_name_moves > 0 )
	    setTimeout("moveDiv(\""+layer_id+"\", "+(-moving_direction)+", "+min_x+", "+max_x+")", 1000);
	else
	    setTimeout("hideMovingLayer(\""+layer_id+"\")", 1000);
    }

}



function animateDiv(layer_id, moving_direction, min_x, max_x) {

    unFreezeMovingLayer(layer_id);
    if ( stop_div_name == layer_id ) {
	stop_div_name = "";
	moveDiv(layer_id, moving_direction, min_x, max_x);
    }

    div_name_moves = 3;
}



function stopMovingLayer(layer_id) {
    stop_div_name = layer_id;
}



function freezeMovingLayer(layer_id) {
    freeze_div_name = layer_id;
}


function unFreezeMovingLayer(layer_id) {
    if ( freeze_div_name == layer_id )
	freeze_div_name = "";
}



function hideMovingLayer(layer_id) {
    stop_div_name = layer_id;
    if ( document.all )
	layer = document.all(layer_id).style;
    else
	if ( document.getElementById )
	    layer = document.getElementById(layer_id).style;
	else
	    layer = document.layers[layer_id];
    layer.visibility = "hidden";
}




function recupmoveDiv() {

    var the_style = getStyleObject("myDiv");
    var the_left = parseInt(the_style.left) + 100;
    var the_top = parseInt(the_style.top) + 100;
    if (document.layers) {
	the_style.left = the_left;
	the_style.top = the_top;
    } else {
	the_style.left = the_left + "px";
	the_style.top = the_top + "px";  
    }

}




function recup() {

    if (document.layers) {
	document.layers[ttls[i]].top -= move;
	document.layers[subs[i]].top -= move;
    } else if (document.all) {
	document.all(ttls[i]).style.pixelTop -= move;
	document.all(subs[i]).style.pixelTop -= move;
    }

}


function RecupmoveBy(obj, deltaX, deltaY) {

    var theObj = getObject(obj);
    if(ns4) {
	theObj.moveBy(deltaX, deltaY);
    } else
	if(ie4) {
	    theObj.style.pixelLeft += deltaX;
	    theObj.style.pixelTop += deltaY;
	} else {
	    theObj.style.left = (getObjectLeft(theObj) + deltaX) + "px";
	    theObj.style.top = (getObjectTop(theObj) + deltaY) + "px";
	}
    return true;
}


var firstdate=0;


function check_date(date, month, year) {

    var now = new Date();
    var d = new Date(year, month - 1, date);

    var weekday=new Array(7);
    weekday[0]="Dimanche";
    weekday[1]="Lundi";
    weekday[2]="Mardi";
    weekday[3]="Mercredi";
    weekday[4]="Jeudi";
    weekday[5]="Vendredi";
    weekday[6]="Samedi";

    var monthstr=new Array(12);
    monthstr[0]="janvier";
    monthstr[1]="février";
    monthstr[2]="mars";
    monthstr[3]="avril";
    monthstr[4]="mai";
    monthstr[5]="juin";
    monthstr[6]="juillet";
    monthstr[7]="août";
    monthstr[8]="septembre";
    monthstr[9]="octobre";
    monthstr[10]="novembre";
    monthstr[11]="décembre";

    if ( date == "1" )
	date = "1<sup>er</sup>";

    if ( now.getYear()  == d.getYear() &&
	 now.getMonth() == d.getMonth() &&
	 now.getDate()  == d.getDate() ) {

	document.write("<table border=0><tbody><tr><td>");

	document.write("<img src=\"images/fleche_mouv1.gif\" " +
		       "style=\"vertical-align:middle;\" class=\"not_print\">");

	document.write("</td><td align=center>");

	document.write("<a name='today' id='todayid'>");

	document.write("<font class=flash>" + weekday[d.getDay()] + " " +
		       date + " " + monthstr[month-1] + " " + year + "</font>");

	document.write("</a>");

	document.write("</td><td>");

	document.write("<img src=\"images/fleche_mouv2.gif\" "+
		       "style=\"vertical-align:middle;\" class=\"not_print\">");

	document.write("</td></tr></tbody></table>");

	firstdate = 1;

    } else {

	if ( now < d && firstdate == 0 ) {
	    document.write("<a name='today' id='todayid'>");
	    document.write("<img src=\"images/fleche_mouv1.gif\" " +
			   "style=\"vertical-align:middle;\" class=\"not_print\">");
	    document.write("</a>");
	    firstdate = 1;
	}

	document.write(weekday[d.getDay()] + " " + date + " " +
		       monthstr[month-1] + " " + year);
    }

}



function check_between_dates(date1, month1, year1, date2, month2, year2) {

    var d1 = new Date(year1, month1 - 1, date1);
    var d2 = new Date(year2, month2 - 1, date2);
    var d3 = new Date(year2, month2 - 1, date2 + 1);
    var now = new Date();

    var weekday=new Array(7);
    weekday[0]="Dimanche";
    weekday[1]="Lundi";
    weekday[2]="Mardi";
    weekday[3]="Mercredi";
    weekday[4]="Jeudi";
    weekday[5]="Vendredi";
    weekday[6]="Samedi";

    var monthstr=new Array(12);
    monthstr[0]="janvier";
    monthstr[1]="février";
    monthstr[2]="mars";
    monthstr[3]="avril";
    monthstr[4]="mai";
    monthstr[5]="juin";
    monthstr[6]="juillet";
    monthstr[7]="août";
    monthstr[8]="septembre";
    monthstr[9]="octobre";
    monthstr[10]="novembre";
    monthstr[11]="décembre";


    if ( date1 == "1" )
	date1 = "1<sup>er</sup>";

    if ( date2 == "1" )
	date2 = "1<sup>er</sup>";

    if ( d1 <= now && d3 > now ) {

	//document.write("<table border=0><tbody><tr><td>");

	document.write("<img src=\"images/fleche_mouv1.gif\" " +
		       "style=\"vertical-align:middle;\" class=\"not_print\">");

	//document.write("</td><td align=center>");

	document.write("<a name='today' id='todayid' href='#'>");

	document.write("<font class=flash>" + "Du " + weekday[d1.getDay()] +
		       " " + date1 + " " + monthstr[month1-1] + " " + year1 +
		       " au " + weekday[d2.getDay()] + " " + date2 + " " +
		       monthstr[month2-1] + " " + year2 + "</font>");

	document.write("</a>");

	//document.write("</td><td>");

	document.write("<img src=\"images/fleche_mouv2.gif\" "+
		       "style=\"vertical-align:middle;\" class=\"not_print\">");

	//document.write("</td></tr></tbody></table>");

	firstdate = 1;

    } else {

	if ( now < d1 && firstdate == 0 ) {
	    document.write("<a name='today' id='todayid'>");
	    document.write("<img src=\"images/fleche_mouv1.gif\" " +
			   "style=\"vertical-align:middle;\" class=\"not_print\">");
	    document.write("</a>");
	    firstdate = 1;
	}

	document.write("Du " + weekday[d1.getDay()] + " " + date1 + " " +
		       monthstr[month1-1] + " " + year1 + " au " + weekday[d2.getDay()] +
		       " " + date2 + " " + monthstr[month2-1] + " " + year2);
    }

}


function check_today() {

    if ( firstdate == 0 ) {

	document.write("<br><center><a name='today' id='todayid'>");

	document.write("<img src=\"images/fleche_mouv1.gif\" " +
		       "style=\"vertical-align:middle;\" class=\"not_print\">");

	document.write("Plus de cours prévus pour l'instant.");

	document.write("<img src=\"images/fleche_mouv2.gif\" "+
		       "style=\"vertical-align:middle;\" class=\"not_print\">");

	document.write("</a></center>");

	firstdate = 1;
    }

}



function softScroll(value) {

    var scroll_step = 20;
    var time_step   = 10;

    if ( value > 0 ) {
	if ( value <= scroll_step )
	    window.scrollBy(0, value);
	else {
	    window.scrollBy(0, scroll_step);
	    setTimeout("softScroll("+ (value - scroll_step)+")", time_step);
	}
    } else {
	if ( -value <= scroll_step )
	    window.scrollBy(0, value);
	else {
	    window.scrollBy(0, -scroll_step);
	    setTimeout("softScroll("+ (value + scroll_step)+")", time_step);
	}
    }
}




function getTop(MyObject) {

    // Fonction permettant de connaître la position d'un objet
    // par rapport au bord haut de la page.

    if (MyObject.offsetParent)
	return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
	return (MyObject.offsetTop);

}



function scrollToAnchor(ID_Anchor, Name_Anchor, ID_Start, Name_Start) {

    // Fonction permettant de scroller la page jusqu'a une ancre
    // sans passer cette ancre a l'url

    var ns4 = (document.layers)? true:false;	     // NS 4
    var ie4 = (document.all)? true:false;	     // IE 4
    var dom = (document.getElementById)? true:false; // DOM

    var scroll = 0;

    if ( ie4 ) {
	now = document.all[ID_Start];
	dest = document.all[ID_Anchor];
	scroll = getTop(dest) - getTop(now);
    } else if (dom) {
	now = document.getElementById(ID_Start);
	dest = document.getElementById(ID_Anchor);
	scroll = getTop(dest) - getTop(now);
    } else if (ns4) {
	now = document.anchors[Name_Start];
	dest = document.anchors[Name_Anchor];
	scroll = dest.y - now.y;
    }

    softScroll(scroll + 10);

}



function scrollToTop() {

    softScroll(-(document.all?iecompattest().scrollTop:pageYOffset + 10));

}



function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}




var ieNOTopera;
var ns4;  // NS 4
var ie4;  // IE 4
var dom;  // DOM
var ref;
var top_button_obj;
var top_menu_obj;



function initializeIT(){

    ieNOTopera=document.all&&navigator.userAgent.indexOf("Opera")==-1;

    top_button_obj = document.all?document.all.backtotopbutton:document.getElementById?document.getElementById("backtotopbutton"):document.backtotopbutton;

    top_menu_obj = document.all?document.all.topMenu:document.getElementById?document.getElementById("topMenu"):document.topMenu;

    ns4 = (document.layers)? true:false;	 // NS 4
    ie4 = (document.all)? true:false;	         // IE 4
    dom = (document.getElementById)? true:false; // DOM

    positionTopMenu();
    positionBackToTop();

    if (document.all||document.getElementById||document.layers) {
	setInterval("positionBackToTop()", 800);
	setInterval("positionTopMenu()",   800);
    }

}



function positionBackToTop(){

    var dsoctop=document.all?iecompattest().scrollTop:pageYOffset;
    var window_height=ieNOTopera?iecompattest().clientHeight:window.innerHeight;
    var Voffset = (window_height / 2) - 12;

    if ( ie4 ) {
	ref = getTop(document.all["BackToTopInitid"]);
    } else if (dom) {
	ref = getTop(document.getElementById("BackToTopInitid"));
    } else if (ns4) {
	ref = getTop(document.anchors["BackToTopInit"]);
    }

    if  ( document.all || document.getElementById){
	if ( dsoctop + Voffset > ref ) {
	    if ( ie4 ) {
		top_button_obj.style.top=dsoctop+Voffset+"px";
	    } else {
		top_button_obj.style.top=Voffset+"px";
		top_button_obj.style.position="fixed";
	    }
	} else {
	    top_button_obj.style.top=ref+"px";
	    top_button_obj.style.position="absolute";
	}
    }
    else
	if (document.layers) {
	    if ( pageYOffset + Voffset > ref ) {
		top_button_obj.top=dsoctop+Voffset;
	    } else {
		top_button_obj.top=ref;
	    }
	}

}



function positionTopMenu(){

    var dsoctop=document.all?iecompattest().scrollTop:pageYOffset;
    var window_height=ieNOTopera?iecompattest().clientHeight:window.innerHeight;
    var Voffset = 0;

    if ( ie4 ) {
	ref = getTop(document.all["TopMenuInitid"]) - 15;
    } else if (dom) {
	ref = getTop(document.getElementById("TopMenuInitid")) - 15;
    } else if (ns4) {
	ref = getTop(document.anchors["TopMenuInit"]) - 15;
    }

    if  ( document.all || document.getElementById){
	if ( dsoctop + Voffset > ref ) {
	    if ( ie4 ) {
		top_menu_obj.style.top=dsoctop+Voffset+"px";
	    } else {
		top_menu_obj.style.top="0px";
		top_menu_obj.style.position="fixed";
	    }
	} else {
	    top_menu_obj.style.top=ref+"px";
	    top_menu_obj.style.position="absolute";
	}
    }
    else
	if (document.layers) {
	    if ( pageYOffset + Voffset > ref ) {
		top_menu_obj.top=dsoctop+Voffset;
	    } else {
		top_menu_obj.top=ref;
	    }
	}

}

