// configuration
var sEmots = "emots"; // id of the container of the emoticons
var sBBbuttons = "buttons"; // id of the container of the bbcode buttons
var sArea = "area_content"; //  id of the textarea
var sFontSize = "fontSize"; // id of the font size option
var sFontColor = "fontColor"; // id of the font color option
// configuration end


// Copyright (c) 2004 Rafael Kukawski - http://rafael.webhelp.pl
D=document,S=[],T=[],C=alert,B=unescape;onload=function(){F=D.getElementById(sArea)}
function bbcode(x,z){(z=s())?A('['+x+']'+z+'[/'+x+']'):R(x)}
function A(x){D.selection?(F.focus(),D.selection.createRange().text=x):(F.selectionStart||F.selectionStart=='0')?F.value=F.value.substring(0,F.selectionStart)+x+F.value.substring(F.selectionEnd,F.value.length):F.value+=x}
function s(){return D.selection?D.selection.createRange().text:F.value.substring(F.selectionEnd||0,F.selectionStart||0)}
function R(x){T[x]?'':T[x]=0;T[x]?CT(x):(S.push(x),T[x]=1,A('['+x+']'),St(x,'*'))}
function St(i,x){D.getElementById(i).value=i+x}Z='%52%4b';function emot(x){A(x)}
function CT(x,a){T[a=S.pop()]=0;A('[/'+a+']');St(a,'');a!=x?CT(x):''}
function CA(e){while(S[0]){A('[/'+(e=S.pop())+']');T[e]=0;St(e,'')}}
function sfc(l,t){A("["+t+"="+l.value+"]"+s()+"[/"+t+"]")}

/******************************************************
author: DAroo, darooo7@interia.pl
do not remove this comment! (nie usuwać tego komentarza!)
******************************************************/

EventUtil.addEventHandler(window, "load", startScript);

function startScript() {
	var oContainer = document.getElementById(sEmots);
	var oImages = oContainer.getElementsByTagName("img");
	var sId = [];
	for(var i = 0; oImages[i]; i++){
		oImages[i].onclick = function() { 
			sId[i] = this.getAttribute("id"); 
			emot(sId[i]); 
		}
		oImages[i].onmouseover = function() { this.style.cursor = "pointer"; }
	}
	var oContainer = document.getElementById(sBBbuttons);
	var oButtons = oContainer.getElementsByTagName("input");
	var sId2 = [];
	for(var i = 0; oButtons[i]; i++){
		oButtons[i].onclick = function() { 
			sId2[i] = this.getAttribute("id"); 
			bbcode(sId2[i]); 
		}		
	}
	oSize = document.getElementById(sFontSize);
	oColor = document.getElementById(sFontColor);
	oSize.onchange = function() { sfc(this, 'size')} 
	oColor.onchange = function() { sfc(this, 'color')} 
};