
/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var dragid;
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){
	if (this.dragapproved == 1) {
		if (Math.abs(parseInt(this.targetobj.style.left.replace('pt',''))) > 10 || Math.abs(parseInt(this.targetobj.style.top.replace('pt',''))) > 10) {
			document.getElementById(dragid.replace("img_","a_")).removeAttribute("href");
			document.getElementById("imgx").value = this.targetobj.style.left;
			document.getElementById("imgy").value = this.targetobj.style.top;
			document.getElementById("searchForm").submit();
		}
	}	
	this.dragapproved=0;
}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="dpproductadmin"){
this.dragapproved=1
this.targetobj.style.zIndex = 5;
dragid = this.targetobj.id;
document.getElementById("imgid").value = dragid;
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"

return false
}
}
}

dragobject.initialize()
/***************
var productNum; 
var dragid;
var productDrag = false;
var px = 0;
var py = 0;
var rowx = 0; var rowy = 0;
var ix = 0;
var iy = 0;

function selectProduct(mpc) {
console.log('productDrag='+productDrag);
	if (productDrag == false) {
//		Determine the offset from the top of the document to the part that is visible
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0){
			if (window.pageYOffset) {
				ScrollTop = window.pageYOffset;
			} else {
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}

		px = -mx;
		py = -my;
		console.log('px='+px+',py='+py);
		console.log(mx+','+(my+ScrollTop));
		
		rowx = parseInt((mx-202)/184)
		rowy = parseInt((ScrollTop+my-205)/188)
		productNum = (rowx+1)+(4*rowy)
//		calculate offset from upper left corner of image
		ix = mx-(rowx*184)-202
		iy = my-(rowy*188)-205
		console.log('ix='+ix+',iy='+iy); 
		console.log(mpc+','+productNum);	
	
//		productDrag = true;
		dragid = "img_"+mpc;
		if(ix<20 && iy<20) {
			document.getElementById(dragid).style.zIndex = 5;
			productDrag = true;
			return false;
		} else {return true;}
	}
	if (productDrag == true) {
		document.getElementById(dragid).style.zIndex = 3;
		productDrag = false;
		return false;
	}
	return false;
}

function dropProduct(mpc) {
	productDrag = false;
//		Determine the offset from the top of the document to the part that is visible
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0){
			if (window.pageYOffset) {
				ScrollTop = window.pageYOffset;
			} else {
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		
	console.log(mx+','+(my+ScrollTop));
	productNum = (parseInt((mx-192)/184)+1)+(4*parseInt((ScrollTop+my-205)/189))
	console.log(mpc+','+productNum);
}

function dragProduct() {
console.log(dragid);
console.log('mx='+mx+',my='+my);
document.getElementById(dragid).style.left = (px+mx) + "px";
document.getElementById(dragid).style.top = (py+my)+"px";


}
*************/
