function selectAll(a,type)
{
   var e = a.parentNode.parentNode.getElementsByTagName('PRE')[0];
   if (window.getSelection)
   {
      var s = window.getSelection();
       if (s.setBaseAndExtent)
      {
         s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
      }
      else
      {
         var r = document.createRange();
         r.selectNodeContents(e);
         var ClipD = r;
         s.removeAllRanges();
         s.addRange(r);
      }
   }
   else if (document.getSelection)
   {
      var s = document.getSelection();
      var r = document.createRange();
      r.selectNodeContents(e);
      var ClipD = r;
      s.removeAllRanges();
      s.addRange(r);
   }
   else if (document.selection)
   {
      var r = document.body.createTextRange();
      r.moveToElementText(e);
      r.select();
      var ClipD = r.text;      
   }
   
   if (type=='copy') { copyToClipboard(ClipD); }
   return false;
}


function copyToClipboard(text, strip_html){
  if (!text){
    alert("No text provided to copy_text_to_clipboard to copy.");
    return false;
  }

  if (window.clipboardData) {   // Internet Explorer
    try{
      if (strip_html){
        // You should probably use IE's innerText here instead, and set strip_html
        // to 0. (Already done if we're called from copy_element_to_clipboard.)
        // This is a rudimentary method of accessing the text content while
        // keeping line returns from <br> and <p> elements.
        text = text.replace(/\s*<BR>\s*/gi, "\r\n").replace(/\s*<P>\s*/gi, "\r\n\r\n").replace(/<\/\w+.*?>/ig, '');
      }

      window.clipboardData.setData("Text", text);
      return true;

    }catch(e){
      alert('Your browser currently does not support copying to the clipboard.');
      return false;
    }
  }else if (navigator.userAgent.match(/ Gecko\//) ) {

    var tempiframe = document.createElement("iframe");
    tempiframe.setAttribute('width', '1');
    tempiframe.setAttribute('height', '1');
    tempiframe.setAttribute('frameborder', '0');
    tempiframe.setAttribute('scrolling', 'no');

    var parent = document.body;
    var myiframe = parent.appendChild(tempiframe);

    // Mozilla needs time to recognize iframe. We'll do the
    // rest in this function after a short timeout.
    function finish_copy_text_to_clipboard(){
      myiframe.contentDocument.designMode = "on"; // Use Midas editor.
      myiframe.contentDocument.body.innerHTML = text;

      var sel = myiframe.contentWindow.getSelection();
      sel.removeAllRanges();
      myiframe.contentWindow.focus();
      var range;
      if (typeof sel != "undefined") {
        try {
          range = sel.getRangeAt(0);
        } catch(e) {
          range = myiframe.contentDocument.createRange();
        }
      } else {
        range = myiframe.contentDocument.createRange();
      }

      range.selectNodeContents(myiframe.contentDocument.body);
      sel.addRange(range);

      try{
        myiframe.contentDocument.execCommand('copy', null, null); // copy data to clipboard
      }catch(e){
        if (confirm("Cannot access Cut/Copy/Paste for security reasons. Click OK to get instructions from InfoGears to enable cut/copy/paste in your browser. (Note: A new window will popup. It may popup behind this window.)")){
          window.open("http://www.infogears.com/cgi-bin/infogears/mozilla_firefox_copy_paste");
        }
        parent.removeChild(myiframe); // the temp iframe is no longer needed
        return false;
      }

      parent.removeChild(myiframe); // the temp iframe is no longer needed

      return true;
    };

    setTimeout(finish_copy_text_to_clipboard, 100); // Mozilla needs time to recognize iframe.
    return true; // This might not be true, because the timeout function may screw up!

  }else{
    alert("Your browser currently does not support copying to the clipboard. Please upgrade to the latest version of Mozilla FireFox or Internet Explorer");
  }

  return false;
}
