function favoris() {
if(navigator.appName!='Microsoft Internet Explorer'){
window.sidebar.addPanel(document.title,location.href,"");
}
else{window.external.AddFavorite(location.href,document.title);
}
}

function pageAccueil(truc) {
var leTruc = document.getElementById(truc);
leTruc.style.behavior='url(#default#homepage)';
leTruc.setHomePage('http://dassault-pr.hosting.transpac.fr/');
}

// removes whitespace-only text node children
/*function cleanWhitespace(element) {
  if (element!=null && element.hasChildNodes() ) {
	  var node = element.firstChild;
	  while (node) {
		var nextNode = node.nextSibling;
		if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
		  element.removeChild(node);
		node = nextNode;
	  }
	  return element;
  }
}*/

function popcredits(u){
	var w = window.open(u, 'Credits','width=390, height=240, left= '+((screen.width-390)/2)+', top= '+((screen.height-240)/2)+', location=no, menubar=no, resizable=0, scrollbars=0, status=no, toolbar=no, fullscreen=no');
	return false;
}

function initMenu(){
	var items = document.getElementById("menu").getElementsByTagName("LI");
	
	for(var i=0; i<items.length; i++){
		liobj = items[i];
		liobj.phrase = liobj.getElementsByTagName("SPAN")[0];
		liobj.onmouseover = function(){
			this.phrase.style.display = "block";
		}
		liobj.onmouseout = function(){
			this.phrase.style.display = "none";
		}
	}
}

function trace(s){
	document.getElementById("tracejs").innerHTML += s+"<br />";	
}

// on surveille la position de la souris
var mouse = null;
function mousePosition(e) {
	if (document.all){
		mouse = {x:event.x+document.body.scrollLeft+document.getElementById("navigation").firstChild.offsetLeft, 
				 y:event.y+document.body.scrollTop+document.getElementById("navigation").offsetTop};
	}else{
		mouse = {x:e.pageX, y:e.pageY};
	}
	
	//trace(navroot.offsetLeft);
	return mouse;
}

// renvoie les limites de l'element
function getBounds(element) {
	var left = 0; 
	var top = 0; 
	var offsetWidth = element.offsetWidth;
    var offsetHeight = element.offsetHeight;
	while (element != null) { 
	  left += element.offsetLeft; 
	  top += element.offsetTop; 
	  element = element.offsetParent; 
	} 
    return {xmin: left, ymin: top, xmax: left+offsetWidth, ymax: top+offsetHeight};
}

// renvoie vrai si l'element est en contact avec le curseur
function hitMouse(element){
	var b = getBounds(element);
	return mouse.x>b.xmin && mouse.x<b.xmax && mouse.y>b.ymin && mouse.y<b.ymax;
}

// affiche le sous-menu de l'item survolÃ©e (et masque le sous-menu de l'item prÃ©cedente)
timer=null;
function displaySubnav(s, item){

	if(hitMouse(item)){
		
		hideSubnav(currentSubnav, currentItem);
		currentItem = item;
		currentSubnav = s;
		
		if(item && item.parentNode.className!="on") 
			rolloverItem(item);
		
		if(s){
			s.style.visibility = "visible";			
			// on surveille si le curseur quitte l'item ou le sous-menu
			if(timer!=null) clearInterval(timer);
			timer = setInterval(function(){ isOnNav(s,item);}, 3000);
		}else{
			timer = setInterval(function(){ isOnNav(null,item);}, 3000);
		}
	}
}

// masque le sous menu
function hideSubnav(s, item){
	if(s) s.style.visibility = "hidden";
	if(item && item.parentNode.className!="on") 
		rolloutItem(item);
}

// teste si le curseur est toujours au dessus de l'item ou du sous-menu
function isOnNav(s,item){
	var b;
	if(s==null) b = hitMouse(item);
	else b = hitMouse(s) || hitMouse(item);
	if(!b){
		hideSubnav(s, item);
		clearInterval(timer);
	}
}

function rolloverItem(item){
	item.className = "on";
}
function rolloutItem(item){
	item.className = "";
}

currentItem = null;
currentSubnav = null;
initNav = function() {
	var isIE = (document.all && document.getElementById);
	navroot = document.getElementById("navigation").getElementsByTagName("UL").item(0);

	if (navroot!=null) {

		var items = navroot.getElementsByTagName("A");
		for(i=0; i<items.length; i++){
			aobj = items[i];
			if(aobj.parentNode.parentNode!=navroot)
				continue;
			aobj.chld = aobj.parentNode.getElementsByTagName("UL").item(0);
			aobj.onmouseover = function(){
				var subnav = this.chld;
				var temp = this;
				// on declenche l'affichage du sous-menu
				setTimeout(function(){ displaySubnav(subnav,temp); }, 500);
			}
//			aobj.onmouseout = function(){}
		}
	}
}

function getWidths(){
	var navroot = document.getElementById("navigation");
	var items = navroot.getElementsByTagName("UL");
	for(i=1; i<items.length; i++){
		l = 10;
		licol = items[i].getElementsByTagName("LI");
		for(j=0;j<licol.length;j++)
			l += parseInt(licol[j].offsetWidth) + 20;
		items[i].style.width = l + 'px';
  }
}

resetNav = function(){
	var navroot = document.getElementById("navigation");
	var items = navroot.getElementsByTagName("A");
	for(i=0; i<items.length; i++)
		items[i].className = '';
}

function initLinks(){
	
	var menu = document.getElementById("links");	
	var items = menu.getElementsByTagName("LI");
	
	for(var i=1; i<items.length; i++){
		var lio = items[i];
		if(lio.childNodes.length > 0){
			if(lio.childNodes[0].title!='')
				continue;
			lio.phrase = document.createElement("SPAN");
			lio.phrase.innerHTML = lio.childNodes[0].innerHTML;
			lio.appendChild(lio.phrase);
			lio.onmouseover = function(){
				this.phrase.style.display = "block";
			}
			lio.onmouseout = function(){
				this.phrase.style.display = "none";
			}
		}	
	}		
}

function initSubnav(){
	
	if(document.getElementById("subnav")){
		var isIE = (document.all && document.getElementById);
		var navroot = document.getElementById("subnav");
		var items = navroot.getElementsByTagName("LI");
		
		
		for(i=0; i<items.length; i++){
			items[i].onmouseover = function(){
				//resetSubnav();
				img = this.getElementsByTagName("IMG")[0];
				if(img){
					if(this.className.split("on").length<2) img.src = img.src.split("-off").join("-on");
					if(isIE) this.className += " over";
				}
			}
			items[i].onmouseout = function(){			
				img = this.getElementsByTagName("IMG")[0];
				if(img){
					if(this.className.split("on").length<2) img.src = img.src.split("-on").join("-off");
					if(isIE) this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}

resetSubnav = function(){
	var navroot = document.getElementById("subnav");
	var items = navroot.getElementsByTagName("IMG");
	for(i=0; i<items.length; i++){
		items[i].src = items[i].src.split("-on").join("-off");
	}	
}

function initPicto(){
	
	var isIE = (document.all && document.getElementById);
	var items = document.getElementsByName("picto");
	for(i=0; i<items.length; i++){
		items[i].onmouseover = function(){
			//resetPicto();
			img = this.getElementsByTagName("IMG")[0];
			if(img){
				if(this.className.split("on").length<2) img.src = img.src.split("-off").join("-on");
				if(isIE) this.className += " over";
			}
		}
		items[i].onmouseout = function(){			
			img = this.getElementsByTagName("IMG")[0];
			if(img){
				if(this.className.split("on").length<2) img.src = img.src.split("-on").join("-off");
				if(isIE) this.className = this.className.replace(" over", "");
			}
		}
	}
}

resetPicto = function(){
	var items = document.getElementsByName("picto");
	for(i=0; i<items.length; i++){
		items[i].src = items[i].src.split("-on").join("-off");
	}	
}

function onglet(ident){
	
	var img1 = document.getElementById("onglet1").firstChild;
	img1.src = img1.src.split("-on").join("-off");
	var img2 = document.getElementById("onglet2").firstChild;
	img2.src = img2.src.split("-on").join("-off");
	var img5 = document.getElementById("onglet5").firstChild;
	img5.src = img5.src.split("-on").join("-off");
	var img3 = document.getElementById("onglet3").firstChild;
	img3.src = img3.src.split("-on").join("-off");
	var img4 = document.getElementById("onglet4").firstChild;
	img4.src = img4.src.split("-on").join("-off");

	
	
	if(ident==1){
		document.getElementById("site1").style.display="block";
		document.getElementById("site2").style.display="none";
		document.getElementById("site5").style.display="none";
		document.getElementById("site3").style.display="none";
		document.getElementById("site4").style.display="none";
		
		img1.src = img1.src.split("-off").join("-on");
		img2.src = img2.src.split("-1").join("");
		img2.src = img2.src.split("-off-1").join("-off");
		img3.src = img3.src.split("-1").join("");
		img3.src = img3.src.split("-off-1").join("-off");
		img4.src = img4.src.split("-1").join("");
		img4.src = img4.src.split("-off-1").join("-off");
		img5.src = img5.src.split("-1").join("");
		img5.src = img5.src.split("-off-1").join("-off");
								
	}
	else if(ident==2){
		document.getElementById("site1").style.display="none";
		document.getElementById("site2").style.display="block";
		document.getElementById("site5").style.display="none";
		document.getElementById("site3").style.display="none";
		document.getElementById("site4").style.display="none";
		
		img2.src = img2.src.split("-1").join("");
		img2.src = img2.src.split("-off").join("-on");
		img3.src = img3.src.split("-1").join("");
		img3.src = img3.src.split("-off-1").join("-off");
		img4.src = img4.src.split("-1").join("");
		img4.src = img4.src.split("-off-1").join("-off");
		img5.src = img5.src.split("-1").join("");
		img5.src = img5.src.split("-off").join("-off-1");
	}
	else if(ident==5){
		document.getElementById("site1").style.display="none";
		document.getElementById("site2").style.display="none";
		document.getElementById("site5").style.display="block";
		document.getElementById("site3").style.display="none";
		document.getElementById("site4").style.display="none";
		
		img5.src = img5.src.split("-1").join("");
		img5.src = img5.src.split("-off").join("-on");		
		img2.src = img2.src.split("-1").join("");
		img2.src = img2.src.split("-off").join("-off-1");
		img3.src = img3.src.split("-1").join("");
		img3.src = img3.src.split("-off").join("-off-1");
		img4.src = img4.src.split("-1").join("");
		img4.src = img4.src.split("-off").join("-off");
	}
	else if(ident==3){
		document.getElementById("site1").style.display="none";
		document.getElementById("site2").style.display="none";
		document.getElementById("site5").style.display="none";
		document.getElementById("site3").style.display="block";
		document.getElementById("site4").style.display="none";
		
		img2.src = img2.src.split("-1").join("");
		img2.src = img2.src.split("-off").join("-off-1");
		img3.src = img3.src.split("-1").join("");
		img3.src = img3.src.split("-off").join("-on");
		img4.src = img4.src.split("-1").join("");
		img4.src = img4.src.split("-off").join("-off-1");
		
		img5.src = img5.src.split("-1").join("");
		img5.src = img5.src.split("-off").join("-off");
		
	}
	else if(ident==4){
		document.getElementById("site1").style.display="none";
		document.getElementById("site2").style.display="none";
		document.getElementById("site5").style.display="none";
		document.getElementById("site3").style.display="none";
		document.getElementById("site4").style.display="block";
		
		img2.src = img2.src.split("-1").join("");
		img2.src = img2.src.split("-off").join("-off-1");		
		img3.src = img3.src.split("-1").join("");
		img3.src = img3.src.split("-off-1").join("-off");
		img4.src = img4.src.split("-1").join("");
		img4.src = img4.src.split("-off").join("-on");
		img5.src = img5.src.split("-1").join("");
		img5.src = img5.src.split("-off-1").join("-off");
				
	}
	return false;
}

function toggleQuestion_FAQ(num){
	var question = document.getElementById("question"+num);
	var titres = document.getElementById("questions").getElementsByTagName("H4");
	var lien = titres[num-1].firstChild;
	
	if(question.style.display=="block"){
		lien.className = "";
		question.style.display="none";
	}else{
		lien.className = "on";
		question.style.display="block";
	}	
}

function toggleQuestion(num){
	var question = document.getElementById("question"+num);
	var titres = document.getElementById("questions").getElementsByTagName("H5");
	var lien = titres[num-1].firstChild;
	
	if(question.style.display=="block"){
		lien.className = "";
		question.style.display="none";
	}else{
		lien.className = "on";
		question.style.display="block";
	}	
}

var orig;
orig = 10;
	
function setFont(sz)	{
	
	var sz;
	if (!document.all && !document.getElementById)
		return;
	//alert("orig = " + orig + " sz = " + sz);
	if (    ( orig <=20 || sz <= 0)  
		 && ( orig >=10  || sz >= 0)  ) {
		orig+=sz;
		if ( orig != 16 ) {
			window.document.body.style.fontSize=orig+'px';
			var sit = document.getElementsByTagName("P");
			sizeTag(sit);
		}
	}
}

function sizeTag(elem) {
	var elem;
	for (x=0;x<elem.length;x++) {
		elem.item(x).style.fontSize=orig+'px';
	}
}

window.onload = function(){
	initMenu();
	initNav();
	initLinks();
	initSubnav();
	initPicto();
	//getWidths();
	
	// !!! pour IE, le calcul de la position de la souris se base sur le premier enfant du bloc navigation
	// on supprime donc les espaces blancs pour calculer la position Ã  partir de navigation.firstChild
	// -> voir mousePosition pour le calcul de la position
//	cleanWhitespace(document.getElementById("navigation"));
	
	document.onmousemove = mousePosition;
}

/* candidature */
var lastH = 0;

function cand_adjust_H(){
ifobj = document.getElementById("candinsert");
if(ifobj.contentDocument)
 h = parseInt(ifobj.contentDocument.body.offsetHeight);
else if(ifobj.Document)
 h = parseInt(ifobj.Document.body.clientHeight);
if((h==0)||(h!=lastH)){
 lastH = h;
 window.setTimeout("cand_adjust_H()", 10);
 return;
}
document.getElementById("candinsert").style.height = h + 'px';
}

function check_prtfunc(){
 if(parent.cand_adjust_H)
  parent.cand_adjust_H();
 else
 	window.setTimeout("check_prtfunc()", 10);
}
