// JavaScript Document (site nucleaire.cea.fr)
// -------------------------------------------
// Ouverture PopUp
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Images
function swap_m(img_name,to_what) { 
		var swap, towhat;
		var arbo = "";
		var count=0;
		var urli = window.location.pathname;
		urlipos = urli.indexOf("CCRT");
		urli = urli.substring(urlipos,urli.length);
		for (var i=0; i<urli.length; i++){
			if (urli.charAt(i)=="/") count ++;
		}
		if (count==0){
			for (i=1; i<urli.length; i++){
				if (urli.charAt(i)=="\\") count ++;
			}
		}
		for (var j = 1; j<count;j++) arbo += "../";
		if (arbo=="") arbo = "./";

		swap	= eval('document.images.'+img_name);
		towhat=arbo+'fr/_img/'+to_what+'.gif';
		swap.src	= towhat;
}

function swap_me(img_name,img_src,nochange) // Image des menus de gauche
{
	swap = eval('document.images.'+img_name);
	noext = ((img_src.length)-5);
	state = img_src.substr(noext,1)
	if ((state!=1))
	{
		noext2 = ((img_src.length)-4);
		src_trim = img_src.substring(0,noext2)
		swap.src=src_trim+"1.gif";
	}
	if ((state==1)&&(nochange==''))
	{
		noext2 = ((img_src.length)-5);
		src_trim = img_src.substring(0,noext2)
		swap.src=src_trim+".gif";
	}
}

function divmenu(divID,divHeight)
{
	if (theDoc.getElementById(divID).style.display!="")
	{
		for (i=1;i<(menunbr+1);i++)
		{
			eval ("document.getElementById('menu_div_"+i+"').style.display='none';");
		}
		theDoc.getElementById(divID).style.display="";

		if (navigator.platform.indexOf("Mac") != 0)
		{
			theDoc.getElementById(divID).style.height="0";
			speed = ((divHeight/12.5)+8);
			open_it(divHeight,divID,speed)
		}
	}
   else
   {
	theDoc.getElementById(divID).style.display="none";
   }
}

function open_it(max,name,hm)
{
	if (hm<0) return;
	maxi = max;
	divname = name;
	act = theDoc.getElementById(divname).style.height;
	act2 = parseInt(act);

	if (act2>=maxi) { clearTimeout(tempoO); theDoc.getElementById(divname).style.height=maxi+"px"; return; };

	y = ((act2-1)+hm);
	hr = hm-1;
	theDoc.getElementById(divname).style.height=y+"px";
	tempoO = setTimeout('open_it(maxi,divname,hr)', 30);
}


/*
 *
 * Bar de navigation dossiers et autres
 *
 */


function standardizeEvent(evt) {
	if (!evt.stopPropagation) { evt.stopPropagation = function(){this.cancelBubble = true;} }
	if (!evt.prevtDefault) { evt.prevtDefault   = function(){this.returnValue = true;} }
	if (typeof evt.layerX == 'undefined' && typeof evt.offsetX == 'number') {
		evt.layerX = evt.offsetX
		evt.layerY = evt.offsetY
	}
	if(!evt.pageX) {
		evt.pageX = event.x + document.body.scrollLeft;
		evt.pageY = event.y + document.body.scrollTop;
	}
	if (!evt.target && evt.srcElement) {
		evt.target = evt.srcElement;
		if (evt.toElement && evt.type.indexOf('mouseout')>-1) {
			evt.relatedTarget = evt.toElement;
		} else if (evt.fromElement && evt.type.indexOf('mouseover')>-1) {
			evt.relatedTarget = evt.fromElement;
		} else {
			evt.relatedTarget = evt.target;
		}
	}
	return evt;
}

function showNavContent(evt,divId,direction) {
	globalSousDossNavId = divId;
	var oDiv = document.getElementById(divId);
	var oDivHider = document.getElementById('divHIDEMENUDOSSIER');
	var oImgHIDERSURFACE = oDivHider.childNodes[0];

	if( !globalSousDossNavDirection ) globalSousDossNavDirection = direction;
	if( globalSousDossNavDirection != direction ) hideNavContent(evt,oDivHider.id);

	var nevt = standardizeEvent(evt);
	var offsetLeft = 20;
	oDiv.style.display = 'block';
	var offsetTop = oDiv.clientHeight;
	var posX, posY;
	if('number' == typeof nevt.target.x) {
		posX = nevt.target.x;
		posY = nevt.target.y;
		offsetLeft -= 40;
		offsetTop += 1;
	} else {
		posY = nevt.pageY-nevt.layerY;
		posX = nevt.pageX-nevt.layerX;
		if(0>navigator.userAgent.toLowerCase().indexOf('opera')) {
			offsetLeft -= 38;
			offsetTop += 3;
		} else {
			offsetLeft -= 40;
			offsetTop  += 1;
		}
	}
	if('bottom'==direction.toLowerCase()) { posY  += 16; }

	oDivHider.style.width  = (parseInt(oDiv.style.width)+40)+'px';
	oDivHider.style.height = (oDiv.clientHeight+20+40)+'px';
	oDivHider.style.left   = (posX-offsetLeft-20)+'px';
	oDivHider.style.top    =  (posY-('top'==direction.toLowerCase()?offsetTop:0)-20-('bottom'==direction.toLowerCase()?20:0))+'px';
	oImgHIDERSURFACE.style.width  = oDivHider.style.width;
	oImgHIDERSURFACE.style.height = oDivHider.style.height;

	oDiv.style.left = posX-offsetLeft+'px';
	oDiv.style.top = posY-('top'==direction.toLowerCase()?offsetTop:0)+'px';
	globalSousDossNav = true;
	globalSousDossNavDirection = direction;

	globalLastWidth = document.body.scrollWidth;
	globalIntvWindowResizeWatch = setInterval('windowResizeWatch()',500);
	return;
}

function hideNavContent(evt,oDivId) {
	var nevt = standardizeEvent(evt);
	var hiderWidth = parseInt(nevt.target.style.width);
	var hiderHeight = parseInt(nevt.target.style.height);

	if( nevt.layerY > hiderHeight-50 && nevt.layerY < hiderHeight-20 ) {
		return;
	} else {
		if( nevt.layerY < 20 || nevt.layerY > (hiderHeight-20) || nevt.layerX < 20 || nevt.layerX > (hiderWidth-20) ) {
			document.getElementById(globalSousDossNavId).style.display = 'none';
			document.getElementById(oDivId).style.display='none';
			clearInterval(globalIntvWindowResizeWatch);
			globalSousDossNav=false;
		}
	}
	return;
}


function activateDivHider() {
	var oDivHider = document.getElementById('divHIDEMENUDOSSIER');
	if( oDivHider && 'div' == oDivHider.tagName.toLowerCase() ) {
		oDivHider.style.display = 'block';
	}
}


function handleLeaveDocument(evt) {
	var nevt = standardizeEvent(evt);
	alert(nevt.relatedTarget+' '+nevt.target);
}

function windowResizeWatch() {
	globalCurrentWidth = document.body.scrollWidth;
	if( globalSousDossNav && globalLastWidth!=globalCurrentWidth ) {
		document.getElementById(globalSousDossNavId).style.display = 'none';
		document.getElementById('divHIDEMENUDOSSIER').style.display='none';
		globalSousDossNav=false;
	}
}
var globalSousDossNav;
var globalSousDossNavId;
var globalSousDossNavDirection;

var IntvWindowResizeWatch;
var globalLastWidth;
var globalCurrentWidth;

// Ajout du 12/11/2007 pour eviter le SPAM des BALs
// Auteur jeanohnet@free.fr
function mail_ccrt(user)
{
	site = "cea.fr";
	document.write('<a href=\"mailto:' + user + '@' + site + '\">');
	//document.write('mailto:' + user + '@' + site);
	//return;
}
function mail_ccrt2(user)
{
	site = "cea.fr";
	document.write('<a href=\"mailto:' + user + '@' + site + '\" class=\"outils\">');
	//document.write('mailto:' + user + '@' + site);
	//return;
}