// Check if browser does support dynamic content and dhtml
var isNS4 = (document.layers) ? 1 : 0;           // the old Netscape 4
var isIE4 = (document.all) ? 1 : 0;              // browser wich uses document.all (IE4+)
//----------------

function popUp(page,largeur,hauteur,options) {
var top=(screen.height-hauteur)/2;

var left=(screen.width-largeur)/2;

window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/***************** AFFICHER/MASQUER DIV *************************/

function afficher(idDiv){ 
masquer();

	if(document.getElementById(idDiv).style.display == "none") 
	{ 
		document.getElementById(idDiv).style.display = "block"; 
		} else { 
		document.getElementById(idDiv).style.display = "none"; 
		} 
	} 

function masquer(idDiv){
	document.getElementById('corylus').style.display = "none";


}

function afficher1(idDiv){ 
masquer1();

	if(document.getElementById(idDiv).style.display == "none") 
	{ 
		document.getElementById(idDiv).style.display = "block"; 
		} else { 
		document.getElementById(idDiv).style.display = "none"; 
		} 
	} 

function masquer1(idDiv){
	document.getElementById('div-mtc').style.display = "none";


}

function afficher2(idDiv){
masquer3();

	if(document.getElementById(idDiv).style.display == "block")
	{
		document.getElementById(idDiv).style.display = "none";
		} else {
		document.getElementById(idDiv).style.display = "block";
		}

	}


function masquer3(idDiv){
	document.getElementById('stage1').style.display = "none";
	document.getElementById('stage2').style.display = "none";
		document.getElementById('stage3').style.display = "none";

}

function afficher3(idDiv){
masquer4();

	if(document.getElementById(idDiv).style.display == "block")
	{
		document.getElementById(idDiv).style.display = "none";
		} else {
		document.getElementById(idDiv).style.display = "block";
		}

	}


function masquer4(idDiv){
	document.getElementById('choix1').style.display = "none";
	document.getElementById('choix2').style.display = "none";
	document.getElementById('choix3').style.display = "none";

}



function afficher5(idDiv){ 
masquer5();

	if(document.getElementById(idDiv).style.display == "none") 
	{ 
		document.getElementById(idDiv).style.display = "block"; 
		} else { 
		document.getElementById(idDiv).style.display = "none"; 
		} 
	} 

function masquer5(idDiv){
	document.getElementById('div-matiaoli-def').style.display = "none";


}



/*************************************************/
function visibilite(thingId){
	masquer2();
var targetElement;
targetElement = document.getElementById(thingId) ;
if (targetElement.style.display == "none")
{
targetElement.style.display = "" ;
}
}

function masquer2(thingId){
document.getElementById(thingId).style.display = "none";
}

/*************************************************/
// Deb CBD : gestion des inscriptions en ligne   //
/*************************************************/

// Renvoi la valeur d'une liste de bouton radio "strObjName" (Ã  partir de son NOM)
function MTradioValue (strObjName)
{
	objRadio = document.getElementsByName(strObjName);
	
	if ((objRadio == null) || (objRadio == "undefined"))
	{
		// objet non trouvÃ©
		return "";
	}
	
	for (intIdx=0; intIdx < objRadio.length; intIdx++)
	{
		if (eval("objRadio[intIdx].checked"))
		{
			// objet cochÃ© trouvÃ© => retourne sa valeur et quitte
			return eval("objRadio[intIdx].value");
		}
	}

	// aucun bouton radio sÃ©lectionnÃ©
	if (isIE4) MTradioValue = "";		// BUG IE6.xp.sp1 ! (undefined)
	return "";
}	

// Test si un groupe de case Ã  cocher "strObjName*" (dÃ©but du NOM) a au moins une de ses cases sÃ©lectionnÃ©e : VRAI si cochÃ©, FAUX sinon
function MTcheckboxChecked (strObjName)
{
	objInput = document.getElementsByTagName("input");
	
	if ((objInput == null) || (objInput == "undefined"))
	{
		// objets non trouvÃ©s
		return false;
	}
	
	for (intIdx=0; intIdx < objInput.length; intIdx++)
	{
		// L'objet est-il une case Ã  cochÃ©e dont le nom commence par "strObjName" ?
		if ((objInput[intIdx].type == "checkbox") && (objInput[intIdx].name.indexOf(strObjName) >= 0))
		{
			if (eval("objInput[intIdx].checked"))
			{
				// un objet cochÃ© trouvÃ© => retourne VRAI et quitte
				return true;
			}
		}
	}

	// aucune case Ã  cocher sÃ©lectionnÃ©e
	return false;
}	

// Gestion erreur : affiche un message d'erreur "strMsgErr" (dans un objet span, ou alert si span non trouvÃ©)
// Active un objet si dÃ©fini "strObjAActiver" (ID)
// Affecte Ã©ventuellement une nouvelle valeur "strNewValue" Ã  l'objet
function MTErreur(strMsgErr,strObjAActiver,strNewValue)
{
	//alert ("MTErreur('"+strMsgErr+"','"+strObjAActiver+"','"+strNewValue+"')");

	objErr = document.getElementById("spErreur");
	if ((objErr == null) || (objErr == "undefined"))
	{
		if ((strMsgErr != null) && (strMsgErr != "undefined") && (strMsgErr != ""))
		{
			alert (strMsgErr);
		}
	}
	else
		objErr.innerHTML = strMsgErr;

	if ((strObjAActiver != null) && (strObjAActiver != "undefined") && (strObjAActiver != ""))
	{
		objAActiver = document.getElementById(strObjAActiver);
		// objet trouvÃ© ?
		if ((objAActiver != null) && (objAActiver != "undefined"))
		{
			objAActiver.className = "objErreur";
			objAActiver.onBlur = "this.className='objPasErreur';";
			
			// valeur Ã  redÃ©finir ?
			if ((strNewValue != null) && (strNewValue != "undefined"))
			{
				objAActiver.value = strNewValue;
			}

			// l'objet gÃ¨re la mÃ©thode focus() ?
			obj_CanFocus = eval("objAActiver.focus");
			if ((obj_CanFocus != null) && (obj_CanFocus != "") && (obj_CanFocus != "undefined"))
			{
				// donne le focus si possible
				objAActiver.focus();
			}
			// l'objet gÃ¨re la mÃ©thode select() ?
			obj_CanSelect = eval("objAActiver.select");
			if ((obj_CanSelect != null) && (obj_CanSelect != "") && (obj_CanSelect != "undefined"))
			{
				// selectionne le contenu si possible
				objAActiver.select();
			}
		}
	}
}

// SÃ©lectionne un item (par sa valeur "strValeur") dans une liste dÃ©roulante "strListe" de type ComboBox (ID)
function MTselectListe(strListe,strValeur)
{
	if ((strListe == null) || (strValeur == null) || (strListe == ""))
		return;
	objListe = document.getElementById(strListe);

	if ((objListe == null) || (objListe == "undefined") || (typeof(objListe) != 'object') || (objListe.type != 'select-one'))
		return ;;

	for (intIdx=0; intIdx < objListe.options.length; intIdx++)
	{
		if (objListe.options[intIdx].value == strValeur)
		{
			// ElÃ©ment trouvÃ© => sÃ©lection puis quitte
			objListe.selectedIndex = intIdx;
			return;
		}
	}
}

// Supprime les espace de gauche d'une chaÃ®ne de caractÃ¨res
function MTlTrim(strChaine)
{
	if ((strChaine == null) || (strChaine == ""))
		return strChaine;

	var rexp = new RegExp(/^\s+/);
	return strChaine.replace(rexp, "");
}

// Supprime les espace de droite d'une chaÃ®ne de caractÃ¨res
function MTrTrim(strChaine)
{
	if ((strChaine == null) || (strChaine == ""))
		return strChaine;

	var rexp = new RegExp(/\s+$/);
	return strChaine.replace(rexp, "");
}

// Supprime les espace de gauche et de droite d'une chaÃ®ne de caractÃ¨res
function MTtrim(strChaine)
{
	if ((strChaine == null) || (strChaine == ""))
		return strChaine;

	return MTlTrim(MTrTrim(strChaine));
}

// Test si une date est au format J(J)/(M)M/(AA)AA, renvoi VRAI si OK, FAUX sinon
function MTvalideDate(strDate)
{
	//var rexp = new RegExp("^\d\d?\/\d\d?\/\d\d(\d\d)?$");
	var rexp = new RegExp(/^\d{1,2}\/\d{1,2}\/(\d\d){1,2}$/);
	return rexp.test(strDate);
}

// Test si une chaine saisie est un entier borné correct, renvoi VRAI si OK, FAUX sinon
function MTvalideInt(strEntier, intValMin, intValMax)
{
	intEntier = parseInt(strEntier);
	strVerifParse = new String(intEntier);
	
	if (strVerifParse != strEntier)
		return false;
	
	if (intEntier < intValMin)
		return false;

	if (intEntier > intValMax)
		return false;

	return true;
}

// Test rapide si une adresse e-mail est au format valide (cf .JS Firefox 3.0)
function MTvalideEmail(strEmail)
{
	var rexp = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	return rexp.test(strEmail);
}

// Soumet un formulaire "strForm" (ID/name) vers une URL donnÃ©e
function MTsubmit(strForm,strURL)
{
	var objForm;
	
	// Recherche le formulaire par l'ID
	objForm = document.getElementById(strForm);
	if ((objForm != null) || (objForm != "undefined"))
	{
		// trouvÃ© => dÃ©fini le action + submit
		objForm.action = strURL;
		objForm.submit();
	}
	else
	{
		// Recherche le formulaire par le NAME
		objForm = document.getElementsByName(strForm);
		if ((objForm != null) || (objForm != "undefined"))
		{
			// trouvÃ© => dÃ©fini le action + submit
			objForm[0].action = strURL;
			objForm[0].submit();
		}
	}
		
}

// Se rend a une URL apres message de confirmation
function MTvalideGo(strMessage,strURL)
{
	var strURLGo = '';

	if (confirm(strMessage))
	{
		strURLGo = strURL;
	}
	else
	{
		strURLGo = '#';
	}
	
	document.location.href = strURLGo;
}

/*************************************************/
// Fin CBD : gestion des inscriptions en ligne   //
/*************************************************/
