//Drag and Drop script - http://www.btinternet.com/~kurt.grigg/javascript

if  (document.getElementById){

(function(){

//Stop Opera selecting anything whilst dragging.
if (window.opera){
document.write("<input type='hidden' id='Q' value=' '>");
}

var n = 500;
var dragok = false;
var y,x,d,dy,dx, crt_ob;

function move(e){
if (!e) e = window.event;
 if (dragok){
  d.style.left = dx + e.clientX - x + "px";
  d.style.top  = dy + e.clientY - y + "px";
  return false;
 }
}

function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement, peCaption=null;
//if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass"){
	if(typeof temp.parentNode != "undefined")
		while((temp.id!='caption' || (peCaption=1)) && temp.tagName != "HTML"|"BODY" && temp.className != "dragclass" && temp.parentNode) temp=temp.parentNode;
	else 
		while((temp.id!='caption' || (peCaption=1)) && temp.tagName != "HTML"|"BODY" && temp.className != "dragclass" && temp.parentElement) temp=temp.parentElement;
  //temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
//}
	if(temp.className == "dragclass") temp.style.zIndex = n++;  //ulterior
	if(!peCaption) return;  //ulterior
	ascunde_select(temp);
	crt_ob=temp;
if (temp.className == "dragclass"){
 if (window.opera){
  document.getElementById("Q").focus();
 }
 dragok = true;
 temp.style.zIndex = n++;
 d = temp;
 dx = parseInt(temp.style.left+0);
 dy = parseInt(temp.style.top+0);
 x = e.clientX;
 y = e.clientY;
 document.onmousemove = move;
 return false;
 }
}

function up(event){
//if (!e) e = window.event;

var dragok_old=dragok;
dragok = false;
document.onmousemove = null;
if(crt_ob){ crt_ob.style.left=0; crt_ob.style.top=0; }

if(d && dragok_old) tras_ncos(event);

}

function ascunde_select(but_not_from_this_div){
	if(!but_not_from_this_div) return;
	var obs=document.body.getElementsByTagName("SELECT"), obs_crt=but_not_from_this_div.getElementsByTagName("SELECT"), gasit=null;	
	for(i=0; i<obs.length; i++){	gasit=false;	
		for(j=0, gasit=0; j<obs_crt.length; j++) if((obs[i]==obs_crt[j]) && (gasit=1)) break;		
		obs[i].style.visibility=(gasit ? '' : 'hidden');		
	}	
}

function tras_ncos(event){
	try{
     var posx = 0, posy = 0;

	 e=event;
     if (!e) var e = window.event;     
	 if(!e) return;
	 
     if (e.pageX || e.pageY) {
          posx = e.pageX;
          posy = e.pageY;
     } else if (e.clientX || e.clientY) {     	
          posx = e.clientX + document.body.scrollLeft;
          posy = e.clientY + document.body.scrollTop;          
     }
     var asus=findPos(document.getElementById('img_cosul_tau'))
     var ajos=findPos(document.getElementById('img_stiati_ca'));
     
     if(!ajos || !asus) return;
     
     if(!(posx>asus[0]-70 && posx<asus[0]+280 && posy>asus[1]-20 && posy<ajos[1]-10)) return;
	 //alert(posx+'  ,'+posy+' / '+asus[0]+','+asus[1]+' / '+ajos[0]+','+ajos[1]+', idp='+d.idprodus);
	 
	 href_cdax=d.href_buton_comanda;
	 idpx=d.idprodus;
	 
	 if(!href_cdax && d.id && (ax=d.id.split('|')) && ax.length==2){
	 	idpx=ax[0];
	 	href_cdax=ax[1];
	 }
	 if(!href_cdax) return;
	 
	 makeRequest('comanda_idp'+idpx, href_cdax,'asteptati... ');
	 
	}catch(e){}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if(!obj) return false;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

document.onmousedown = down;
document.onmouseup = up;

})();
}//End.