
//-------------------------------------------------
// Initialisation et gestion des rollovers
// ------------------------------------------------
var nbsec=0.5;
function loadNav()
{
	initializeMenu("listINF", "catINF");
	initializeMenu("listVID", "catVID");
	initializeMenu("listSCI", "catSCI");
	initializeMenu("listMAN", "catMAN");
	initializeMenu("listDRO", "catDRO");
	initializeMenu("listBTP", "catBTP");
	initializeMenu("listVIE", "catVIE");
}

var currentMenu = null;

window.lastmenu = null;
window.menuactive = 0;
window.inactivedelay = 0;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId)
{
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
    var select = document.getElementById("themes");

    if (menu == null || actuator == null) return;

    actuator.onmouseover  = function() {
       if (currentMenu == null) {
           tid = window.setTimeout(this.showMenu,500);
        }
        else {
            currentMenu.style.visibility = "hidden";
            tid = window.setTimeout(this.showMenu,100);
        }
    }
    	
    actuator.onmouseout = function() {
    	window.clearTimeout(tid);
	window.menuactive=1;
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            this.hideMenu();
        }
        return true;
    }

    actuator.showMenu = function() {
        menu.style.left = actuator.offsetLeft + "px";
        menu.style.top = actuator.offsetTop + actuator.offsetHeight + "px";
        menu.style.visibility = "visible";
        select.style.visibility = "hidden";
        currentMenu = menu;
        window.lastmenu=actuator;
        window.menuactive=0;
        window.inactivedelay = 0;
    }
    actuator.hideMenu = function() {
         if (currentMenu != null) {      
		  currentMenu.style.visibility = "hidden";
            currentMenu = null;
	    }
            select.style.visibility = "visible";
            window.menuactive=0;
    }
    
    menu.onmouseover = actuator.showMenu;
    menu.onmouseout = actuator.onmouseout;
}

function autohide() {
	if (window.menuactive==1) {
		if (++window.inactivedelay==3 && window.lastmenu != null) {
			window.lastmenu.hideMenu();
		}
	}
	else
		window.inactivedelay = 0;
}
window.setInterval("autohide()",nbsec*1000/3);


// ----------------------------------------------
// StyleSwitcher - written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// modified by Aaron Jones 10/10/2002
// - - - - - - - - - - - - - - - - - - - - - - -
// For details, visit ALA:
// http://www.alistapart.com/stories/alternate/
// ----------------------------------------------

function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
 if (reset == 1) {
	  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
	var style = readCookie("wstyle");
	if (style != null) {
		setActiveStyleSheet(style, 0);
	}
}

function loupe(sens) {
 var style = readCookie("wstyle"), tstyles = new Array("Texte petit","","Texte grand","Texte plus grand");
 if (window.loupeidx==null)
 	window.loupeidx = 1; // style par défaut

 prev = window.loupeidx;
 if (prev != (window.loupeidx=Math.max(0,Math.min(tstyles.length-1,window.loupeidx+sens)) ) )
 setActiveStyleSheet(tstyles[window.loupeidx],1);
 placepied();
}

// ----------------------------------------------
// Cookie functions from www.wired.com
// ----------------------------------------------
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = ";expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+";domain=.eyrolles.com;path=/;";
}

// ----------------------------------------------

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

// ----------------------------------------------
// Placement du pied
// --------------------------------------------

function getHaut(obj) {
	return obj.offsetHeight + obj.offsetTop;
}
function placepied() {
	if (document.getElementById!=null) {
		var footer = document.getElementById("pied");
		if (footer.offsetHeight!=null) {
			var zc = document.getElementById("zoneClient")
			var ct = document.getElementById("contenu");
			var maxheight = Math.max(getHaut(zc),getHaut(ct));
			var pr = document.getElementById("promotions");
			
			if(pr) {
				maxheight = Math.max(maxheight,getHaut(pr));
			}
//			alert(getHaut(zc) + "-" + getHaut(ct) + "-" + getHaut(pr));
			
			maxheight = maxheight+5;
			with (footer.style) {
				position="absolute";
				top=maxheight+"px";
				marginRight="0";
				marginLeft="0";
				width="100%";
			}
		}
	}
}

// Popup couverture
function zoomCouv(ean13)
{
	window.open('/popup_couv.php?ouv_ean13='+ean13,'zoomCouv',
	'resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,width=450,height=520');
}

// Popup aide
function zoomAide(aide,ancre)
{
	window.open('/popup_aide.php?page='+aide+'&ancre='+ancre,'zoomAide',
	'resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,width=450,height=380');
}

// Popup vidéo Autodidakt
function zoomVideo(vid) {
	window.open('/Informatique/Dossiers/CollectionAutodidakt/popup.php?v='+vid,'zoomVideo',
	'resizable=yes,scrollbars=no,toolbar=no,location=no,menubar=no,width=641,height=509');
}

// Popup
function zoomPopup(page,w,h,sb)
{
	if (!w) { var w = 450; }
	if (!h) { var h = 380; }
	if (!sb) { var sb = 'yes'; }
	
	var wh = 'width='+w+',height='+h;
	
	window.open('/popup.php?page='+page,'zoomPopup',
	'resizable=yes,scrollbars='+sb+',toolbar=no,location=no,menubar=no,'+wh);
}

// Popup envoi de facture
function sendBillPopup(id, name)
{
	window.open('/popup_send_bill.php?com='+id+'&nom='+name, 
		'EnvoiFacture', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=250'
	);
}

// ----------------------------------------------
// Newsletters
// ----------------------------------------------

function checkAllNewsletters()
{
    var listNewsletter = document.getElementsByName('formCompte[newsletters][]');
    var checkboxNewsletters = document.getElementById('newsletters-checkbox');
    
    if (checkboxNewsletters)
    {
        checkboxNewsletters.style.display = '';
        placepied();
    }
    
    if (listNewsletter)
    {
        for (var i=0; i < listNewsletter.length; i++)
		{
            listNewsletter[i].checked = true;
		}
    }
}

function uncheckAllNewsletters()
{
    var listNewsletter = document.getElementsByName('formCompte[newsletters][]');
    var noPartenaire = document.getElementById('insPart0');
    var checkboxNewsletters = document.getElementById('newsletters-checkbox');
    
    if (checkboxNewsletters)
    {
        checkboxNewsletters.style.display = 'none';
        placepied();
    }
    
    if (listNewsletter)
    {
        for (var i=0; i < listNewsletter.length; i++)
		{
            listNewsletter[i].checked = false;
		}
        
        if (noPartenaire) noPartenaire.checked = true;
    }
}

function loadDepartements()
{
    var evenement = document.getElementById('newsletter9');
    var departement = document.getElementById('newsletter-departement');
    
    if (evenement && departement)
    {
        if (evenement.checked)
        {
             departement.style.display = '';
        }
        else
        {
            departement.style.display = 'none';
        }
    }
    
    setTimeout("loadDepartements()", 10);
}


// ----------------------------------------------
// Affichage d'un bloc
// ----------------------------------------------

function toggleDisplayElement(myId)
{
	if ($(myId))
	{
		if ($(myId).style.display == 'none')
		{
			$(myId).style.display = '';
		}
		else
		{
			$(myId).style.display = 'none';
		}
		
		placepied();
	}
}

//-----------------------------------------------

window.onload = function() { loadNav(); setStyle(); placepied(); loadDepartements(); }
window.onresize = placepied;
