function OCA(destination) {
	if (document.getElementById(destination).style.display == 'none')
 	 { OA(destination); }
	else
	 { CA(destination); }
 }
function is_mail(champs){
	var pattern = /^[\w\-]+(\.[\w\-]+)*@[\w\-]+(\.[\w\-]+)*\.[\w\-]{2,}$/;
	answer=pattern.test(champs);
	return answer;
}
function Vide(dest) {
	document.getElementById(dest).innerHTML = '';
 }
function Centrer(destination, largeur, hauteur)
 {
	var container = document.documentElement;
	var containerHeight;
	var scrollposition;
	if (container.innerWidth) {
		containerHeight = container.innerHeight;
	}
	else {
		containerHeight = container.clientHeight;
	}	
	if (document.documentElement.scrollTop > 0)
	 { scrollposition = document.documentElement.scrollTop; }
	else if (document.body.scrollTop > 0)
	 { scrollposition = document.body.scrollTop; }
	else 
	{ scrollposition = 0; }

	if (hauteur == 0) { var dh = parent.document.getElementById(destination).offsetHeight; } else { var dh = hauteur; }
	if (largeur == 0) { var dw = parent.document.getElementById(destination).offsetWidth - 2; } else { var dw = largeur; }
	var x = (document.body.clientWidth - dw) / 2;
	var y = ((containerHeight - dh) / 2)+scrollposition;
	document.getElementById(destination).style.top = y+'px';
	document.getElementById(destination).style.left = x+'px';
 }
function OA(destination){
	if (document.getElementById(destination)) {
		document.getElementById(destination).style.display=''; 
	 }
	else {
		parent.document.getElementById(destination).style.display='';
	 }
}
function CA(destination){
	if (document.getElementById(destination)) {
		document.getElementById(destination).style.display='none'; 
	 }
	else 
	 {
		parent.document.getElementById(destination).style.display='none';
	 }
}
function etirefond()
 {
	var container = document.documentElement;
	var BodyHeight;
	if (document.body.clientHeight) {
		BodyHeight = document.body.clientHeight;
	}
	else {
		BodyHeight = document.documentElement.clientHeight;
	}	
	
	var ClientHeight = 0;
	
	if(document.documentElement && document.documentElement.clientHeight) {
		ClientHeight = document.documentElement.clientHeight;
	}
	
	if(BodyHeight < ClientHeight) BodyHeight = ClientHeight;
	
	document.getElementById('popupfond').style.height = BodyHeight+'px';
 }
function trim(myString) 
{ 
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'') 
} 
function divpopup(options){
	var title = (options.title != null) ? options.title : '';
	var cont_div = (options.cont != null) ? document.getElementById(options.cont) : null;	
	var cont = (cont_div) ? cont_div.innerHTML : '';
	
	var pop_style = (options.type != null && options.type == 'large') ? 'poplarg' : 'poplayer';
	
	var html = '<div class="'+pop_style+'">'+
					'<div class="haut"></div>'+
					'<div class="cent">'+
						'<div class="cont">'+
							'<div class="titre">'+
								'<a style="float: right;" href="javascript:Vide(\'layeralert\');CA(\'popupfond\');" class="btclose"><span>fermer</span></a>'+
								'<h2>'+title+'</h2>'+
							'</div>'+
							cont+
						'</div>'+
					'</div>'+
					'<div class="bas"></div>'+					
				'</div>';
				
	document.getElementById('layeralert').innerHTML = html;
	
	var centrer_X = (options.type != null && options.type == 'large') ? 800 : 500;
	Centrer('layeralert',centrer_X,300);
	OA('popupfond');
	etirefond('popupfond');	
}
function agenda_nav(mode, lmr_ID)
{
	if (mode == 'next')
	 { 
		document.getElementById('evenement_'+document.getElementById('encours_cal_'+lmr_ID).value).style.display='none';
		document.getElementById('encours_cal_'+lmr_ID).value = parseInt(document.getElementById('encours_cal_'+lmr_ID).value) + 1;
	 }
	else
	 { 
		document.getElementById('evenement_'+(parseInt(document.getElementById('encours_cal_'+lmr_ID).value) - 1)).style.display='';
		document.getElementById('encours_cal_'+lmr_ID).value = parseInt(document.getElementById('encours_cal_'+lmr_ID).value) - 1;
	 }

	if (document.getElementById('evenement_'+(parseInt(document.getElementById('encours_cal_'+lmr_ID).value) - 1)))
	 { document.getElementById('prev_'+lmr_ID).style.display=''; }
	else
	 { document.getElementById('prev_'+lmr_ID).style.display='none'; }

	if (document.getElementById('evenement_'+(parseInt(document.getElementById('encours_cal_'+lmr_ID).value) + 1)))
	 { document.getElementById('next_'+lmr_ID).style.display=''; }
	else
	 { document.getElementById('next_'+lmr_ID).style.display='none'; }
}
function verifJC()
{
	CA('erreurLogin');
	CA('erreurEmail');
	CA('erreurFichier');
	var erreur = 0;
	if (document.getElementById('nickname').value.length == 0)
	{
		OA('erreurLogin');
		CA('formchargement');
		OA('formdiv');
		erreur = 1;
	}
	if (!is_mail(document.getElementById('email').value))
	{
		OA('erreurEmail');
		CA('formchargement');
		OA('formdiv');	
		erreur = 1;
	}
	if (document.getElementById('fichier1').value.length == 0)
	{
		OA('erreurFichier'); 
		CA('formchargement');
		OA('formdiv');
		erreur = 1;
	}
	if (document.getElementById('fichier2').value.length == 0)
	{ 
		OA('erreurFichier');
		CA('formchargement');
		OA('formdiv');
		erreur = 1;
	}
	if (document.getElementById('fichier3').value.length == 0)
	{ 
		OA('erreurFichier');
		CA('formchargement');
		OA('formdiv');
		erreur = 1;
	}
	if (document.getElementById('fichier4').value.length == 0)
	{ 
		OA('erreurFichier');
		CA('formchargement');
		OA('formdiv');
		erreur = 1;
	}
	if (document.getElementById('fichier5').value.length == 0)
	{ 
		OA('erreurFichier');
		CA('formchargement');
		OA('formdiv');
		erreur = 1;
	}

	
	if (erreur == 1)
	{ return false; }
}
function nextgal(lmrID, action) {
	div = (parseInt(parent.document.getElementById('encours_'+lmrID).value) * 4);
	if (parent.document.getElementById('elem_'+(div + 0)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 0)+'_'+lmrID).style.display = 'none'; }
	if (parent.document.getElementById('elem_'+(div + 1)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 1)+'_'+lmrID).style.display = 'none'; }
	if (parent.document.getElementById('elem_'+(div + 2)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 2)+'_'+lmrID).style.display = 'none'; }
	if (parent.document.getElementById('elem_'+(div + 3)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 3)+'_'+lmrID).style.display = 'none'; }


	div = ((parseInt(parent.document.getElementById('encours_'+lmrID).value) + action) * 4);
	if (parent.document.getElementById('elem_'+(div + 0)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 0)+'_'+lmrID).style.display = ''; }
	if (parent.document.getElementById('elem_'+(div + 1)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 1)+'_'+lmrID).style.display = ''; }
	if (parent.document.getElementById('elem_'+(div + 2)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 2)+'_'+lmrID).style.display = ''; }
	if (parent.document.getElementById('elem_'+(div + 3)+'_'+lmrID))
	 { parent.document.getElementById('elem_'+(div + 3)+'_'+lmrID).style.display = ''; }

	parent.document.getElementById('encours_'+lmrID).value = parseInt(parent.document.getElementById('encours_'+lmrID).value) + action;

	if (parent.document.getElementById('encours_'+lmrID).value == 0)
	 { parent.document.getElementById('prev_'+lmrID).style.display = 'none'; }
	else
	 { parent.document.getElementById('prev_'+lmrID).style.display = ''; }

	if (div >= (parseInt(parent.document.getElementById('max_'+lmrID).value) - 4))
	 { parent.document.getElementById('next_'+lmrID).style.display = 'none'; }
	else
	 { parent.document.getElementById('next_'+lmrID).style.display = ''; }
}
