var Interval = "";
var CliWin = '';

function StartTrigger(){
   Interval = window.setInterval("TestReload()",1000);
}

function TestReload(){
  if (CliWin.closed) {
  window.clearInterval(Interval);
    window.location.reload();
  }
}

function openPopup(url, h, scrollbars, reload, w) {
  if (!w) { w = 530 };
  if (scrollbars=='yes') { scs='yes'; } else { scs='no'; }
  CliWin=window.open(url, '_blank', "location=no,status=no,toolbar=no,menubar=no,scrollbars="+scs+",resizable=yes,width="+w+",height="+h);
  if (reload) StartTrigger();
}

//------- VALIDATION

var re_mail = new RegExp("^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,3})$");
var re_date = new RegExp("^[0-3]?[0-9]. *[0-1]?[0-9]. *2[0-9]{3}$");
var re_url = new RegExp("^[^@\. /][^@ ]+\.[^@ ]{2,}$");
var re_phone = new RegExp("^([0\+]{1,2}[0-9]{2,3})? ?[0-9 ]{9,12}$");
var re_postcode = new RegExp("^[1-9][0-9]{2} ?[0-9]{2}$");
var re_name = new RegExp("^[A-Z؎ҍa-z -]{2,}$");
var re_street = new RegExp("^[A-Z1-9؎ҍa-z \.-]{3,} [0-9/-]+$");
var re_town = new RegExp("^[A-Z؎ҍa-z \./-][A-Z؎ҍa-z \./0-9-]+$");

  var timerID = null;
  var menu = null;

  function showMenu(id, ref)
  {
    if (menu) {
      hideMenu();
    }
    menu=document.getElementById('submenu_'+id);
    if (menu) {
      leftOffset=(id=="more") ? -5 : 142;
      menu.style.left=ref.offsetLeft+leftOffset;
      menu.style.visibility='visible';
      if (navigator.appName.indexOf("Microsoft") != -1) {
        setSelectsVisible(false);
      }
    }
  }

  function hideMenu()
  {
    if (menu) {
      menu.style.visibility='hidden';
    }
    menu = null;
    if (navigator.appName.indexOf("Microsoft") != -1) {
      setSelectsVisible(true);
    }
  }

  function onMenu()
  {
    clearTimeout(timerID);
  }

  function prepareHideMenu()
  {
    timerID = setTimeout('hideMenu()', 200);
  }

  function setSelectsVisible(val)
  {
    for (i=0; i<document.forms.length; i++) {
      f=document.forms[i];
      for (j=0; j<f.elements.length; j++) {
        e=f.elements[j];
        if (e.nodeName=="SELECT") {
          e.style.visibility=val?"visible":"hidden";
        }
      }
    }
  }

  function setTRColor(tr, color) {
    var td = null;
    td = tr.cells;
    for (i = 0; i < td.length; i++) {
      td[i].style.backgroundColor = '#'+color;
    }
  }

  function setDivColor(div, color) {
    var offs = null;
    offs = div.childNodes;
    for (i = 0; i < offs.length; i++) {
      if (offs[i].nodeName=="DIV") {
        offs[i].style.backgroundColor = '#'+color;
      }
    }
  }

  function ValidateMail(f) {
    if (!re_mail.test(f.mail.value)) {
      window.alert("Vyplte sprvnou e-mailovou adresu.");
      f.mail.focus();
      return false;
    } else {
      return true;
    }
  }

  function showUser(id) {
    window.open('../home/userdetail.php3?id='+id, 'user'+id, "location=no,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes,width=350,height=300");
  }

                    function submitLogin()
                    {
                      x=false;
                      f=document.loginForm;
                      if (!re_mail.test(f.mail.value)) {
                        x="Chyba v e-mailu!";
                        f.mail.focus();
                      }
                      if (x) {
                        window.alert(x);
                      }
                      else {
                        f.submit();
                      }
                    }

                    function showLogin()
                    {
                      document.loginForm.mail.focus();
                      td=document.getElementById("loginTD");
                      td.style.borderColor="#E1C240";
                      td.style.backgroundColor="#FDF9E9";
                    }

  function toggleCheckbox(cb)
  {
    oCB=document.getElementById("cb_"+cb);
    iCB=document.getElementById("cbi_"+cb);
    val=iCB.value==1 ? "0" : "1";
    iCB.value=val;
    oCB.className="checkbox "+(val==1 ? "" : "un")+"checked";
  }

