wysiwyg = false;
var glselect;

// floating layer
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isActive=false;

function MoveInit(e){
  topOne=isIE ? "BODY" : "HTML";
  whichOne=isIE ? document.all.FloatingLayer : document.getElementById("FloatingLayer");
  ActiveOne=isIE ? event.srcElement : e.target;
  while (ActiveOne.id!="titleBar"&&ActiveOne.tagName!=topOne){
    ActiveOne=isIE ? ActiveOne.parentElement : ActiveOne.parentNode;
  }
  if (ActiveOne.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichOne.style.left);
    nowY=parseInt(whichOne.style.top);
    MoveEnabled=true;
    document.onmousemove=Move;
  }
  pageMousedown(event);
}

function MoveInitC(e){
  topOne=isIE ? "BODY" : "HTML";
  whichOne=isIE ? document.all.FloatingLayerColor : document.getElementById("FloatingLayerColor");
  ActiveOne=isIE ? event.srcElement : e.target;
  while (ActiveOne.id!="titleBarC"&&ActiveOne.tagName!=topOne){
    ActiveOne=isIE ? ActiveOne.parentElement : ActiveOne.parentNode;
  }
  if (ActiveOne.id=="titleBarC"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichOne.style.left);
    nowY=parseInt(whichOne.style.top);
    MoveEnabled=true;
    document.onmousemove=Move;
  }
  pageMousedown(event);
}


function Move(e){
  if (!MoveEnabled) return;
  whichOne.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
  whichOne.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;
}

function MoveN4(whatOne){
  if (!isN4) return;
  N4=eval(whatOne);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isActive){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function ToggleFloatingLayer(DivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[DivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(DivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[DivID].style.visibility = iState ? "visible" : "hidden";
    }
}


// editor fce - ftp

  function ZobrazFTP(show)
  {
//     alert(document.onmousedown);
     if (show)
     {
        ZobrazColor(0);
        document.onmousedown=MoveInit;
        document.onmouseup=Function("MoveEnabled=false");
     }
     else
     {
        document.onmousedown= pageMousedown;
        document.onmouseup=null;
     }
     ToggleFloatingLayer('FloatingLayer',show);
  }

  function ZobrazColor(show)
  {
//     alert(document.onmousedown);
//     alert(parent.editor.document.selection.createRange().text);
/*     if (glselect == null)
     {
        glselect = editor.document.selection.createRange();
     }
     else
     {
       glselect.select();
     }
     alert(glselect);
*/
     if (show)
     {
        ZobrazFTP(0);
        document.onmousedown=MoveInitC;
        document.onmouseup=Function("MoveEnabled=false");
     }
     else
     {
        document.onmousedown= pageMousedown;
        document.onmouseup=null;
     }
     ToggleFloatingLayer('FloatingLayerColor',show);
  }

/*
<!-- Start Floating Layer -->
<div id="FloatingLayer" style="position:absolute;width:250px;left:100;top:100;visibility:visible">
  <table border="0" width="250" bgcolor="#FF6600" cellspacing="0" cellpadding="5">
    <tr>
      <td width="100%"> <table border="0" width="100%" cellspacing="0" cellpadding="0" height="36">
          <tr>
            <td id="titleBar" style="cursor:move" width="100%"> <ilayer width="100%" onSelectStart="return false">
              <layer width="100%" onMouseover="isActive=true;if (isN4) MoveN4(FloatingLayer)" onMouseout="isActive=false">
              <font face="Arial" color="#FFFFFF">Layer Title</font></layer>
              </ilayer></td>
            <td style="cursor:hand" valign="top"> <a href="#" onClick="ToggleFloatingLayer('FloatingLayer',0);return false"><font color="#ffffff" size="2" face="arial"  style="text-decoration:none">X</font></a>
            </td>
          </tr>
          <tr>
            <td width="100%" bgcolor="#FFFFFF" style="padding:4px" colspan="2">
              <!-- place your HTML content here-->
			  Put text, tables or any other HTML contents here, as you would put
in any other HTML page.
 ..... and more.

              <!-- End of content area -->
            </td>
          </tr>
        </table></td>
    </tr>
  </table>
</div>
<!-- End Floating layer -->
*/
/*
<!-- To Show The Layer -->
<a href="javascript:ToggleFloatingLayer('FloatingLayer',1);">Show</a>
<input type="button" onClick="ToggleFloatingLayer('FloatingLayer',1);" value="Show Layer">

<!-- To Hide The Layer -->
<a href="javascript:ToggleFloatingLayer('FloatingLayer',0);">Hide</a>
<input type="button" onClick="ToggleFloatingLayer('FloatingLayer',0);" value="Hide Layer">
*/

// prehled article fce


// fce edit news
function SubmitNews(index, opID)
{
//  location.replace(index+"?menu=edit_news&volba=del");
//  document.it_news.actionID.value = opID;
  document.frm_news.action = index+"?menu=edit_news&volba="+opID;
  document.frm_news.submit();
}

function SubmitCourse(index, opID)
{
  document.frm_course.action = index+"?menu=edit_catalog&volba="+opID;
  document.frm_course.submit();
}

function overeniDisData(formular)
{
  ok = true;
  msg = "Chyba! Nejsou vyplněny správně následující položky:";
  if (document.forms[formular].dis_jmeno.value.length < 1)
  {
     ok = false;
     msg += " jméno"
  }
  if (document.forms[formular].dis_email.value.length < 1)
  {
     ok = false;
     msg += " email"
  }
  else
  {
       re = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$")
       if (!re.test(document.forms[formular].dis_email.value))
       {
          msg += " email";
          ok = false;
       }
  }

  if (document.forms[formular].dis_caption.value.length < 1)
  {
     ok = false;
     msg += " název"
  }
  
  if (document.forms[formular].dis_text.value.length < 1)
  {
     ok = false;
     msg += " obsah"
  }
  msg += '.';
  if (ok)
  {
     document.forms[formular].submit();
  }
  else
  {
     alert(msg);
  }
  
  return ok;
}

function overeniKomData(formular)
{
  ok = true;
  msg = "Chyba! Nejsou vyplněny správně následující položky:";
  if (document.forms[formular].kom_jmeno.value.length < 1)
  {
     ok = false;
     msg += " jméno"
  }
  if (document.forms[formular].kom_email.value.length < 1)
  {
     ok = false;
     msg += " email"
  }
  else
  {
       re = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$")
       if (!re.test(document.forms[formular].kom_email.value))
       {
          msg += " email";
          ok = false;
       }
  }

  
  if (document.forms[formular].kom_text.value.length < 1)
  {
     ok = false;
     msg += " obsah"
  }
  msg += '.';
  if (ok)
  {
     document.forms[formular].submit();
  }
  else
  {
     alert(msg);
  }
  
  return ok;
}

function overeniRegistrace(formular)
{
   ok = true
   if (document.forms[formular].reg_prijmeni.value.length < 1)
   {
      alert("Chybí nebo špatně vyplněné příjmení!")
      ok = false
   }
   else
   if (document.forms[formular].reg_jmeno.value.length < 1)
   {
      alert("Chybí nebo špatně vyplněné jméno!")
      ok = false
   }
   else
   if (document.forms[formular].reg_tele.value.length < 6)
   {
      alert("Chybí nebo špatně vyplněný telefon!")
      ok = false
   }
/*   else
   if (document.forms[formular].reg_mail.value.length < 3)
   {
      alert("Chybí nebo špatně vyplněný email!")
      ok = false
   }
*/ 

   if (document.forms[formular].reg_mail.value.length > 0)
   {
       re = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$")
       if (!re.test(document.forms[formular].reg_mail.value))
       {
          alert('Emailová adresa není ve správně zadaná!');
          ok = false
       }
   }

   if (document.forms[formular].reg_tele.value.length > 5)
   {

       re = new RegExp("^[ 0-9\.\+\/\-]{8,}$")
       if (!re.test(document.forms[formular].reg_tele.value))
       {
          alert('Telefonní číslo není správně zadané!');
          ok = false
       }
   }
   
   if (ok)
   {
       document.forms[formular].submit();
   }
   
   return ok;
}

function SubmitSupply(index, opID)
{
//  location.replace(index+"?menu=edit_news&volba=del");
//  document.it_news.actionID.value = opID;
  document.frm_supply.action = index+"?menu=edit_supply&volba="+opID;
  document.frm_supply.submit();
}

function selectnewsrow(aobj, selected)
{
  num = aobj.id.slice(3);
  eval("idfnr = fnr"+num);
  eval("idsnr = snr"+num);

  if (selected)
  {

     if (idfnr.className=='backnewsrow03')
     {
       idfnr.className = 'backnewsrowsel01';
       idsnr.className = 'backnewsrowsel01';
     }
     else
     {
       idfnr.className = 'backnewsrowsel';
       idsnr.className = 'backnewsrowsel';
     }
//     idfnr.style.backgroundColor = "#B3C8DC";
//     idsnr.style.backgroundColor = "#B3C8DC";
  }
  else
  {

// class="backnewsrow01"':'class="backnewsrow02"'
     if (idfnr.className=='backnewsrowsel01')
     {
       idfnr.className = 'backnewsrow03';
       idsnr.className = 'backnewsrow03';
     }
     else
     {
       idfnr.className = ((num % 2) == 0?"backnewsrow01":"backnewsrow02");
       idsnr.className = ((num % 2) == 0?"backnewsrow01":"backnewsrow02");
     }
/*
     idfnr.style.backgroundColor = "#EAEAEE";
     idsnr.style.backgroundColor = "#EAEAEE";
*/
  }
}


//  ftp
function ZobrazSoubor(object)
{
  if (object.options[object.selectedIndex].value == "d")
  {
     libraryavailitem1.style.display="none";
     libraryavailitem2.style.display="none";
  }
  else
  {
     libraryavailitem1.style.display="block";
     libraryavailitem2.style.display="block";
  }
}


function SmazatAdresar(index, adresaritem, lid, lsid)
{

    if (adresaritem == "" && lid ==0 && lsid ==0)
    {
      if (confirm ("Opravdu chcete smazat všechny adresářové položky? "))
      {
         location.replace(index+"?menu=edit_ftp&volba=del&lid="+lid+"&lsid="+lsid)
      }
    }
    else
    {
      if (confirm ("Opravdu chcete smazat vybranou adresářovou položku: "+adresaritem+"\n včetně podadresářů?"))
      {
         location.replace(index+"?menu=edit_ftp&volba=del&lid="+lid+"&lsid="+lsid)
      }
    }
}


function vyber(myForm, myField, isCheck)
{
//   alert("Je");
   var obj = document.forms[myForm].elements[myField];
//   alert(toString(obj.length));
   for (i = 0; i < obj.length; i++)
   {
      obj[i].checked = isCheck;
//      alert(obj[i].value.toString(10));
   }
}

//menu fce
function SmazatMenu(menuitem, mid, msid)
{

    if (menuitem == "" && mid ==0 && msid ==0)
    {
      if (confirm ("Opravdu chcete smazat všechny položky menu? "))
      {
         location.replace("index.php?menu=edit_menu&volba=del&mid="+mid+"&msid="+msid)
      }
    }
    else
    {
      if (confirm ("Opravdu chcete smazat vybranou položku menu: "+menuitem+"\n včetně podmeny?"))
      {
         location.replace("index.php?menu=edit_menu&volba=del&mid="+mid+"&msid="+msid)
      }
    }
}

// editor
function editorDoCmd(Object, Cmd, Flag, Value)
{
   Object.focus();
   Object.document.execCommand(Cmd, Flag, Value);
}

function editorFont(select, Object, Name)
{
  if(Name != '')
  {
     Object.focus();
     Object.document.execCommand('fontname', false, Name);
     select.selectedIndex=0;
  }
}

function editorFontsize(select, Object, Size)
{
  if(Size != null)
  {
     Object.focus();
     Object.document.execCommand('fontsize', false, Size);
     select.selectedIndex=0;
  }
}

function editorFormatBlock(select, Object, Name)
{
  if(Name != '')
  {

     if (Name == 'removeFormat')
     {
      Object.focus();
      Object.document.execCommand('removeFormat');
      select.selectedIndex=0;
     }
     else
     {
      Object.focus();
      Object.document.execCommand('FormatBlock', false, Name);
      select.selectedIndex=0;
     }
  }
}

function generujTable(Object, Typ)
{
    Object.focus();
    var cursor = Object.document.selection.createRange();
    if (Typ == "spinning")
    {
        var dny = new Array("Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle");
        var interval = new Array("7:00-8:00", "7:30-8:30", "10:00-11:00", "11:00-12:00", "12:00-13:00", "12:30-13:30", "16:30-17:30", "17:30-18:30", "18:00-19:00", "18:30-19:30", "19:30-20:30");

/*
7,00
7,30
10,00
11,00
12,00
12,30
16,30
17,30
18,00
18,30
19,30
*/
        style = "style='border: 1px solid #aeaeae;' width='64'";
        style_nadpis = "style='border: 1px solid #aeaeae; background-color: #FDC25A; text-align: center;' width='64'";
    }
    else
    {
        var dny = new Array("Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek"); //, "Sobota", "Neděle");
        var interval = new Array("7:15-8:15", "9:00-10:00", "10:00-11:00", "12:00-13:00", "16:00-17:00", "17:00-18:00", "18:00-19:00", "19:00-20:00", "20:00-21:00");
        style = "style='border: 1px solid #aeaeae;' width='85'";
        style_nadpis = "style='border: 1px solid #aeaeae; background-color: #FDC25A; text-align: center;' width='85'";
    }
    cmd = "<table style='table-layout: fixed; border-collapse: collapse; font-size: 9px;'>";
    cmd = cmd + "<tr>";
    cmd = cmd + "<td "+style_nadpis+">";
    cmd = cmd + "&nbsp;";
    cmd = cmd + "</td>";
    for (ind=0; ind < dny.length; ind++)
    {
        cmd = cmd + "<td "+style_nadpis+" >";
        cmd = cmd + dny[ind];
        cmd = cmd + "</td>";
    }
    cmd = cmd + "</tr>";
    for (ynd=0; ynd < interval.length; ynd++)
    {
       cmd = cmd + "<tr>";
       cmd = cmd + "<td "+style_nadpis+">";
       cmd = cmd + interval[ynd];
       cmd = cmd + "</td>";
       for (ind=0; ind < dny.length; ind++)
       {
           cmd = cmd + "<td "+style+" onclick='this.style.backgroundColor=#E2E2E2'>";
           cmd = cmd + "&nbsp;";
           cmd = cmd + "</td>";
       }
       cmd = cmd + "</tr>";
    }
    cmd = cmd + "</table>";
//  cmd = insertarticlecmd + it_caption
//  cmd = insertarticlecmd + "</a>";
  cursor.pasteHTML(cmd);


}

function testicek(editor)
{
  //alert(editor.style.backgroundColor);
//  fe = editor.document.childNodes.item(0).childNodes.item(1);
//   fe = document.getElementById("editor");
//   alert(fe.nodeName);
//  alert(editor.document.getNodeName());
//  editor.style.backgroundColor = "red";
    editor.focus();
    instext = editor.document.selection.createRange().text;
//    alert(editor.document.selection.createRange().nodeName);
    txtobj = editor.document.selection.createRange();
    if (txtobj.parentElement().className != "green")
    {
       txtobj.parentElement().className = "green";
    }
    else
    {
       txtobj.parentElement().className = "";
    }
/*    var cursor = editor.document.selection.createRange();
    cmd = '<div class="green">';
    cmd = cmd + instext;
    cmd = cmd + '</div>';
    cursor.pasteHTML(cmd); */
}

function generujTableList(select, Object, Typ)
{
    Object.focus();
    var cursor = Object.document.selection.createRange();
    if (Typ == "spinning")
    {
        var dny = new Array("Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle");
        var interval = new Array("7:00-8:00", "7:30-8:30", "10:00-11:00", "11:00-12:00", "12:00-13:00", "12:30-13:30", "16:30-17:30", "17:30-18:30", "18:00-19:00", "18:30-19:30", "19:30-20:30");

        style = "style='border: 1px solid #aeaeae;' width='64'";
        style_nadpis = "style='border: 1px solid #aeaeae; background-color: #FDC25A; text-align: center;' width='64'";
    }
    else
    if (Typ == "badmington")
    {
        var dny = new Array("Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle");
        var interval = new Array("7:00-8:00", "8:00-9:00", "9:00-10:00", "10:00-11:00", "11:00-12:00", "12:00-13:00", "13:00-14:00", "14:00-15:00", "15:00-16:00", "16:00-17:00", "17:00-18:00", "18:00-19:00", "19:00-20:00", "20:00-21:00", "21:00-22:00");

        style = "style='border: 1px solid #aeaeae;' width='64'";
        style_nadpis = "style='border: 1px solid #aeaeae; background-color: #FDC25A; text-align: center;' width='64'";
    }
    else
    {
        var dny = new Array("Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek"); //, "Sobota", "Neděle");
        var interval = new Array("7:15-8:15", "9:00-10:00",  "12:00-13:00", "16:00-17:00", "17:00-18:00", "18:00-19:00", "19:00-20:00", "20:00-21:00");
        style = "style='border: 1px solid #aeaeae;' width='85'";
        style_nadpis = "style='border: 1px solid #aeaeae; background-color: #FDC25A; text-align: center;' width='85'";
    }
    cmd = "<table style='table-layout: fixed; border-collapse: collapse; font-size: 9px;'>";
    cmd = cmd + "<tr>";
    cmd = cmd + "<td "+style_nadpis+">";
    cmd = cmd + "&nbsp;";
    cmd = cmd + "</td>";
    for (ind=0; ind < dny.length; ind++)
    {
        cmd = cmd + "<td "+style_nadpis+" >";
        cmd = cmd + dny[ind];
        cmd = cmd + "</td>";
    }
    cmd = cmd + "</tr>";
    for (ynd=0; ynd < interval.length; ynd++)
    {
       cmd = cmd + "<tr>";
       cmd = cmd + "<td "+style_nadpis+">";
       cmd = cmd + interval[ynd];
       cmd = cmd + "</td>";
       for (ind=0; ind < dny.length; ind++)
       {
           cmd = cmd + "<td "+style+" ondblclick='this.style.backgroundColor=\"green\"'>";
//           cmd = cmd + "<td "+style+">";
           cmd = cmd + "&nbsp;";
           cmd = cmd + "</td>";
       }
       cmd = cmd + "</tr>";
    }
    cmd = cmd + "</table>";
//  cmd = insertarticlecmd + it_caption
//  cmd = insertarticlecmd + "</a>";

  cursor.pasteHTML(cmd);

  select.selectedIndex=0;
}



function SubmitArticles(index, opID)
{
  document.prehled.action = index+"?menu=edit_article&volba="+opID;
  document.prehled.submit();
}


function SynchronizeEditorArea(awysiwyg)
{
  if (awysiwyg)
  {
     document.edit_prispevek.editor_area.value = editor.innerHTML;
  }
  else
  {
     editor.innerHTML = document.edit_prispevek.editor_area.value;
  }
}

function editorCheck()
{
  if (wysiwyg)
  {
     wysiwyg = false;
     SynchronizeEditorArea(wysiwyg);
/*     editor.style.display="block";
     editornastroje.style.display="block";
     document.edit_prispevek.editor_area.style.display = "none";
*/
  }
  else
  {
     wysiwyg = true;
     SynchronizeEditorArea(wysiwyg);
/*     editor.style.display="none";
     editornastroje.style.display="none";
     document.edit_prispevek.editor_area.style.display = "block";
*/
  }
}


function editorSwitch()
{
  if (wysiwyg)
  {
     wysiwyg = false;
     SynchronizeEditorArea(wysiwyg);
     editor.style.display="block";
     editornastroje.style.display="block";
     document.edit_prispevek.editor_area.style.display = "none";
  }
  else
  {
     wysiwyg = true;
     SynchronizeEditorArea(wysiwyg);
     editor.style.display="none";
     editornastroje.style.display="none";
     document.edit_prispevek.editor_area.style.display = "block";
     ZobrazFTP(0);
  }
}


function editorSubmit()
{
//  SynchronizeEditorArea(!wysiwyg);

  document.edit_prispevek.obsah.value = editor.innerHTML;
  document.edit_prispevek.submit();
}




function editorPasteLink(Object, linkFile)
{
//  alert(obrazek.imgsirka.value);
  Object.focus();
  var cursor = Object.document.selection.createRange();

  nadpis = document.obrazek.imgtitle.value;

  cmd = "<a href='"+linkFile;
  cmd =cmd + "' title='"+nadpis+"' alt='"+nadpis+"'> ";
  cmd =cmd + nadpis;
  cmd =cmd + "</a>";
//  cmd = insertarticlecmd + it_caption
//  cmd = insertarticlecmd + "</a>";

  cursor.pasteHTML(cmd);
}

function editorPasteImg(Object, imgFile, imgFileLink)
{
//  alert(obrazek.imgsirka.value);
  Object.focus();
  var cursor = Object.document.selection.createRange();
  vyska = document.obrazek.imgvyska.value;
  sirka = document.obrazek.imgsirka.value;
  jeramecek = document.obrazek.imgborderf.checked;
//  alert(jeramecek);
  ramecek = document.obrazek.imgborder.value;
  nadpis = document.obrazek.imgtitle.value;
  mtop = (document.obrazek.imgmargint.value=="")?0:document.obrazek.imgmargint.value;
  mbottom = (document.obrazek.imgmarginb.value=="")?0:document.obrazek.imgmarginb.value;
  mleft = (document.obrazek.imgmarginl.value=="")?0:document.obrazek.imgmarginl.value;
  mright = (document.obrazek.imgmarginr.value=="")?0:document.obrazek.imgmarginr.value;
  zarovnani = document.obrazek.imgalign.value;
  obtekani = document.obrazek.imgfloat.value;
//  alert(mright);

  cmd = "";
  if (imgFileLink == "")
  {

     cmd = cmd + "<img src="+imgFile;
     if (sirka > 0)
     {
         cmd = cmd + " width='"+sirka+"' ";
     }
     if (vyska > 0)
     {
        cmd = cmd + " height='"+vyska+"' ";
     }

     if (jeramecek)
     {
        cmd = cmd + " border='"+ramecek+"' ";
     }
     if (nadpis != "")
     {
        cmd = cmd + " title='"+nadpis+"' alt='"+nadpis+"'";
     }
     cmd = cmd + " align='"+zarovnani+"' ";
     cmd =cmd + " style='margin-top: "+mtop+"px; margin-bottom: "+mbottom+"px; margin-left: "+mleft+"px; margin-right: "+mright+"px; float: "+obtekani+";' ";
     cmd =cmd + " />";
  }
  else
  {
     cmd = cmd + "<a href="+imgFileLink;
     cmd = cmd + " title='"+nadpis+"' alt='"+nadpis+"' target='_blank'>";

     cmd = cmd +  "<img src="+imgFile;
     if (sirka > 0)
     {
         cmd = cmd + " width='"+sirka+"' ";
     }
     if (vyska > 0)
     {
        cmd = cmd + " height='"+vyska+"' ";
     }

     if (jeramecek)
     {
//        cmd = cmd + " border='"+ramecek+"' ";
                  cmd = cmd + " style='border: "+ramecek+"px solid black;'";
     }
     else
     {
        cmd = cmd + " border='0' ";
     }
     if (nadpis != "")
     {
        cmd = cmd + " title='"+nadpis+"' alt='"+nadpis+"'";
     }
     cmd = cmd + " align='"+zarovnani+"' ";
     cmd =cmd + " style='margin-top: "+mtop+"px; margin-bottom: "+mbottom+"px; margin-left: "+mleft+"px; margin-right: "+mright+"px; float: "+obtekani+";' ";
     cmd =cmd + " />";
     cmd =cmd + "</a>";
  }
   //  cmd = insertarticlecmd + it_caption
   //  cmd = insertarticlecmd + "</a>";

  cursor.pasteHTML(cmd);
}


// menu script

var activeButton = null;

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);



 function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
//  if (el.offsetParent != null)
//    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
//  if (el.offsetParent != null)
//    y += getPageOffsetTop(el.offsetParent);

  return y;
}



/*
function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

*/
function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}


function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}


function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}


function menuInit(menu) {

  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // For IE, replace arrow characters.

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

   // Find the width of a menu item.

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;
  // For items with arrows, add padding to item text to make the
  // arrows flush right.


  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null) {
      textEl.style.paddingRight = (itemWidth
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
      // For Opera, remove the negative right margin to fix a display bug.
      if (browser.isOP)
        arrowEl.style.marginRight = "0px";
    }
  }

  // Fix IE hover problem by setting an explicit width on first item of
  // the menu.

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

// Mark menu as initialized.

   menu.isInitialized = true;

}

function closeSubMenu(menu) {

  if (menu == null || menu.activeItem == null)
    return;

  // Recursively close any sub menus.

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}


function resetButton(button) {

  // Restore the button's style class.

  removeClassName(button, "menuButtonActive");

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.

  button.className += " menuButtonActive";

  // Position the associated drop down menu under the button and
  // show it.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

function buttonClick(event, menuId) {

  var button;

  // Get the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  button.blur();
  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.
//  && (document.getElementById(menuId) != null)
  if ((button.menu == null) && (document.getElementById(menuId) != null)) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
       menuInit(button.menu);
  }
 // Reset the currently active button, if any.
  if ((activeButton != null))
    resetButton(activeButton);

      // Activate this button, unless it was the currently active one.

  if ((button != activeButton) && (button.menu != null)) {
    depressButton(button);
    activeButton = button;
  }
  else
  {
    activeButton = null;
  }

  return false;
}

function buttonMouseover(event, menuId) {

  var button;

  // Find the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function menuMouseover(event) {

  var menu;

  // Find the target menu element.

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // Close any active sub menu.

  if (menu.activeItem != null)
     closeSubMenu(menu);

}

function menuItemMouseover(event, menuId) {

  var item, menu, x, y;

  // Find the target item element and its parent menu element.

  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;

  menu = getContainerWith(item, "DIV", "menu");
 // Close any active sub menu and mark this one as active.

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

 // Highlight the item element.

  item.className += " menuItemHighlight";

// Initialize the sub menu, if not already done.

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

// Get position for submenu based on the menu item.

  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  // Adjust position to fit in view.

  var maxX, maxY;

  if (browser.isIE) {
    maxX =
      (document.documentElement.scrollLeft   != 0 ?
         document.documentElement.scrollLeft
       : document.body.scrollLeft)
    + (document.documentElement.clientWidth  != 0 ?
       document.documentElement.clientWidth
       : document.body.clientWidth);
    maxY =
      (document.documentElement.scrollTop    != 0 ?
       document.documentElement.scrollTop
       : document.body.scrollTop)
    + (document.documentElement.clientHeight != 0 ?
       document.documentElement.clientHeight
       : document.body.clientHeight);
  }
  if (browser.isOP) {
    maxX = document.documentElement.scrollLeft + window.innerWidth;
    maxY = document.documentElement.scrollTop  + window.innerHeight;
  }
  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));


  // Position and show it.

  item.subMenu.style.left = x + "px";
  item.subMenu.style.top  = y + "px";
  item.subMenu.style.visibility = "visible";


 // Stop the event from bubbling.

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function pageMousedown(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element that was clicked on.

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  // If the active button was clicked on, exit.

  if (el == activeButton)
    return;

  // If the element is not part of a menu, reset and clear the active
  // button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

// funkce pro asistenci formular

// --- date fnc
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
        var date=getDateFromFormat(val,format);
        if (date==0) { return false; }
        return true;
        }

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
        var d1=getDateFromFormat(date1,dateformat1);
        var d2=getDateFromFormat(date2,dateformat2);
        if (d1==0 || d2==0) {
                return -1;
                }
        else if (d1 > d2) {
                return 1;
                }
        return 0;
        }

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
        format=format+"";
        var result="";
        var i_format=0;
        var c="";
        var token="";
        var y=date.getYear()+"";
        var M=date.getMonth()+1;
        var d=date.getDate();
        var E=date.getDay();
        var H=date.getHours();
        var m=date.getMinutes();
        var s=date.getSeconds();
        var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
        // Convert real date parts into formatted versions
        var value=new Object();
        if (y.length < 4) {y=""+(y-0+1900);}
        value["y"]=""+y;
        value["yyyy"]=y;
        value["yy"]=y.substring(2,4);
        value["M"]=M;
        value["MM"]=LZ(M);
        value["MMM"]=MONTH_NAMES[M-1];
        value["NNN"]=MONTH_NAMES[M+11];
        value["d"]=d;
        value["dd"]=LZ(d);
        value["E"]=DAY_NAMES[E+7];
        value["EE"]=DAY_NAMES[E];
        value["H"]=H;
        value["HH"]=LZ(H);
        if (H==0){value["h"]=12;}
        else if (H>12){value["h"]=H-12;}
        else {value["h"]=H;}
        value["hh"]=LZ(value["h"]);
        if (H>11){value["K"]=H-12;} else {value["K"]=H;}
        value["k"]=H+1;
        value["KK"]=LZ(value["K"]);
        value["kk"]=LZ(value["k"]);
        if (H > 11) { value["a"]="PM"; }
        else { value["a"]="AM"; }
        value["m"]=m;
        value["mm"]=LZ(m);
        value["s"]=s;
        value["ss"]=LZ(s);
        while (i_format < format.length) {
                c=format.charAt(i_format);
                token="";
                while ((format.charAt(i_format)==c) && (i_format < format.length)) {
                        token += format.charAt(i_format++);
                        }
                if (value[token] != null) { result=result + value[token]; }
                else { result=result + token; }
                }
        return result;
        }
        
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
        var digits="1234567890";
        for (var i=0; i < val.length; i++) {
                if (digits.indexOf(val.charAt(i))==-1) { return false; }
                }
        return true;
        }
function _getInt(str,i,minlength,maxlength) {
        for (var x=maxlength; x>=minlength; x--) {
                var token=str.substring(i,i+x);
                if (token.length < minlength) { return null; }
                if (_isInteger(token)) { return token; }
                }
        return null;
        }
        
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
        val=val+"";
        format=format+"";
        var i_val=0;
        var i_format=0;
        var c="";
        var token="";
        var token2="";
        var x,y;
        var now=new Date();
        var year=now.getYear();
        var month=now.getMonth()+1;
        var date=1;
        var hh=now.getHours();
        var mm=now.getMinutes();
        var ss=now.getSeconds();
        var ampm="";
        
        while (i_format < format.length) {
                // Get next token from format string
                c=format.charAt(i_format);
                token="";
                while ((format.charAt(i_format)==c) && (i_format < format.length)) {
                        token += format.charAt(i_format++);
                        }
                // Extract contents of value based on format token
                if (token=="yyyy" || token=="yy" || token=="y") {
                        if (token=="yyyy") { x=4;y=4; }
                        if (token=="yy")   { x=2;y=2; }
                        if (token=="y")    { x=2;y=4; }
                        year=_getInt(val,i_val,x,y);
                        if (year==null) { return 0; }
                        i_val += year.length;
                        if (year.length==2) {
                                if (year > 70) { year=1900+(year-0); }
                                else { year=2000+(year-0); }
                                }
                        }
                else if (token=="MMM"||token=="NNN"){
                        month=0;
                        for (var i=0; i<MONTH_NAMES.length; i++) {
                                var month_name=MONTH_NAMES[i];
                                if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
                                        if (token=="MMM"||(token=="NNN"&&i>11)) {
                                                month=i+1;
                                                if (month>12) { month -= 12; }
                                                i_val += month_name.length;
                                                break;
                                                }
                                        }
                                }
                        if ((month < 1)||(month>12)){return 0;}
                        }
                else if (token=="EE"||token=="E"){
                        for (var i=0; i<DAY_NAMES.length; i++) {
                                var day_name=DAY_NAMES[i];
                                if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
                                        i_val += day_name.length;
                                        break;
                                        }
                                }
                        }
                else if (token=="MM"||token=="M") {
                        month=_getInt(val,i_val,token.length,2);
                        if(month==null||(month<1)||(month>12)){return 0;}
                        i_val+=month.length;}
                else if (token=="dd"||token=="d") {
                        date=_getInt(val,i_val,token.length,2);
                        if(date==null||(date<1)||(date>31)){return 0;}
                        i_val+=date.length;}
                else if (token=="hh"||token=="h") {
                        hh=_getInt(val,i_val,token.length,2);
                        if(hh==null||(hh<1)||(hh>12)){return 0;}
                        i_val+=hh.length;}
                else if (token=="HH"||token=="H") {
                        hh=_getInt(val,i_val,token.length,2);
                        if(hh==null||(hh<0)||(hh>23)){return 0;}
                        i_val+=hh.length;}
                else if (token=="KK"||token=="K") {
                        hh=_getInt(val,i_val,token.length,2);
                        if(hh==null||(hh<0)||(hh>11)){return 0;}
                        i_val+=hh.length;}
                else if (token=="kk"||token=="k") {
                        hh=_getInt(val,i_val,token.length,2);
                        if(hh==null||(hh<1)||(hh>24)){return 0;}
                        i_val+=hh.length;hh--;}
                else if (token=="mm"||token=="m") {
                        mm=_getInt(val,i_val,token.length,2);
                        if(mm==null||(mm<0)||(mm>59)){return 0;}
                        i_val+=mm.length;}
                else if (token=="ss"||token=="s") {
                        ss=_getInt(val,i_val,token.length,2);
                        if(ss==null||(ss<0)||(ss>59)){return 0;}
                        i_val+=ss.length;}
                else if (token=="a") {
                        if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
                        else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
                        else {return 0;}
                        i_val+=2;}
                else {
                        if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
                        else {i_val+=token.length;}
                        }
                }
        // If there are any trailing characters left in the value, it doesn't match
        if (i_val != val.length) { return 0; }
        // Is date valid for month?
        if (month==2) {
                // Check for leap year
                if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
                        if (date > 29){ return 0; }
                        }
                else { if (date > 28) { return 0; } }
                }
        if ((month==4)||(month==6)||(month==9)||(month==11)) {
                if (date > 30) { return 0; }
                }
        // Correct hours value
        if (hh<12 && ampm=="PM") { hh=hh-0+12; }
        else if (hh>11 && ampm=="AM") { hh-=12; }
        var newdate=new Date(year,month-1,date,hh,mm,ss);
       
        return newdate.getTime();
        }

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
        var preferEuro=(arguments.length==2)?arguments[1]:false;
        generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
        monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
        dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
        var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
        var d=null;
        for (var i=0; i<checkList.length; i++) {
                var l=window[checkList[i]];
                for (var j=0; j<l.length; j++) {
                        d=getDateFromFormat(val,l[j]);
                        if (d!=0) { return new Date(d); }
                        }
                }
        return null;
        }
// --- date fnc


function validateDate(datum) {
   var checkstr = "0123456789";
var DateField = datum;
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;

   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Špatně zadané datum!!\nSprávný formát [dd.mm.yyyy].\nnapř. 01.01.2000\n\ndd - den (01)\nmm - měsíc (12)\nyyyy - rok (2009/09)");
      
      DateField.select();
	    DateField.focus();
      return false;
   }

   return true;
}

function validateTime(time) {
 var inputTime = time
 err = false;
 
 var regex=/^(2[0-3])|[01][0-9]:[0-5][0-9]$/;
 if (!regex.test(inputTime.value)) {
    err = true;
 } else if (inputTime.value.substring(2,3) != ":") {
    err = true;
 }

 if (err) {
    alert("Špatně zadaný čas!!");
    inputTime.select();
    inputTime.focus();
    return false;
 }

return true;
}


function prepocitej(odeslat) {
    //v =  5* 10;
    //alert("Sem tu");
//    alert(document.forms['obj_asistence'].varianta.length);
   // var formular = document.getElementById(obj_asistence);
    //var pocet = document.getElementsByTagName('pocet');
    var ceny = new Array(1890, 980, 1320, 440, 70);

    var varianta  = document.forms["obj_asistence"].elements["varianta[]"];
    var pocet  = document.forms["obj_asistence"].elements["pocet[]"];
    var pocetHod  = document.forms["obj_asistence"].elements["pocetHod[]"];
    var datumOd = document.forms["obj_asistence"].elements["datumOd"];
    
//     var casOd = document.forms["obj_asistence"].elements["casOd[]"];
//     var datumDo = document.forms["obj_asistence"].elements["datumDo[]"];
//     var casDo = document.forms["obj_asistence"].elements["casDo[]"];
//     
     v = 0;
     // priplatek 30%
     var currentDate = new Date();
   //  alert(currentDate.getTime());
     if (!validateDate(datumOd))  {
         return false;
     }

     for (var i=0; i < varianta.length; i ++ ) {

         if (varianta[i].checked) {
          
 /*           if (!validateTime(casOd[i])) { // || !validateDate(datumDo[i])) {
               return false;
            }*/
            hodin = pocetHod[i].value; //(dtt - dtf) / 1000 / 60 / 60;
            
  //          alert(hodin + "hod./ "+dobaObjDny+" dni predem");
            v += pocet[i].value * ( ceny[i] * hodin );
         }
     }

     if (v == 0) {
        alert("Není vybrána žádná položka, nebo chybně vyplněny počty.");
	odeslat = false;
     } else {

            dtf = getDateFromFormat(datumOd.value, "dd.MM.y");
            // vypocet (dtt - dtf) / 1000 / 60 /60
            dobaObjDny = Math.round((dtf - currentDate.getTime()) / 1000 / 60 / 60 / 24); // na dny;
            document.getElementById('prirazka').innerHTML = "";
     /*       if (dobaObjDny < 30) {
               v = v * 1.30; // +30% kdyz je to mene jak 30dni pred.
               document.getElementById('prirazka').innerHTML = "<span style='color: red;'>Termín je méně než 30dní. V ceně zahrnuta 30% přirážka.</span>";
            } */
     }

    document.getElementById('fakt').value = v;
   
    if (odeslat) {
       if (zkontroluj()) {
       		document.forms['obj_asistence'].submit();
       }
    }
    return v;
}

function zkontroluj() {
  ok = true; 
 if (true) {
  msg = "Nejsou vyplněny následující položky: \n";
  var frm = document.forms["obj_asistence"];
  
  if (frm.elements['frm_lokalita'].value.length < 1) {
     msg += "lokalita plánované akce: \n";
     ok = false;
  }
	
  if (frm.elements['frm_firma'].value.length < 1) {
     msg += "název firmy\n";
     ok = false;
  }

  

  if (frm.elements['frm_osoba'].value.length < 1) {
     msg += "kontaktní osoba\n";
     ok = false;
  }

  if (frm.elements['frm_telefon'].value.length < 1) {
     msg += "telefon\n";
     ok = false;
  }

  if (frm.elements['frm_email1'].value.length < 1) {
     msg += "email\n";
     ok = false;
  } else {
       re = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$")
       if (!re.test(frm.elements['frm_email1'].value)) {
          msg += "email je zadán špatně\n";
       }
  }
}

//   if (frm.elements['frm_ulice'].value.length < 1) {
//      msg += "ulice\n";
//      ok = false;
//   }
//   
//   if (frm.elements['frm_mesto'].value.length < 1) {
//      msg += "město\n";
//      ok = false;
//   }
// 
//   if (frm.elements['frm_psc'].value.length < 1) {
//      msg += "PSČ\n";
//      ok = false;
//   }

//   if (frm.elements['frm_ic'].value.length < 1) {
//      msg += "IČ\n";
//      ok = false;
//   }
// 
//   if (frm.elements['frm_dic'].value.length < 1) {
//      msg += "DIČ\n";
//      ok = false;
//  }


  if (ok) {
   // frm.submit();
  } else {
    alert(msg);
  }
  return ok;
}