function checkMail(from)
{
	var re = /^[A-Za-z0-9.-_--]+@[A-Za-z0-9.-_--]+\.[A-Za-z]{2,5}$/;
	if (re.test(from.value)) {	return true;}
	else	{alert("Format adresse e-mail invalide.");	}
	return false;
}
function razValue(obj, vlDef)
{
	if (obj.value == vlDef)
		obj.value="";
}
function isIE()
{
	return (navigator.appName.match(/Explorer/i));
}
var shortcut = '';
function myInit(wuVerticalJS) {	
	if (document.getElementById('wuInHeader')) { var wuInHeader = document.getElementById('wuInHeader').clientHeight; }
	else { var wuInHeader = 0; }
	if (document.getElementById('wuInFooter')) { var wuInFooter = document.getElementById('wuInFooter').clientHeight; }
	else { var wuInFooter = 0; }
	var contentHeight = document.getElementById('wuAll').clientHeight - wuInHeader - wuInFooter;
	if (document.getElementById('wuContent').clientHeight < contentHeight) document.getElementById('wuContent').height = contentHeight;
	if (document.getElementById('wuAllContent').clientHeight < contentHeight) document.getElementById('wuAllContent').height = contentHeight;
	if (shortcut != '') {		
		if(shortcutPos == 'left') { document.getElementById(shortcut).style.left = '0px'; }
		if(shortcutPos == 'right') { document.getElementById(shortcutDiv).style.left = document.getElementById(shortcut).clientWidth - shortcutWidth; }	
	}	
	if(isIE() != 'Explorer' && wuVerticalJS == true) {
	  if (window.innerWidth != screen.width) {	   
      window.resizeBy(1,1);
      window.resizeBy(-1, -1);
    }
  }
}

// Fonction nav html
function menu (id, alignImg, img, imgWidth, imgHeight, imgAlt, ewResources, unvisible, font, pcolor, color, bgpcolor, bgcolor, align, textdecoration, fontweight, fontstyle, textsize, borderstyle, borderpx, borderpcolor, bordercolor, bordermg)
{
	var quote = '\'\"';
	var qquote = ' ';	
	//Image
	if (img !='' ) {
		if (alignImg ==  'fond') {
			document.getElementById('cadre'+id).style.backgroundPosition='center center';
			document.getElementById('cadre'+id).style.backgroundRepeat='no-repeat';
			document.getElementById('cadre'+id).style.backgroundImage='url('+ewResources+img+')';
			//document.getElementById('cadre'+id).style.width=imgWidth;
			//document.getElementById('cadre'+id).style.height=imgHeight;
			document.getElementById('cadre'+id).title=imgAlt.replace(quote, qquote);
			document.getElementById('cadre'+id).style.cursor=isIE()? 'hand' : 'pointer';
		} else {
			document.getElementById('img'+id).src=ewResources+img;
			document.getElementById('img'+id).width=imgWidth;
			document.getElementById('img'+id).height=imgHeight;
			document.getElementById('img'+id).title=imgAlt.replace(quote, qquote);
			document.getElementById('img'+id).style.display='block';
			document.getElementById('cadre'+id).style.cursor=isIE()? 'hand' : 'pointer';
		}
	} else {
		if (alignImg == 'fond') {
			document.getElementById('cadre'+id).style.backgroundImage='url()';
			//document.getElementById('cadre'+id).style.width='';
			//document.getElementById('cadre'+id).style.height='';
			document.getElementById('cadre'+id).title='';
		} else {
			if (img != '' ) {
				document.getElementById('img'+id).src='';
				document.getElementById('img'+id).width='';
				document.getElementById('img'+id).height='';
				document.getElementById('img'+id).title='';
				document.getElementById('img'+id).style.display='block';
			}
		}
	}
	//Visibilite texte
	if (unvisible =='on') {
		document.getElementById('divLink'+id).style.display='none';
	} else {
		document.getElementById('divLink'+id).style.display='block';
	}
	//alignement du texte
	if (align != '' ) {
		document.getElementById('divLink'+id).style.textAlign=align;
	} else {
		document.getElementById('divLink'+id).style.textAlign='left';
	}
	//Cadre
	if (borderstyle != '')
	{
		if (borderpcolor != '' && borderpcolor != 'none') {
			document.getElementById('divLink'+id).style.border=borderpx+'px '+borderstyle+' '+borderpcolor;
		} else {
			if (bordercolor != '' && bordercolor != 'none') {
				document.getElementById('divLink'+id).style.border=borderpx+'px '+borderstyle+' '+bordercolor;
			} else {
				document.getElementById('divLink'+id).style.border=borderpx+'px '+borderstyle+' black';
			}
		}
	}
	//Marge 
	if (bordermg != '') {
		document.getElementById('spanLink'+id).style.padding=bordermg+'px' ;
	} else {
		document.getElementById('spanLink'+id).style.padding='0px' ;
	}
	//Curseur  -->
	document.getElementById('divLink'+id).style.cursor=isIE()? 'hand' : 'pointer';
	//Class du texte
	if (font != '') {
		document.getElementById('spanLink'+id).className=font;
	} else {
		document.getElementById('spanLink'+id).className= 'wuDefaultText';
	}
	//Couleur du texte
	if (pcolor != '' ) {
		document.getElementById('spanLink'+id).style.color=pcolor;
	} else {
		if (color != 'none' && color != '') {
			document.getElementById('spanLink'+id).style.color=color;
		}
	}
	//Couleur de fond du texte
	if (bgpcolor != '' ) {
		document.getElementById('spanLink'+id).style.backgroundColor=bgpcolor;
	} else {
		if (bgcolor != 'none' && bgcolor != '') {
			document.getElementById('spanLink'+id).style.backgroundColor=bgcolor;
		}
	}				
	//soulignement 
	if (textdecoration != '' ) {
		document.getElementById('spanLink'+id).style.textdecoration=textdecoration;
	}
	//bold du texte
	if (fontweight != '' ) {
		document.getElementById('spanLink'+id).style.fontWeight=fontweight;
	}
	//italique du texte
	if (fontstyle != '' ) {
		document.getElementById('spanLink'+id).style.fontStyle=fontstyle;
	}
	//taille du texte
	if (textsize != '' ) {
		document.getElementById('spanLink'+id).style.fontSize=textsize;
	}
	
}

function changeStatus(obj, imgOpen, imgClose, ArboID, wuOpenObjects) {	
	document.getElementById(obj).style.display = document.getElementById(obj).style.display == "none" ? "block" : "none";
	document.getElementById('i'+obj).src = document.getElementById(obj).style.display == "none" ? imgClose : imgOpen;	
	if (document.getElementById(obj).style.display == "none") {
		 wuOpenObjects = wuOpenObjects.replace(obj, "");
	} else {
		if (wuOpenObjects.indexOf(obj) <= 0) {
			wuOpenObjects += obj;
		}
	}	
	document.getElementById('wuTempOpenObjects_'+ArboID).value = wuOpenObjects;		
  doRequest('wuAjax.php?phpFile=plugins/arbo/wuOpenArbo.php&location=1&arboID='+ArboID+'&wuOpen='+wuOpenObjects, '' );					
}

function navAgenda(opp, agID) {
  doRequest('wuAjax.php?phpFile=plugins/agenda/wuAgenda-utils.php&location=1&agID='+agID+'&action=nav&opp='+opp, 'wuAgenda_'+agID);				
}

function detailAgenda(div, agID, events, widthDiv, masqueBgColor, masqueOpacity) {
  doRequest('wuAjax.php?phpFile=plugins/agenda/wuAgenda-utils.php&location=1&agID='+agID+'&action=detail&events='+events, div);  
  openMasque(div, widthDiv, masqueBgColor, masqueOpacity, 'center', '50', '');  
}

function closeDetailAgenda(div) {
  document.getElementById(div).style.display = 'none';
  closeMasque();
}

function ajaxPopup(div, popupID, widthDiv, masqueBgColor, masqueOpacity, posH, posV, linkID) {
  doRequest('wuAjax.php?phpFile=plugins/ajaxPopup/wuAjaxPopup.php&location=1&divID='+div+'&popupID='+popupID+'&widthDiv='+widthDiv+'&masqueOpacity='+masqueOpacity+'&posH='+posH+'&posV='+posV+'&linkID='+linkID+'&masqueBgColor='+masqueBgColor, div);
}

function closeAjaxPopup(div) {
  document.getElementById(div).style.display = 'none';
  document.getElementById(div).innerHTML = '';
  closeMasque();
}

function sendFriendPopup(div) {
  doRequest('wuAjax.php?phpFile=plugins/tools/sendFriendForm.php&location=1&div='+div, div);  
  openMasque(div, '470', '#CCCCCC', '50', 'center', 'middle', '');  
}

function closeSendFriendPopup(div) {
  document.getElementById(div).style.display = 'none';
  closeMasque();
}

function rssPopup(div, linkID, contID) {
  doRequest('wuAjax.php?phpFile=plugins/tools/rssUrl.php&location=1&div='+div+'&contID='+contID, div);  
  openMasque(div, '400', '#CCCCCC', '50', 'center', 'middle', linkID);  
}

function closeRssPopup(div) {
  document.getElementById(div).style.display = 'none';
  closeMasque();
}

function openMasque(div, widthDiv, masqueBgColor, masqueOpacity, posH, posV, linkID, noBorder) {
  if(linkID != '' && linkID != 'undefined') var posLink = findPos(document.getElementById(linkID));
  //definition var width et height
  //------------------------------
  if (isIE()) {
    if(document.body.clientHeight > document.getElementById('index').offsetHeight) var height = document.body.clientHeight;
    else var height = document.getElementById('index').offsetHeight;
    var width = document.body.offsetWidth + document.body.scrollLeft;    
  } 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
  document.getElementById(div).style.zIndex = '5000';
  document.getElementById(div).style.display = 'block';
  if(noBorder != 1) document.getElementById(div).style.border = '1px solid black';
  //position de la div
  //------------------
  if (isIE()) {
    //position horizontale
    if(posH == 'link') var popupLeft = posLink[0]; //au niveau du lien
    else if(posH == 'left') var popupLeft = document.body.scrollLeft + 15; //left
    else if(posH == 'center')var popupLeft = document.body.scrollLeft + ((document.body.offsetWidth - widthDiv) / 2) ; //center
    else if(posH == 'right') var popupRight = 15; //right
    else var popupLeft = document.body.scrollLeft + parseInt(posH); //pos
    if(posH == 'right') { document.getElementById(div).style.right = popupRight+'px'; }
    else { document.getElementById(div).style.left = popupLeft+'px'; }
    document.getElementById('masque').style.filter = 'alpha(opacity='+masqueOpacity+')';
    //position verticale
    if(posV == 'under') var popupTop = document.getElementById(linkID).offsetHeight + posLink[1] + 5; //sous lien
    else if(posV == 'top') var popupTop = document.body.scrollTop + 15; //top
    else if(posV == 'middle')var popupTop = document.body.scrollTop + ((document.body.clientHeight - document.getElementById(div).offsetHeight) / 2) ; //middle
    else if(posV == 'bottom') var popupBottom = 15; //bottom
    else var popupTop = document.body.scrollTop + parseInt(posV); //pos 
    if(posV == 'bottom') { document.getElementById(div).style.bottom = popupBottom+'px'; }
    else { document.getElementById(div).style.top = popupTop+'px'; }    
  }
  else {     
    //position horizontale    
    if(posH == 'link') var popupLeft = posLink[0]; //au niveau du lien
    else if(posH == 'left') var popupLeft = window.pageXOffset + 15; //left
    else if(posH == 'center')var popupLeft = window.pageXOffset + ((window.innerWidth - widthDiv) / 2) ; //center
    else if(posH == 'right') var popupRight = 15; //right
    else var popupLeft = window.pageXOffset + parseInt(posH); //pos
    if(posH == 'right') { document.getElementById(div).style.right = popupRight+'px'; }
    else { document.getElementById(div).style.left = popupLeft+'px'; }
    document.getElementById('masque').style.opacity = opacity;
    //position verticale
    if(posV == 'under') var popupTop = document.getElementById(linkID).offsetHeight + posLink[1] + 5; //sous lien
    else if(posV == 'top') var popupTop = window.pageYOffset + 15; //top
    else if(posV == 'middle')var popupTop = window.pageYOffset + ((window.innerHeight - document.getElementById(div).offsetHeight) / 2) ; //middle
    else if(posV == 'bottom') var popupBottom = 15; //bottom
    else var popupTop = window.pageYOffset + parseInt(posV); //pos
    if(posV == 'bottom') { document.getElementById(div).style.bottom = popupBottom+'px'; }
    else { document.getElementById(div).style.top = popupTop+'px'; }
  }
     
}

function closeMasque() {  
  document.getElementById('masque').style.width = 0;
  document.getElementById('masque').style.height = 0;
}

function findPos(obj){
  //position x / y de l'objet
  var x = obj.offsetLeft || 0;
  var y = obj.offsetTop || 0;
  //tant qu'il y a un parent, on ajoute la position de son parent
  while (obj = obj.offsetParent) {
      x += obj.offsetLeft
      y += obj.offsetTop
  }
  return new Array(x,y);
}


function verifSendFriend() {
    var filtreMail = /^[A-Za-z0-9.-_--]+@[A-Za-z0-9.-_--]+\.[A-Za-z]{2,5}$/;
    if(document.getElementById('ami').value == '') {
      alert('Merci de renseigner votre nom.');
      document.getElementById('ami').focus();  
      return false;    
    }
    else {
      if (filtreMail.test(document.getElementById('mailFrom').value) != true) {
        alert('Merci de renseigner votre adresse E-mail ou de saisir une adresse E-mail valide.');
        document.getElementById('mailFrom').focus();  
        return false;
      }
      else {        
        if (filtreMail.test(document.getElementById('mailDest').value) != true) {
          alert('Merci de renseigner l\'adresse E-mail de votre ami(e) ou de saisir une adresse E-mail valide.');
          document.getElementById('mailDest').focus();  
          return false;
        }
        else {
          if(document.getElementById('objet').value == '') {
            alert('Merci de renseigner l\'objet de votre message.');
            document.getElementById('objet').focus();  
            return false;    
          }     
        }
      }      
    }  
    return true;
  }
  
  function verifSendFriendAjax() {
    var filtreMail = /^[A-Za-z0-9.-_--]+@[A-Za-z0-9.-_--]+\.[A-Za-z]{2,5}$/;
    if(document.getElementById('ami').value == '') {
      alert('Merci de renseigner votre nom.');
      document.getElementById('ami').focus();  
      return false;    
    }
    else {
      if (filtreMail.test(document.getElementById('mailFrom').value) != true) {
        alert('Merci de renseigner votre adresse E-mail ou de saisir une adresse E-mail valide.');
        document.getElementById('mailFrom').focus();  
        return false;
      }
      else {        
        if (filtreMail.test(document.getElementById('mailDest').value) != true) {
          alert('Merci de renseigner l\'adresse E-mail de votre ami(e) ou de saisir une adresse E-mail valide.');
          document.getElementById('mailDest').focus();  
          return false;
        }
      }      
    }    
  }
  
  function submitSendFriendAjax(Form, id) {
    doRequest('wuAjax.php?phpFile=sendForm.php&location=3&divID=wuSendFriend_'+id, 'wuSendFriend_'+id, getDataFromForm(Form));
  }
    
  function getContentActu(id) {
    document.getElementById('divPrintActu').innerHTML = window.opener.document.getElementById('print_'+id).innerHTML;    
  }
  
  function getContentPrint(id) {
    document.getElementById('divContentPrint').innerHTML = window.opener.document.getElementById(id).innerHTML;    
  }
