function loaded()
{
	if(self.location!="about:blank")
	{
		fndblock=0
		doc=document.getElementById("actualContent")
		if(doc == null) return

		var tagy = new Array("table", "img")
		for(j = 0; j < tagy.length; j++)
		{
			tags=doc.getElementsByTagName(tagy[j])
			for(i=0;i<tags.length;++i)
			{
				tags[i].ondblclick = doit;
			}
		}
	}
}

function HtmlManager()
{
	if(editor_on == 1)
	{
		MyWindowOpen(GetFormPath("HTML"),"HTML",370,300,"no","no")
		opener=self;
	}
}

function InsertList(obj)
{
	ky = doc.selection.createRange();
	if(doc.queryCommandState(obj)==true)
	{
		doc.execCommand(obj);
		ky.select();
		doc.onkeypress = dokeypress;
	}
	else
	{
		ky.pasteHTML('<P>');
		doc.execCommand(obj);
		doc.onkeypress = dumbkeypress;
	}
}

function doit()
{
	selectedTD=0;
	if(editor_on==1)
	{
		selectedEL=event.srcElement;
		if(selectedEL.tagName.toUpperCase() == "IMG")
		{
			adjust_img(selectedEL);
		}
		else
		{		
			if(selectedEL.tagName.toUpperCase() != "TD")
			{
				upEL=selectedEL.parentElement;
				while(upEL.tagName.toUpperCase() != "TD")
				{
					if(upEL.tagName.toUpperCase() == "TD")
					{
						selectedTD=upEL;
						break;
					}
					else
					{
						upEL=upEL.parentElement;
					}
				}
			}
			else
			{
				selectedTD = selectedEL;
			}
		}
		if(selectedTD != 0)
		{
			tablemechanic();
		}
	}
}

function get_color(which)
{
	color_what=which;
	if (editor_on == 1)	
	{
		wid=280;
		hei=360;
		LeftPos = (screen.availWidth-wid)/2;
		TopPos = (screen.availHeight-hei)/2;
		w=window.open(GetFormPath("COLOR"),"COLOR","top="+TopPos+",left="+LeftPos+",width="+wid+",height="+hei);
		w.focus();
		opener=self;
	}
}
function set_color(obj)
{
	document.execCommand(color_what, false, obj);
}
function toedit()
{
	if(editor_on==0)
	{
		document.Form1.URL.value=self.location
		for(i=1;i<doc.all.length;i++)
		{
			if(doc.all[i].getAttribute('editblock') && doc.all[i].style.borderStyle != "solid")
			{
				document.all[i].style.borderStyle = "dashed";
				document.all[i].style.borderColor = "#3366ff";
				document.all[i].style.borderWidth = "1";
				document.all[i].unselectable = "off";
				document.all[i].contentEditable=true;
			}
		}
		show_cells()
		editor_on=1;
	}
	else if(editor_on==1)
	{
		for(i=1;i<document.all.length;i++)
		{
			if(document.all[i].getAttribute('editblock') && doc.all[i].style.borderStyle != "solid")
			{
				document.all[i].style.borderStyle = "none"
				document.all[i].style.borderWidth = "0"
				document.all[i].unselectable = "on";
				document.all[i].contentEditable=false
			}
		}
		unshow_cells()
		editor_on=0;
	}
}
function show_cells()
{
	for(i=1;i<doc.all.length;i++)
	{
		if(doc.all[i].getAttribute('contentEditable') == "false" &&  (doc.all[i].tagName.toUpperCase()=="TD" || doc.all[i].tagName.toUpperCase()=="TABLE"))
		{
			if(doc.all[i].getAttribute('border')<1)
			{
				doc.all[i].style.borderStyle = "dashed"
				doc.all[i].style.borderWidth = "1"
				doc.all[i].style.borderColor = "#cccccc"
			}
		doc.all[i].contentEditable="true"
		doc.all[i].unselectable = "off";
		}	
	}
}
function unshow_cells()
{
	for(i=1;i<doc.all.length;i++)
	{
		if(doc.all[i].getAttribute('contentEditable') == "true" && (doc.all[i].tagName.toUpperCase()=="TD" || doc.all[i].tagName.toUpperCase()=="TABLE"))
		{
			if(doc.all[i].getAttribute('border')<1)
			{
				doc.all[i].style.borderStyle = "none"
				doc.all[i].style.borderWidth = "0"
				doc.all[i].style.borderColor = ""		
			}
			doc.all[i].contentEditable="false"
			doc.all[i].unselectable = "on";
		}
	}
}

function toggle(obj)
{
	//sel=document.selection.createRange();
	if (obj != "" && editor_on == 1 && obj == "Refresh")
	{
		if (confirm("Chcete naozaj zrušiť všetky zmeny?"))
		{
			document.execCommand(obj)
		}
		init()
	}
	if (obj != "" && editor_on == 1 && obj != "Refresh")
	{
		//document.execCommand(obj);
		document.execCommand(obj,false,true)
	}
}

function chng_size(obj)
{
	if (obj != "" && editor_on == 1)
	{	
		document.execCommand("FontSize", false, obj);
	}
}
function chng_family(obj)
{
	if (obj != "" && editor_on == 1)
	{
		document.execCommand("FontName", false, obj);
	}
}
function getfont()
{
	if(editor_on == 1)
	{
		LeftPos = (document.body.offsetWidth-110)/2;
		TopPos = (document.body.offsetHeight-170)/2;
		fntWin=window.open(GetFormPath("FONT"),"FONT","status=0,top="+TopPos+",left="+LeftPos+",width=110,height=170")
		window.status=""
		opener=self
	}
}
imgURL='';
function setimage()
{
	if(editor_on == 1)
	{
		if(imgURL.length > 10)
		{
			imgURL=unescape(imgURL);
			document.execCommand("InsertImage", false, imgURL);
			loaded();
		}
		else
		{
			LeftPos = (document.body.offsetWidth-430)/2;
			TopPos = (document.body.offsetHeight-485)/2;
			window.open(GetFormPath("IMAGER"),"IMAGER","status=0,resizable=1,top="+TopPos+",left="+LeftPos+",width=417,height=480");
			opener=self;
		}
		imgURL='';
	}
}
function VybratObr(ctrlid, previd, fulltag)
{
	var params;
	temp = GetFormPath("IMAGER");
	if(ctrlid != null && ctrlid != "")
		params = "ctrlid=" + ctrlid;
	if(previd != null && previd != "")
	{
		if(params != "") params += "&";
		params += "previd=" + previd;
	}
	if(fulltag != null && fulltag != "")
	{
		if(params != "") params += "&";
		params += "fulltag=" + fulltag;
	}
	if(params != "") temp += "?" + params;
	LeftPos = (document.body.offsetWidth-430)/2;
	TopPos = (document.body.offsetHeight-485)/2;
	window.open(temp,"IMAGER","status=0,resizable=1,top="+TopPos+",left="+LeftPos+",width=417,height=470");
}
function help()
{
	LeftPos = (document.body.offsetWidth-430)/2;
	TopPos = (document.body.offsetHeight-415)/2;
	window.open(GetFormPath("HELPER"),"HELPER","status=0,resizable=0,scrollbars=1,top="+TopPos+",left="+LeftPos+",width=430,height=415")
}
function pictures(obj)
{
	if(editor_on == 1)
	{
		url="Forms/Imager.html";
		if(obj == "deleteimage")
		{	
			wid=340;
		}
		else
		{
			wid=530;
		}
		LeftPos = (document.body.offsetWidth-wid)/2;
		TopPos = (document.body.offsetHeight-170)/2;
		window.open(url,"PICTURES","status=0,resizable=0,top="+TopPos+",left="+LeftPos+",width="+wid+",height=170");
		opener=self;
	}
}
function CreateInput()
{
	if(editor_on == 1)
	{
		url=GetFormPath("CREATEINPUT");
		wid=490;
		LeftPos = (document.body.offsetWidth-wid)/2;
		TopPos = (document.body.offsetHeight-170)/2;
		window.open(url,"CREATEINPUT","top="+TopPos+",left="+LeftPos+",width="+wid+"px,height=201px");
		opener=self;
	}
}
function CreateButton()
{
	if(editor_on == 1)
	{
		url=GetFormPath("CREATEBUTTON");
		wid=590;
		LeftPos = (document.body.offsetWidth-wid)/2;
		TopPos = (document.body.offsetHeight-170)/2;
		window.open(url,"CREATEBUTTON","top="+TopPos+",left="+LeftPos+",width="+wid+"px,height=201px");
		opener=self;
	}
}
function CreateLink()
{
	if(editor_on == 1)
	{
		url=GetFormPath("CREATELINK");
		wid=490;
		LeftPos = (document.body.offsetWidth-wid)/2;
		TopPos = (document.body.offsetHeight-170)/2;
		window.open(url,"CREATELINK","top="+TopPos+",left="+LeftPos+",width="+wid+"px,height=201px");
		opener=self;
	}
}
function upx(obj)
{
	document.all[obj].style.border="1px outset"
	document.all[obj].style.backgroundColor="buttonhighlight"
}	
function dnx(obj)
{
	document.all[obj].style.border="1px inset"
	document.all[obj].style.backgroundColor="buttonface"
}	
function outx(obj)
{
	document.all[obj].style.border="1px solid buttonface"
	document.all[obj].style.backgroundColor="buttonface"
}	
function adjusting_img()
{
	liveImg.width=aimg.document.forms[0].wid.value
	liveImg.height=aimg.document.forms[0].hei.value
	liveImg.hspace=aimg.document.forms[0].hor.value
	liveImg.vspace=aimg.document.forms[0].ver.value
	liveImg.border=aimg.document.forms[0].bdr.value
	liveImg.alt=aimg.document.forms[0].alt.value
	liveImg.align=aimg.document.forms[0].align.value
}
liveImg=''
function adjust_img(img)
{
	liveImg=img;
	wid=395;
	hei=260;
	LeftPos = (screen.width) ? (screen.width-wid)/2 : 0;
	TopPos = (screen.height) ? (screen.height-hei)/2 : 0;
	aimg=window.open(GetFormPath("IMGADJ"),"IMGADJ","scrollbars=1,top="+TopPos+",left="+LeftPos+",width="+wid+",height="+hei);
	aimg.focus();
	opener=self;
}

function tablewizard()
{
	if(editor_on == 1)
	{
		wid=350;
		hei=480;
		LeftPos = (screen.availWidth-wid)/2;
		TopPos = (screen.availHeight-hei)/2;	
		window.open(GetFormPath("CREATETABLE"),"CREATETABLE",
		"scrollbars=1,top="+TopPos+",left="+LeftPos+",width="+wid+",height="+hei);
		opener=self;
	}
}
function insert_the_table(tblTBL)
{
	sel=document.selection.createRange();
	sel.pasteHTML(tblTBL);
	sel.select();
	show_cells();
	loaded();
}

function tablemechanic()
{
		wid=300;
		hei=335;
		LeftPos = (screen.width) ? (screen.width-wid)/2 : 0;
		TopPos = (screen.height) ? (screen.height-hei)/2 : 0;
		w=window.open(GetFormPath("TABLADJ"),"TABLADJ",	"scrollbars=1,top="+TopPos+",left="+LeftPos+",width="+wid+",height="+hei);
		w.focus();
		opener=self;
}
function check_page()
{
	loaded()
}
function init()
{
	editor_on=0;
	toedit();
}

function GetFormPath(form)
{	
	switch(form)
	{
		case "HTML":
			cesta = "Forms/HtmlManager.aspx"; break;
		case "COLOR":
			cesta = "Forms/Colorer.html"; break;
		case "FONT":
			cesta = "Forms/Fonter.html"; break;
		case "IMAGER":
			cesta = "Forms/Imager.aspx"; break;
		case "HELPER":
			cesta = "Forms/Help.html"; break;
		case "CREATEINPUT":
			cesta = "Forms/Inputer.aspx"; break;
		case "CREATEBUTTON":
			cesta = "Forms/Buttoner.aspx"; break;
		case "CREATELINK":
			cesta = "Forms/Linker.aspx"; break;
		case "CREATETABLE":
			cesta = "Forms/Tabler.html"; break;
		case "TABLADJ":
			cesta = "Forms/TablerModif.html"; break;
		case "IMGADJ":
			cesta = "Forms/ImagerModif.aspx"; break;
	}
	return GetRootPath() + "/Admin/" + cesta;
}
				

function keygen()
{
	MyWindowOpen('Admin/KeyGen/KeyGen.aspx','keygen',300,50,false,false);
}

function pagemap()
{
	MyWindowOpen('PortalMap.aspx','portalmap',700,700,'yes','yes');
}

function OpenModifications()
{
	MyWindowOpen('Admin/ModifObjList.aspx','mdfobj',520,250,false,false);
}

function Mode(divId, editable)
{
	var objDiv = document.getElementById("actCont" + divId)
	var objMode = document.getElementById(divId + "Hmode")
	var objHeight = objDiv.style.height
	if(!objHeight) objHeight = "400px"
	if(objMode.value == "False")
	{
	editor_on= 0;
		objDiv.outerHTML = "<TEXTAREA "+editable+" id='actCont"+divId+"' style='margin:0px;width:100%;height:"+objHeight+"'>"+objDiv.innerHTML+"</TEXTAREA>"
		if((imgObj = document.getElementById(divId + "Obr")) != null) imgObj.src = GetRootPath() +"/Images/System/design.gif"
		objMode.value = "True"
		
	}
	else
	{
	editor_on= 1;
		cntEd = (editable != null) ? "False" : "True";
		objDiv.outerHTML = "<div id='actCont"+divId+"' contentEditable='"+cntEd+"' class='htmlField' style='height:"+objHeight+"'>"+objDiv.value+"</div>"
		if((imgObj = document.getElementById(divId + "Obr")) != null) imgObj.src = GetRootPath() +"/Images/System/html.gif"
		objMode.value = "False"
	}
}