function addMyEvent(element, eventName, functionName, propagation){ 
	if (element.addEventListener) { 
		element.addEventListener(eventName, functionName, propagation); 
	} else if (element.attachEvent) { 
		element.attachEvent('on' + eventName, functionName); 
	} 
} 
function delMyEvent(element, eventName, functionName, propagation){ 
  if (element.addEventListener) { 
    element.removeEventListener(eventName, functionName, propagation); 
  } else if (element.attachEvent) { 
    element.detachEvent('on' + eventName, functionName); 
  } 
}
function GetWindowHeight(){ 
   	var heightWindow = 0;
   	if(typeof(window.innerHeight)=='number'){
		heightWindow = window.innerHeight;
	} 
	else if(document.documentElement && document.documentElement.clientHeight){
		heightWindow = document.documentElement.clientHeight;
	}	
	return heightWindow;
}
function GetWindowWidth(){ 
   	var widthWindow = 0;
   	if(typeof(window.innerWidth)=='number'){
		widthWindow = window.innerWidth;
	} 
	else if(document.documentElement && document.documentElement.clientWidth){
		widthWindow = document.documentElement.clientWidth;
	}	
	return widthWindow;
}
function GetHeight(div){ 
   	var heightDiv = 0;
   	var obj = document.getElementById(div); 	
   	if(obj.offsetHeight){
		heightDiv=obj.offsetHeight;
	}
	else if(obj.style.pixelHeight){
		heightDiv=obj.style.pixelHeight;
	}
	return heightDiv;
}
function GetWidth(div){ 
   	var widthDiv = 0;
   	var obj = document.getElementById(div); 	
   	if(obj.offsetWidth){
		widthDiv=obj.offsetWidth;
	}
	else if(obj.style.pixelWidth){
		widthDiv=obj.style.pixelWidth;
	}
	return widthDiv;
}

function ScrollBarResize(thumb,bar){
	var DivBar = document.getElementById(bar);
	var HeightThumb = GetHeight(thumb);
	if(HeightThumb < 20){HeightThumb = 25;}
	DivBar.style.height = HeightThumb - 20 + "px";
}
function getbarH(divContent){
	var Hc = GetHeight(divContent);
	return Hc;
	//alert(Hc);
}
function resizeScroll(scroll, scrollname, ref, width){
		var flecheW = 14;
		var flecheH = 19;
		var barW = 14;
		var middleTop = 19;
		var middleW = width; //Largeur du bloc **A modifier**
		var allBarH = getbarH(ref) - 19;
		if(allBarH < 19){allBarH = 50;}
		scroll.divs[0] = new ScrDiv(scrollname+'Outer', '0', middleTop, middleW, allBarH, 2, getRef(ref));
		scroll.divs[1] = new ScrDiv(scrollname+'Bar', middleW-barW+1, flecheH+15, barW, allBarH-30, 1, getRef(ref));
		scroll.divs[2] = new ScrDiv(scrollname+'Thumb', middleW-barW+2, '', barW-2, '', 1, getRef(ref));
		scroll.divs[3] = new ScrDiv(scrollname+'UpArrows', middleW-barW+1, middleTop, flecheW, flecheH, 1, getRef(ref));
		scroll.divs[4] = new ScrDiv(scrollname+'DownArrows', middleW-barW+1, allBarH, flecheW, flecheH, 1, getRef(ref));
}
function resizeScroll2(scroll, scrollname, ref, width){
		var flecheW = 14;
		var flecheH = 19;
		var barW = 14;
		var middleTop = 0;
		var middleW = width; //Largeur du bloc **A modifier**
		var allBarH = getbarH(ref);
		if(allBarH < 19){allBarH = 50;}
		scroll.divs[0] = new ScrDiv(scrollname+'Outer', '0', middleTop, middleW, allBarH, 2, getRef(ref));
		scroll.divs[1] = new ScrDiv(scrollname+'Bar', middleW-barW+1, flecheH-4, barW, allBarH-30, 1, getRef(ref));
		scroll.divs[2] = new ScrDiv(scrollname+'Thumb', middleW-barW+2, '', barW-2, '', 1, getRef(ref));
		scroll.divs[3] = new ScrDiv(scrollname+'UpArrows', middleW-barW+1, middleTop, flecheW, flecheH, 1, getRef(ref));
		scroll.divs[4] = new ScrDiv(scrollname+'DownArrows', middleW-barW+1, allBarH-19, flecheW, flecheH, 1, getRef(ref));
		//scroll.page.minH = 180;
}
function updateScroll(){
	document.write = new Function();
 	if (scrOL) scrOL();
 	for (var s in DSL) DSL[s].setup();
}

function updateOneScroll(myScroll){
	//var DSL = DHTMLScroller.list[myScroll.myName];
	document.write = new Function();
	if (scrOL) scrOL();
		//for (var s in DSL) DSL[s].setup();	
		myScroll.setup();
}
function getlineQty(){
	var HTop = 65; //Hauteur du top + bordure
	var cont1 = document.getElementById('cont1');
	//var cont2 = document.getElementById('cont2');
	var windowH = GetWindowHeight();
	var ZoneH = GetHeight('EZoneConteneur');
	var HcontentDispo = ZoneH - HTop;
	var HcontentReste = HcontentDispo - 19;
	if(cont1){
		var applikcontent1 = document.getElementById('applikcontent1');
		var Happlikcontent1 = GetHeight('applikcontent1');
		HcontentReste = HcontentReste - Happlikcontent1;
		//if (cont2.tagName=="TABLE"){
		//	var tableRawQty = Math.floor(HcontentReste / 18);
		//	return tableRawQty;
		//}
	}
	var tableRawQty = Math.floor(HcontentReste / 18.1);
	return tableRawQty;
}

function refreshSize(){
	resizeScroll(middle, 'middle', 'cadre2content', 200);
	resizeScroll(scroller3, 'scroller3', 'cadre3content', 200);
	resizeScroll(scroller4, 'scroller4', 'applikcontent1', GetWidth('Econtent')-1);
	updateScroll();
}
/*
function swapColBack(elemBack,color,except){	
	if(elemBack.className != except){
		elemBack.style.backgroundColor=color;
	}
}
function swapColText(elemText,color,except){
	if(elemText.className != except){
		elemText.style.color=color;
	}
}*/
function clearTdClass(ref){
	var divRef = document.getElementById(ref);
	var tagTd = divRef.getElementsByTagName("td");
	for (var i = 0; i < tagTd.length; i++) {
		tagTd[i].className = 'none';
	}
}
function activeCell(elem,ref,except){
	clearTdClass(ref);
	elem.className = except;
}
function overCell(elem,classe,except){
	if(elem.className != except){
		elem.className=classe;
	}
}
function outCell(elem,except){
	if(elem.className != except){
		elem.className='none';
	}
}

function closeDiv(x) {
	var element = document.getElementById(x);
	element.parentNode.removeChild(element);
}
function hideDiv(x) {
	var Div = document.getElementById(x);
	Div.style.display = 'none';
}
function closeForm(x,ref) {
	var element = document.getElementById(x);
	element.parentNode.removeChild(element);
	var refelement = document.getElementById(ref);
	refelement.style.height = "0px";
	refelement.style.display = 'none';
}

function setclass(divform, classform) {
	var Div = document.getElementById(divform);
	Div.setAttribute('class',classform);
	Div.setAttribute('className',classform);
}
function setclass2(elem, classform) {
	elem.setAttribute('class',classform);
	elem.setAttribute('className',classform);
}

/********************
Applik Menu Vers.062010
@2010 Intercap
********************/
var menuClick = 'off';
var menuColor = '#BCBCBC';
var menuColorOver = '#000000';
var menuColorBack = '#57BEEC';

function resetColor(){
	var divapplikmenu = document.getElementById('applikm');	
	if (divapplikmenu){
		var tagLi = divapplikmenu.getElementsByTagName("li"); 
		for (var i = 0; i < tagLi.length; i++) { 
			tagLi[i].style.color = menuColor;
			tagLi[i].style.backgroundColor = 'transparent';
		}
	}
}

function fixColor(div, color, colorBack){
	resetColor();	
	if (menuClick == 'off'){
		div.style.color = color;
		div.style.backgroundColor = colorBack;
	}else{
		div.style.color = menuColorOver;
		div.style.backgroundColor = menuColorBack;
	}
}

function displayLayout(etat, layoutName, posTop, posLeft){
	var layout = document.getElementById(layoutName);
	if (layout){
		if (menuClick == 'on'){
			if(etat == 'over'){
				closeLayout();
				layout.style.display = 'inline';
				layout.style.top = posTop + 'px';
				layout.style.left = posLeft + 'px';
				layout.onmouseover = function(){ this.style.display = 'inline' };	
			}
			if(etat == 'down'){
				closeLayout();
				resetColor();
			}
			if(etat == 'up'){
				menuClick = 'off';	
			}
		}else{
			if(etat == 'over'){
				layout.style.display = 'none';
			}
			if(etat == 'down'){
				layout.style.display = 'inline';
				layout.style.top = posTop + 'px';
				layout.style.left = posLeft + 'px';
			}
			if(etat == 'up'){
				menuClick = 'on';
			}
		}
	}else{
		if(menuClick == 'on'){
			closeLayout();
		}
	}
}

function closeLayout(){
	var divapplikmlayout = document.getElementById('applikmlayout');
	var tagLayout = divapplikmlayout.getElementsByTagName("div");
	for (var i = 0; i < tagLayout.length; i++){ 
		tagLayout[i].style.display = 'none';
	}
}

function closeMenu(event){
	var divM = event.target || event.srcElement;
	while(divM.tagName != 'DIV'){	
		if(divM.parentNode == null){
			break;
		}else{
			divM = divM.parentNode;
		} 
	}
	var divMclass = divM.getAttribute('class');
	if(divMclass != 'applikm'){
		closeLayout();
		menuClick = 'off';	
		resetColor();	
	}
}
function applikmenu(){
	addMyEvent(document.getElementById('EZoneConteneur'), 'mouseup', closeMenu, false);
	addMyEvent(document, 'DOMMouseScroll', selectOff, false);
	//document.onmousedown = closeMenu;
	var divapplikmenu = document.getElementById('applikm');
	if (divapplikmenu){
		var tagLi = divapplikmenu.getElementsByTagName("li"); 
		var menuTop = divapplikmenu.offsetTop;
		var menuLeft = divapplikmenu.offsetLeft;
		var menuH = divapplikmenu.offsetHeight;
		for (var i = 0; i < tagLi.length; i++) { 
			tagLi[i].onmouseover = function(){  
				fixColor(this, menuColorOver, menuColorBack); 
				displayLayout('over', this.innerHTML, this.offsetTop+menuTop+menuH, this.offsetLeft+menuLeft) 
			};  
  			tagLi[i].onmousedown = function(){
  				if(menuClick == 'on'){ fixColor(this, menuColor, 'transparent') } else { fixColor(this, menuColorOver, menuColorBack) } 
  				displayLayout('down', this.innerHTML, this.offsetTop+menuTop+menuH, this.offsetLeft+menuLeft) 
  			};
  			tagLi[i].onmouseout = function(){
  				fixColor(this, menuColor, 'transparent');
  			};
  			tagLi[i].onmouseup = function(){				
  				displayLayout('up', this.innerHTML, this.offsetTop+menuTop+menuH, this.offsetLeft+menuLeft);				
  			};  	
		}		
	}
}

function setWindow3(nCadre, IdCadreFix1, IdCadreFix2){
	var HTop = 65; //Hauteur du top + bordure
	var MinHeight = 366; //Hauteur minimum visible
	var MinWidth = 600; //Largeur minimum visible
	var DivMenuGauche = document.getElementById('Emenugauche');
	var DivContent = document.getElementById('Econtent');
	var DivZone =  document.getElementById('EZoneConteneur');
	var DivResult = document.getElementById('cont2');
	var DivTopZone = document.getElementById('ETopZone');
	var windowH = GetWindowHeight();
	var windowW = GetWindowWidth();
	var menuGaucheW = GetWidth('Emenugauche');
	var menuGaucheH = GetHeight('Emenugauche');
	var ZoneH = GetHeight('EZoneConteneur');
	var ZoneW = GetWidth('EZoneConteneur');
	var ContentW = GetWidth('Econtent');
	var HauteurMenu = 0;
	var HmenuDispo = windowH - HTop;
	
	if (windowH>MinHeight){ //La hauteur de la fenêtre est superieur à la taille mini
		
		DivMenuGauche.style.height = windowH - HTop +"px";
		DivContent.style.height = windowH - HTop +"px";
		if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
			DivTopZone.style.width = windowW + "px";
			DivContent.style.width = windowW - menuGaucheW + "px";
		}else{
			DivTopZone.style.width = MinWidth + "px";
			DivContent.style.width = MinWidth - menuGaucheW + "px";
		}
		//Il y a une Table dans le Content
		if (DivResult){
			var ResultW = GetWidth('cont2');
			if(ResultW > windowW){//La largeur de la table est plus grande que la fenêtre
				DivContent.style.width = ResultW +"px";
				DivTopZone.style.width = ResultW + menuGaucheW + "px";
				DivContent.style.height = ZoneH - HTop +"px";
				DivMenuGauche.style.height = ZoneH - HTop +"px";
				/*if(HauteurMenu+HTop>windowH){//La hauteur du menu est plus grande que la hauteur de la fenêtre
					DivMenuGauche.style.height = HauteurMenu+"px";
					DivContent.style.height = HauteurMenu +"px";
				}*/ //enlevé le 19-07-2010
				HmenuDispo = ZoneH - HTop;
				//refreshSize();				
			}else{//La largeur de la table est plus petite que la fenêtre
				if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
					DivTopZone.style.width = windowW + "px";
					DivContent.style.width = windowW - menuGaucheW + "px";
				}else{
					DivTopZone.style.width = MinWidth + "px";
					DivContent.style.width = MinWidth - menuGaucheW + "px";
				}
				DivMenuGauche.style.height = windowH - HTop +"px";
				DivContent.style.height = windowH - HTop +"px";
				if(HauteurMenu+HTop>windowH){//La hauteur du menu est plus grande que la hauteur de la fenêtre
					DivMenuGauche.style.height = HauteurMenu+"px";
					DivContent.style.height = HauteurMenu +"px";
					if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
						DivTopZone.style.width = ZoneW + "px";
						DivContent.style.width = ZoneW - menuGaucheW + "px";
					}else{
						DivTopZone.style.width = MinWidth + "px";
						DivContent.style.width = MinWidth - menuGaucheW + "px";
					}
				}
			}
		}else{
		//Il n'y a pas de Table dans le Content
			if(HauteurMenu+HTop>windowH){//La hauteur du menu est plus grande que la hauteur de la fenêtre
				DivMenuGauche.style.height = HauteurMenu+"px";
				DivContent.style.height = HauteurMenu +"px";
				if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
					DivTopZone.style.width = ZoneW + "px";
					DivContent.style.width = ZoneW - menuGaucheW + "px";
				}else{
					DivTopZone.style.width = MinWidth + "px";
					DivContent.style.width = MinWidth - menuGaucheW + "px";
				}
			}
		}
		
	}else{ //La hauteur de la fenêtre est INFERIEUR à la taille mini
		DivMenuGauche.style.height = MinHeight - HTop+"px";
		DivMenuGauche.style.minheight = MinHeight - HTop+"px";
		DivContent.style.height = MinHeight - HTop +"px";
		DivContent.style.minHeight = MinHeight - HTop +"px";
		
		if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
			DivTopZone.style.width = windowW + "px";
			DivContent.style.width = windowW - menuGaucheW + "px";
		}else{
			DivTopZone.style.width = MinWidth + "px";
			DivContent.style.width = MinWidth - menuGaucheW + "px";
		}

		if (DivResult){
			var ResultW = GetWidth('cont2');
			if(ResultW > windowW){//La largeur de la table est plus grande que la fenêtre
				DivContent.style.width = ResultW +"px";
				DivTopZone.style.width = ResultW + menuGaucheW + "px";
				DivContent.style.height = MinHeight - HTop +"px";
				DivMenuGauche.style.height = MinHeight - HTop +"px";
				if(HauteurMenu+HTop>windowH){//La hauteur du menu est plus grande que la hauteur de la fenêtre
					DivMenuGauche.style.height = HauteurMenu+"px";
					DivContent.style.height = HauteurMenu +"px";
				}
				HmenuDispo = ZoneH - HTop;
				//refreshSize();
			}else{//La largeur de la table est plus petite que la fenêtre
				if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
					DivTopZone.style.width = windowW + "px";
					DivContent.style.width = windowW - menuGaucheW + "px";
				}else{
					DivTopZone.style.width = MinWidth + "px";
					DivContent.style.width = MinWidth - menuGaucheW + "px";
				}
				DivMenuGauche.style.height = MinHeight - HTop +"px";
				DivContent.style.height = MinHeight - HTop +"px";
				if(HauteurMenu+HTop>windowH){//La hauteur du menu est plus grande que la hauteur de la fenêtre
					DivMenuGauche.style.height = HauteurMenu+"px";
					DivContent.style.height = HauteurMenu +"px";
					if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
						DivTopZone.style.width = ZoneW + "px";
						DivContent.style.width = ZoneW - menuGaucheW + "px";
					}else{
						DivTopZone.style.width = MinWidth + "px";
						DivContent.style.width = MinWidth - menuGaucheW + "px";
					}
				}
			}
		}else{
		//Il n'y a pas de Table dans le Content
			if(HauteurMenu+HTop>windowH){//La hauteur du menu est plus grande que la hauteur de la fenêtre
				DivMenuGauche.style.height = HauteurMenu+"px";
				DivContent.style.height = HauteurMenu +"px";
				if (windowW>MinWidth){//Verification largeur de la fenêtre / minimum
					DivTopZone.style.width = ZoneW + "px";
					DivContent.style.width = ZoneW - menuGaucheW + "px";
				}else{
					DivTopZone.style.width = MinWidth + "px";
					DivContent.style.width = MinWidth - menuGaucheW + "px";
				}
			}
		}
	}

	var HCadreFix1 = 0;
	var HCadreFix2 = 0;
	var nCadreFlex = nCadre;
	//alert(nCadreFlex);
	if(IdCadreFix1 != null ){
		HCadreFix1 = GetHeight(IdCadreFix1);
		HmenuDispo = HmenuDispo - HCadreFix1;
		nCadreFlex = nCadreFlex - 1;
	}
	if(IdCadreFix2 != null ){
		HCadreFix2 = GetHeight(IdCadreFix2);
		HmenuDispo = HmenuDispo - HCadreFix2;
		nCadreFlex = nCadreFlex - 1;
	}
	//alert(nCadreFlex);
	if (nCadreFlex > 0){
		var hCadreFlex = Math.floor(HmenuDispo / nCadreFlex);
		//alert(HmenuDispo);
		//alert(hCadreFlex);
		for (i=1; i<=nCadre; i++){			
			if (IdCadreFix1 != 'cadre'+i && IdCadreFix2 != 'cadre'+i){
				var cadre = document.getElementById('cadre'+i);
				if(i == nCadre){
					cadre.style.height = HmenuDispo + "px";				
				}else{
					cadre.style.height = hCadreFlex + "px";
					HmenuDispo = HmenuDispo - hCadreFlex;
				}
				
			}
			//HauteurMenu = HauteurMenu + GetHeight('cadre'+i);
		}
	}
	
	var cont1 = document.getElementById('cont1');
	var cont2 = DivResult;
	var applikcontent1 = document.getElementById('applikcontent1');
	var applikcontent2 = document.getElementById('applikcontent2');
	var HcontentDispo = windowH - HTop;
	var HcontentReste = HcontentDispo;
	var line = document.getElementById('line');
	if(cont1){
		applikcontent1.style.display = 'inline';
		var Hcont1 = GetHeight('cont1');
		//alert(Hcont1);
		var Hcontentmoit = Math.floor(HcontentDispo / 1.3);
		if(Hcont1>Hcontentmoit-19){
			applikcontent1.style.height = Hcontentmoit + "px";	
			line.style.display = 'inline';
			applikcontent1.style.marginBottom = "1px";
			HcontentReste = HcontentDispo - Hcontentmoit;
		}else{
			applikcontent1.style.height = Hcont1+ 19 + "px";
			applikcontent1.style.marginBottom = "0px";
			line.style.display = 'none';
			HcontentReste = HcontentDispo - Hcont1+19;
		}
	}else{
		applikcontent1.style.height = "0px";
		applikcontent1.style.display = 'none';
	}
	//if(cont2){
		//var Hcont2 = GetHeight('cont2');
		//if (cont2.tagName=="TABLE"){
			//alert(GetHeight('applikcontent2'));
			//reloadDatabz('table');
		//}
	//}
	
	//alert(GetWidth('applikcontent1'));
	//alert(windowW);
}