// JavaScript Document

/********************************************************
*  IMPORT DOJO
********************************************************/
/*
 * Configuration Dojo (import)
 */
/*dojo.require("dojo.io.*");
dojo.require("dojo.io.IframeIO");
dojo.require("dojo.event.*");
dojo.require("dojo.xml.Parse");
dojo.require("dojo.widget.Parse");
dojo.require("dojo.widget.Tooltip");
dojo.require("dojo.widget.Tree");
dojo.require("dojo.widget.TreeNode");
dojo.require("dojo.widget.TreeSelector");
dojo.require("dojo.crypto.MD5");*/
dojo.hostenv.writeIncludes();

// modales Dojo (verouillage session a prevoir)
var dlgSession;

// onload page
dojo.event.connect(dojo.hostenv, "loaded", window, "init");



/********************************************************
*  EXTERNAL LINK
********************************************************/
function externalLinks() {
	
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
 
}

/********************************************************
*  NAVIGATION IE
********************************************************/

function navHover() {
	
	var lis 	=	document.getElementById("navmenu").getElementsByTagName("LI");
	//var nodes 	= 	$A(lis);
	
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
	
}


/********************************************************
*  OPENMENU
********************************************************/


function openMenu(id_){
	
	//close all elements
	var elUL_array = $('navmenu').childElements();
	
	for (var i=0; i<elUL_array.length; i++) {
		var elLI = elUL_array[i];
		var elUL = elLI.childElements();
		if(elUL[1] != undefined)elUL[1].hide();
	}
	
	//open element ID
	if($(id_)){
		var elUL = $(id_).childElements();
		if(elUL[1] != undefined)elUL[1].show();
	}
}

Event.observe(window, 'load', externalLinks, false);

if(navigator.userAgent.indexOf("MSIE 6") != -1)
	Event.observe(window, 'load', navHover, false);


/********************************************************
*  AJOUTER FAVORIS
********************************************************/

function favoris(name_, url_){
	if(window.sidebar){
		window.sidebar.addPanel(name_, url_,"");
	}else if( document.all ){
		window.external.AddFavorite(url_, name_);
	}
} 

window.onload = function(){
   BubbleTips.activateTipOn("abbr");
   BubbleTips.activateTipOn("acronym");
};

/********************************************************
*  NEWSLETTER
********************************************************/

function PopupNewsLetter(page,nom,largeur,hauteur,options) {
	 var top=(screen.height-hauteur)/2;
	 var left=(screen.width-largeur)/2;
	 window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function gonews(){	
	PopupNewsLetter('','popup',500,300,'menubar=no,scrollbars=no,statusbar=no');
	
	var boxActionInscr = document.forms["f_newsletter"].insc;
	var boxActionDesinscr = document.forms["f_newsletter"].desinsc;

	if(wysi==1)	{
		if (boxActionInscr.checked) {
			stat('efigip', '', '', '', '/lettre_info_abonn/');
		}
		else if(boxActionDesinscr.checked){
			stat('efigip', '', '', '', '/lettre_info_desabonn/');
		}
	}
	
	document.forms["f_newsletter"].submit();
	document.forms["f_newsletter"].email.value="traitement en cours...";
	return false;
}




/********************************************************
*  PARSE LINKS
********************************************************/
function parseLinks(bloc){

	if($(bloc))
	{
	  var liens = $(bloc).select("a");
	  
	  for (var i = 0; i < liens.length; i++) {
		liens[i].observe('click', onClickLien.bind(liens[i]));
	  }
	}
	
}

 function onClickLien(){
 	
	var tabHref = this.href.split('/');
	
	var type = tabHref[4];
	
	if (type == 'ressources' || type == 'publications'){
		var key = tabHref[5];
		
		pdfReg = /[0-9a-zA-Z\+\-\.]+/;
		
		if (wysi == 1 && pdfReg.test(key)) {
			var suivi = 'telechargement';
			if (type == 'ressources') suivi = type;
			
			stat('efigip','PV', '', suivi+';'+key, '/'+type+'/telechargement/'); 
		}
	}
 }
 
 
/********************************************************
*  UTILS
********************************************************/ 
function toggleVisibility()
{
	
}
function toggleDisplay(eltId)
{
  var elt = document.getElementById(eltId);
  if(elt.style.display == "none" )
  {
    elt.style.display = "";
  }
  else
  {
    elt.style.display = "none";
  }
}

