  /**
   * Sets a Cookie with the given name and value.
   *
   * name       Name of the cookie
   * value      Value of the cookie
   * [expires]  Expiration date of the cookie (default: end of current session)
   * [path]     Path where the cookie is valid (default: path of calling document)
   * [domain]   Domain where the cookie is valid
   *              (default: domain of calling document)
   * [secure]   Boolean value indicating if the cookie transmission requires a
   *              secure transmission
   * example <a href="#" onclick='setCookie("name", "Jason Davies")'>Set Cookie!</a>
   */
  function setCookie(name, value, expires, path, domain, secure)
  {
      document.cookie= name + "=" + escape(value) +
          ((expires) ? "; expires=" + expires.toGMTString() : "") +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          ((secure) ? "; secure" : "");
  }
  
  /**
   * Gets the value of the specified cookie.
   *
   * name  Name of the desired cookie.
   *
   * Returns a string containing value of specified cookie,
   *   or null if cookie does not exist.
   * example: <a href="#" onclick='alert(getCookie("name"))'>Get Cookie!</a>
   */
  function getCookie(name)
  {
      var dc = document.cookie;
      var prefix = name + "=";
      var begin = dc.indexOf("; " + prefix);
      if (begin == -1)
      {
          begin = dc.indexOf(prefix);
          if (begin != 0) return null;
      }
      else
      {
          begin += 2;
      }
      var end = document.cookie.indexOf(";", begin);
      if (end == -1)
      {
          end = dc.length;
      }
      return unescape(dc.substring(begin + prefix.length, end));
  }
  
  /**
   * Deletes the specified cookie.
   *
   * name      name of the cookie
   * [path]    path of the cookie (must be same as path used to create cookie)
   * [domain]  domain of the cookie (must be same as domain used to create cookie)
   */
  function deleteCookie(name, path, domain)
  {
      if (getCookie(name))
      {
          document.cookie = name + "=" + 
              ((path) ? "; path=" + path : "") +
              ((domain) ? "; domain=" + domain : "") +
              "; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
  }


  function suma()
  {
    var vD1 = document.Form1.D1;
    var vSuma = document.Form1.SUMA;
    
    var text, value;
    var ok = true;
    var suma = 0;
  
    for (i=0;i<vD1.options.length;i++)
      suma = suma + parseInt(vD1.options[i].value, 10);
      
    vSuma.value = suma;
  }

  //-----------------------------------------------------------------------------------------------------
  function go()
  {
    var Dcv = document.Form1.VALU;
    var vD1 = document.Form1.D1;
    
    var text, value;
    var ok = true;
    var sCookieName;
  
    if (Dcv.options.selectedIndex == -1)
      alert('Nie je ozna&#268;ený záznam !');
    else
    {
      text = Dcv.options[Dcv.selectedIndex].text;
      value = Dcv.options[Dcv.selectedIndex].value;
      
      if (vD1.options[0].value == 0)
        vD1.options[0] = null;
  
      for (i=0;i<vD1.options.length;i++)
        if (vD1.options[i].text == text)
          ok = false;
      
  //    text.rightTrim().leftTrim();
  //    if (text.length == 0)
  //      ok = false;
        
      if (ok)
      {
        vD1.options[vD1.options.length]=new Option(text,value)
        vD1.options[vD1.options.length-1].className = ((vD1.options.length%2)==0)?'BgRow1':'BgRow2';
        sCookieName = 'Text' + (vD1.options.length-1);
        setCookie(sCookieName, text);
        sCookieName = 'Value' + (vD1.options.length-1);
        setCookie(sCookieName, value);
        setCookie('Count', vD1.options.length);
    
        suma();
      }
    }    
  }
  
  //-----------------------------------------------------------------------------------------------------
  function ba()
  {
    var vD1 = document.Form1.D1;
    var sCookieName;
    var nCountItems;
    var nSelected;
    
    if (vD1.options.selectedIndex == -1)
      alert('Nie je ozna&#268;ený záznam !');
    else
    {
      nCountItems = vD1.options.length;
      setCookie('Count', (nCountItems - 1));
     
      nSelected = vD1.options.selectedIndex;
      vD1.options[nSelected] = null;
      
      sCookieName = 'Text' + (nSelected);
      deleteCookie(sCookieName);
      sCookieName = 'Value' + (nSelected);
      deleteCookie(sCookieName);
      
      if (nSelected < nCountItems-1)
      {
        for (i=nSelected;i<nCountItems - 1;i++)
        {
          sCookieName = 'Text' + (i+1);
          text = getCookie(sCookieName);
          sCookieName = 'Text' + (i);
          setCookie(sCookieName, text);

          sCookieName = 'Value' + (i+1);
          text = getCookie(sCookieName);
          sCookieName = 'Value' + (i);
          setCookie(sCookieName, text);
        }
      }
    }
      
    suma();
      
  }

  //-----------------------------------------------------------------------------------------------------
  function loadform()
  {
    var vD1 = document.Form1.D1;
    var nLength;
    var sText;
    var sValue;
    var sCookieName;
    
    nLength = parseInt(getCookie('Count'));
    
    if (nLength > 0) {
      for (i=0;i<nLength;i++)
      {
        sCookieName = 'Text' + i;
        sText = getCookie(sCookieName);
        sCookieName = 'Value' + i;
        sValue = getCookie(sCookieName);
        
        vD1.options[i]=new Option(sText,sValue);
        vD1.options[i].className = ((vD1.options.length%2)==0)?'BgRow1':'BgRow2';
      }
      suma();
    } else {
        vD1.options[0]=new Option('                                        ','');
    }    
  }
  



