// JavaScript Document
//display features
//show if hidded and hide if shown 
function toggle(id){
	var el = document.getElementById(id);
	if (el.visible == true){
		el.style.display = "none";
		el.visible = false;
	}else{
		el.style.display = "block";
		el.visible = true;
	}
}
//show and hide last element
var lastid = "";
function showHide(id){
	//hide old id
	if ((lastid != "") && (lastid != id)) {
		document.getElementById(lastid).style.display = "none";
	}
	//show and hide the selected id
	if (document.getElementById(id).style.display == "block"){
		document.getElementById(id).style.display="none";
		lastid = id;
	}else {
		document.getElementById(id).style.display="block";
		lastid = id;
	}
}
//show or hide an element
function show(id, visible){
	var el = document.getElementById(id);
	if (visible){
		el.style.display="block";
	}else{
		el.style.display="none";
	}
}
//get url param 
function getVar (nomVariable)
 {
	 var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
	 if (infos.indexOf("#")!=-1)
		 infos = infos.substring(0,infos.indexOf("#"))+"&"
	 var variable=0
	 {
		 nomVariable = nomVariable + "="
		 var taille = nomVariable.length
		 if (infos.indexOf(nomVariable)!=-1)
			 variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
	 }
	 return variable
}
//form features
//fille a input field
function fill(el,val){
	document.getElementById(el).value = val;
}
//return the value of an input field
function getValue(el){
	return(document.getElementById(el).value);
}
//cookie features
//return a cookie
function readCookie(name){
	var allCookies = document.cookie;
	var startPos = allCookies.indexOf(name+"=") + name.length + 1; //look for start position of the value
	var endPos = allCookies.indexOf(";",startPos) ; //look for end position of the value
	if ((startPos <= name.length) | (endPos <= -1)){//if cookie doesnt exist
		return(null);
	}
	return (unescape(allCookies.slice(startPos,endPos)));
}
//set a cookie
function setCookie(name, value){
	if (value!=""){
	document.cookie=name + "=" + escape(value);
	}
}
//popup function
//open window with div content
function openDivPopUp(id,width,height){
	var content = "<html><head>"+document.getElementsByTagName('head').item(0).innerHTML+"</head><body><div>"+document.getElementById(id).innerHTML+"</div></body></html>";
	//alert(content);
	var popup = window.open('index.html','selector','width='+width+',height='+height);
	popup.document.open();
	popup.document.write(content);
	popup.document.close();
}
//redirect  to a specify url after a delay in millisec
function redirect(url, delay){
	setTimeout("window.location='"+url+"'",delay);
}


//specific function
function printDivPopUp(id,width,height){
	var content = "<html><head>"+document.getElementsByTagName('head').item(0).innerHTML+"</head><body><div>"+document.getElementById(id).innerHTML+"</div><script language='javascript'>window.print();</script></body></html>";
	//alert(content);
	var popup = window.open('index.html','selector','width='+width+',height='+height);
	popup.document.open();
	popup.document.write(content);
	popup.document.close();
}


var currentmonth = "";
	function pick(month){
			var menuMonth = "menu"+month;
			var currentMenuMonth = "menu"+currentmonth;
			//hide old id
			if ((currentmonth != "") && (currentmonth != month)) {
				document.getElementById(currentmonth).style.display = "none";
				document.getElementById(currentMenuMonth).className = "inactivemmbtn";
			}
			//show and hide the selected id
			if (document.getElementById(month).style.display == "block"){
				document.getElementById(month).style.display="none";
				document.getElementById(currentMenuMonth).className = "inactivemmbtn";
				currentmonth = month;
			} else {
				document.getElementById(month).style.display="block";
				document.getElementById(menuMonth).className = "activemmbtn";
				currentmonth = month;
			}
	}
	// Check que la valeur du champ myid est inférieur à max, Sinon la valeur de myid devient max
function checkInput2(checked,myid,max){
	var test = new Number(checked);
	validCharacters = /\d/;
	nonDigit = /\D/;
	startReplace="none";
	for(i=0;i<checked.length;i++){
		if(!validCharacters.test(checked.charAt(i))){
			startReplace = i;
			break;
		}
	}
	if ((startReplace=="none")&&(test<=max)){
		// si le caractère est valide, on affiche checked
		document.getElementById(myid).value = checked;
	}else if(startReplace=="none"){
		document.getElementById(myid).value = max;
	}else {
		document.getElementById(myid).value = checked.substring(0,startReplace);
	}
	
}