var popUpWin=0;
   var editor;
  	var pismo = "1";
	
	function incP(f){
	
		if (f<36) {f++;}else{f = f;}
		pismo = f;
		return pismo;
	}
	function decP(f){
		if (f>1) {f--;}else{f = f;}
		pismo = f;
		return pismo;
	}
	
	
	function showHTML() {
		window.document.getElementById("editor").style.visibility = "hidden";
		window.document.getElementById("editor").style.display = "none";
		window.document.getElementById("clanek").style.visibility = "visible";
		window.document.getElementById("clanek").style.display = "block";
		make_pre();
		window.document.getElementById("showWhat").innerHTML = "<a href=\"javascript: showDES();\" title=\"Design\"><img src=\"images/design.jpg\" border=\"0\" /></a>"
	}

	function showDES() {
		window.document.getElementById("clanek").style.visibility = "hidden";
		window.document.getElementById("clanek").style.display = "none";
		window.document.getElementById("editor").style.visibility = "visible";
		window.document.getElementById("editor").style.display = "block";
		setup();
		loadIFrame();
		window.document.getElementById("showWhat").innerHTML = "<a href=\"javascript: showHTML();\" title=\"Zdrojový kód\"><img src=\"images/source.jpg\" border=\"0\" /></a>"
	}
	
	function make_pre() {
		window.document.getElementById("clanek").value = editor.contentWindow.document.body.innerHTML;
		}
  
   function setup() {
    editor = "";
	editor = document.getElementById('editor');
    editor.contentWindow.document.designMode='on';
   }
   function editor_alert() {
    alert(editor.contentWindow.document.body.innerHTML);
   }

  function editor_execCommand(cmd) {
    if (document.all.editor._selection!=null) {
      document.all.editor._selection.select()
      if (arguments[1]==null)
        document.all.editor._selection.execCommand(cmd)
      else 
        document.all.editor._selection.execCommand(cmd,true,arguments[1])
      document.all.editor._selection.select()
    }
  }

function editor_execCommand(command, value) {
   editor.contentWindow.document.execCommand(command, false, value);
 }
		
function err(e){
alert("Error: "+e);return true;
}

window.onload = function(){
//		window.document.onerror = err();
		setup();
		loadIFrame();
	}

function popImgs()
	{
		preview.style.visibility = "hidden";
		preview.style.display = "none";
		obrazy.style.display = "block";
		obrazy.style.visibility = "visible";
	}
function erase_main(count)
	{
		x = 0;
		while (x<count)
			{
				var menu = "menu_" + x;
				document.getElementById(menu).style.backgroundColor = '#FFFFFF';
				x++;
			}
	}

function fill_main_uid(uid,name,typ,odkaz,poradi,count,ktery)
	{
		erase_main(count);
		var menu = "menu_" + ktery;
		document.getElementById(menu).style.backgroundColor = '#CCCCCC';
		document.getElementById("main_uid").value = uid;
		document.getElementById("main_name").value = name;
		document.getElementById("sub_uid").value = "";
		document.getElementById("sub_name").value = "";
		document.getElementById("typ").value = typ;
		document.getElementById("odkaz").value = odkaz;
		document.getElementById("pocet").value = poradi;
		document.getElementById("poradi").value = poradi+1;
	}
function fill_sub_uid(uid,sub_uid,main_name,name,typ,odkaz,poradi)
	{
		document.getElementById("main_uid").value = uid;
		document.getElementById("sub_uid").value = sub_uid;
		document.getElementById("main_name").value = main_name;
		document.getElementById("sub_name").value = name;
		document.getElementById("typ").value = typ;
		document.getElementById("odkaz").value = odkaz;
		document.getElementById("pocet").value = poradi;
		document.getElementById("poradi").value = poradi+1;
	}

function addImgL(id) {
	
	var URI = "obrazek.php?id=" + id + "\"class = 'left'";
	
	editor_execCommand('insertImage',URI);
}
function addImgR(id) {
	
	var URI = "obrazek.php?id=" + id + "\" class = 'right'";
	
	editor_execCommand('insertImage',URI);
}
function view(text) {
//	obrazy.style.display = "none";
//	obrazy.style.visibility = "hidden";
//	preview.innerHTML=text;

//	preview.innerHTML=text;
	}

	

function linkThis() {
		editor_execCommand('createlink');
}

function downThis(down) {
		what = "http://www.aveelektro.com/";
		what += down;
		editor_execCommand('createlink',what);
}

function picFils() {
		document.getElementById("obrazy").style.visibility = "hidden";
		document.getElementById("obrazy").style.display = "none";
		document.getElementById("soubory").style.visibility = "visible";
		document.getElementById("soubory").style.display = "block";
}

function filsPic() {
		document.getElementById("soubory").style.visibility = "hidden";
		document.getElementById("soubory").style.display = "none";
		document.getElementById("obrazy").style.visibility = "visible";
		document.getElementById("obrazy").style.display = "block";
}

function changeColor(barva){
	editor_execCommand('ForeColor',barva);
	window.document.getElementById("colors").style.visibility = "hidden";	
}

function repaint(barva){
		window.document.getElementById("picker").style.backgroundColor = barva;
}
function reset(){
		window.document.getElementById("picker").style.backgroundColor = "#FFFFFF";
//		window.document.getElementById("picker").style.background = "url(images/none.jpg) norepeat";
}

function nothing(){
	window.document.getElementById("colors").style.visibility = "hidden";	
}

function colors(){
/*var colorsTbl = new Array("#000000","#000033","#000066","#000099","#0000CC","#0000FF","#330000","#330033","#330066","#330099","#3300CC","#3300FF","#660000","#660033","#660066","#660099","#6600CC","#6600FF","#990000","#990033","#990066","#990099","#9900CC","#9900FF","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#003300","#003333","#003366","#003399","#0033CC","#0033FF","#333300","#333333","#333366","#333399","#3333CC","#3333FF","#663300","#663333","#663366","#663399","#6633CC","#6633FF","#993300","#993333","#993366","#993399","#9933CC","#9933FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#006600","#006633","#006666","#006699","#0066CC","#0066FF","#336600","#336633","#336666","#336699","#3366CC","#3366FF","#666600","#666633","#666666","#666699","#6666CC","#6666FF","#996600","#996633","#996666","#996699","#9966CC","#9966FF","#CC6600","#CC6633","#CC6666","#CC6699","#CC66CC","#CC66FF","#FF6600","#FF6633","#FF6666","#FF6699","#FF66CC","#FF66FF","#009900","#009933","#009966","#009999","#0099CC","#0099FF","#339900","#339933","#339966","#339999","#3399CC","#3399FF","#669900","#669933","#669966","#669999","#6699CC","#6699FF","#999900","#999933","#999966","#999999","#9999CC","#9999FF","#CC9900","#CC9933","#CC9966","#CC9999","#CC99CC","#CC99FF","#FF9900","#FF9933","#FF9966","#FF9999","#FF99CC","#FF99FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#66CC00","#66CC33","#66CC66","#66CC99","#66CCCC","#66CCFF","#99CC00","#99CC33","#99CC66","#99CC99","#99CCCC","#99CCFF","#CCCC00","#CCCC33","#CCCC66","#CCCC99","#CCCCCC","#CCCCFF","#FFCC00","#FFCC33","#FFCC66","#FFCC99","#FFCCCC","#FFCCFF","#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC","#00FFFF","#33FF00","#33FF33","#33FF66","#33FF99","#33FFCC","#33FFFF","#66FF00","#66FF33","#66FF66","#66FF99","#66FFCC","#66FFFF","#99FF00","#99FF33","#99FF66","#99FF99","#99FFCC","#99FFFF","#CCFF00","#CCFF33","#CCFF66","#CCFF99","#CCFFCC","#CCFFFF","#FFFF00","#FFFF33","#FFFF66","#FFFF99","#FFFFCC","#FFFFFF");*/
var colorsTbl = new Array("#000000","#000033","#000066","#000099","#0000CC","#0000FF","#330000","#330033","#330066","#330099","#3300CC","#3300FF","#003300","#003333","#003366","#003399","#0033CC","#0033FF","#333300","#333333","#333366","#333399","#3333CC","#3333FF","#006600","#006633","#006666","#006699","#0066CC","#0066FF","#336600","#336633","#336666","#336699","#3366CC","#3366FF","#009900","#009933","#009966","#009999","#0099CC","#0099FF","#339900","#339933","#339966","#339999","#3399CC","#3399FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC","#00FFFF","#33FF00","#33FF33","#33FF66","#33FF99","#33FFCC","#33FFFF","#660000","#660033","#660066","#660099","#6600CC","#6600FF","#990000","#990033","#990066","#990099","#9900CC","#9900FF","#663300","#663333","#663366","#663399","#6633CC","#6633FF","#993300","#993333","#993366","#993399","#9933CC","#9933FF","#666600","#666633","#666666","#666699","#6666CC","#6666FF","#996600","#996633","#996666","#996699","#9966CC","#9966FF","#669900","#669933","#669966","#669999","#6699CC","#6699FF","#999900","#999933","#999966","#999999","#9999CC","#9999FF","#66CC00","#66CC33","#66CC66","#66CC99","#66CCCC","#66CCFF","#99CC00","#99CC33","#99CC66","#99CC99","#99CCCC","#99CCFF","#66FF00","#66FF33","#66FF66","#66FF99","#66FFCC","#66FFFF","#99FF00","#99FF33","#99FF66","#99FF99","#99FFCC","#99FFFF","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#CC6600","#CC6633","#CC6666","#CC6699","#CC66CC","#CC66FF","#FF6600","#FF6633","#FF6666","#FF6699","#FF66CC","#FF66FF","#CC9900","#CC9933","#CC9966","#CC9999","#CC99CC","#CC99FF","#FF9900","#FF9933","#FF9966","#FF9999","#FF99CC","#FF99FF","#CCCC00","#CCCC33","#CCCC66","#CCCC99","#CCCCCC","#CCCCFF","#FFCC00","#FFCC33","#FFCC66","#FFCC99","#FFCCCC","#FFCCFF","#CCFF00","#CCFF33","#CCFF66","#CCFF99","#CCFFCC","#CCFFFF","#FFFF00","#FFFF33","#FFFF66","#FFFF99","#FFFFCC","#FFFFFF");	
		var counter = 0;
		var obsah="";
		var total = colorsTbl.length;
//		alert(colorsTbl.length);
		var colorDiv = window.document.getElementById("colors");
		colorDiv.style.visibility = "visible";
		colorDiv.style.display = "block";
		obsah += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td><a href=\"javascript:nothing()\" title=\"ádná barva\"><img src=\"images/none.jpg\" border=\"0\" /></a></td><td colspan=\"12\"><a href=\"javascript:nothing()\" title=\"aktuálne vybraná barva\" class=\"long\" id=\"picker\"></a></td></tr>";
		
		for (var x=0;x<total;x+=12){
			obsah += "<tr>";
			for (var y=0;y<12;y++){
				obsah +="<td style=\"background-color:"+ colorsTbl[counter] +"\"><a href=\"javascript:changeColor('" + colorsTbl[counter] + "')\" title=\"" + colorsTbl[counter] + "\" onmouseover=\"javascript:repaint('"+colorsTbl[counter]+"')\" onmouseout=\"javascript:reset()\"></a></td>";
				counter++;
			}
			obsah += "</tr>";
		}
		obsah += "</table>";
		colorDiv.innerHTML = obsah;
	}

function loadIFrame()
	{
		var clanek = document.getElementById("clanek");
//		var tmp_1 = "<script language=\"javascript\" type=\"text/javascript\">window.onload = function(){parent.alert(\"start\");}window.onerror = err(e);function //err(e){window.document.innerHTML = \"error\" + e;}var iFram = parent.document.getElementById(\"editor\");iFram.contentWindow.document.onkeypress = //function(e){alert(\"Jooo!!!\");/*parent.content.document._clanek.clanek.value = editor.contentWindow.document.body.innerHTML;*/}<" + "/script>" + //_clanek.clanek.value;
//		window.document.getElementById("editorContainer").innerHTML = "";
		editor.contentWindow.document.close();
		editor.contentWindow.src = "http://www.aveelektro.com/blanc.html";
		editor.contentWindow.document.write("<link href=\"style_edit.css\" rel=\"stylesheet\" type=\"text/css\" />");
		editor.contentWindow.document.write(clanek.value);
//		editor.contentWindow.document.body.style.backgroundColor = "#fbdf96";
//		editor.contentWindow.document.body.style.fontFamily = "'Trebuchet MS', sans-serif";
//		editor.contentWindow.document.body.style.fontSizeAdjust = "10px";
//		editor.contentWindow.document.body.getElementsByTagName("img").style.setProperty('float','right',null);
//		editor.contentWindow.document.body.src = window.document._clanek.clanek.value;
//		window.document.getElementById("editorContainer").innerHTML = "<iFrame id=\"editor\" src=\"javascript:editor.contentWindow.document.body.innerHTML = window.document._clanek.clanek.value;\"></iFrame>";
	}

