/************************************************************************************************/
/*	Duch  [www.icilalune.com]	gregory@icilalune.com 					*/
/*	Nabab [ITSys] 	                nabab@gmx.fr						*/
/*  Modified by Joce (joce@mesdiscussions.net)                              */
/************************************************************************************************/

var style=new Array('g','/g','i','/i','s','/s','email','/email','lien=','/lien','img','/img','quote','/quote','fixed','/fixed','cpp','/cpp','url','/url');
var stockage=new Array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
lien="http://";

function montrer_spoiler(value) {
	var actual=document.getElementById(value).style.visibility;
	if (actual=='visible') document.getElementById(value).style.visibility='hidden';
	else document.getElementById(value).style.visibility='visible';
}
function aff_partie_sondage() {
	if (document.getElementById('sondage').style.display=='block') {
		document.getElementById('sondage').style.display='none';
	} else {
		document.getElementById('sondage').style.display='block';
	}
}
function apercevoir() {
	document.getElementById('apercu').style.display=(document.all && !opera)?'block':'table-row';
	document.getElementById('apercu_contenu').value=document.hop.contenu.value;
	document.getElementById('apercu_smiley').value=document.hop.smiley.checked?'1':'0';
	document.getElementById('apercu_form').submit();
}
function openChild(file,window) {
	childWindow=open(file,window,'width=800,height=600');
	if (childWindow.opener ==null) childWindow.opener=self;
}
function passfocus() {
	document.getElementById('passf').style.display=(document.all && !opera)?'block':'table-row';
}

function MM_findObj(n, d) { //v3.0
	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); return x;
}

function storeCaret (textEl) {
	if (textEl.createTextRange) textEl.caretPos=document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos=textEl.caretPos;
		caretPos.text=caretPos.text.charAt(caretPos.text.length - 1)==' ' ? text + ' ' : text;
	}
}

function insertInCaret (textEl, text, text2) {
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos=textEl.caretPos;
		selectedtext=caretPos.text;
		caretPos.text=	caretPos.text.charAt(caretPos.text.length - 1)=='' ? text + '' : text;
		caretPos.text=caretPos.text + selectedtext + text2;
	}
}

function palette(id,vernav) {
	if (vernav>=4) {
		MM_findObj('contenu').focus();
		if (MM_findObj('contenu').createTextRange && MM_findObj('contenu').caretPos) {
			var caretPos=MM_findObj('contenu').caretPos;
			if (caretPos.text.length>0) {
				if (id !=8)insertInCaret(MM_findObj('contenu'),"["+style[id]+"]","["+style[id+1]+"]");
				else {
					geturl=prompt("veuillez entrer l'url",'http://');
					insertInCaret(MM_findObj('contenu'),"["+style[id]+geturl+"]","["+style[id+1]+"]");
				}
			} else {
				if ( (countbalise('['+style[id],'contenu')+countbalise('['+style[id+1],'contenu'))%2 ==0) {
					if (id !=8) insertAtCaret(MM_findObj('contenu'),"["+style[id]+"]");
					else {
						geturl=prompt("veuillez entrer l'url",'http://');
						insertAtCaret(MM_findObj('contenu'),"["+style[id]+geturl+"]");
					}
				} else {
					insertAtCaret(MM_findObj('contenu'),"["+style[id+1]+"]");
				}
				MM_findObj('contenu').focus()
			}
		}
	} else {
		if (stockage[id]=='0') {
			var temp=document.hop.contenu.value;
			document.hop.contenu.value=temp+' '+'['+style[id]+']';
			stockage[id]='1';
		} else {
			var temp=document.hop.contenu.value;
			document.hop.contenu.value=temp+'['+style[id+1]+']'+' ';
			stockage[id]='0';
		}
	}
}

function countbalise(b,ch) {
	count=0;
	pos=MM_findObj(ch).value.indexOf(b);
	while ( pos !=-1 ){
		count++;
		pos=MM_findObj(ch).value.indexOf(b,pos+1);
	}
	return count;
}

function insertElt(MyString,vernav) {
	if (vernav>=4) {
		MM_findObj('contenu').focus();
		if ((MM_findObj('contenu').createTextRange) && (MM_findObj('contenu').caretPos)) {
			var caretPos=MM_findObj('contenu').caretPos;
			if (caretPos.text.length>0) insertInCaret(MM_findObj('contenu'),MyString,"");
			else insertAtCaret(MM_findObj('contenu'),MyString);
		}
	} else {
		var temp=document.hop.contenu.value;
		document.hop.contenu.value=temp+MyString;
	}
}

function insertTag(MyString,vernav) {
	if (vernav>=4) {
		MM_findObj('contenu').focus();
		if (MM_findObj('contenu').createTextRange && MM_findObj('contenu').caretPos) {
			var caretPos=MM_findObj('contenu').caretPos;
			if (caretPos.text.length>0) insertInCaret(MM_findObj('contenu'),"["+MyString+"]","[/"+MyString+"]");
			else {
				if ( (countbalise('['+MyString,'contenu')+countbalise('[/'+MyString,'contenu'))%2 ==0) insertAtCaret(MM_findObj('contenu'),"["+MyString+"]");
				else insertAtCaret(MM_findObj('contenu'),"[/"+MyString+"]");
				MM_findObj('contenu').focus();
			}
		}
	} else {
		if (stockage[12]=='0') {
			var temp=document.hop.contenu.value;
			document.hop.contenu.value=temp+' '+'['+MyString+']';
			stockage[12]='1';
		} else {
			var temp=document.hop.contenu.value;
			document.hop.contenu.value=temp+'[/'+MyString+']'+' ';
			stockage[12]='0';
		}
	}
}


///Color
col0=new Array(255,255,0,255,0,0);
col1=new Array(255,0,255,255,0,0);
col2=new Array(0,0,255,0,0,255);
col3=new Array(0,255,0,0,255,0);

var base_hexa="0123456789ABCDEF";
function dec2Hexa(number) {
	return base_hexa.charAt(Math.floor(number / 16)) + base_hexa.charAt(number % 16);
}

function RGB2Hexa(TR,TG,TB) {
	return "#" + dec2Hexa(TR) + dec2Hexa(TG) + dec2Hexa(TB);
}

function lightCase(MyObject) {
	document.getElementById('ColorUsed').bgColor=document.getElementById(MyObject).bgColor;
	document.getElementById('ColorUsedMem').value=document.getElementById(MyObject).bgColor;

}

function highlightCase(MyObject) {
	document.getElementById('ColorUsed').bgColor=document.getElementById(MyObject).bgColor;
}

function backlightCase(MyObject) {
	document.getElementById('ColorUsed').bgColor=document.getElementById('ColorUsedMem').value;
}

function rgb(dm,ta,index,img,explication) {
	fm=dm + 18;
	for (i=dm;i<fm+1;i++) {
		r=Math.floor(ta[0] + (i-dm)*(ta[1]-ta[0])/(fm-dm));
		g=Math.floor(ta[2] + (i-dm)*(ta[3]-ta[2])/(fm-dm));
		b=Math.floor(ta[4] + (i-dm)*(ta[5]-ta[4])/(fm-dm));
		codehex=dec2Hexa(r) + '' + dec2Hexa(g) + '' + dec2Hexa(b);
		document.write('<td style="cursor:pointer; padding:0px; width:3px" onclick="TAinsert(\'[\'+document.getElementById(\'tableId'+index+'\').bgColor+\']\',\'[/\'+document.getElementById(\'tableId'+index+'\').bgColor+\']\');lightCase(\'tableId'+index+'\');\" onmouseover=\"highlightCase(\'tableId'+index+'\');" onmouseout="backlightCase();" id="tableId'+index+'" bgcolor="'+RGB2Hexa(r,g,b)+'" width="3" height="17"><img title="'+explication+' : [#'+codehex+']text[/#'+codehex+']" src="'+img+'" alt="" width="3" height="17"/></td>\n');
		index++;
	}
}

function rgb2(rte,dm,ta,index,img,explication) {
	fm=dm + 18;
	for (i=dm;i<fm+1;i++) {
		r=Math.floor(ta[0] + (i-dm)*(ta[1]-ta[0])/(fm-dm));
		g=Math.floor(ta[2] + (i-dm)*(ta[3]-ta[2])/(fm-dm));
		b=Math.floor(ta[4] + (i-dm)*(ta[5]-ta[4])/(fm-dm));
		codehex=dec2Hexa(r) + '' + dec2Hexa(g) + '' + dec2Hexa(b);
		document.write('<td style="cursor:pointer; padding:0; margin:0" onclick="FormatText(\''+rte+'\',\'forecolor\',document.getElementById(\'tableId'+index+'\').bgColor);lightCase(\'tableId'+index+'\');" onmouseover=\"highlightCase(\'tableId'+index+'\');" onmouseout="backlightCase();" id="tableId'+index+'" bgcolor="' + RGB2Hexa(r,g,b) + '" width="2" height="15"><img title="'+explication+'" src="'+img+'" alt="" width="2" height="15" style="padding:0px; margin:0px; width:2px; height:15px" /></td>\n');
		index++;
	}
}
/************************************************************/
/*	freekill (freekill.free.fr) 					*/
/************************************************************/

function countInstances(open,closed) {
	var opening=document.hop.contenu.value.split(open);
	var closing=document.hop.contenu.value.split(closed);
	return opening.length + closing.length - 2;
}

function TAinsert(text1,text2) {
	var ta=document.getElementById('contenu');
	if (document.selection) {
		var str=document.selection.createRange().text;
		ta.focus();
		var sel=document.selection.createRange();
		if (text2!="") {
			if (str=="") {
				var instances=countInstances(text1,text2);
				if (instances%2 !=0) sel.text=sel.text + text2;
				else sel.text=sel.text + text1;
			} else sel.text=text1 + sel.text + text2;
		} else sel.text=sel.text + text1;
	} else if (ta.selectionStart || ta.selectionStart ==0) {
		if (ta.selectionEnd > ta.value.length) ta.selectionEnd=ta.value.length;
		var firstPos=ta.selectionStart;
		var secondPos=ta.selectionEnd+text1.length;
		var contenuScrollTop=ta.scrollTop;

		ta.value=ta.value.slice(0,firstPos)+text1+ta.value.slice(firstPos);
		ta.value=ta.value.slice(0,secondPos)+text2+ta.value.slice(secondPos);

		ta.selectionStart=firstPos+text1.length;
		ta.selectionEnd=secondPos;
		ta.focus();
		ta.scrollTop=contenuScrollTop;
	} else { // Opera
		var sel=document.hop.contenu;
		var instances=countInstances(text1,text2);
		if (instances%2 !=0 && text2 !="") sel.value=sel.value + text2;
		else sel.value=sel.value + text1;
	}
}


