// @author Dmiry Pljonkin (Дмитрий Пленкин)
// @url    http://www.sukebe.ru
// @date   2006-03-07

      function insertCopyToClipboardButton(wrapper_id)
      {
          if (!document.getElementById || !document.getElementById(wrapper_id) || !window.clipboardData) {
              return false;
          }
          else {
              wrapper = document.getElementById(wrapper_id);
          }

          if (wrapper && wrapper.parentNode.insertBefore) {
              button = document.createElement("a");
              button.setAttribute("href", "#");
              button.innerHTML = "<span><img src='/img/ico_cb.gif' alt='' style='vertical-align: middle;' /> </span>Скопировать в буфер";
              button.onclick = function() {
                  copyToClipboard(innerText(wrapper));
                  return false;
              } 
              // emulate insertAfter:
              wrapper.parentNode.insertBefore(button, wrapper.nextSibling);
          }
          else { 
              return false
          }
      }
      
      function innerText(node) {
          // http://www-128.ibm.com/developerworks/xml/library/x-matters41.html
          // @author	Dethe Elza
          // @article	"XML Matters: Beyond the DOM. Tips and tricks for a friendlier DOM"
          if (node.nodeType == 3 || node.nodeType == 4) {
              return node.data;
          }
          var i;
          var returnValue = [];
          for (i = 0; i < node.childNodes.length; i++) {
              returnValue.push(innerText(node.childNodes[i]));
          }
          return returnValue.join('');
      }

      
      function copyToClipboard(text)
      {
          if (!document.getElementById) {
              return false;
          }
          
          if (window.clipboardData) {
              window.clipboardData.setData("Text", text);
              alert('Код ссылки скопирован в буфер обмена');
          }
      }
      

