
// The Cookie Jar
////// Standard functions for Setting, Getting, and Deleting Cookies
////// john@xcentrixlc.com

// To set a cookie pass in the name, value, and persist type
// SetCookie("name", "value", 1) set the persist type to 1 to store your cookie
// or to 0 to last for this browser session only.  By default the storage time is for one year.
// You can add another argument to hold the length of time you want to store the cookie:
// SetCookie("name", "value",1,15768000000) would store the cookie for 6 months.
// the time is calcutaled in miliseconds so for one month of milliseconds you calculate:
// 31 * 24 * 60 * 60 * 1000=2678400000
// To get or delete a cookie simply pass in the name of the cookie you want to effect
// GetCookie("name")  DeleteCookie("name")
// if you ask for a cookie that does not exist it will return null.

function getCookieVal(offset) {	
  endstr = document.cookie.indexOf (";", offset)
  if(endstr == -1) endstr = document.cookie.length
  return unescape(document.cookie.substring(offset, endstr))
}

function GetCookie(name) {
  arg = name + "="
  alen = arg.length
  clen = document.cookie.length
  var i = 0
  while (i < clen) {
    j = i + alen
    if(document.cookie.substring(i, j) == arg) { 
	return getCookieVal(j)
	}
    i = document.cookie.indexOf(" ", i) + 1
    if(i == 0) break
  }
  return null
}

function SetCookie (name, value, per, exp) {
  cstr = name + "=" + escape(value) + ";"
  if(per){
    addtime=(exp>0) ? exp : 31536000000
    expdate = new Date()
    expdate.setTime(expdate.getTime() + addtime)
    expdate = expdate.toGMTString()
   cstr+=" expires=" + expdate
  }
  document.cookie = cstr
}

function DeleteCookie(name) {
  exp = new Date()
  exp.setTime (exp.getTime() - 1)
  cval = GetCookie(name)
  if(cval != null)
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()
}

// JavaScript Document
jQuery.noConflict()


//INITILIALISATION DES SCRIPTS UTILISANT JQUERY

//Placer dans la fonction init tous les scripts qui doivent Ã¿Âªtre initalisÃ¿Â©s lorsque le document est chargÃ©
function init() {
     // Ajouter une classe alternative pour les rangÃ©es impaires de tableau de contenu (typo3)
	if ( jQuery("table").length ){
	  jQuery("table").each(function() {
	    /*if (jQuery(this).is('table') && jQuery(this).find('thead').length == 0) {
              // No 'thead' section
              jQuery(this).prepend("<thead></thead>"); // add thead
              jQuery(this).find('tbody tr:first').remove().appendTo(jQuery(this).find('thead') ); // remove first row from tbody, add it to thead
            }*/
            jQuery(this).find("tbody > tr:odd").addClass("odd");
	  });
	}
}

function comportementPopUp (objAct, popUp) {
	    //alert('comportementPopUp')
        jQuery(popUp).fadeOut(0);
		jQuery(objAct).hover(function() {
			//jQuery('body').append('ho:');
			// if the element is currently being animated (to fadeOut)...
		 	if (jQuery(popUp).is(':animated')) {
				//jQuery('body').append('isanim<br/>');
				// ...stop the current animation, and fade it to 1 from current position
				jQuery(popUp).stop().fadeTo(500, 1);
			} else {
				//jQuery('body').append('isnot<br/>');
				jQuery(popUp).fadeIn(500);
			}
			return false
		}, function () {
			//jQuery('body').append('notho:');
			if (jQuery(popUp).is(':animated')) {
				//jQuery('body').append('isanim<br/>');
				jQuery(popUp).stop().fadeTo(500, 0);
			} else {
				//jQuery('body').append('isnot<br/>');
				jQuery(popUp).fadeOut(500);
			}
			return false
		});
}

jQuery(document).ready(function() {init();});

// GÃ©rer la taille du texte dans la zone de contenu via classes txtsize5 (140%), txtsize4 (140%), txtsize3 (130%), txtsize2 (120%), txtsize1(110%), txtnormal (100%).
// La valeur par dÃ©faut est txtnormal : 100%
// Important : utiliser avec cookiejar.js (SetCookie est une fonction de cookiejar.js)
// Pour initialiser la taille du texte, il faut ajouter un appel Ã  la fonction initFontSize de la faÃ§on suivante (initFontSize('id de l'Ã©lement', cookie))

function setFontSize (idElement,increment) {
	var el = document.getElementById(idElement);
	maxSize = 150 ;//pourcent
	minSize = 100 ;//pourcent
	if (el.style.fontSize.indexOf("%") == -1) {
		// pas en pourcentage ou indÃ©fini
		el.style.fontSize = "100%";
	}
	actualSize = parseFloat(el.style.fontSize);
	if (increment == "plus" && actualSize < maxSize) {
		actualSize += 10
	} else if (increment == "moins" && actualSize > minSize) {
		actualSize -= 10
	}
	el.style.fontSize = actualSize+"%"
	SetCookie("fsCookie", el.style.fontSize, 0)
	
}
function initFontSize (idElement) {
	var fs=GetCookie('fsCookie');
	if (fs) {
		var el = document.getElementById(idElement);
		el.style.fontSize = fs;
		return	
	} else {
		return null	
	}
}

