function copysel(iu,pid)
{
 document.getElementById(iu).select();
 copyclip(document.getElementById(iu).value);
// window.clipboardData.setData("text",document.getElementById(iu).value);
 if (pid!=0)
 {
  var elem = document.createElement("script");
  obj=document.body.insertBefore(elem, document.body.firstChild);
  obj.setAttribute("id", "js");
  obj.setAttribute("language", "Javascript");
  obj.setAttribute("type", "text/javascript");
  obj.setAttribute("src", "http://www.qarchive.org/php/copyurl.php?PID="+pid+"\&rnd="+Math.random());
 }	
}

function copyclip(meintext)
{

 if (window.clipboardData) 
   {
   
   // the IE-way
   window.clipboardData.setData("Text", meintext);
   
   // Probabely not the best way to detect netscape/mozilla.
   // I am unsure from what version this is supported
   }
   else if (window.netscape) 
   { 
   
   // This is importent but it's not noted anywhere
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // create interface to the clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // create a transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specify the data we wish to handle. Plaintext in this case.
   trans.addDataFlavor('text/unicode');
   
   // To get the data from the transferable we need two new objects
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   return false;
}
