var ie = document.all;
var ie5 = document.all && !document.fireEvent && !window.opera;
var nouze = 0


if (ie5){ var objEdit = frames.iedit }
else	{ var objEdit = document.getElementById('iedit').contentWindow; }

function init()	{
	if (!objEdit || window.opera) { nouzovka(); return; }

	document.getElementById("editor").style.display = 'block'
	document.getElementById("textarea").style.display = 'none'

	objEdit.document.designMode="On";
	value = document.getElementById('textarea').value
	if (!value)
	value="<p>&nbsp;</p>";
	txt  = "<html><head><style>p{ font-family: verdana; font-size: 12px;}</style></head>"
	txt += "<body style='margin: 5px;'>"+value+"</body></html>"

	objEdit.document.open()
	objEdit.document.write(txt)
	objEdit.document.close()

	if (!ie) {  objEdit.document.execCommand('useCSS', false, true); }

	if(!ie) {
		objEdit.document.addEventListener("keyup", cntLen, true);
		objEdit.document.addEventListener("change", cntLen, true);
	}
	else {
		objEdit.document.onchange  = cntLen;
	}
	document.getElementById('textarea').form.onsubmit = for_submit;
	cntLen()
}

function cmdExec(cmd,opt) {
	if (cmd=='createLink' && !ie) { opt=prompt("Zadejte URL: ", "http://"); }
	objEdit.focus();
	objEdit.document.execCommand(cmd,false,opt);
	objEdit.focus();
	cntLen();
}

function emoticon(smile_ID) {
	if (nouze==1) {
		var txtarea = document.getElementById('textarea');
		txtarea.value  += " :"+smile_ID+":";
		txtarea.focus();
	} else {
		if ( smile_ID >= 1 ) {
			objEdit.focus();
			
			if(document.selection) {
				sel = objEdit.document.selection.createRange();
				sel.pasteHTML('<img src="http://www.horror.cz/editor/smiles/'+smile_ID+'.gif" alt="" width="17" height="17" border="0" /> ');
				sel.select()
			} else {
					try	{
						theSelection = objEdit.getSelection();
					} catch (e)	{
						return false;
					}
					
					theRange = theSelection.getRangeAt(0);
					theRange.collapse(false);
					var theImageNode = document.createElement("img");
					theImageNode.src = "http://www.horror.cz/editor/smiles/"+smile_ID+".gif";
					theImageNode.alt = "";
					theRange.insertNode(theImageNode);			
			}
		}
	}
	return false;
}

function for_submit() {
	if (nouze==0) 	{
		document.getElementById('textarea').value = objEdit.document.body.innerHTML
	}
	return true
}

function showColor() {
	if (document.getElementById('colorTab').style.display == 'none')
		document.getElementById('colorTab').style.display = 'block';
	else
		document.getElementById('colorTab').style.display = 'none';
}
document.getElementById('colorTab').innerHTML = color();
function setColor(fcolor) {
	objEdit.document.execCommand("foreColor",false,fcolor);
}

function color() {
	txt = ""
	txt += "<table border=0 cellpadding=0 cellspacing=1 bgcolor='black' style='margin-top: 0px;'>"
	c = new Array("","FF","CC","99","66","33","00")
	for (i=1;i <=6;i++) 	{
		if (i >1)
			txt = txt + "</tr>\n<tr>\n"
		for (m=1;m <=6;m++) 		{
			for (n=1;n <=6;n++) 			{
				colour = c[n] + c[i] + c[m]; 
				txt += "<td bgcolor=\"#"+colour+"\" ><a href=\"javascript:setColor('"+colour+"')\"><img src='./editor/coltab.gif'></a></td>\n"
			}
		}
	}
	return txt
}
setTimeout("init()",800)
