	function startCrop(){
		var cropObject = document.getElementById("cropTool");
		cropArea["starX"]=fixPx(cropObject.style.left);
		cropArea["starY"]=fixPx(cropObject.style.top);

		var cropLine1 = document.createElement("div");
		cropLine1.id="cropLine1";
		cropLine1.style.borderWidth=1; 
		cropLine1.style.borderColor='red'; 
		cropLine1.style.borderStyle='solid'; 
		cropLine1.style.left=cropArea["starX"];
		cropLine1.style.top=cropArea["starY"];
		cropLine1.style.position="absolute";
		cropLine1.style.zIndex=101;
		document.body.appendChild(cropLine1);
	}

	function drawCrop(){
		var cropObject = document.getElementById("cropTool");
		cropArea["endX"]=fixPx(cropObject.style.left);
		cropArea["endY"]=fixPx(cropObject.style.top);
		var cropLine1=document.getElementById("cropLine1");
		if ((cropArea["endX"]-cropArea["starX"])<0) {
			cropLine1.style.left=cropArea["endX"];
			cropLine1.style.width=(cropArea["starX"]-cropArea["endX"]);
		} else {
			cropLine1.style.width=(cropArea["endX"]-cropArea["starX"]);
		}

		if ((cropArea["endY"]-cropArea["starY"])<0) {
			cropLine1.style.top=cropArea["endY"];
			cropLine1.style.height=(cropArea["starY"]-cropArea["endY"]);
		} else {
			cropLine1.style.height=(cropArea["endY"]-cropArea["starY"]);
		}
	}

	function processCrop(){
		var cropConfirm=confirm("Would you like to crop the image according to the selected area?");
		if (cropConfirm){
			var cropLine='';
			var backgroundPosition=Array();
			cropLine+=findPosX(document.getElementById("imPropBackground")) + ':';
			cropLine+=findPosY(document.getElementById("imPropBackground")) + ';';
			cropLine+=cropArea["starX"] + ':' + cropArea["starY"] + ':' + cropArea["endX"] + ':' + cropArea["endY"];			
			document.form1.mAction.value='crop';
			//document.form1.mAction.value='';
			document.form1.processLine.value=cropLine;
			document.form1.submit();
		} else {
			var cropLine1=document.getElementById("cropLine1")			
			document.body.removeChild(cropLine1);
			var cropTool=document.getElementById("cropTool")			
			document.body.removeChild(cropTool);
			processColoring=true;
		}
	}

	function initCrop(e){
		processColoring=false;
		mousePosition=getMouseXY(e);

		var cropObject = document.createElement("img");
		cropObject.src="http://ww2.thedollpalace.com/images/icon/icon-crop-tool.gif";
		cropObject.id="cropTool";
		cropObject.style.position="absolute";
		cropObject.style.left=mousePosition["PosX"]-10;
		cropObject.style.top=mousePosition["PosY"]-10;		
		cropObject.style.zIndex=100;
		document.body.appendChild(cropObject);
		document.onmousemove=function(e){
			var cropObject = document.getElementById("cropTool");
			mousePosition=getMouseXY(e);
			cropObject.style.left=mousePosition["PosX"]-10;
			cropObject.style.top=mousePosition["PosY"]-10;	
		}
		Drag.init(cropObject);
		cropObject.onDragStart = startCrop;
		cropObject.onDrag = drawCrop;		
		cropObject.onDragEnd = processCrop;
	}
