var tempimg = new Image();
tempimg.src = "layout/styles/loading.gif";

function editor_toEditor(target)
{
  var editor = document.getElementById('editor_'+target);
  var text = document.getElementById('data_'+target);
  editor.contentWindow.document.body.innerHTML = text.innerHTML;
  return true;
}
function editor_toTextarea(target)
{
  var editor = document.getElementById('editor_'+target);
  var text = document.getElementsByName(target)[0];
  text.value = editor.contentWindow.document.body.innerHTML;
  return true;
}
function editor_setup()
{
	var editors = document.getElementsByTagName('iframe');
	var i;
	for(i = 0; i < editors.length; i++)
	{
		editors[i].contentWindow.document.designMode = 'on';
	}
}
function editor_submit()
{
	var editors = document.getElementsByTagName('iframe');
	var i;
	for(i = 0; i < editors.length; i++)
	{
		var eid = editors[i].id;
		var tname = eid.split("_")[1];
		var text = document.getElementsByName(tname)[0];
		
		text.value = editors[i].contentWindow.document.body.innerHTML;
	}
}
function editor_execCommand(target, command, value)
{
  var top = document.body.scrollTop;
  var editor = document.getElementById('editor_'+target);
  editor.contentWindow.document.execCommand(command, false, value);
  editor.contentWindow.focus();
  document.body.scrollTop = top;
}
function editor_eurl(target)
{
  var url = document.getElementById('url_'+target).value;
  editor_execCommand(target, 'createLink', url);
}
function editor_eimg(target)
{
  var url = document.getElementById('img_'+target).value;
  editor_execCommand(target, 'insertImage', url);
}
function editor_galerie(target)
{
  window.open("galerie_shout.php?target="+target,"x","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=yes,width=800,height=300,left=500,top=50"); 
}
function editor_insertimg(target, img)
{
  var pos = document.getElementById('pos').value;
  var vel = document.getElementById('vel').value;
  var url = 'data/galerie/'+vel+'/'+img;
  var urlp = 'data/galerie/'+vel+'/'+img+'xyz';
  var urlm = "javascript:zobraznahled('data/galerie/medium/"+img+"')";
  var editor = window.opener.document.getElementById('editor_'+target);
  editor.contentWindow.document.execCommand('insertImage', false, urlp);
  var str = editor.contentWindow.document.body.innerHTML;
  var newstr = str.replace('<img src="'+urlp+'">', '<a href="'+urlm+'"><img src="'+url+'" style="float:'+pos+';" class="text'+pos+'"></a>');
  editor.contentWindow.document.body.innerHTML = newstr;
  editor.contentWindow.focus();
}
function editor_inserturl(target)
{
  var url = document.getElementById('url_'+target).value;
  var urlp = document.getElementById('url_'+target).value+'xyz';
  var editor = document.getElementById('editor_'+target);
  editor.contentWindow.document.execCommand('createLink', false, urlp);
  var str = editor.contentWindow.document.body.innerHTML;
  var newstr = str.replace('href="'+urlp+'"', 'href="'+url+'" onclick="target=\'_blank\';"');
  editor.contentWindow.document.body.innerHTML = newstr;
  editor.contentWindow.focus();
}

function zobrazskryj(cil)
{
  var item = document.getElementById(cil);
  if(item.style.display == 'block')
    item.style.display = 'none';
  else
    item.style.display = 'block';
}
function gzobraz(cil)
{
  var img = document.getElementById('img'+cil);
  var over = document.getElementById('over'+cil);
  img.style.display = 'block';
  if(document.getElementById('txt'+cil) != null) document.getElementById('txt'+cil) = 'block';
}
function gskryj(cil)
{
  var img = document.getElementById('img'+cil);
  var over = document.getElementById('over'+cil);
  img.style.display = 'none';
  if(document.getElementById('txt'+cil) != null) document.getElementById('txt'+cil) = 'block';
}

function winHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
    myHeight = window.innerHeight;
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    myHeight = document.documentElement.clientHeight;
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    myHeight = document.body.clientHeight;
  return myHeight;
}
function zobraznahled(i)
{
  var nahled = document.getElementById("nahled");
  var img = document.getElementById("nahledimg");
  var imgn = document.getElementById("imgn");
  var button = document.getElementById("nahledbutton");
  var ph = "layout/styles/loading.gif";
  imgn.src = ph;
  imgn.src = i;
  button.style.left = ((screen.width / 2) - 45) + 'px';
  nahled.style.display = 'block';
  nahled.style.height = winHeight() + 'px';
  img.style.display = 'block';
}
function skryjnahled()
{
  var nahled = document.getElementById("nahled");
  var img = document.getElementById("nahledimg");
  nahled.style.display = 'none';
  img.style.display = 'none';
}
function faqq(i)
{
	faq = document.getElementById('faq'+i);
	if(faq.style.display == 'block')
		faq.style.display = 'none';
	else
		faq.style.display = 'block';
}