// **************************************************************************
// Génériques ***************************************************************

function $(element) {
  if (typeof element == 'string')
    return document.getElementById(element);
}

function setWidth(element, theWidth){
	$(element).style.width = theWidth + 'px';
}

function openWin(name, url, w, h, params){
	params = (params != '') ? params : "toolbar=0,location=0,directories=0,menubar=0,status=1,resizable=1,scrollbars=1";
	allParams = "width=" + w + ",height=" + h + params;
	win = window.open(url, name, allParams);
	win.focus();
	return false;
}

function sendFriend(){
	retour = '%0d%0a';
	chaine_mail = "mailto:?subject= Page à voir sur Programme Pharaon";
	chaine_mail += "&body= Bonjour," + retour + retour + "Je vous recommande cette page : " + document.title + ".";
	chaine_mail += retour + retour + "Consultable à l'adresse : " + location.href;
	location.href = chaine_mail;
}


// **************************************************************************
// Cookies ******************************************************************

function setCookieValue(cookieName, cookieValue, nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString() + ";path=/";
}

function getCookieValue(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}




// **************************************************************************
// changer la taille de la police *******************************************

var allStyleSize = ["85%", "100%" , "115%" , "130%", "145%" ];
var currentStyleSize = 1;

cookieStyle = getCookieValue("styleSizePharaon");
if (cookieStyle!='') {
	currentStyleSize = cookieStyle;
}

function changeStyleSize(element, witchDirection) {
	if ( ( currentStyleSize >= 1 ) && ( witchDirection == -1 ) ) { currentStyleSize--; }
	if ( ( currentStyleSize < 4 ) && ( witchDirection == 1 ) ) { currentStyleSize++; }
	applyStyleSize(element,currentStyleSize);
	setCookieValue("styleSizePharaon", currentStyleSize, 10);
	return false;
}

function applyStyleSize(element, styleSize) {
	$(element).style.fontSize = allStyleSize[styleSize];
}
