var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
  XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
  XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID) {
  if(XMLHttpRequestObject) {
    var obj = document.getElementById(divID);
    XMLHttpRequestObject.open("GET", dataSource);

    XMLHttpRequestObject.onreadystatechange = function() {
      if (XMLHttpRequestObject.readyState == 4 &&
      XMLHttpRequestObject.status == 200) {
        obj.innerHTML = XMLHttpRequestObject.responseText;
      }
    }

    XMLHttpRequestObject.send(null);
  }
}

function makeUrl(sourceElement, targetElement) {
  source = document.getElementById(sourceElement).value;
  target = document.getElementById(targetElement);
  
   co = ["ě","š","č","ř","ž","ý","á","í","é","ú","ů","ď","ť","°","#","&","@","{","}","^",":","?","!",'"',"'","*","/","=","ˇ","_","-","|","€","[","]","(",")"];
  cim = ["e","s","c","r","z","y","a","i","e","u","u","d","t"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","",""];


  source = source.toLowerCase();
  source = source.replace(/\s\s+/g, "-");

  pocetSource = source.length;
  pocetCo = co.length;
  pocetCim = cim.length;

  for(j=0;j<pocetCo;j++) {
    source = Switch(source, co[j], cim[j]);
    source = source.replace(" ", "-");
  }
  out = source;
  
  //text = "/"+out+"/";
  text = ""+out+"";
  target.value = text;
}
function makeUrlClen(source1, source2, targetElement) {
  source1 = document.getElementById(source1).value;
  source2 = document.getElementById(source2).value;
  target = document.getElementById(targetElement);
  
   co = ["ě","š","č","ř","ž","ý","á","í","é","ú","ů","ď","ť","°","#","&","@","{","}","^",":","?","!",'"',"'","*","/","=","ˇ","_","-","|","€","[","]","(",")"];
  cim = ["e","s","c","r","z","y","a","i","e","u","u","d","t"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","",""];


  source1 = source1.toLowerCase();
  source1 = source1.replace(/\s\s+/g, "-");
  pocetSource = source1.length;

  source2 = source2.toLowerCase();
  source2 = source2.replace(/\s\s+/g, "-");
  pocetSource = source2.length;


  pocetCo = co.length;
  pocetCim = cim.length;

  for(j=0;j<pocetCo;j++) {
    source1 = Switch(source1, co[j], cim[j]);
    source1 = source1.replace(" ", "-");
  }
  for(j=0;j<pocetCo;j++) {
    source2 = Switch(source2, co[j], cim[j]);
    source2 = source2.replace(" ", "-");
  }
  out = source1+'-'+source2;
  
  //text = "/"+out+"/";
  text = ""+out+"";
  target.value = text;
}


var _ONE=0;
function Switch(item,OldChar,NewChar)
{
  var _ret="";
  var _flag=0;
  var _item=item.split("");
  for(var i=0;i<_item.length;i++)
  {
    if(!_flag&&_item[i]==OldChar)
	{
	  _item[i]=NewChar;
      _flag=_ONE;
	}
	_ret+=_item[i];
  }
  return(_ret);
}






function add_to_form(what) {
  document.forms.add_comment.text.focus();
  document.forms.add_comment.text.value=document.forms.add_comment.text.value+what;
}

function check_form() {
  var nick = document.add_comment.nick.value;
  var mail = document.add_comment.mail.value;
  var web = document.add_comment.web.value;
  var text = document.add_comment.text.value;

  if((nick=="") || (text=="")) {
    window.alert('Musíte vyplnit Jméno a Text príspevku!');
    return false;
   }
   exit;
}

function zkontroluj_email(adresa) {
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
  return adresa.search(re) == 0;
}

function kontrola() {
  var a = document.mail.nick.value;
  var b = document.mail.mail.value;
  var c = document.mail.subject.value;
  var d = document.mail.text.value;

  if (a=="" || b=="" || c=="" || d=="" || !zkontroluj_email(document.mail.mail.value)) {
    window.alert("Musíte vyplnit všechny údaje!");
    return false;
   }
  else return true;
}




function showPic(i) {
  document.getElementById("showHidePic"+i).style.visibility="visible";
}
function hidePic(i) {
  document.getElementById("showHidePic"+i).style.visibility="hidden";
}


function displayInvisible(what) {
  obj=document.getElementById(what);
  if (obj.style.display=='none') {
    obj.style.display='';
  } else {
    obj.style.display='none';
  }
}


function show(what) {
  document.getElementById(what).style.display='inline';
}
function hide(what) {
  document.getElementById(what).style.display='none';
}



function openWindow() {
  window.open("","okno","width=800,height=500,scrollbars=yes,resizable=yes,top=10,left=10");
}




function show(desc) {
  document.getElementById(desc).style.visibility='visible';
}

function hide(desc) {
  document.getElementById(desc).style.visibility='hidden';
}




























function textovePolickoOdebratRadek(policko) {
  var policko = document.getElementById(policko);
  policko.rows = policko.rows - 1;
}
function textovePolickoPridatRadek(policko) {
  var policko = document.getElementById(policko);
  policko.rows = policko.rows + 1;
}
function hideDynamicFieldset(name, imageA, imageB) {
  var img = document.getElementById("img_"+name);
  var div = document.getElementById('div_'+name);

  if(div.style.display == 'block') {
    div.style.display = 'none';
    img.src = imageA;
  } else {
    div.style.display = 'block';
    img.src = imageB;
  }
}
function OpenFile( fileUrl ) {
  window.opener.document.getElementById('src').value = fileUrl;

  if (window.opener.document.getElementById('src').onchange != null) {
    window.opener.document.getElementById('src').onchange();
  }

  window.top.close();
  window.top.opener.tinyfck.focus();
}




function checkAll(name, max) {
  for(i=0;i<max;i++) {
    document.getElementById(name+'_'+i).checked = true;
  }
}
function unCheckAll(name, max) {
  for(i=0;i<max;i++) {
    document.getElementById(name+'_'+i).checked = false;
  }
}





function moveElement(event) {
  var testDiv = document.getElementById('test');
  x=event.clientX;
  y=event.clientY;
  testDiv.style.left = x + 'px';
  testDiv.style.top = y + 'px';
}






function openWindow(element) {
  document.getElementById(element).style.display='block';
}
function closeWindow(element) {
  document.getElementById(element).style.display='none';
}


