/**
 * Latz v0.36 béta
 * http://latz.laligatz.com
 *
 * @author Alexis MINEAUD <laligatz@laligatz.com>
 * @copyright Copyright © 2005-2006, 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;
}


//////////////////////
// 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;
}

/**
 * Lien onclick pour les zones
 */
function goUrl(url){
	window.location.replace(url)
}
