//Permet d'appliquer hauteur du contenu sur composants d'ergo
function myInit(parentID, diffHeight) {  
  // Redef var zones si modif contenu ajax
  switch (parentID) {
    case 'wuHeaderExt' : heightHeaderExt = Math.round(heightHeaderExt + diffHeight); document.getElementById(parentID).style.height = heightHeaderExt+"px"; break;
    case 'wuFooterExt' : heightFooterExt = Math.round(heightFooterExt + diffHeight); document.getElementById(parentID).style.height = heightFooterExt+"px"; break;
    case 'wuHeaderInt' : heightHeaderInt = Math.round(heightHeaderInt + diffHeight); document.getElementById(parentID).style.height = heightHeaderInt+"px"; break;
    case 'wuFooterInt' : heightFooterInt = Math.round(heightFooterInt + diffHeight); document.getElementById(parentID).style.height = heightFooterInt+"px"; break;
    case 'wuColExtG' : heightColExtG = Math.round(heightColExtG + diffHeight); document.getElementById(parentID).style.height = heightColExtG+"px"; break;
    case 'wuColExtD' : heightColExtD = Math.round(heightColExtD + diffHeight); document.getElementById(parentID).style.height = heightColExtD+"px"; break;    
    case 'wuColIntG' : heightColIntG = Math.round(heightColIntG + diffHeight); document.getElementById(parentID).style.height = heightColIntG+"px"; break;
    case 'wuColIntD' : heightColIntD = Math.round(heightColIntD + diffHeight); document.getElementById(parentID).style.height = heightColIntD+"px"; break;
    case 'wuRub' : heightRub = Math.round(heightRub + diffHeight); document.getElementById(parentID).style.height = heightRub+"px"; break;  
  }    
  // Hauteur content exterieur (col ext + ent int + bas int + col int + rub)
  var heightContentExt = document.getElementById('wuContentExt').offsetHeight;
  // Hauteur content interieur (ent int + bas int + col int + rub)
  var heightContentInt = document.getElementById('wuContentInt').offsetHeight;
  // Hauteur content (col int + rub)
  var heightContent = document.getElementById('wuContent').offsetHeight;  
  // Hauteur entete int
  if (document.getElementById('wuHeaderInt')) { heightHeaderInt = document.getElementById('wuHeaderInt').offsetHeight; }
  else { heightHeaderInt = 0; }
  // Hauteur bas int
  if (document.getElementById('wuFooterInt')) { heightFooterInt = document.getElementById('wuFooterInt').offsetHeight; }
  else { heightFooterInt = 0; }  
  // Redef heightContentExt si interieur < exterieur
  if(heightContentExt < heightContentInt) { heightContentExt = heightContentInt; }
  // Redef heightContentInt si interieur > exterieur
  if(heightContentExt > heightContentInt) { heightContentInt = heightContentExt; }
  // Redef heightContent     
  heightContent = Math.round(heightContentExt - (heightHeaderInt + heightFooterInt));    
  // Def hauteur col exterieur gauche
  if (document.getElementById('wuColExtG')) document.getElementById('wuColExtG').style.height = Math.round(heightContentExt - diffColExtG)+"px" ;
  // Def hauteur col exterieur droite
  if (document.getElementById('wuColExtD')) document.getElementById('wuColExtD').style.height = Math.round(heightContentExt - diffColExtD)+"px" ; 
  // Def hauteur col interieur gauche
  if (document.getElementById('wuColIntG')) document.getElementById('wuColIntG').style.height = Math.round(heightContent - diffColIntG)+"px" ;    
  // Def hauteur col interieur droite
  if (document.getElementById('wuColIntD')) document.getElementById('wuColIntD').style.height = Math.round(heightContent - diffColIntD)+"px" ;
  // Def hauteur content
  if (document.getElementById('wuRub')) document.getElementById('wuRub').style.height = Math.round(heightContent - diffRub)+"px" ;
}

//Recupere nom du navigateur
function isIE() {
	return (navigator.appName.match(/Explorer/i));
}

//TimeOut des diaporamas automatiques
function diapoAuto(ID, objClass, timeOut, page, zoom) {  
  setTimeout("doRequest('wuAjax.php?phpFile=plugins/wuPlugin_listObj.php&&location=1&&objID="+ID+"&&objClass="+objClass+"&&page="+page+"&&zoom="+zoom+"&&noAutoHeight=1', 'wu_"+ID+"_object_content')", timeOut);
}

//Recupere le premier parent d'ergo qu'il trouve en fonction du currentID
function parentDOM(currentID) {  
  if(currentID == 'wuRub' || 
     currentID == 'wuColIntG' || currentID == 'wuColIntD' ||
     currentID == 'wuColExtG' || currentID == 'wuColExtD' ||
     currentID == 'wuHeaderInt' || currentID == 'wuHeaderExt' ||
     currentID == 'wuFooterInt' || currentID == 'wuFooterExt') {
     return currentID;     
  }
  else {
    currentID = document.getElementById(currentID).parentNode.id;
    return parentDOM(currentID); 
  }
}

// supprime les espace en debut et fin de chaine
function wuJsTrim(str) {
	while (str.substring(0,1) == ' ' || str.substring(0,1) == '\t' || str.substring(0,1) == '\r' || str.substring(0,1) == '\n') {
		str = str.substring(1, str.length);
	}
	while (str.substring(str.length-1, str.length) == ' ' || str.substring(str.length-1, str.length) == '\t' || str.substring(str.length-1, str.length) == '\r' || str.substring(str.length-1, str.length) == '\n') {
		str = str.substring(0,str.length-1);
	}
	return str;
}


//Permet d effacer valeur par defaut des champs
function razValue(obj, vlDef) {  
	if (wuJsTrim(obj.value) == vlDef) {		
    obj.value="";
  }
}

//Efface les valeurs d un formulaire
function wuResetForm(formID) {
  document.getElementById(formID).reset();
}

//Affiche le detail des definition
function wuAfficheDef(event, divID, defID) {
	document.getElementById(divID).innerHTML = '';
  doRequest('wuAjax.php?phpFile=plugins/wuPlugin_def.php&&location=1&&objID='+defID, divID);  
  var height = document.getElementById('wuContentAll').offsetHeight + document.documentElement.scrollTop;
  var width = document.body.offsetWidth + document.documentElement.scrollLeft;
  document.getElementById(divID).style.left = document.documentElement.scrollLeft + (document.body.offsetWidth - 400) / 2+"px";
  document.getElementById(divID).style.top = document.documentElement.scrollTop + 150+"px";
  document.getElementById(divID).style.display = 'block';     
  /*var coordX = event.clientX + document.body.scrollLeft;
	var coordY = event.clientY + document.body.scrollTop;
	document.getElementById(divID).style.left = coordX - 5+"px";
  document.getElementById(divID).style.top = coordY - 5+"px";   
  document.getElementById(divID).style.display = 'block';   */
}

//Recupere le top et left des balises (bug IE)
function findPos(obj) {
  var posX = 0, posY = 0;          
  do {
    posX += obj.offsetLeft;
    posY += obj.offsetTop;
    obj = obj.offsetParent;
  }
  while( obj != null );
  var pos = [];
  pos['X'] = posX;
  pos['Y'] = posY; 
  return pos; 
}

function openMasque(div, widthDiv, masqueBgColor, masqueOpacity) {
  //definition var width et height
  //------------------------------
  if (isIE()) {
    //if(document.body.clientHeight > document.getElementById('wuContentAll').offsetHeight) var height = document.body.clientHeight;
    //else var height = document.getElementById('wuContentAll').offsetHeight;
    //var width = document.body.offsetWidth + document.body.scrollLeft;    
    var width = screen.availWidth;
    var height = screen.availHeight;
  } else { 
    if(window.innerHeight > document.height) var height = window.innerHeight;
    else var height = document.height;
    var width = document.width;
    var opacity = masqueOpacity / 100;
  }
  //affichage du masque et div
  //--------------------------
  document.getElementById('masque').style.width = width+'px';
  document.getElementById('masque').style.height = height+'px';
  document.getElementById('masque').style.backgroundColor = masqueBgColor;
  document.getElementById('masque').style.zIndex = '3000';
  document.getElementById('masque').style.left = 0;
  document.getElementById('masque').style.top = 0;
  if(div != '') {
    document.getElementById(div).style.zIndex = '5000';
    document.getElementById(div).style.display = 'block';
  }
  //position de la div
  //------------------
  if (isIE()) {  
    if(div != '') {
      var popupLeft = document.body.scrollLeft + ((document.body.offsetWidth - widthDiv) / 2) ;     
      document.getElementById(div).style.left = popupLeft+'px';    
      //var popupTop = document.body.scrollTop + ((document.body.clientHeight - document.getElementById(div).offsetHeight) / 2) ; 
      var popupTop = 100 ;
      document.getElementById(div).style.top = popupTop+'px';
    }     
    document.getElementById('masque').style.filter = 'alpha(opacity='+masqueOpacity+')';
  }
  else {
    if(div != '') {
      var popupLeft = window.pageXOffset + ((window.innerWidth - widthDiv) / 2) ;
      document.getElementById(div).style.left = popupLeft+'px';    
      var popupTop = window.pageYOffset + ((window.innerHeight - document.getElementById(div).offsetHeight) / 2) ;
      document.getElementById(div).style.top = popupTop+'px';
    } 
    document.getElementById('masque').style.opacity = opacity;
  }     
}
function closeMasque() {  
  document.getElementById('masque').style.width = 0;
  document.getElementById('masque').style.height = 0;
}

