function copyToClipboard(theField){
	var tempval=document.getElementById(theField);
	tempval.focus();
	tempval.select();
	if (document.all)
	 {
		therange = tempval.createTextRange();
		therange.execCommand("Copy");
	 }
	else
	 {
	 	var val = jQuery('#'+theField).val();
		putTextToClipboard(val);
	 }

}

function putTextToClipboard(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);
   
   }
//   alert("Following info was copied to your clipboard:\n\n" + meintext);
   return false;
}

