var MOZILLA_CLIPBOARD_ID = "@mozilla.org/widget/clipboard;1";
var MOZILLA_TRANSFER_ID  = "@mozilla.org/widget/transferable;1";
var MOZILLA_STRINGOBJ_ID = "@mozilla.org/supports-string;1";

function textToClipboard(theText)
{

	// Is there something the clipboard.
	if (window.clipboardData) 
   	{
		window.clipboardData.setData("Text", theText);
   	}
   	else 
   	{
	   	return; // Only doing IE for now.
	   	
	   	if (window.netscape) 
	   	{ 
			// Mozilla/Firefox
		   	// Request the priveleges necessary to access the clipboard.  Requires
		   	//  the Javascript to be digitally signed.
	   		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	   
	   		var clipboardObj = 
	   			Components.classes[MOZILLA_CLIPBOARD_ID].createInstance(Components.interfaces.nsIClipboard);
	   			
	   		if (!clipboardObj) 
	   		{
		   		alert("(textToClipboard) Unable to request enhanced priveleges for clipboard access.");
	   			return;
   			} // if (!clipboardObj) 
				   
	   		var transferObj = 
	   			Components.classes[MOZILLA_TRANSFER_ID].createInstance(Components.interfaces.nsITransferable);
	   			
	   		if (!transferObj)
	   		{
		   		alert("(textToClipboard) Transfer object creation failed.");
	   			return;
   			} // if (!clipboardObj) 

   			// Specify unicode text as the clipboard data type.	   
		   	transferObj.addDataFlavor('text/unicode');
		   
		   	var stringObj = new Object();
		   
		   	var stringObj = Components.classes[MOZILLA_STRINGOBJ_ID].createInstance(Components.interfaces.nsISupportsString);
			if (!stringObj)
   			{
				alert("(textToClipboard) String object creation failed.");
   				return;
			} // if (!stringObj) 
		   
		   	stringObj.data = theText;
		   
		   	// Adjust for unicode text length.
		   	var unicodeLen = theText.length * 2;
		   	
		   	transferObj.setTransferData("text/unicode", stringObj, unicodeLen);
							   		   
		   	// Get a handle to the clipboard.
		   	var clipboardID = Components.interfaces.nsIClipboard;
		   
		   	if (!clipboardID)
   			{
	   			alert("(textToClipboard) Unable to get the clipboard global ID.");
   				return;
			} // if (!clipboardObj)
		   
		   	clipboardObj.setData(transferObj, null, clipboardID.kGlobalClipboard);
	   } // if (window.netscape) 
	   
	   return false;
	} // else (window.clipboardData) 
} // function textToClipboard(theText)

// Get the text that is in the clipboard.
function clipboardToText()
{
	if (clipboardData.getData("Text"))
		return clipboardData.getData("Text");
	return "(Clipboard error)";
} // function clipboardToText()
 