/* ouverture de fenêtre */
function openWindow(url, name, w, h, r, s, m, left, top) {
	popupWin = window.open(url, name, 'width=' + w + ',height=' + h + ',resizable=' + r + s + ',menubar=' + m + ',left=' + left + ',top=' + top);
}
// parameters available:
//      resizable (r),  location (l), directories (d), menubar (m)
//      status (st), toolbar (t), scrollbars (s), copyhistory (c)
/* fin de : ouverture de fenêtre */



/* swap menus 
if (document.images){
	var menu1 = new Image();
	menu1.src = "/images/index/";
	var menu1_over = new Image();
	menu1_over.src = "/images/index/";
}*/

/* pour tous les swap 
attendue : nom de l image && nom de l image par defaut (qui restera OVER) */
function swapOver(imgName, defautImgName){
	if (document.images && defautImgName != imgName){
		document.images[imgIndex].src = eval(imgName + '_over.src');
	}
}
function swapOut(imgName, defautImgName){
	if (document.images && defautImgName != imgName){
		document.images[imgIndex].src = eval(imgName + '.src');
	}
}

/*
Permit to display DHTML menu in all pages of Diagamter
*/
function show(id){
	document.getElementById(id).style.display = "block";
}
function hide(id){
	document.getElementById(id).style.display = "none";
}
function hideAll(){
	document.getElementById("dhtml_1").style.display = "none";
	document.getElementById("dhtml_2").style.display = "none";
	document.getElementById("dhtml_3").style.display = "none";
}
function time(){
	timer = setTimeout("hideAll();",1);
}
function stopTime(){
	clearTimeout(timer);
}

/*
Permit to display DHTML menu in "espaceFranchises" pages
*/
startVar = false;
function start(){
	startVar = true;
}
function showFranchises(id){
	if(startVar == true){
		document.getElementById(id).style.display = "block";
	}
}
function hideFranchises(id){
	if(startVar == true){
		document.getElementById(id).style.display = "none";
	}
}
function hideAllInFranchises(){
	if(startVar == true){
		document.getElementById("DHTML_savoir").style.display = "none";
		document.getElementById("DHTML_travailler").style.display = "none";
		document.getElementById("DHTML_communiquer").style.display = "none";
		document.getElementById("DHTML_seFormer").style.display = "none";
	}
}
function timeFranchises(){
	timerFranchises = setTimeout("hideAllInFranchises();",1);
}
function stopTimeFranchises(){
	clearTimeout(timerFranchises);
}

/*
Permit to display special row DHTML menu
*/
function showSubLinks(id){
	document.getElementById(id).style.display = "block";
}
function hideSubLinks(id){
	document.getElementById(id).style.display = "none";
}
function hideAllSubLinks(){
	document.getElementById("rowLiensSousPagesBoite").style.display = "none";
}
function timeSubLinks(){
	timerSubLinks = setTimeout("hideAllSubLinks();",1);
}
function stopTimeSubLinks(){
	clearTimeout(timerSubLinks);
}

/*///////////////////////
Open PopUp
/////////////////////////
onclick="popUp(this.href,'console',400,200);return false;"
console, fixed or elasctic
*/
var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
			newWin.close();
		}
	}
function popUp(strURL,strType,strHeight,strWidth,location){
	closeWin();
	var strOptions="";
	
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}

/* //////////////////////////////////////////
FUNCTION getElementsByClassName
Examples of how to call the function:

- To get all a elements in the document with a "info-links" class:
getElementsByClassName(document, "a", "info-links");

- To get all div elements within the element named "container", with a "col" and a "left" class:
getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]);
 ////////////////////////////////////////// */

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

/* Array support for the push method in IE 5 */
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}

/**********************************************
* Browser definition                          *
**********************************************/
var browserOK = false;
if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 && navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
	var isIE = true;
	var menutimer;
	//get IE version
	if (navigator.userAgent.toLowerCase().indexOf("msie 5.5") != -1) {
		var isIE55 = true;
		browserOK = true;
	} else if (navigator.userAgent.toLowerCase().indexOf("msie 6") != -1)  {
		var isIE6 = true;
		browserOK = true;
	} else if (navigator.userAgent.toLowerCase().indexOf("msie 7") != -1)  {
		var isIE7 = true;
		browserOK = true;
	}
	var timerdiv;
	var timerli;
	var elementdiv;
	var elementli;
} else if (navigator.userAgent.toLowerCase().indexOf('opera') != -1) {
	//not compatible for now (tried with opera 8 & 9)
	var isOp = true;
} else if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1 || 
		  (navigator.userAgent.toLowerCase().indexOf('mozilla') != -1 && (navigator.userAgent.toLowerCase().indexOf('rv:1.7') != -1 || navigator.userAgent.toLowerCase().indexOf('rv:1.8') != -1))) {
	browserOK = true;
	var isMoz = true;
}
/* Add events on object*/
if (typeof 'addEvent' != 'function') {
	function addEvent(obj, evType, fn)
	{
		if (obj.addEventListener) {
			obj.addEventListener(evType, fn, true);
			return true;
		} else if (obj.attachEvent) {
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} else {
			return false;
		}
		return true;
	}
}
/*add some events on menu for IE compatibility only*/
function startMenu() {
	if (isIE && !isIE7) {
		var menu1 = document.getElementById("principal_gauche_haut_diagnostics");
  		menu1.onmouseenter=function() {
  			this.className = "over";
    	}
  		menu1.onmouseleave=function() {
  			this.className = this.className = "";
		}
		var menu2 = document.getElementById("nousRejoindre");
  		menu2.onmouseenter=function() {
  			this.className = "over";
    	}
  		menu2.onmouseleave=function() {
  			this.className = this.className = "";
		}
		var menu3 = document.getElementById("nousConnaitre");
  		menu3.onmouseenter=function() {
  			this.className = "over";
    	}
  		menu3.onmouseleave=function() {
  			this.className = this.className = "";
		}
		var menu4 = document.getElementById("outils");
  		menu4.onmouseenter=function() {
  			this.className = "over";
    	}
  		menu4.onmouseleave=function() {
  			this.className = this.className = "";
		}
	}
}

/** 
  * Add window.onload event
  * launch some functions according to the current page
  */
addEvent(window, 'load', function(){
	startMenu();
	return true;
});