var imageTag = false;
var theSelection = false;


var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav  = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));

var is_win   = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac    = (clientPC.indexOf("mac")!=-1);
var DOM = document.getElementById ? 1 : 0, 
        opera = window.opera && DOM ? 1 : 0, 
        IE = !opera && document.all ? 1 : 0, 
        NN6 = DOM && !IE && !opera ? 1 : 0; 
opera=0;

bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]\r\n[*]\r\n','[/list]',"[list=1]\r\n[*]\r\n",'[/list]','[img]','[/img]','[url]','[/url]','[s]','[/s]','[left]','[/left]','[center]','[/center]','[block]','[/block]','[right]','[/right]','[sub]','[/sub]','[sup]','[/sup]','[user]','[/user]',"[list=a]\r\n[*]\r\n","[/list]",'[smallcaps]','[/smallcaps]','[pad]','[/pad]','[table]','[/table]','[o]','[/o]','[flash]','[/flash]','[sound]','[/sound]','[video]','[/video]');
imageTag = false;

function helpline(help) {
	document.post.helpbox.value = eval(help + "_help");
}


function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}


function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function checkForm() {

	formErrors = false;    

	if (document.post.message.value.length < 2) {
		formErrors = ERROR;
	}

	if (formErrors) {
		alert(formErrors);
		return false;
	} else {
		bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}
function quoteSelection() {

     theSelection = false;
     
     if (window.getSelection) theSelection=window.getSelection();
   	 else if (document.getSelection) theSelection=document.getSelection();
     else if (document.selection) theSelection=document.selection.createRange().text;
  
//alert(theSelection);
     if (theSelection && theSelection!="") {
           // Add tags around selection
            emoticon( '[quote]\n' + theSelection + '\n[/quote]\n');
             document.post.message.focus();
             theSelection = '';
               return;
      }else{
             alert(NOTXT);
      }
}
function mozWrap(txtarea, open, close) {
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	txtarea.focus();
	return;
}
function mozSelection(txtarea, txt1, txt2, endung) {
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
		if(selEnd!=selStart){
			mozWrap(txtarea, txt1, txt2)
			var position = selEnd + txt1.length;
			if(selEnd > selStart) {
				position = position + txt2.length;
			}
			txtarea.selectionStart = position;
			txtarea.selectionEnd = position;
			txtarea.focus();
			return true;
		}else if(endung){
			txtarea.value += txt1 + txt2;
			txtarea.focus();
			return false;
			
		}
	
}
/*
function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.post.message.createTextRange && document.post.message.caretPos) {
		var caretPos = document.post.message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.post.message.focus();
	} else {
	document.post.message.value  += text;
	document.post.message.focus();
	}
}*/
function addText(text){
	
	var txtarea = document.post.message;
	txtarea.focus();
	if(is_ie) {
		if (document.post.message.createTextRange && document.post.message.caretPos) {
			//var caretPos = document.post.message.caretPos;
			//caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
			
			var caretPos = txtarea.caretPos;
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
				txtarea.focus();
		}
		else {
			document.post.message.focus();
			document.post.message.value  += text;
			storeCaret(document.post.message);
		}
	}
	else{
		var selStart = document.post.message.selectionStart;
		var selEnd = document.post.message.selectionEnd;
		mozWrap(document.post.message, text, '')
		document.post.message.selectionStart = selStart + text.length;
		document.post.message.selectionEnd = selStart + text.length;
	}
	document.post.message.focus();
	
}
function emoticon(text) {
	text = ' ' + text + ' ';
	addText(text);
}

function bbfontstyle(bbopen, bbclose) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			
			document.post.message.value += bbopen + bbclose;
			document.post.message.focus();
			return;
		}
		result = bbopen + theSelection + bbclose;
		with(document.selection.createRange()) {text = result; collapse(); select()}
		document.post.message.focus();
		return;
	}else if(NN6){
		 mozSelection(document.post.message, bbopen, bbclose, true)
	}else {
		document.post.message.value += bbopen + bbclose;
		document.post.message.focus();
		return;
	}
	storeCaret(document.post.message);

  
}


function bbstyle(bbnumber) {

	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { 
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			document.post.message.value += bbtags[butnumber + 1];
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; 
		document.post.message.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win){
		//document.post.message.focus();
		theSelection = document.selection.createRange().text; // Get text selection
		
		if (theSelection) {
			result = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			//alert(document.post.message.value);
			if(document.post.message.value){
				with(document.selection.createRange()) {text = result; collapse();  select()}
				
			}else{	
				document.post.message.value += result;
			}
			document.post.message.focus();
			//with(document.selection.createRange()) {text = result; collapse(); select()}	
			theSelection = '';
			return;
		}
		
	}else{
		if(mozSelection(document.post.message, bbtags[bbnumber], bbtags[bbnumber+1], false)){
			return;
		}
	}
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {/*
			while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.post.addbbcode' + butnumber + '.value');
				eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}*/
			while (bbcode[bblast]) {
				//alert(bbcode[bblast]);
				butnumber = arraypop(bbcode) - 1;
				//alert(bbtags[bbnumber]);
				//document.post.message.value += bbtags[butnumber + 1];
				addText(bbtags[butnumber + 1]);
				//buttext = eval('document.post.addbbcode' + butnumber + '.value');
				//eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				onUnClickButton(document.getElementById('addbbcode'+butnumber));
				outButton(document.getElementById('addbbcode'+butnumber));
				imageTag = false;
			}
			document.post.message.focus();
			return;
	} else { // Open tags
	
		if (imageTag && (bbnumber != 14)) {		
			//document.post.message.value += bbtags[15];
			addText(bbtags[15]);
			lastValue = arraypop(bbcode) - 1;
			document.post.addbbcode14.value = "Img";
			document.post.message.focus();
			imageTag = false;
		}
		
		// Open tag
		//document.post.message.value += bbtags[bbnumber];
		addText(bbtags[bbnumber]);
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; 
		arraypush(bbcode,bbnumber+1);
		
		onClickButton(document.getElementById('addbbcode'+bbnumber));
		//eval('document.post.addbbcode'+bbnumber+'.value += "*"');
		document.post.message.focus();
		return;
	}
	storeCaret(document.post.message);
}

function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
	//textEl.focus();
	return
}



var colorPickerOn=0;
var colorPickerCreated=0;
var colorPickerVersion=0;

function setColor(color){
	if(colorPickerVersion==0){
		bbfontstyle('[color=#' + color + ']', '[/color]');	
	}else{
		bbfontstyle('[bgcolor=#' + color + ']', '[/bgcolor]');	
	}
	resetColorButtons();
	hidecolorPicker();
}

function hidecolorPicker(){
	colorPickerOn =0;
	resetColorButtons();
	document.getElementById("colorPicker").style.visibility='hidden';
	document.getElementById("colorPicker").style.display='none';
	document.getElementById("smilesPicker").style.visibility='visible';
	document.getElementById("smilesPicker").style.display='block';
}

function resetColorButtons(){
	onUnClickButton(document.getElementById('addbbcodeColor0'));	
	onUnClickButton(document.getElementById('addbbcodeColor1'));	
	outButton(document.getElementById('addbbcodeColor0'));	
	outButton(document.getElementById('addbbcodeColor1'));	
	
	
}

function showcolorPicker(version) {
	colorPickerVersion=version;
	resetColorButtons();
	onClickButton(document.getElementById('addbbcodeColor'+version));
	
	if(colorPickerOn == 1) {
		hidecolorPicker ();
		return;
	}
	
	width=4;
	height=4;

	colorPickerOn = 1;
	
	if(colorPickerCreated==0){
	
		var html = "";
		var zeichen			= new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
		var colorList 		= new Array('00','33','66','99','AA','FF');
		var colorListFull 	= new Array('00','10','20','30','40','50','60','70','80','90','A0','B0','C0','D0','E0','FF');
		//var colorListFull_ 	= new Array('00','02','05','07','10','12','15','17','20','22','25','27','30','32','35','37','40','42','45','47','50','52','55','57','60','62','65','67','70','72','75','77','80','82','85','87','90','92','95','97','A0','A2','A5','A7','B0','B2','B5','B7','C0','C2','C5','C7','D0','D2','D5','D7','E0','E2','E5','E7','F0','F2','F5','F7','FF');
		var namedColors		= new Array('000000','FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF','FFFFFF');
		
		var colorListFull_ 	= new Array();
		for(a = 0; a < zeichen.length; a++) {
			
			for(b = 0; b < zeichen.length-1; b++) {
				if(b%4!=0)continue;
				colorListFull_[colorListFull_.length]=String(zeichen[a])+String(zeichen[b]);
				//alert(String(zeichen[a])+String(zeichen[b]));
			}
		}
		
		
		html = '<div id="ColorPreview"></div>';
		html += '<table class="ColorPalette"><tr>';
		
		for(i = 0; i < namedColors.length; i++) {
			color = String(namedColors[i]);
			html += '<td " bgcolor="#' + color + '" onMouseOver="ColorPreView(\'' + color + '\');" onmousedown="setColor(\''+color + '\');" style="width:'+(width*4)+';height:'+(height*4)+';"></td>';
			
		}
	
		html += '</tr></table><table class="ColorPalette"><tr>';
		
			
		for(i = 0; i < colorListFull_.length; i++) {
			color = String(colorListFull_[i]) + String(colorListFull_[i]) + String(colorListFull_[i]);
			html += '<td bgcolor="#' + color + '" onMouseOver="ColorPreView(\'' + color + '\');" onmousedown="setColor(\''+color + '\');" style="width:2px;height:'+(height*4)+';"></td>';
			
		}
				
		html += '</tr></table><table class="ColorPalette">';
		for(k = 0; k < colorList.length; k++) {
			if(k==1 || k==3|| k==4)continue;
			 //html += '<tr>';
			 //for(k = a*2; k < a*2+2; k++) {
				for(i = 0; i < colorListFull.length; i++) {
					html += '</tr><tr>';
					for(j = 0; j < colorListFull.length; j++) {
						color = String(colorListFull[j]) + String(colorList[k])+ String(colorListFull[i]);
						html += '<td  onMouseOver="ColorPreView(\'' + color + '\');" bgcolor="#' + color + '"  onmousedown="setColor(\''+color + '\');"></td>';
					}
				}	
		}
		html += '</table>';
	
		
		document.getElementById("colorPicker").innerHTML = html;
		colorPickerCreated=1;
	}
	
	document.getElementById("colorPicker").style.visibility='visible';
	document.getElementById("colorPicker").style.display='block';
	
	document.getElementById("smilesPicker").style.visibility='hidden';
	document.getElementById("smilesPicker").style.display='none';
	
	return;
}

function ColorPreView(color) {
  document.getElementById("ColorPreview").style.backgroundColor = '#' + color;
}





function init() {
	tinyMCEPopup.resizeToInnerSize();
}

var charmap = new Array();

// for mor details please see w3c.org
// now here is the complete list ;)



	

charmapSonderzeichen = [
	['&amp;',     '&#38;',   true, 'ampersand'],
	['&quot;',    '&#34;',   true, 'quotation mark'],
// finance
	['&cent;',    '&#162;',  true, 'cent sign'],
	['&euro;',    '&#8364;', true, 'euro sign'],
	['&pound;',   '&#163;',  true, 'pound sign'],
	['&yen;',     '&#165;',  true, 'yen sign'],
// signs
	['&copy;',    '&#169;',  true, 'copyright sign'],
	['&reg;',     '&#174;',  true, 'registered sign'],
	['&trade;',   '&#8482;', true, 'trade mark sign'],
	['&permil;',  '&#8240;', true, 'per mille sign'],
	['&micro;',   '&#181;',  true, 'micro sign'],
	['&middot;',  '&#183;',  true, 'middle dot'],
	['&bull;',    '&#8226;', true, 'bullet'],
	['&hellip;',  '&#8230;', true, 'three dot leader'],
	['&prime;',   '&#8242;', true, 'minutes / feet'],
	['&Prime;',   '&#8243;', true, 'seconds / inches'],
	['&sect;',    '&#167;',  true, 'section sign'],
	['&para;',    '&#182;',  true, 'paragraph sign'],
	['&szlig;',   '&#223;',  true, 'sharp s / ess-zed'],
// quotations
	['&lsaquo;',  '&#8249;', true, 'single left-pointing angle quotation mark'],
	['&rsaquo;',  '&#8250;', true, 'single right-pointing angle quotation mark'],
	['&laquo;',   '&#171;',  true, 'left pointing guillemet'],
	['&raquo;',   '&#187;',  true, 'right pointing guillemet'],
	['&lsquo;',   '&#8216;', true, 'left single quotation mark'],
	['&rsquo;',   '&#8217;', true, 'right single quotation mark'],
	['&ldquo;',   '&#8220;', true, 'left double quotation mark'],
	['&rdquo;',   '&#8221;', true, 'right double quotation mark'],
	['&sbquo;',   '&#8218;', true, 'single low-9 quotation mark'],
	['&bdquo;',   '&#8222;', true, 'double low-9 quotation mark'],
	['&lt;',      '&#60;',   true, 'less-than sign'],
	['&gt;',      '&#62;',   true, 'greater-than sign'],
	['&le;',      '&#8804;', true, 'less-than or equal to'],
	['&ge;',      '&#8805;', true, 'greater-than or equal to'],
	['&ndash;',   '&#8211;', true, 'en dash'],
	['&mdash;',   '&#8212;', true, 'em dash'],
	['&macr;',    '&#175;',  true, 'macron'],
	['&oline;',   '&#8254;', true, 'overline'],
	['&curren;',  '&#164;',  true, 'currency sign'],
	['&brvbar;',  '&#166;',  true, 'broken bar'],
	['&uml;',     '&#168;',  true, 'diaeresis'],
	['&iexcl;',   '&#161;',  true, 'inverted exclamation mark'],
	['&iquest;',  '&#191;',  true, 'turned question mark'],
	['&circ;',    '&#710;',  true, 'circumflex accent'],
	['&tilde;',   '&#732;',  true, 'small tilde'],
	['&deg;',     '&#176;',  true, 'degree sign'],
	['&minus;',   '&#8722;', true, 'minus sign'],
	['&plusmn;',  '&#177;',  true, 'plus-minus sign'],
	['&divide;',  '&#247;',  true, 'division sign'],
	['&frasl;',   '&#8260;', true, 'fraction slash'],
	['&times;',   '&#215;',  true, 'multiplication sign'],
	['&sup1;',    '&#185;',  true, 'superscript one'],
	['&sup2;',    '&#178;',  true, 'superscript two'],
	['&sup3;',    '&#179;',  true, 'superscript three'],
	['&frac14;',  '&#188;',  true, 'fraction one quarter'],
	['&frac12;',  '&#189;',  true, 'fraction one half'],
	['&frac34;',  '&#190;',  true, 'fraction three quarters'],
// math / logical
	['&fnof;',    '&#402;',  true, 'function / florin'],
	['&int;',     '&#8747;', true, 'integral'],
	['&sum;',     '&#8721;', true, 'n-ary sumation'],
	['&infin;',   '&#8734;', true, 'infinity'],
	['&radic;',   '&#8730;', true, 'square root'],
	['&sim;',     '&#8764;', false,'similar to'],
	['&cong;',    '&#8773;', false,'approximately equal to'],
	['&asymp;',   '&#8776;', true, 'almost equal to'],
	['&ne;',      '&#8800;', true, 'not equal to'],
	['&equiv;',   '&#8801;', true, 'identical to'],
	['&isin;',    '&#8712;', false,'element of'],
	['&notin;',   '&#8713;', false,'not an element of'],
	['&ni;',      '&#8715;', false,'contains as member'],
	['&prod;',    '&#8719;', true, 'n-ary product'],
	['&and;',     '&#8743;', false,'logical and'],
	['&or;',      '&#8744;', false,'logical or'],
	['&not;',     '&#172;',  true, 'not sign'],
	['&cap;',     '&#8745;', true, 'intersection'],
	['&cup;',     '&#8746;', false,'union'],
	['&part;',    '&#8706;', true, 'partial differential'],
	['&forall;',  '&#8704;', false,'for all'],
	['&exist;',   '&#8707;', false,'there exists'],
	['&empty;',   '&#8709;', false,'diameter'],
	['&nabla;',   '&#8711;', false,'backward difference'],
	['&lowast;',  '&#8727;', false,'asterisk operator'],
	['&prop;',    '&#8733;', false,'proportional to'],
	['&ang;',     '&#8736;', false,'angle'],
// undefined
	['&acute;',   '&#180;',  true, 'acute accent'],
	['&cedil;',   '&#184;',  true, 'cedilla'],
	['&ordf;',    '&#170;',  true, 'feminine ordinal indicator'],
	['&ordm;',    '&#186;',  true, 'masculine ordinal indicator'],
	['&dagger;',  '&#8224;', true, 'dagger'],
	['&Dagger;',  '&#8225;', true, 'double dagger'],
// alphabetical special chars
	['&Agrave;',  '&#192;',  true, 'A - grave'],
	['&Aacute;',  '&#193;',  true, 'A - acute'],
	['&Acirc;',   '&#194;',  true, 'A - circumflex'],
	['&Atilde;',  '&#195;',  true, 'A - tilde'],
	['&Auml;',    '&#196;',  true, 'A - diaeresis'],
	['&Aring;',   '&#197;',  true, 'A - ring above'],
	['&AElig;',   '&#198;',  true, 'ligature AE'],
	['&Ccedil;',  '&#199;',  true, 'C - cedilla'],
	['&Egrave;',  '&#200;',  true, 'E - grave'],
	['&Eacute;',  '&#201;',  true, 'E - acute'],
	['&Ecirc;',   '&#202;',  true, 'E - circumflex'],
	['&Euml;',    '&#203;',  true, 'E - diaeresis'],
	['&Igrave;',  '&#204;',  true, 'I - grave'],
	['&Iacute;',  '&#205;',  true, 'I - acute'],
	['&Icirc;',   '&#206;',  true, 'I - circumflex'],
	['&Iuml;',    '&#207;',  true, 'I - diaeresis'],
	['&ETH;',     '&#208;',  true, 'ETH'],
	['&Ntilde;',  '&#209;',  true, 'N - tilde'],
	['&Ograve;',  '&#210;',  true, 'O - grave'],
	['&Oacute;',  '&#211;',  true, 'O - acute'],
	['&Ocirc;',   '&#212;',  true, 'O - circumflex'],
	['&Otilde;',  '&#213;',  true, 'O - tilde'],
	['&Ouml;',    '&#214;',  true, 'O - diaeresis'],
	['&Oslash;',  '&#216;',  true, 'O - slash'],
	['&OElig;',   '&#338;',  true, 'ligature OE'],
	['&Scaron;',  '&#352;',  true, 'S - caron'],
	['&Ugrave;',  '&#217;',  true, 'U - grave'],
	['&Uacute;',  '&#218;',  true, 'U - acute'],
	['&Ucirc;',   '&#219;',  true, 'U - circumflex'],
	['&Uuml;',    '&#220;',  true, 'U - diaeresis'],
	['&Yacute;',  '&#221;',  true, 'Y - acute'],
	['&Yuml;',    '&#376;',  true, 'Y - diaeresis'],
	['&THORN;',   '&#222;',  true, 'THORN'],
	['&agrave;',  '&#224;',  true, 'a - grave'],
	['&aacute;',  '&#225;',  true, 'a - acute'],
	['&acirc;',   '&#226;',  true, 'a - circumflex'],
	['&atilde;',  '&#227;',  true, 'a - tilde'],
	['&auml;',    '&#228;',  true, 'a - diaeresis'],
	['&aring;',   '&#229;',  true, 'a - ring above'],
	['&aelig;',   '&#230;',  true, 'ligature ae'],
	['&ccedil;',  '&#231;',  true, 'c - cedilla'],
	['&egrave;',  '&#232;',  true, 'e - grave'],
	['&eacute;',  '&#233;',  true, 'e - acute'],
	['&ecirc;',   '&#234;',  true, 'e - circumflex'],
	['&euml;',    '&#235;',  true, 'e - diaeresis'],
	['&igrave;',  '&#236;',  true, 'i - grave'],
	['&iacute;',  '&#237;',  true, 'i - acute'],
	['&icirc;',   '&#238;',  true, 'i - circumflex'],
	['&iuml;',    '&#239;',  true, 'i - diaeresis'],
	['&eth;',     '&#240;',  true, 'eth'],
	['&ntilde;',  '&#241;',  true, 'n - tilde'],
	['&ograve;',  '&#242;',  true, 'o - grave'],
	['&oacute;',  '&#243;',  true, 'o - acute'],
	['&ocirc;',   '&#244;',  true, 'o - circumflex'],
	['&otilde;',  '&#245;',  true, 'o - tilde'],
	['&ouml;',    '&#246;',  true, 'o - diaeresis'],
	['&oslash;',  '&#248;',  true, 'o slash'],
	['&oelig;',   '&#339;',  true, 'ligature oe'],
	['&scaron;',  '&#353;',  true, 's - caron'],
	['&ugrave;',  '&#249;',  true, 'u - grave'],
	['&uacute;',  '&#250;',  true, 'u - acute'],
	['&ucirc;',   '&#251;',  true, 'u - circumflex'],
	['&uuml;',    '&#252;',  true, 'u - diaeresis'],
	['&yacute;',  '&#253;',  true, 'y - acute'],
	['&thorn;',   '&#254;',  true, 'thorn'],
	['&yuml;',    '&#255;',  true, 'y - diaeresis'],
    ['&Alpha;',   '&#913;',  true, 'Alpha'],
	['&Beta;',    '&#914;',  true, 'Beta'],
	['&Gamma;',   '&#915;',  true, 'Gamma'],
	['&Delta;',   '&#916;',  true, 'Delta'],
	['&Epsilon;', '&#917;',  true, 'Epsilon'],
	['&Zeta;',    '&#918;',  true, 'Zeta'],
	['&Eta;',     '&#919;',  true, 'Eta'],
	['&Theta;',   '&#920;',  true, 'Theta'],
	['&Iota;',    '&#921;',  true, 'Iota'],
	['&Kappa;',   '&#922;',  true, 'Kappa'],
	['&Lambda;',  '&#923;',  true, 'Lambda'],
	['&Mu;',      '&#924;',  true, 'Mu'],
	['&Nu;',      '&#925;',  true, 'Nu'],
	['&Xi;',      '&#926;',  true, 'Xi'],
	['&Omicron;', '&#927;',  true, 'Omicron'],
	['&Pi;',      '&#928;',  true, 'Pi'],
	['&Rho;',     '&#929;',  true, 'Rho'],
	['&Sigma;',   '&#931;',  true, 'Sigma'],
	['&Tau;',     '&#932;',  true, 'Tau'],
	['&Upsilon;', '&#933;',  true, 'Upsilon'],
	['&Phi;',     '&#934;',  true, 'Phi'],
	['&Chi;',     '&#935;',  true, 'Chi'],
	['&Psi;',     '&#936;',  true, 'Psi'],
	['&Omega;',   '&#937;',  true, 'Omega'],
	['&alpha;',   '&#945;',  true, 'alpha'],
	['&beta;',    '&#946;',  true, 'beta'],
	['&gamma;',   '&#947;',  true, 'gamma'],
	['&delta;',   '&#948;',  true, 'delta'],
	['&epsilon;', '&#949;',  true, 'epsilon'],
	['&zeta;',    '&#950;',  true, 'zeta'],
	['&eta;',     '&#951;',  true, 'eta'],
	['&theta;',   '&#952;',  true, 'theta'],
	['&iota;',    '&#953;',  true, 'iota'],
	['&kappa;',   '&#954;',  true, 'kappa'],
	['&lambda;',  '&#955;',  true, 'lambda'],
	['&mu;',      '&#956;',  true, 'mu'],
	['&nu;',      '&#957;',  true, 'nu'],
	['&xi;',      '&#958;',  true, 'xi'],
	['&omicron;', '&#959;',  true, 'omicron'],
	['&pi;',      '&#960;',  true, 'pi'],
	['&rho;',     '&#961;',  true, 'rho'],
	['&sigmaf;',  '&#962;',  true, 'final sigma'],
	['&sigma;',   '&#963;',  true, 'sigma'],
	['&tau;',     '&#964;',  true, 'tau'],
	['&upsilon;', '&#965;',  true, 'upsilon'],
	['&phi;',     '&#966;',  true, 'phi'],
	['&chi;',     '&#967;',  true, 'chi'],
	['&psi;',     '&#968;',  true, 'psi'],
	['&omega;',   '&#969;',  true, 'omega'],
// symbols
	['&alefsym;', '&#8501;', false,'alef symbol'],
	['&piv;',     '&#982;',  false,'pi symbol'],
	['&real;',    '&#8476;', false,'real part symbol'],
	['&thetasym;','&#977;',  false,'theta symbol'],
	['&upsih;',   '&#978;',  false,'upsilon - hook symbol'],
	['&weierp;',  '&#8472;', false,'Weierstrass p'],
	['&image;',   '&#8465;', false,'imaginary part'],
// arrows
	['&larr;',    '&#8592;', true, 'leftwards arrow'],
	['&uarr;',    '&#8593;', true, 'upwards arrow'],
	['&rarr;',    '&#8594;', true, 'rightwards arrow'],
	['&darr;',    '&#8595;', true, 'downwards arrow'],
	['&harr;',    '&#8596;', true, 'left right arrow'],
	['&crarr;',   '&#8629;', false,'carriage return'],
	['&lArr;',    '&#8656;', false,'leftwards double arrow'],
	['&uArr;',    '&#8657;', false,'upwards double arrow'],
	['&rArr;',    '&#8658;', false,'rightwards double arrow'],
	['&dArr;',    '&#8659;', false,'downwards double arrow'],
	['&hArr;',    '&#8660;', false,'left right double arrow'],
	['&there4;',  '&#8756;', false,'therefore'],
	['&sub;',     '&#8834;', false,'subset of'],
	['&sup;',     '&#8835;', false,'superset of'],
	['&nsub;',    '&#8836;', false,'not a subset of'],
	['&sube;',    '&#8838;', false,'subset of or equal to'],
	['&supe;',    '&#8839;', false,'superset of or equal to'],
	['&oplus;',   '&#8853;', false,'circled plus'],
	['&otimes;',  '&#8855;', false,'circled times'],
	['&perp;',    '&#8869;', false,'perpendicular'],
	['&sdot;',    '&#8901;', false,'dot operator'],
	['&lceil;',   '&#8968;', false,'left ceiling'],
	['&rceil;',   '&#8969;', false,'right ceiling'],
	['&lfloor;',  '&#8970;', false,'left floor'],
	['&rfloor;',  '&#8971;', false,'right floor'],
	['&lang;',    '&#9001;', false,'left-pointing angle bracket'],
	['&rang;',    '&#9002;', false,'right-pointing angle bracket'],
	['&loz;',     '&#9674;', true,'lozenge'],
	['&spades;',  '&#9824;', false,'black spade suit'],
	['&clubs;',   '&#9827;', true, 'black club suit'],
	['&hearts;',  '&#9829;', true, 'black heart suit'],
	['&diams;',   '&#9830;', true, 'black diamond suit'],
	['&ensp;',    '&#8194;', false,'en space'],
	['&emsp;',    '&#8195;', false,'em space'],
	['&thinsp;',  '&#8201;', false,'thin space'],
	['&zwnj;',    '&#8204;', false,'zero width non-joiner'],
	['&zwj;',     '&#8205;', false,'zero width joiner'],
	['&lrm;',     '&#8206;', false,'left-to-right mark'],
	['&rlm;',     '&#8207;', false,'right-to-left mark'],
	['&shy;',     '&#173;',  false,'soft hyphen']
];



charmapCyr = [
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	['',     '',   true, ''],
	[' A',     '',   true, ''],
	[' B',     '',   true, ''],
	[' V',     '',   true, ''],
	[' G',     '',   true, ''],
	[' D',     '',   true, ''],
	[' E',     '',   true, ''],
	[' JO / YO',     '',   true, ''],
	[' ZH',     '',   true, ''],
	[' Z',     '',   true, ''],
	[' I',     '',   true, ''],
	[' J',     '',   true, ''],
	[' K',     '',   true, ''],
	[' L',     '',   true, ''],
	[' M',     '',   true, ''],
	[' N',     '',   true, ''],
	[' O',     '',   true, ''],
	[' P',     '',   true, ''],
	[' R',     '',   true, ''],
	[' S',     '',   true, ''],
	[' T',     '',   true, ''],
	[' U',     '',   true, ''],
	[' F',     '',   true, ''],
	[' X, h',     '',   true, ''],
	[' C',     '',   true, ''],
	[' CH',     '',   true, ''],
	[' SH',     '',   true, ''],
	[' SHH, w',     '',   true, ''],
	[" ##",     '',   true, ''],
	[' Y',     '',   true, ''],
	[' &prime;&prime;',     '',   true, ''],
	[' JE',     '',   true, ''],
	[' JU',     '',   true, ''],
	[' JA / Q',     '',   true, ''],
	[' a',     '',   true, ''],
	[' b',     '',   true, ''],
	[' v',     '',   true, ''],
	[' g',     '',   true, ''],
	[' d',     '',   true, ''],
	[' e',     '',   true, ''],
	[' jo / yo',     '',   true, ''],
	[' zh',     '',   true, ''],
	[' z',     '',   true, ''],
	[' i',     '',   true, ''],
	[' j',     '',   true, ''],
	[' k',     '',   true, ''],
	[' l',     '',   true, ''],
	[' m',     '',   true, ''],
	[' n',     '',   true, ''],
	[' o',     '',   true, ''],
	[' p',     '',   true, ''],
	[' r',     '',   true, ''],
	[' s',     '',   true, ''],
	[' t',     '',   true, ''],
	[' u',     '',   true, ''],
	[' f',     '',   true, ''],
	[' x,h',     '',   true, ''],
	[' c',     '',   true, ''],
	[' ch',     '',   true, ''],
	[' sh',     '',   true, ''],
	[' shh / w',     '',   true, ''],
	[' #',     '',   true, ''],
	[' y',     '',   true, ''],
	[' &prime;',     '',   true, ''],
	[' je',     '',   true, ''],
	[' ju',     '',   true, ''],
	[' ja',     '',   true, '']	
]


var charMapOn=false;
var aktiveButton=false;
function renderCharMapHTML(mode) {
	
	onUnClickButton(document.getElementById('addbbcodecharmapCyr'));
	onUnClickButton(document.getElementById('addbbcodecharmap'));
	outButton(document.getElementById('addbbcodecharmapCyr'));
	outButton(document.getElementById('addbbcodecharmap'));
	document.getElementById('codeA').innerHTML='&nbsp;';
	document.getElementById('codeB').innerHTML='&nbsp;';
	
	
	if(mode=='Cyr'){
		document.getElementById("htmlCode").style.visibility='hidden';
		document.getElementById("htmlCode").style.display='none';
		document.getElementById("codeNTr").style.visibility='hidden';
		document.getElementById("codeNTr").style.display='none';
		document.getElementById("TranslitCode").style.visibility='visible';
		document.getElementById("TranslitCode").style.display='block';
		
		charmap=charmapCyr;
		if(aktiveButton && aktiveButton.id!='addbbcodecharmapCyr')charMapOn=false;
		aktiveButton=document.getElementById('addbbcodecharmapCyr');
		
	}else{
		
		document.getElementById("htmlCode").style.visibility='visible';
		document.getElementById("htmlCode").style.display='block';
		document.getElementById("codeNTr").style.visibility='visible';
		document.getElementById("codeNTr").style.display='block';
		document.getElementById("TranslitCode").style.visibility='hidden';
		document.getElementById("TranslitCode").style.display='none';
		charmap=charmapSonderzeichen;
		if(aktiveButton &&  aktiveButton.id!='addbbcodecharmap')charMapOn=false;
		aktiveButton=document.getElementById('addbbcodecharmap');
	}
	
	
	
	if(!charMapOn){
		document.getElementById("CharMapTable").style.visibility='visible';
		document.getElementById("CharMapTable").style.display='block';
		onClickButton(aktiveButton);
		charMapOn=true;
	}else{
		document.getElementById("CharMapTable").style.visibility='hidden';
		document.getElementById("CharMapTable").style.display='none';	
		onUnClickButton(aktiveButton);
		charMapOn=false;
	}
	var charsPerRow = 18, tdWidth=18, tdHeight=18;
	var html = '<table border="0" cellspacing="1" cellpadding="0" width="' + (tdWidth*charsPerRow) + '"><tr height="' + tdHeight + '">';
	var cols=-1;
	for (var i=0; i<charmap.length; i++) {
		if (charmap[i][2]==true) {
			cols++;
			html += ''
				+ '<td width="' + tdWidth + '" height="' + tdHeight + '" class="charmap"'
				+ ' onmouseover="'
				+ 'previewChar(\'' + charmap[i][1] + '\',\'' + charmap[i][0].substring(1,charmap[i][0].length) + '\',\'' + charmap[i][3] + '\');"'
				+ ' onmouseout=""'
				+ ' nowrap="nowrap" onclick="addText(\'' + charmap[i][1] + '\');"><a style="text-decoration: none;" href="javascript:insertChar(\'' + charmap[i][1].substring(2,charmap[i][1].length-1) + '\');" onclick="return false;" onmousedown="return false;" title="' + charmap[i][3] + '">'
				+ charmap[i][1]
				+ '</a></td>';
			if ((cols+1) % charsPerRow == 0)
				html += '</tr><tr height="' + tdHeight + '">';
		}
	 }
	if (cols % charsPerRow > 0) {
		var padd = charsPerRow - (cols % charsPerRow);
		for (var i=0; i<padd-1; i++)
			html += '<td width="' + tdWidth + '" height="' + tdHeight + '" class="charmap">&nbsp;</td>';
	}
	html += '</tr></table>';
	
	
	
	
	if(colorPickerOn == 1) {
		hidecolorPicker ();
		return;
	}
	document.getElementById("CharMap").innerHTML = html;
			
	

}

function insertChar(chr) {
	addText('&#' + chr + ';');

	
}

function previewChar(codeA, codeB, codeN) {
	var elmA = document.getElementById('codeA');
	var elmB = document.getElementById('codeB');
	var elmV = document.getElementById('codeV');
	var elmN = document.getElementById('codeN');

	if (codeA=='#160;') {
		elmV.innerHTML = '__';
	} else {
		elmV.innerHTML = '' + codeA;
	}
	if(!codeB){
		codeB="&nbsp;";
	}
	elmB.innerHTML = '' + codeB;
	elmA.innerHTML = '&amp;' + codeB;
	elmN.innerHTML = codeN;
}

		 
function viewTooltip(msg){
	if(msg && msg!='undefined'){
		document.getElementById('ToolTipView').innerHTML=msg;
		document.getElementById('ToolTipView').style.display='block';
			
			document.getElementById('smilesPicker').style.display='block';
		
		document.getElementById("colorPicker").style.visibility='hidden';
		document.getElementById("colorPicker").style.display='none';
		document.getElementById("smilesPicker").style.visibility='hidden';
		document.getElementById("smilesPicker").style.display='none';
	}

}
		 
function hideTooltip(){		 	
	document.getElementById('ToolTipView').style.display='none';
	
	if(colorPickerOn==1){
		document.getElementById("colorPicker").style.visibility='visible';
		document.getElementById("colorPicker").style.display='block';
	}else{
		document.getElementById("smilesPicker").style.visibility='visible';
		document.getElementById("smilesPicker").style.display='block';
	}
}
		 
function onButton(button){

	viewTooltip(button.alt);
	if(button.className=='coolbuttonOnClick' || button.className=='coolbuttonOnClickOnMouse'){
		button.className='coolbuttonOnClickOnMouse';
	}else{
		button.className='coolbuttonOnMouse';
	}
}
		 
function outButton(button){
	hideTooltip();
	if(button.className=='coolbuttonOnClick' || button.className=='coolbuttonOnClickOnMouse'){
		button.className='coolbuttonOnClick';
	}else{
 		button.className='coolbutton';
	}
}
 
function onClickButton(button){
 	button.className='coolbuttonOnClickOnMouse';
}
function onUnClickButton(button){
 	button.className='coolbuttonOnMouse';
}


function vergroessereFeld(){
 	document.getElementById('message').style.width=(parseInt(document.getElementById('message').style.width)+50);
 	document.getElementById('message').style.height=(parseInt(document.getElementById('message').style.height)+30);
}
function verkleinereFeld(){
 	document.getElementById('message').style.width=(parseInt(document.getElementById('message').style.width)-50);
 	document.getElementById('message').style.height=(parseInt(document.getElementById('message').style.height)-30);
}
	
