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

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function jsMenus() {
	var navi = navigator.userAgent;
	if (navi.indexOf("Opera") != -1) {
		document.getElementById('Principal').style.fontSize = "110%";
	}
	document.getElementById('EnteteMenu').className = "";

	leUL = document.getElementById('ulEnteteMenu');

	for (i=0; i<leUL.childNodes.length; i++) {
		if (leUL.childNodes[i].tagName == "LI") {
			zeLI = leUL.childNodes[i];
			if (zeLI.className == "selectedMenu") {
				if (zeLI.childNodes[3] == null) {
					monUL = zeLI.childNodes[2].childNodes[0];
					monUL.className = "widthAuto";
					if (navi.indexOf("MSIE 7") != -1) {
						leMarginLeft = zeLI.childNodes[0].offsetLeft - monUL.offsetWidth/2+zeLI.childNodes[0].offsetWidth/2;
					} else {
						leMarginLeft = (zeLI.childNodes[0].offsetLeft - monUL.offsetWidth/2+zeLI.childNodes[0].offsetWidth/2)/2;
					}
				} else {
					monUL = zeLI.childNodes[3].childNodes[1];

					if (navi.indexOf("Opera") == -1) {
						monUL.className = "widthAuto";
					} else {
						monUL.style.width = "990px";
					}
					leOffsetLeft = zeLI.childNodes[1].offsetLeft;

					if (navi.indexOf("Opera") != -1) {
						monUL.className = "widthAuto";
					}

					leMarginLeft = leOffsetLeft - monUL.offsetWidth/2+zeLI.childNodes[1].offsetWidth/2;
				}
				
				if (leMarginLeft < 0) {
					leMarginLeft = 0;
				}

				if (leMarginLeft+monUL.offsetWidth <= 960) {
					monUL.style.marginLeft = leMarginLeft+"px";
				} else {
					if (zeLI.childNodes[3] == null) {
						zeLI.childNodes[2].className = "right";
					} else {
						zeLI.childNodes[3].className = "right";
					}
					if (navi.indexOf("Opera") != -1) {
						monUL.style.marginLeft = (960 - monUL.offsetWidth)+"px";
					}
				}

				if (navi.indexOf("Opera") != -1) {
					zeLI.childNodes[3].childNodes[1].style.marginRight = (960 - leMarginLeft - zeLI.childNodes[3].childNodes[1].offsetWidth)+"px";
				}
			}
			for (z=0; z<zeLI.childNodes.length; z++) {
				if (zeLI.childNodes[z].tagName == "STRONG") {
					zeLI.childNodes[z].onclick = function truc() {
						leUL = document.getElementById('ulEnteteMenu');

						for (j=0; j<leUL.childNodes.length; j++) {
							if (leUL.childNodes[j].tagName == "LI") {
								monsieurLI = leUL.childNodes[j];
								monsieurLI.className = '';
								for (k=0; k<monsieurLI.childNodes.length; k++) {
									if (monsieurLI.childNodes[k].tagName == "DIV") {
										for (p=0; p<monsieurLI.childNodes[k].childNodes.length; p++) {
											if (monsieurLI.childNodes[k].childNodes[p].tagName == "UL") {
												monsieurLI.childNodes[k].childNodes[p].style.display = 'none';
											}
										}
									}
								}
							}
						}
						htmls = document.getElementsByTagName("HTML");

						espace = (htmls[0].offsetWidth - 960) / 2;

						this.parentNode.className = "selectedMenu";

						if (this.parentNode.childNodes[2] != null || this.parentNode.childNodes[3] != null) {
							if (this.parentNode.childNodes[2].tagName == "DIV") {
								this.parentNode.childNodes[2].childNodes[0].style.display = 'block';
								if (this.parentNode.childNodes[2].childNodes[0].offsetWidth+(this.offsetLeft-espace) < 960) {
									if (navi.indexOf("MSIE 7") != -1) {
										if ((this.offsetLeft-this.parentNode.childNodes[2].childNodes[0].offsetWidth/2+this.offsetWidth/2) >= 0.0) {
											this.parentNode.childNodes[2].childNodes[0].style.marginLeft = (this.offsetLeft-this.parentNode.childNodes[2].childNodes[0].offsetWidth/2+this.offsetWidth/2)+"px";
										}
									} else {
										if ((this.offsetLeft/2-this.parentNode.childNodes[2].childNodes[0].offsetWidth/4+this.offsetWidth/4) >= 0.0) {
											this.parentNode.childNodes[2].childNodes[0].style.marginLeft = (this.offsetLeft/2-this.parentNode.childNodes[2].childNodes[0].offsetWidth/4+this.offsetWidth/4)+"px";
										}
									}
								} else {
									this.parentNode.childNodes[2].className = "right";
								}
							} else if (this.parentNode.childNodes[3].tagName == "DIV") {
								leOffSetLeft = this.offsetLeft;
								if (leOffSetLeft-this.parentNode.childNodes[3].childNodes[1].offsetWidth/2+this.offsetWidth/2 >= 0) {
									leMarginLeft = leOffSetLeft-this.parentNode.childNodes[3].childNodes[1].offsetWidth/2+this.offsetWidth/2;
								} else {
									leMarginLeft = 0;
								}

								this.parentNode.childNodes[3].childNodes[1].style.display = 'block';
								zeLI.childNodes[1].childNodes[0].style.width = "auto !important";

								lemarginRight = 990 - leMarginLeft - this.parentNode.childNodes[3].childNodes[1].offsetWidth;

								if (this.parentNode.childNodes[3].childNodes[1].offsetWidth+(leOffSetLeft-espace) < 960) {
									if (((leOffSetLeft)-this.parentNode.childNodes[3].childNodes[1].offsetWidth/2+this.offsetWidth/2) >= 0.0) {
										this.parentNode.childNodes[3].childNodes[1].style.marginLeft = (leOffSetLeft-this.parentNode.childNodes[3].childNodes[1].offsetWidth/2+this.offsetWidth/2)+"px";
									}
									if (navi.indexOf("Opera") != -1) {
										this.parentNode.childNodes[3].childNodes[1].style.marginRight = lemarginRight+"px";
									}
								} else {
									this.parentNode.childNodes[3].className = "right";
									if (navi.indexOf("Opera") != -1) {
										this.parentNode.childNodes[3].childNodes[1].style.marginLeft = (960 - this.parentNode.childNodes[3].childNodes[1].offsetWidth)+"px";
									}
								}
							}
							return false;
						}
						return true;
					};
				}
			}
		}
	}

	if (navi.indexOf("MSIE") != -1) {
		tables = getElementsByClass('table2',null,null);

		for (i=0; i<tables.length; i++) {
			sousTables = tables[i].getElementsByTagName('table');
			for (j=0; j<sousTables.length; j++) {
				//alert(sousTables[j].parentNode.tagName+" "+sousTables[j].parentNode.offsetHeight);
				//alert(sousTables[j].offsetHeight+" "+(sousTables[j].parentNode.parentNode.offsetHeight-1));
				if (sousTables[j].offsetHeight < sousTables[j].parentNode.parentNode.offsetHeight-1) {
					sousTables[j].style.height = (sousTables[j].parentNode.parentNode.offsetHeight-1-sousTables[j].childNodes[1].childNodes[0].offsetHeight-6)+"px";
				}
			}
		}
	}
}

// Fonction pour déterminer le navigateur
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

// détermine le navigateur
var bw=new lib_bwcheck()

// Fonction pour ouvrir une fenêtre pour installer un plug in (acrobat,...)
function getacrobat() {
	var strurl = 'http://www.adobe.fr/products/acrobat/readstep.html'
	var fencommande = window.open('blank.htm','Commande','width=600,height=400,resizable,scrollbars,toolbar,menubar,status');
	fencommande.moveTo((screen.availWidth-600)/2, (screen.availHeight-400)/2);
	fencommande.document.location=strurl
	fencommande.focus(); 
}

// Fonction pour ouvrir le bon de commande dans une fenêtre
function ouvrecommande() {
	var strurl = 'commander.htm'
	var fencommande = window.open(strurl,'Commande','width=645,height=450,resizable,scrollbars,toolbar,menubar,status');
	fencommande.moveTo((screen.availWidth-645)/2, (screen.availHeight-450)/2);
	fencommande.focus(); 
}

// Fonction fenetre vers le site A2i COM Interactive
function gotoaeronaute() {
	var strurl = 'http://www.aeronaute.fr'
	var fenaiicom = window.open('blank.htm','aeronaute','width=760,height=400,resizable,scrollbars,toolbar,menubar,status');
	fenaiicom.moveTo((screen.availWidth-600)/2, (screen.availHeight-400)/2);
	fenaiicom.document.location=strurl
	fenaiicom.focus(); 
}