/* This script uses Prototype JS Framework (includes in Ovidentia) */

/*  Function which created a cookie
	If expiration does not exist, the cookie works only during the session of the site
	To delete a cookie, it is necessary to put expiration in 0
	Example: ovidentia_themedefaut_savecookie("count", 10, (new Date(2010, 12).getTime())); */
function ovidentia_themedefaut_setcookie(nom, valeur, expiration) {
	if (expiration != undefined && expiration != "") {
		var timestamp = new Date(expiration);
		document.cookie = nom + "=" + escape(valeur) + "; expires=" + timestamp.toGMTString();
	} else {
		document.cookie = nom + "=" + escape(valeur) + "; expires=";
	}
}

/*  Function which recovers the data of a cookie
	Return undefined if the cookie is not defined */
function ovidentia_themedefaut_getcookie(name) {
	var cookies = document.cookie.split(/;/);
	for(var i=0;i<=cookies.length - 1;i++) {
		var cook = cookies[i].split(/=/);
		cook[0] = cook[0].replace(/(^\s*)|(\s*$)/g,"");
		if (cook[0] == name) {
			return unescape(cook[1]);
		}
	}
	return '';
}

/* Function called when they click on the icon in the toolbar: spreads the body of the page by hiding the header and the sections */
function ovidentia_themedefaut_fullbody() {
	var cookievalue = ovidentia_themedefaut_getcookie('ovidentia_themedefaut_fullbody');
	if (cookievalue == undefined || cookievalue == 1) {
		ovidentia_themedefaut_setcookie('ovidentia_themedefaut_fullbody', 0);
		$$('body').each(function(s, index) {
		  s.removeClassName('ovidentia_themedefaut_fullbody');
		});
	} else {
		ovidentia_themedefaut_setcookie('ovidentia_themedefaut_fullbody', 1);
		$$('body').each(function(s, index) {
		  s.addClassName('ovidentia_themedefaut_fullbody');
		});
	}
}


/* Show the link for manage full body */
function ovidentia_themedefaut_showfullbodylink() {
	$$('.ovidentia_toolbar_fullbodylink').each(function(s, index) {
	  s.setStyle({
		display: 'block'
	  });
	});
}

bab_initFunctions.push(function() { ovidentia_themedefaut_showfullbodylink(); });
