// the object that you are dragging:
var dragdropObj = new Object;

// string to hold source of object being dragged:
var dragdropDummyObj;


//putting data into the clipBoard
function mouseClickCopyToClipBoard(dataType, draggingData){	
	
	if( window.clipboardData ){
		window.clipboardData.clearData("HTML");
		window.clipboardData.setData(dataType, draggingData);
	}
	else{
		copy_clip(draggingData)
	}
		
//return false;
}

function fnBeforeCopy()
{
	
	event.returnValue = false;
	
}

function startDrag( dataType, draggingData){

if (  event.dataTransfer)
	{
	
	

    // get what is being dragged:
    //dragdropObj = window.event.srcElement;

    // store the source of the object into a string acting as a dummy object so we don't ruin the original object:
    //dragdropDummyObj = dragdropObj.outerHTML;

    // post the data for Windows:
    var dragData = window.event.dataTransfer;

    // set the type of data for the clipboard:
    dragData.setData( dataType, draggingData);

    // allow only dragging that involves moving the object:
    dragData.effectAllowed = 'linkMove';

    // use the special 'move' cursor when dragging:
    dragData.dropEffect = 'move';
    
    }
else
	{
	alert("Din browser underst?tter ikke funktionaliteten, tr?k og slip.")
	return false;
	}	
}

function enterDrag() {
    confirm('enterDrag');

    // allow target object to read clipboard:
    window.event.dataTransfer.getData('Text');
}

function endDrag() {
    //confirm('endDrag');

    // when done remove clipboard data
    window.event.dataTransfer.clearData();
}

function overDrag() {
    confirm('overDrag');

    // tell onOverDrag handler not to do anything:
    window.event.returnValue = false;
}


function drop() {
    confirm('drop');

    // eliminate default action of ondrop so we can customize:
    window.event.returnValue = false;

    // manually add new attributes:
    dragdropDummyObj = addAttribute(dragdropDummyObj, 'height="25" width="25" alt="' + dragdropObj.myLabel + '"');

    // add the picture below shopping cart:
    // miniProductBar.innerHTML += dragdropDummyObj + '&nbsp;';

    // change shopping cart message:
    // productBarStatus.innerHTML = '<b>' + dragdropObj.myLabel + '<\/b> has been added to the shopping cart.';
}


// since we aren't working with an actual object, we will add our attributes manually:
function addAttribute(oObj, sVal) {
    var loc = oObj.indexOf(">");
    return oObj.substring(0, loc) + ' ' + sVal + '>';
}


function copy_clip(meintext)
{
 if (window.clipboardData) 
   {
   
   // the IE-manier
   window.clipboardData.setData("Text", meintext);
   
   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   
   // dit is belangrijk maar staat nergens duidelijk vermeld:
   // you have to sign the code to enable this, or see notes below 
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');
   
   // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
   // nodig om het in op te slaan
   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;
}