////////////////////////////////////////////////////////////////////////////////////
// CONSTANTS
// Don't touch these. :)
////////////////////////////////////////////////////////////////////////////////////
var INARRAY		=	1;
var CAPARRAY		=	2;
var STICKY		=	3;
var BACKGROUND		=	4;
var NOCLOSE		=	5;
var CAPTION		=	6;
var LEFT		=	7;
var RIGHT		=	8;
var CENTER		=	9;
var OFFSETX		=	10;
var OFFSETY		=	11;
var FGCOLOR		=	12;
var BGCOLOR		=	13;
var TEXTCOLOR		=	14;
var CAPCOLOR		=	15;
var CLOSECOLOR		=	16;
var WIDTH		=	17;
var BORDER		=	18;
var STATUS		=	19;
var AUTOSTATUS		=	20;
var AUTOSTATUSCAP	=	21;
var HEIGHT		=	22;
var CLOSETEXT		=	23;
var SNAPX		=	24;
var SNAPY		=	25;
var FIXX		=	26;
var FIXY		=	27;
var FGBACKGROUND	=	28;
var BGBACKGROUND	=	29;
var PADX		=	30; // PADX2 out
var PADY		=	31; // PADY2 out
var FULLHTML		=	34;
var ABOVE		=	35;
var BELOW		=	36;
var CAPICON		=	37;
var TEXTFONT		=	38;
var CAPTIONFONT		=	39;
var CLOSEFONT		=	40;
var TEXTSIZE		=	41;
var CAPTIONSIZE		=	42;
var CLOSESIZE		=	43;
var FRAME		=	44;
var TIMEOUT		=	45;
var FUNCTION		=	46;
var DELAY		=	37;
var HAUTO		=	48;
var VAUTO		=	49;
var CLOSECLICK		=	50;
var CSSOFF		=	51;
var CSSSTYLE		=	52;
var CSSCLASS		=	53;
var FGCLASS		=	54;
var BGCLASS		=	55;
var TEXTFONTCLASS	=	56;
var CAPTIONFONTCLASS	=	57;
var CLOSEFONTCLASS	=	58;
var PADUNIT		=	59;
var HEIGHTUNIT		=	60;
var WIDTHUNIT		=	61;
var TEXTSIZEUNIT	=	62;
var TEXTDECORATION	=	63;
var TEXTSTYLE		=	64;
var TEXTWEIGHT		=	65;
var CAPTIONSIZEUNIT	=	66;
var CAPTIONDECORATION	=	67;
var CAPTIONSTYLE	=	68;
var CAPTIONWEIGHT	=	69;
var CLOSESIZEUNIT	=	70;
var CLOSEDECORATION	=	71;
var CLOSESTYLE		=	72;
var CLOSEWEIGHT		=	73;
var LAYER		=	74;

////////////////////////////////////////////////////////////////////////////////////
// DEFAULT CONFIGURATION
// You don't have to change anything here if you don't want to. All of this can be
// changed on your html page or through an overLIB call.
////////////////////////////////////////////////////////////////////////////////////

// Width of the popups in pixels
// 100-300 pixels is typical
if (typeof ol_width == 'undefined') { var ol_width = "150";}

// How many pixels to the right/left of the cursor to show the popup
// Values between 3 and 12 are best
if (typeof ol_offsetx == 'undefined') { var ol_offsetx = 12;}

// How many pixels to the below the cursor to show the popup
// Values between 3 and 12 are best
if (typeof ol_offsety == 'undefined') { var ol_offsety = 0;}

// Default text for popups
// Should you forget to pass something to overLIB this will be displayed.
if (typeof ol_text == 'undefined') { var ol_text = "Default Text"; }

// Sets the popups horizontal position to a fixed column.
// Anything above -1 will cause fixed position.
if (typeof ol_fixx == 'undefined') { var ol_fixx = -1; }

// Sets the popups vertical position to a fixed row.
// Anything above -1 will cause fixed position.
if (typeof ol_fixy == 'undefined') { var ol_fixy = -1; }

// Default frame. We default to current frame if there is no frame defined.
if (typeof ol_frame == 'undefined') { var ol_frame = self; }

// Default timeout. By default there is no timeout.
if (typeof ol_timeout == 'undefined') { var ol_timeout = 0; }

// Default timeout. By default there is no timeout.
if (typeof ol_delay == 'undefined') { var ol_delay = 0; }

//Ajout PGU pour gestion du multi-layers
if (typeof ol_layer == 'undefined') { var ol_layer = "overDiv";}

// Runtime variables init. Used for runtime only, don't change, not for config!
var o3_text = "";
var o3_offsetx = 2;
var o3_offsety = 0;
var o3_width = 100;
var o3_fixx = -1;
var o3_fixy = -1;
var o3_frame = self;
var o3_timeout = 0;
var o3_timerid = 0;
var o3_allowmove = 0;
var o3_delay = 0;
var o3_delayid = 0;
// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_allow = 0;
// Our layer
var o3_layer = null;
var over = null;

// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;

// Microsoft Stupidity Check(tm).
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}

// Capture events, alt. diffuses the overlib function.
if ( (ns4) || (ie4) || (ns6)) {
	document.onmousemove = mouseMove
	if (ns4) document.captureEvents(Event.MOUSEMOVE)
} else {
	overlib = no_overlib;
	nd = no_overlib;
	ver3fix = true;
}

// Fake function for 3.0 users.
function no_overlib() {
	return ver3fix;
}

// overlib(arg0, ..., argN)
// Loads parameters into global runtime variables.
function overlib() {
	// Load defaults to runtime.
	o3_text = ol_text;
	o3_offsetx = ol_offsetx;
	o3_offsety = ol_offsety;
	o3_width = ol_width;
	o3_fixx = ol_fixx;
	o3_fixy = ol_fixy;
	o3_timeout = ol_timeout;
	o3_delay = ol_delay;
	o3_layer = ol_layer;	

	// What the next argument is expected to be.
	var parsemode = -1;
	var ar = arguments;
	for (i = 0; i < ar.length; i++) {
		if (parsemode < 0) {

			// Arg is maintext, unless INARRAY
			if (ar[i] == INARRAY) {
				o3_text = ol_texts[ar[++i]];
			} else {
				o3_text = ar[i];
			}
			parsemode = 0;

		} else {
			// Note: NS4 doesn't like switch cases with vars.
			if (ar[i] == INARRAY) { o3_text = ol_texts[ar[++i]]; continue; }
			if (ar[i] == OFFSETX) { o3_offsetx = ar[++i]; continue; }
			if (ar[i] == OFFSETY) { o3_offsety = ar[++i]; continue; }
			if (ar[i] == WIDTH) { o3_width = ar[++i]; continue; }
			if (ar[i] == FIXX) { o3_fixx = ar[++i]; continue; }
			if (ar[i] == FIXY) { o3_fixy = ar[++i]; continue; }
			if (ar[i] == TIMEOUT) { o3_timeout = ar[++i]; continue; }
			if (ar[i] == DELAY) { o3_delay = ar[++i]; continue; }
			if (ar[i] == LAYER) { o3_layer = ar[++i]; continue; }
		}
	}

	//Ajout PGU pour effacer le bon layer
	AffectLayer( o3_layer );
	if (o3_delay == 0) {
		return overlib350();
	} else {
		o3_delayid = setTimeout("overlib350()", o3_delay);
		return false;
	}
}

//Ajout PGU pour cacher le bon layer
function AffectLayer( pLayer ) {
	if ( (ns4) || (ie4) || (ns6) ) {
		o3_frame = ol_frame;
		if (ns4) over = o3_frame.document.eval(pLayer);
		if (ie4) over = o3_frame.eval(pLayer).style;
		if (ns6) over = o3_frame.document.getElementById(pLayer);
	}
}

// Clears popups if appropriate
function nd(pLayer) {
		if (ns4) {
			obj = o3_frame.document.eval(pLayer);
			obj.visibility = "hide";
			}
        else if (ie4) {
			obj = o3_frame.eval(pLayer).style;
			obj.visibility = "hidden";
			}
		else if (ns6) {
			obj = o3_frame.document.getElementById(pLayer);
			obj.style.visibility = "hidden";
			}
	return true;
}

// This function decides what it is we want to display and how we want it done.
function overlib350() {
	// Make layer content
	var layerhtml;
	// Decide which kinda box.
	// Plain
	layerhtml = ol_content_simple(o3_text);
	// Write layer
	layerWrite(layerhtml);
	// When placing the layer the first time, even stickies may be moved.
	o3_allowmove = 0;
	// Initiate a timer for timeout
	if (o3_timeout > 0) {          
		if (o3_timerid > 0) clearTimeout(o3_timerid);
		o3_timerid = setTimeout("hideLayer()", o3_timeout);
	}
	// Show layer
	disp();
	o3_allowmove = 0;
	return false;
}

// Makes simple table without caption
function ol_content_simple(text) {
	txt = "<TABLE WIDTH="+o3_width+" class=\"tabbordermenu\" BORDER=0 CELLSPACING=0 CELLPADDING=1><TR><TD>" + text + "</TD></TR></TABLE>";
	if (ie4) over.backgroundImage = "none";
	if (ns6) over.style.backgroundImage = "none";
	return txt;
}

// Displays the popup
function disp() {
	if ( (ns4) || (ie4) || (ns6) ) {
		if (o3_allowmove == 0) 	{
			placeLayer();
			showObject(over);
			o3_allowmove = 1;
		}
	}
}



// Decides where we want the popup.
function placeLayer() {
	var placeX, placeY;
	// Fixed position
	placeX = o3_fixx;
	// VERTICAL PLACEMENT
	if (o3_fixy > -1) {
		// Fixed position
		placeY = o3_fixy;
	} else {
		// BELOW
		placeY = o3_y + o3_offsety;
	}

	// Actually move the object.	
	repositionTo(over, placeX, placeY);
}

// Moves the layer
function mouseMove(e) {
	if ( (ns4) || (ns6) ) {o3_x=e.pageX; o3_y=e.pageY;}
	if (ie4) {o3_x=event.x; o3_y=event.y;}
	if (ie5) {o3_x=event.x+o3_frame.document.body.scrollLeft; o3_y=event.y+o3_frame.document.body.scrollTop;}
	if (o3_allowmove == 1) {
		placeLayer();
	}
}

// The Close onMouseOver function for stickies
function cClick() {
	hideObject(over);
	return false;
}
// Writes to a layer
function layerWrite(txt) {
	txt += "\n";
        if (ns4) {
                var lyr = o3_frame.document.eval(o3_layer).document
                lyr.write(txt)
                lyr.close()
        } else if (ie4) {
		o3_frame.document.all[o3_layer].innerHTML = txt
	} else if (ns6) {
		range = o3_frame.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
	}
}

// Make an object visible
function showObject(obj) {
        if (ns4) obj.visibility = "show";
        else if (ie4) obj.visibility = "visible";
	else if (ns6) obj.style.visibility = "visible";
}

// Hides an object
function hideObject(obj) {
        if (ns4) obj.visibility = "hide";
        else if (ie4) obj.visibility = "hidden";
		else if (ns6) obj.style.visibility = "hidden";
	if (o3_timerid > 0) clearTimeout(o3_timerid);
	if (o3_delayid > 0) clearTimeout(o3_delayid);
	o3_timerid = 0;
	o3_delayid = 0;
    self.status = "";
}
//Ajout PGU pour effacer tous les layers
function hideLayer() {
		if (ns4) {
			obj = o3_frame.document.eval('overDivSChap');
			obj.visibility = "hide";
			obj = o3_frame.document.eval('overDivPage');
			obj.visibility = "hide";
			}
        else if (ie4) {
			obj = o3_frame.eval('overDivSChap').style;
			obj.visibility = "hidden";
			obj = o3_frame.eval('overDivPage').style;
			obj.visibility = "hidden";
			}
		else if (ns6) {
			obj = o3_frame.document.getElementById('overDivSChap');
			obj.style.visibility = "hidden";
			obj = o3_frame.document.getElementById('overDivPage');
			obj.style.visibility = "hidden";
			}
	if (o3_timerid > 0) clearTimeout(o3_timerid);
	if (o3_delayid > 0) clearTimeout(o3_delayid);
	o3_timerid = 0;
	o3_delayid = 0;
	self.status = "";
}
// Move a layer
function repositionTo(obj,xL,yL) {
	if ( (ns4) || (ie4) ) {
	        obj.left = xL;
	        obj.top = yL;
	} else if (ns6) {
		obj.style.left = xL + "px";
		obj.style.top = yL+ "px";
	}
}

