/**
 * Latz v0.35 beta
 * http://latz.laligatz.com
 * Dernière modification le : 20/11/2005
 *
 * @author Alexis MINEAUD <laligatz@laligatz.com>
 * @copyright Copyright © 2005, Alexis MINEAUD
 * @license xxx
*/

/////////////////////
// Insertions balises [g][/g] etc...
/////////////////////
function addText(form, instext) {
    var mess = form.texte;
	//IE support
	if (document.selection) {
		mess.focus();
		sel = document.selection.createRange();
		sel.text = instext;
		form.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (mess.selectionStart || mess.selectionStart == "0") {
		var startPos = mess.selectionStart;
		var endPos = mess.selectionEnd;
		var chaine = mess.value;

		mess.value = chaine.substring(0, startPos) + instext + chaine.substring(endPos, chaine.length);

		mess.selectionStart = startPos + instext.length;
		mess.selectionEnd = endPos + instext.length;
		mess.focus();
	} else {
		mess.value += instext;
		mess.focus();
	}
}


/////////////////////
// Confirmations
/////////////////////
function confirmation() {
	x = window.confirm("Etes-vous sûr(e) ?");
	return x;
}

/////////////////////
// Confirmations avancée
/////////////////////
function confirmSuppression(element,url){
	resultat = confirm('confirmez la suppression : '+element);
	if(resultat=="1") {
		window.location.replace(url)
	}
}

/////////////////////
// Lien onclick
/////////////////////
function goUrl(url){
	window.location.replace(url)
}

//////////////////////
// Popup
//////////////////////
function popup(page, largeur, hauteur, options) {
	var top=(screen.height-hauteur)/5;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}


//////////////////////
// Popup centré
//////////////////////
function popupCentre(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);
}


/////////////////////
// Sélect automatique
/////////////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/////////////////////
// Passe un élément en display : none à la volée sur un lien
/////////////////////
props_aff=new Array;
function aff_masq(id) {
	if(document.getElementById(id).style.display!='none'){
		props_aff[id]=document.getElementById(id).style.display;
		document.getElementById(id).style.display='none';
	}else{
		if(props_aff[id] & props_aff[id]!='none')
			document.getElementById(id).style.display=props_aff[id];
		else
			document.getElementById(id).style.display='block';
	}
}


/**
 * Change le paramètre style d'une balise html.
 * Exemple : onClick="changeVisible(mon_bouton_radio.checked, 'name_div', 'block', 'none');"
 */
function changeVisible(input, id, select, nonselect) {
	if (input) {
		element = findObj(id);
		if (element.style.display != select)  element.style.display = select;
	} else {
		element = findObj(id);
		if (element.style.display != nonselect)  element.style.display = nonselect;
	}
}


/**
 * Trouve un objet dans la page.
 */
var memo_obj = new Array();
function findObj(n) { 
	var p,i,x;

	// Voir si on n'a pas deja memoriser cet element		
	if (memo_obj[n]) {
		return memo_obj[n];
	}
	
	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 = findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n); 
	
	// Memoriser l'element
	memo_obj[n] = x;
	
	return x;
}

/**
 * Roll over sur les images
 */
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];
  	}
  }
}

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];
  	  }
  	}
  }
}


/**
 * Association d'éléments dans une liste
 */
function assoc(source, destination) {
	if(source.selectedIndex != -1) {
		//nouvel objet
		var o = new Option(source[source.selectedIndex].innerHTML, source[source.selectedIndex].value);
		
		//insertion de l'élément dans le second select
		destination.options[destination.options.length] = o;
		//document.getElementById('source2').options[document.form.source2.options.length] = o;
		
		//supression de l'élément dans le premier select
		source.options[source.options.selectedIndex] = null;
	}
}

function dissoc(source, destination) {
	if(destination.selectedIndex != -1) {
		//nouvel objet
		var o = new Option(destination[destination.selectedIndex].innerHTML, destination[destination.selectedIndex].value);
		
		//insertion de l'élément dans le premier select
		source.options[source.options.length] = o;
		
		//supression de l'élément dans le second select
		destination.options[destination.options.selectedIndex] = null;
	}
}

function selectAssociations(destination) {
	for(var i=0; i<destination.options.length; i++) {
		destination[i].selected = true;
	}
}

props_aff=new Array;
function aff_masq(id) {
	if(document.getElementById(id).style.display!='none'){
		props_aff[id]=document.getElementById(id).style.display;
		document.getElementById(id).style.display='none';
	}else{
		if(props_aff[id] & props_aff[id]!='none')
			document.getElementById(id).style.display=props_aff[id];
		else
			document.getElementById(id).style.display='block';
	}
}


/**
 * Affichage du pop-up mentions légales
 */
function affMentions(){
	var fen = window.open("/mentions.html","Mentions","width=700,height=500,menubar=yes,status=no,resizable=no,location=no,toolbar=no,scrollbars=yes");
	fen.focus();
}