_Smilies = new Array(">:D", ">:(", ">;)", ">:", ":-))", ":-)", ":-D", ":-((",
":-(", ":'(", ":ass:", ":punch:", "x(", "x0", ":klopf:", ":00:", ":com:", ":pfurz:", ":knife:",
":party:", ":party2:", ":kotz:", ":kotz2:", ":klatsch:", ":drink:", ":dance:", ":eat:", ":birthday:",
":bang:", ":hallo:", ":daumen:", ";-)", ":rofl:", ":kiss:", ":fuck:", ":kiss2:", ":heart:", 
":rose:", ":love:", ":love2:", ":music:", ":sing:", ":guitar:", ":ak:", ":rocket:", ":rocket2:", 
":uzi:", ":shot:", ":shot2:", ":shot3:", ":jump:", ":jump2:", ":jump3:", ":jump4:", ":xmas:", ":sleep:",
":tired:", ":gähn:", ":schreck:", ":-O", ":-?", ">o", ":wc:", ":piss:", ":dusche:", ":bad:",
":meal:", ":schaf:", ":worm:", ":tittn:", ":bitte:", ":danke:", ":crazy:", ":happens:", ":schmoll:",
":-S", ":kiss3:", ":cool:", ":cool2:", ":rolleyes:", ":tv:", ":pc:", ":pc2:", ":pc3:", ":angel:",
":angel2:", ":angel3:", ":holy:", ":ill:", ":sex:", ":hdl:", ":tröst:", ":knutsch:", ":cloud:", ":beer:", 
":lol:", ":hack:", "8-))", ":xmas?:", ":drive:", ":ill2:", ":kotz3:", ":wand:", ":-p", 
":muha:", ":blöd:", ":geil:", ":knie:");

_SmileyCodes = new Array("51", "49", "50", "48", "30", "01", "02", "04", "03",
"05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "20", "24", "16", "18", "17", "19", "21",
"22", "23", "25", "26", "27", "28", "29", "31", "32", "33", "34", "35", "36", "37", "38", "39",
"40", "41", "42", "43", "44", "45", "46", "47", "52", "53", "54", "55", "56", "57", "58", "59", "60",
"61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75",
"76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "88", "89", "87", "90", "91",
"92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "15",
"105", "106", "107", "109");

var _SmiliesMenueLeft = 0;
var _SmiliesMenueTop = 0;
var _SmiliesMenueWidth = 0;
var _SmiliesMenueHeight = 0;
var _SmileyAddObj = null;
var _SmiliesCloseNot = -1;
var _SmiliesAddFrame = "";
var _SmiliesAddObjId = null;
var _SmileyId = 1;
var _SmiliesCloseProcessRunning = false;
var _SmiliesMyXML = null;

function SmiliesShow(addFrame, addObjId){
	_SmiliesAddFrame = addFrame;
	_SmiliesAddObjId = addObjId;
	_SmiliesMenueLeft = _x + 3;
	_SmiliesMenueTop = _y + 3;
	document.getElementById("smilies").style.left = _SmiliesMenueLeft + "px";
	document.getElementById("smilies").style.top = _SmiliesMenueTop + "px";
	document.getElementById("smilies").style.zIndex = _zindex;
	_zindex++;
	document.getElementById("smilies").style.display = document.getElementById("smilies").style.display == "none" ? "" : "none";
	_SmiliesMenueWidth = document.getElementById("smilies").clientWidth;
	_SmiliesMenueHeight = document.getElementById("smilies").clientHeight;
}
function SmiliesShowAll(ret){
	if(ret == -1)
		ret = _SmiliesMyXML;
		
	if(_SmiliesCloseProcessRunning){
		if(ret != null){
			_SmiliesMyXML = ret;
			ret = -1;
		}
		window.setTimeout("SmiliesShowAll(" + ret + ")", 15);
		return;
	}
	if(document.getElementById("smiliesAll").style.display != "none")
		return;
	
	var tbody = document.createElement("tbody");
	var screenCenterWidth = _innerWidth/2;
	var screenCenterHeight = _innerHeight/2;
	var maxWidth = 0;
	var maxHeight = 0;

	if(_SmiliesMenueLeft > screenCenterWidth)
		maxWidth = (_SmiliesMenueLeft - _SmiliesMenueWidth);
	else
		maxWidth = (_innerWidth - _SmiliesMenueLeft - _SmiliesMenueWidth);
	
	if(_SmiliesMenueTop > screenCenterHeight)
		maxHeight = _SmiliesMenueTop + _SmiliesMenueHeight;
	else
		maxHeight = _innerHeight - _SmiliesMenueTop;
	
	
	if(ret == null){
		tbody = SmiliesCreateTableAll(maxWidth, tbody);
	}else{
		tbody = SmiliesCreateTableMy(maxWidth, tbody, ret);
		document.getElementById("smiliesWait").style.display = "none";
	}
	
	document.getElementById("smiliesAllTbl").appendChild(tbody);
	
	document.getElementById("smiliesAll").style.zIndex = _zindex;
	document.getElementById("smiliesAll").style.visibility = "hidden";
	document.getElementById("smiliesAll").style.display = "";
	
	//SmileyList Höhe/Breite
	var smiliesAllHeight = document.getElementById("smiliesAll").clientHeight;
	var smiliesAllWidth = document.getElementById("smiliesAll").clientWidth;
	
	if(document.getElementById("smiliesAll").clientHeight > maxHeight)
		smiliesAllHeight = maxHeight - 10;
	
	if(document.getElementById("smiliesAll").clientWidth > maxWidth)
		smiliesAllWidth = maxWidth - 10;
		
	document.getElementById("smiliesAll").style.width = smiliesAllWidth + "px";
	document.getElementById("smiliesAll").style.height = smiliesAllHeight + "px";
	document.getElementById("smiliesAll").style.overflow = "auto";
	
	// SmileyList Position
	if(_SmiliesMenueLeft > screenCenterWidth)
		document.getElementById("smiliesAll").style.left = (_SmiliesMenueLeft - smiliesAllWidth - 2) + "px";
	else
		document.getElementById("smiliesAll").style.left = (_SmiliesMenueLeft + _SmiliesMenueWidth + 2) + "px";
	
	if(_SmiliesMenueTop > screenCenterHeight){
		document.getElementById("smiliesAll").style.top = ((_SmiliesMenueTop + _SmiliesMenueHeight) - smiliesAllHeight) + "px";
	}else
		if(ret == null)
			document.getElementById("smiliesAll").style.top = _SmiliesMenueTop + "px";
		else
			document.getElementById("smiliesAll").style.top = ((_SmiliesMenueTop + _SmiliesMenueHeight) - 29) + "px";
	
	document.getElementById("smiliesAll").style.visibility = "visible";
	_zindex++;
}

function SmiliesCreateTableAll(maxWidth, tbody){
	var tr = document.createElement("tr");
	var width = 0;
	
	for(i = 0; i < _Smilies.length; i++){
		var code = _SmileyCodes[i];

		tr = SmiliesCreateTableSmiley(tr, "/images/smilies/" + code + ".gif", _Smilies[i]);
		width += 120;
		
		if(width >= maxWidth){
			tbody.appendChild(tr);
			tr = document.createElement("tr");
			width = 0;
		}
	}
	return tbody;
}
function SmiliesCreateTableMy(maxWidth, tbody, ret){
	var tr = document.createElement("tr");
	var width = 0;
	
	var smilies = ret.getElementsByTagName("smiley");
	
	for(i = 0; i < smilies.length; i++){
		var kurzel = unescape(getNodeValue(smilies[i], "kurzel"));
		var img = "/upload/smilies/" + unescape(getNodeValue(smilies[i], "bildname"));
		
		tr = SmiliesCreateTableSmiley(tr, img, kurzel);
		width += 120;
		
		if(width >= maxWidth){
			tbody.appendChild(tr);
			tr = document.createElement("tr");
			width = 0;
		}
	}
	return tbody;
}

function SmiliesCreateTableSmiley(tr, img, kurzel){
	var td = document.createElement("td");
	td.setAttribute("id", "std1_" + _SmileyId, 0);
	td.setAttribute("name", _SmileyId, 0);
	td.onmouseover = function(){ 
		document.getElementById("std1_" + this.getAttribute("name")).style.backgroundColor = "#EEEEEE";
		document.getElementById("std2_" + this.getAttribute("name")).style.backgroundColor = "#EEEEEE";
	}
	td.onmouseout = function(){ 
		document.getElementById("std1_" + this.getAttribute("name")).style.backgroundColor = "#FFFFFF";
		document.getElementById("std2_" + this.getAttribute("name")).style.backgroundColor = "#FFFFFF";
	}
	td.onclick = function(){
		SmiliesAdd(document.getElementById("std2_" + this.getAttribute("name")).innerHTML);
	}
	td = setElementStyle(td, "cursor:pointer; border-left:1px solid #CCCCCC; border-top:1px solid #CCCCCC; text-align:right;");
	td.innerHTML = "<img id=\"sImg_" + _SmileyId + "\" height=\"15\" src=\"" + img + "\" />";
	tr.appendChild(td);
	
	td = document.createElement("td");
	td.setAttribute("id", "std2_" + _SmileyId, 0);
	td.setAttribute("name", _SmileyId, 0);
	td.onmouseover = function(){ 
		document.getElementById("smiliesVorschau").innerHTML = "<img src=\"" + document.getElementById("sImg_" + this.getAttribute("name")).src + "\" />";
		document.getElementById("smiliesVorschau").style.display = "";
		document.getElementById("smiliesVorschau").style.zIndex = _zindex;
		document.getElementById("smiliesVorschau").style.left = _x + 5 + "px";
		document.getElementById("smiliesVorschau").style.top = _y + 5 + "px";
		document.getElementById("std1_" + this.getAttribute("name")).style.backgroundColor = "#EEEEEE"; 
		document.getElementById("std2_" + this.getAttribute("name")).style.backgroundColor = "#EEEEEE";
	}
	td.onmouseout = function(){ 
		document.getElementById("smiliesVorschau").style.display = "none";
		document.getElementById("std1_" + this.getAttribute("name")).style.backgroundColor = "#FFFFFF";
		document.getElementById("std2_" + this.getAttribute("name")).style.backgroundColor = "#FFFFFF";
	}
	td.onclick = function(){
		SmiliesAdd(document.getElementById("std2_" + this.getAttribute("name")).innerHTML);
	}
	td = setElementStyle(td, "cursor:pointer; border-top:1px solid #CCCCCC; text-align:left;");
	td.innerHTML = kurzel;
	tr.appendChild(td);
	
	_SmileyId++;
	return tr;
}

function SmiliesCloseAll(dontClose){
	SmiliesCloseMenue();
	_SmiliesCloseProcessRunning = true;
	window.setTimeout("SmiliesCloseOnCheck(" + dontClose + ")", 20);
}
function SmiliesCloseOnCheck(dontClose){
	if(_SmiliesCloseNot != dontClose && _SmiliesCloseNot != 0){
		if(!document.getElementById("smiliesAllTbl").getElementsByTagName("tbody")[0]){
			_SmiliesCloseProcessRunning = false;
			return;
		}
		var tbody = document.getElementById("smiliesAllTbl").getElementsByTagName("tbody")[0];
		tbody.parentNode.removeChild(tbody);
		document.getElementById("smiliesAll").style.visibility = "hidden";
		document.getElementById("smiliesAll").style.left = "";
		document.getElementById("smiliesAll").style.top = "";
		document.getElementById("smiliesAll").style.width = "";
		document.getElementById("smiliesAll").style.height = "";
		document.getElementById("smiliesAll").style.display = "none";
	}
	_SmiliesCloseProcessRunning = false;
}

function SmiliesLoadMy(){
	var screenCenterWidth = _innerWidth/2;
	var screenCenterHeight = _innerHeight/2;
	var waitDiv = document.getElementById("smiliesWait");
	
	if(_SmiliesMenueLeft > screenCenterWidth)
		waitDiv.style.left = _SmiliesMenueLeft - 100 - 2 + "px";
	else
		waitDiv.style.left = _SmiliesMenueLeft + _SmiliesMenueWidth + 2 + "px";
	
	waitDiv.style.top = (_SmiliesMenueTop + _SmiliesMenueHeight) - 29 + "px";
	waitDiv.style.display = "";
	waitDiv.style.zIndex = _zindex++;
	
	axSendXML("/configs/ajax/functions.php", "a=7", "SmiliesShowAll");
}

function SmiliesAdd(code){
	if(_SmiliesAddObjId == null)
		return;
	if(_SmiliesAddFrame != ""){
		for(var i = 0; i < window.frames.length; i++){
			if(window.frames[i].name == _SmiliesAddFrame){
				window.frames[i].document.getElementById(_SmiliesAddObjId).value += " " + code;
			}
		}
	}else
		document.getElementById(_SmiliesAddObjId).value += " " + code;
}

function SmiliesCloseMenue(){
	this.check = function(){
		if(_SmiliesCloseNot == -1){
			document.getElementById("smilies").style.display = "none";
		}
	}
	window.setTimeout("this.check()", 700);
}
