//met une liste d'éléments de formulaire en disabled et une autre liste en actif
function toggleDisableEnable(dis, ena) {
	for (i=0;i<dis.length;i++) {
		disableThis(dis[i]);
	}
	for (i=0;i<ena.length;i++) {
		enableThis(ena[i]);
	}
}

function enableThis(id) {
	var obj = document.getElementById(id);
	if ( obj.disabled == true ) {
		obj.disabled = false;
	}
}
function disableThis(id) {
	var obj = document.getElementById(id);
	if ( obj.disabled == false ) {
		obj.disabled = true;
	}
}
//Met un élément en disable true /false
function toggleDisable(id) {
	var obj = document.getElementById(id);
	if ( obj.disabled != true ) {
		obj.disabled = true;
	}
	else {
		obj.disabled = false;
	}
}

function toggle(id) {
	var obj = document.getElementById(id);
	if ( obj.style.display != 'none' ) {
		obj.style.display = 'none';
	}
	else {
		obj.style.display = '';
	}
}

function afficheId(baliseId)
{
	if (document.getElementById && document.getElementById(baliseId) != null)
	{
		document.getElementById(baliseId).style.visibility='visible';
		document.getElementById(baliseId).style.display='block';
	}
}

function cacheId(baliseId)
{
	if (document.getElementById && document.getElementById(baliseId) != null)
	{
		document.getElementById(baliseId).style.visibility='hidden';
		document.getElementById(baliseId).style.display='none';
	}
}
// si JavaScript est disponible, cache le contenu dès le
// chargement de la page. Sans JavaScript, le contenu sera
// affiché.
cacheId('contenu_info');

function apercu(lien)
{
	w = window.open(lien,'apercu','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=640,height=480');
	w.focus();
}

function apercu2(lien, larg, haut)
{
	w = window.open(lien,'apercu','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+larg+',height='+haut);
	w.focus();
}
function apercu3(lien, larg, haut, nom_fenetre)
{
	w = window.open(lien, nom_fenetre,'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+larg+',height='+haut);
	w.focus();
}

function mep(lien)
{
	window.open(lien,'mise en page','toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=600');
}

function check(f, val) {
	if (f.value.length > val)
	{
		alert('Vous avez dépassé les '+ val + ' caractères autorisés: vous avez mis: ' + f.value.length + ' caractères.');
		return(false);
	}
	return(true);
}

/* Efface le contenu pour un input (ex : pour un document)
*/
// function videDocument(laclasse) {
	// var input = $(laclasse);
	// input.value = "";
// }

window.addEvent('domready', function () {
	
	// function videDocument(laclasse) {
		// var input = $(laclasse);
		// input.value = "";
	// }
	
	$$('a.supprelt').addEvent('click', function (){
		var laclasse = this.get('rel');
		$(laclasse).value = "";
	});
	$$('select.supprelt').addEvent('change', function (){
		var laclasse = this.get('rel');
		$(laclasse).value = "";
	});
});

function open_ext() {
	$$('a').each(function(el) {
		if (/externe/.test(el.get('class'))) {
			var title = (el.get('title') != null) ? el.get('title')+' (s\'ouvre dans une nouvelle fenêtre)' : ' (s\'ouvre dans une nouvelle fenêtre)';
			el.set('title', title);
			el.addEvent('click', function(){window.open(this.get('href'));return false;});
		}
	});
}
window.addEvent('domready', open_ext);

function pop(ladate) {
	var myAs = document.getElementsByTagName('a');
	for (var a = 0; a < myAs.length; ++a)
	{
// Si le lien a une classe de type pop
		if (myAs[a].className == 'pop')
		{
// on extrait l'id de la popup à partir du href
			var pop = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
// si la popup existe on l'affiche (display block)
			if (pop)
			{       
				pop.style.display = 'none';
				myAs[a].onclick = function()
				{
					thisPopup = document.getElementById(this.href.substring(this.href.lastIndexOf('#') + 1))
					thisPopup.style.display = (thisPopup.style.display == 'none') ? 'block' : 'none';
					return false;
				};
// on efface la popup en cliquant dessus
				pop.onclick = function()
				{
					this.style.display = 'none';
				};
			}
		}
	}
}
window.onload = pop;
