
        var tempX=0
		var tempY=0
		var cropTop = 0
		var cropLeft = 0
		var cropHeight = 0
		var cropWidth = 0
		var cropping=false;
		var draggin = false
		var draggingResultId = "";
		var ResizeKeepAspect = false;
		var minimumHeight = 50;
		var minimumWidth = 50;
		var OriginalX = 0
		var ZFactor = 1;
		
		
		function MozillaDragEnter(eventInd){
            if(draggingResultId!=""){
                makeCropArea(eventInd) 
            }
	        if(eventInd.target.id && eventInd.target.id+"" == "picture"){
	            if(draggingResultId==""){
	                makeCropPosition(eventInd);
	            }
	            draggingResultId=eventInd.target.id;
	        }
		}
		
		function MozillaDragExit(eventInd){
	        if(eventInd.target.id && eventInd.target.id+"" == "picture"){
               makeCropSize(eventInd);
               draggingResultId="";
            }
		}
		
		function MozillaMouseMove(eventInd){
		    if(draggingResultId!=""){
		        draggingResultId="";
	            makeCropSize(eventInd);
		    }
		}
		
		function MozillaDragGesture(eventInd){
    		makeCropArea(eventInd) 
		}
				
		function setWindow()
		{
		    if(window.addEventListener){
                window.addEventListener("dragenter",MozillaDragEnter,true) 
                window.addEventListener("draggesture",MozillaDragGesture,true) 
                window.addEventListener("dragover",MozillaDragEnter,true) 
                window.addEventListener("mousemove",MozillaMouseMove,true) 
            }
		}
		/*try{
		    addLoadEvent(setWindow);
		 }
		 catch(e)  
		 {
		    alert('error in setWindow')
		 }
		//window.onload = setWindow;
		*/
		function makeCrop()
		{
			if (cropping)
			{
				makeCropSize()
				cropping=false
			}
			else
			{
				cropping=true
				makeCropPosition()
			}
		}
		
		function makeCropPosition(eventInd)
		{
	        var e=window.event?window.event:eventInd;	
	        var srcElement=e.srcElement?e.srcElement:e.target;
			cropTop = e.clientY + document.body.scrollTop
			cropLeft = e.clientX + document.body.scrollLeft
			
			document.getElementById('crop').style.top = cropTop
			document.getElementById('crop').style.left = cropLeft
		    document.getElementById('crop').style.display = ''
			cropTop = parseInt(document.getElementById('crop').style.top);
			cropLeft = parseInt(document.getElementById('crop').style.left);
			
		}
		
		function makeCropArea(eventInd)
		{
	        var e=window.event?window.event:eventInd;	
	        var srcElement=e.srcElement?e.srcElement:e.target;
			var areaHeight = (e.clientY + document.body.scrollTop) - cropTop
			var areaWidth = (e.clientX + document.body.scrollLeft) - cropLeft
			if (areaHeight > 0 && areaWidth > 0)
			{
				document.getElementById('crop').style.width= areaWidth 
				document.getElementById('crop').style.height= areaHeight
			}
		}
		
		
		/*
		function makeCropSizeKeepAspect(eventInd)
		{
	        var e=window.event?window.event:eventInd;	
	        var srcElement=e.srcElement?e.srcElement:e.target;
	        var Xfactor = parseFloat(parseInt(document.getElementById(cropSizeForcedWidthID).value)/parseInt(document.getElementById(cropSizeForcedHeightID).value))
			cropWidth = e.clientX + document.body.scrollLeft - cropLeft
            cropHeight = parseInt(parseFloat(cropWidth) / Xfactor)
			document.getElementById(cropSizeTopID).value = cropTop
			document.getElementById(cropSizeLeftID).value = cropLeft
			document.getElementById(cropSizeHeightID).value = cropHeight
			document.getElementById(cropSizeWidthID).value = cropWidth
		}
	
		
		function setImgUri(url)
		{
		    if (OriginalX == 0)
		    {
		        OriginalX = parseInt(document.getElementById('picture').width);
		    }
		    document.getElementById('picture').src = url;
		    document.getElementById('crop').style.top='8px';
		    document.getElementById('crop').style.left='8px';
		    setTimeout('setMinimumCrop()',300);
		    
		}
		
		
		*/
		function makeCropAreaFromInput()
		{
			
			var areaHeight =  document.getElementById(cropSizeForcedHeightID).value
			var areaWidth  = document.getElementById(cropSizeForcedWidthID).value 
			if (areaHeight > document.getElementById('picture').height || areaWidth > document.getElementById('picture').width || areaWidth < 16 || areaHeight < 16)
			{
				alert('Beskæring skal forgå inden for x,y(16-'+document.getElementById('picture').width+',16-'+document.getElementById('picture').height+') pixel')
			}
			else
			{
				document.getElementById(cropSizeHeightID).value = areaHeight
				document.getElementById(cropSizeWidthID).value = areaWidth
				
				cropHeight = areaHeight
				cropWidth = areaWidth
				cropTop=0
				cropLeft=0
				
				if (areaHeight > 0 && areaWidth > 0)
				{
					document.getElementById('crop').style.width= areaWidth 
					document.getElementById('crop').style.height= areaHeight 
					document.getElementById('crop').style.top= cropTop
					document.getElementById('crop').style.left= cropLeft 
				}
				document.getElementById(previewWidthID).value = document.getElementById('picture').width
				document.getElementById(previewHeightID).value = document.getElementById('picture').height
				document.getElementById('crop').style.display = ''
			}
		}
		
		function makeCropSize(eventInd)
		{
	        var e=window.event?window.event:eventInd;	
	        var srcElement=e.srcElement?e.srcElement:e.target;
			cropHeight = e.clientY + document.body.scrollTop - cropTop
			cropWidth = e.clientX + document.body.scrollLeft - cropLeft
			document.getElementById(cropSizeTopID).value = cropTop
			document.getElementById(cropSizeLeftID).value = cropLeft
			document.getElementById(cropSizeHeightID).value = cropHeight
			document.getElementById(cropSizeWidthID).value = cropWidth
			document.getElementById(previewWidthID).value = document.getElementById('picture').width
			document.getElementById(previewHeightID).value = document.getElementById('picture').height
		}
		
		function restartCrop()
		{
			document.getElementById('crop').style.width= 1 
			document.getElementById('crop').style.height= 1
			document.getElementById(cropSizeTopID).value = 0
			document.getElementById(cropSizeLeftID).value = 0
			document.getElementById(cropSizeHeightID).value = 0
			document.getElementById(cropSizeWidthID).value = 0
			document.getElementById(cropSizeForcedHeightID).value = ''
			document.getElementById(cropSizeForcedWidthID).value = ''
			cropTop = 0
			cropLeft = 0
			cropHeight = 0
			cropWidth = 0
			cropping=false;
			draggin = false
			document.getElementById('crop').style.display= 'none'
		}
		
		function startResizeKeepAspect()
		{
		    ResizeKeepAspect = true;
		}
		function stopResizeKeepAspect()
		{
		    ResizeKeepAspect = false;
		}
		
		function restartCropKeepAspect()
		{
			document.getElementById('crop').style.width= parseInt(document.getElementById(cropSizeForcedWidthID).value)
			document.getElementById('crop').style.height= parseInt(document.getElementById(cropSizeForcedHeightID).value)
			document.getElementById(cropSizeTopID).value = 0
			document.getElementById(cropSizeLeftID).value = 0
			document.getElementById(cropSizeHeightID).value = parseInt(document.getElementById(cropSizeForcedHeightID).value)
			document.getElementById(cropSizeWidthID).value = parseInt(document.getElementById(cropSizeForcedWidthID).value)
			//document.getElementById(cropSizeForcedHeightID).value = ''
			//document.getElementById(cropSizeForcedWidthID).value = document.getElementById(cropSizeForcedWidthID).value 
			cropTop = 0
			cropLeft = 0
			cropHeight = parseInt(document.getElementById(cropSizeForcedHeightID).value)
			cropWidth = parseInt(document.getElementById(cropSizeForcedWidthID).value)
			cropping=false;
			draggin = false
			//document.getElementById('crop').style.display= 'none'
		}
		
		function SetdragCropArea()
		{
			draggin	=true
		}
		
		function unSetdragCropArea()
		{
			document.getElementById(cropSizeTopID).value = cropTop
			document.getElementById(cropSizeLeftID).value = cropLeft
			draggin	= false
		}
		
		
		function dragCropArea(eventInd)
		{
	        var e=window.event?window.event:eventInd;	
	        var srcElement=e.srcElement?e.srcElement:e.target;
				
				if(draggin)
				{
					
					cropTop = e.clientY + document.body.scrollTop
					cropLeft = e.clientX + document.body.scrollLeft
			
					if (parseInt(cropTop) + parseInt(cropHeight) < (document.getElementById('picture').height+8) && cropTop > 7)
						document.getElementById('crop').style.top = cropTop-8+'px'
					if (parseInt(cropLeft)+parseInt(cropWidth) < document.getElementById('picture').width+8 && cropLeft > 7)
						document.getElementById('crop').style.left = cropLeft-8+'px'
			
			        cropTop = parseInt(document.getElementById('crop').style.top);
			        cropLeft = parseInt(document.getElementById('crop').style.left);
				}
		}
		
		function setCropArea()
		{
		   
		    var Xfaktor = (document.getElementById('picture').width/parseInt(document.getElementById('maxwidthID').value))
		    cropTop = 0
			cropLeft = 0
			cropHeight = parseInt(document.getElementById('ResizeHeight').value)*Xfaktor
			cropWidth = parseInt(document.getElementById('ResizeWidth').value)*Xfaktor
		    
		    // MU		    
		    document.getElementById(cropSizeWidthID).value = document.getElementById('ResizeWidth').value;
		    document.getElementById(cropSizeHeightID).value = document.getElementById('ResizeHeight').value;
		    		    
		    if (cropHeight > 0 && cropWidth > 0)
		    {
				document.getElementById('crop').style.width= cropWidth 
				document.getElementById('crop').style.height= cropHeight 
				document.getElementById('crop').style.top= cropTop
				document.getElementById('crop').style.left= cropLeft 
			}
				document.getElementById(previewWidthID).value = document.getElementById('picture').width
				document.getElementById(previewHeightID).value = document.getElementById('picture').height
				document.getElementById('crop').style.display = ''
		}
		
		//
		
		function SetCropWindowSize()
		{
		   //alert(document.getElementsByTagName('img')[0].height)
		   /* alert(document.getElementsByTagName('body')[0].height)
		    alert(document.getElementsByTagName('body')[0].height)
		    alert(window.screen.height)
		    */
		    
		    try{
		        var newHeight =(parseInt(document.getElementsByTagName('img')[0].height)+250)
		        var newWidth = (parseInt(document.getElementsByTagName('img')[0].width));
                window.resizeTo(newWidth,newHeight)
                }
                catch(e)
                {
                
                }
               
		    
		}