//Store a value in cookie
function setCookie(title,val)
{
	document.cookie = title+"="+val+";";
}


//This function active (or disable stylesheet). First it disable, or enable the stylesheet with the title titleStyleToDisable and store in the cookie if the titleStyle is use or not. Next he enable (or disable) the titleStyle.
function activeStylesheet(titleStyleToDisable,titleStyle)
{
	var i, oneLink;
	var disable;
	for( i = 0; (oneLink = document.getElementsByTagName("link")[i]); i++)
	{
		if(oneLink.getAttribute("rel").indexOf("stylesheet") !=-1 )
		{	
			if (oneLink.getAttribute("title") && oneLink.getAttribute("title") == titleStyleToDisable) //We disable or enable the stylesheet titleStyleToDisable
			{
				if(oneLink.disabled){
					oneLink.disabled = false;
					setCookie(titleStyle,"false");
					disable = -1;
				}
				else{
					oneLink.disabled = true;
					setCookie(titleStyle,"true");
					 disable = 0;
				}
			}
		}
	}
	for( i = 0; (oneLink = document.getElementsByTagName("link")[i]); i++)
	{
		if(oneLink.getAttribute("title") && (oneLink.getAttribute("rel").indexOf("stylesheet") !=-1 ))
		{	
			if (oneLink.getAttribute("title") == titleStyle) { //We search the titleStyle and enable the stylesheet if the default is disable and reverse
				oneLink.disabled = true;
				if (disable == 0){
					oneLink.disabled = false;
					
				}else{
					oneLink.disabled = true;
				}
			}
		}
	}
}

//Function for change the icon (if the text if small, medium and big and if there is contrast or not
function changeIcon(nbicon)
{
	if (nbicon==1)
	{
		document.getElementById("smallA").src="tpls/images/le/A1_sel.gif";
		document.getElementById("mediumA").src="tpls/images/le/A2.gif";
		document.getElementById("bigA").src="tpls/images/le/A3.gif";
	}else if (nbicon==2)
	{
		document.getElementById("smallA").src="tpls/images/le/A1.gif";
		document.getElementById("mediumA").src="tpls/images/le/A2_sel.gif";
		document.getElementById("bigA").src="tpls/images/le/A3.gif";
	}else if (nbicon==3)
	{
		document.getElementById("smallA").src="tpls/images/le/A1.gif";
		document.getElementById("mediumA").src="tpls/images/le/A2.gif";
		document.getElementById("bigA").src="tpls/images/le/A3_sel.gif";
	}else if(nbicon==4)
	{
		if (document.getElementById("BWA").src.indexOf("tpls/images/le/A4.gif")!=-1)
		{
			document.getElementById("BWA").src="tpls/images/le/A4_sel.gif";
		}else{
			document.getElementById("BWA").src="tpls/images/le/A4.gif";
		}
	}
}

//Function who change the size of the text and call the function for change the icon
function small()
{
	setCookie("fontSize","1");
	document.body.style.fontSize="1em";
	changeIcon(1);
}
function medium()
{
	setCookie("fontSize","2");
	document.body.style.fontSize="1.15em";
	changeIcon(2);
}
function large()
{
	setCookie("fontSize","3");
	document.body.style.fontSize="1.25em";
	changeIcon(3);
}

//Load the contrast stylesheet (call the good function) and change the Icon
function contrast()
{
	activeStylesheet("style","contrast");
	changeIcon(4);
}


//Function for the load of the page, it's lunch the textmode or the contrast if necessary and change the size of the font
function getCookie()
{
	var allcookies = document.cookie;
	if (allcookies =="") return;
	
	//Check the contrast
	if (allcookies.indexOf('contrast=true') != -1){
		activeStylesheet("style","contrast");
	}
	
	//Now change the size of the font
	if (allcookies.indexOf('fontSize=2')!= -1)
	{
		document.body.style.fontSize="1.15em";
	}else{
		if (allcookies.indexOf('fontSize=3')!= -1)
		{
			document.body.style.fontSize="1.25em";
		}	
	}
	return 0;
}

//Change the icon (and the links for text mode) when the page is loaded, this is seperate of the getCookie because getCookie is call when there is nothing load on the page, we have to wait the load of the icon for change them
function getCookieIcon()
{
	var allcookies = document.cookie;
	if (allcookies.indexOf('fontSize=2')!= -1)
	{
		changeIcon(2);
	}else{
		if (allcookies.indexOf('fontSize=3')!= -1)
		{
			changeIcon(3);
		}else{
			changeIcon(1);
		}
	}
	if (allcookies.indexOf('contrast=true')!= -1)
	{
		changeIcon(4);
	}
}



/** Mouse out and over for image **/

//Go button for the search
function mOversubsearch(){
	e = document.getElementById('subsearch');
	e.getElementsByTagName("img")[0].src="tpls/images/le/search_on.gif";
}
function mOutsubsearch(){
	e = document.getElementById('subsearch');
	e.getElementsByTagName("img")[0].src="tpls/images/le/search_off.gif";
}


//Erase the input of the search
function eraseSearch()
{
	search = document.getElementById('search');
	if (search.value=="search")
		search.value="";
}

