  function DeleteConfirm(url)
  {
    if (confirm("Are you sure you want to delete this item?")) location = url;
  }

  function ClearConfirm()
  {
    if (confirm("Are you sure you want to clear your shopping cart?"))
    {
      document.itemsform.actn.value='clear';
      document.itemsform.submit();
    };
  }

  function UpdateConfirm()
  {
    document.itemsform.actn.value='update';
    document.itemsform.submit();
  }

  function cookie_enabled()
  {
    document.cookie="CTest=true;";
    if (document.cookie.indexOf("CTest") < 0)
    {
      alert("Cookie must be enabled to work with this feature!");
      return false; 
    }
    else return true;
  }

  function addItem(newItem, newQtty)
  {
    if (!cookie_enabled()) return;

    var cookie_name = "HCart";
    var cookie_str = document.cookie;

    var RE = new RegExp("^[0-9]+$");
    var ZERO = new RegExp("^0+$");

    if ((!RE.exec(newQtty)) || (ZERO.exec(newQtty))) alert('Invalid quantity. Please, change it. \nThe quantity must be integer and positive!');
    else
    {
      if ((start_index < 0)||(end_index < 0))
      {
        window.alert("The item can't be added to shopping cart. Please, contact web master.");
        return;
      }

      if (cookie_str.indexOf(cookie_name) >= 0)
      {
        var start_index = cookie_str.indexOf(cookie_name) + cookie_name.length + 1;
        var end_index = cookie_str.indexOf('.', start_index-1);
        if (end_index < 0) end_index = cookie_str.length;
        var value = cookie_str.substring(start_index, end_index);
      }; else value='';

      document.cookie = cookie_name + "=" + value + "[" + newItem + ":" + newQtty + "].";
      window.alert('The item has been added to your shopping cart!');
    }
  }
  
  function ViewCartLink()
  {
    if (!cookie_enabled()) return;

    var cookie_name = "HCart";
    var cookie_str = document.cookie;
	var value = '';

    if (cookie_str.indexOf(cookie_name) >= 0)
    {
      var start_index = cookie_str.indexOf(cookie_name) + cookie_name.length + 1;
      var end_index = cookie_str.indexOf('.', start_index-1);
      if (end_index < 0) end_index = cookie_str.length;
      value = cookie_str.substring(start_index, end_index);

    }

    if (value != '') document.write('<td align="right"><div class="content" id="noMargins"><div class="h1">&nbsp;<a href="?structure=./contents/sparts/scart_view.xml"><span id="noUnder"><img src="img/scart.gif" width="16" height="16" border="0" align="absmiddle">&nbsp;</span>My&nbsp;Cart</a></div></div></td>');
  }


  function openWindow(url, target, width, height) {
    var left = Math.round((screen.width - width)/2);
    var top = Math.round((screen.height - height)/2);

    var args = "menubar=0, scrollbars=0, titlebar=1, resizable=0,"
    + "width=" + width + ","
    + "height=" + height + ","
    + "status=0,"
    + "left=" + left + ","
    + "top=" + top + ","
    + "screenX=" + left + ","
    + "screenY=" + top;

    window.open(url, target, args )  
  }
