BORDER_WIDTH=3;TABLE_SPACE=0;BORDER_STYLE="1px dotted #888";function GetTopPos(B){if(!B){return 0;}var A=B.offsetTop;while((B=B.offsetParent)!=null){if(B.tagName!="HTML"){A+=B.offsetTop;}}return A;}function GetLeftPos(B){if(!B){return 0;}var A=B.offsetLeft;while((B=B.offsetParent)!=null){if(B.tagName!="HTML"){A+=B.offsetLeft;}}return A;}DragBox=Class.create();DragBox.prototype={initialize:function(A,C,B){this.bTransparencyWhenDragging=false;this.nAutoScrollSpeed=40;this.aDraggables=A;this.aDropables=C;this.aDraggableParents=B;this.oDragObject=null;this.oDragObjectParent=null;this.oDestObject=null;this.oRectangleDiv=null;this.aDropInfos=Array();this.oImageInfo=null;this.bOkToMove=true;this.bAutoScrollActive=false;this.bHighLightDropZone=true;this.nDocumentHeight=null;this.nDocumentScrollHeight=null;this.nAutoScrollDir=-1;this.nAutoScrollYPos=-1;this.nMouseX=0;this.nMouseY=0;this.nElX=0;this.nElY=0;this.bOpera=navigator.userAgent.toLowerCase().indexOf("opera")>=0?true:false;this.CreateHelpObject();this.InitEvents();this.old_hovered_elem_id="";this.old_hovered_elem_x=0;this.old_hovered_elem_y=0;},CreateHelpObject:function(){this.oRectangleDiv=document.createElement("DIV");this.oRectangleDiv.id="rectangleDiv";this.oRectangleDiv.style.display="none";document.body.appendChild(this.oRectangleDiv);},AutoScroll:function(){if(document.documentElement.scrollHeight>this.nDocumentScrollHeight&&this.nAutoScrollDir>0){return ;}if(this.bOpera){return ;}window.scrollBy(0,this.nAutoScrollDir);if(!this.oDragObject){return ;}if(this.nAutoScrollDir<0){if(document.documentElement.scrollTop>0){this.oDragObject.style.top=(this.nElY-this.nMouseY+this.nAutoScrollYPos+document.documentElement.scrollTop)+"px";}else{this.bAutoScrollActive=false;}}else{if(this.nAutoScrollYPos>(this.nDocumentHeight-50)){this.oDragObject.style.top=(this.nElY-this.nMouseY+this.nAutoScrollYPos+document.documentElement.scrollTop)+"px";}else{this.bAutoScrollActive=false;}}if(this.bAutoScrollActive){setTimeout(this.AutoScroll.bind(this),5);}},AddDraggable:function(C,B,A){if(this.aDraggables.indexOf(C)==-1){this.aDraggables.push(C);}if(this.aDropables.indexOf(B)==-1){this.aDropables.push(B);}if(this.aDraggableParents.indexOf(A)==-1){this.aDraggableParents.push(A);}$(C).onmousedown=this.InitDragDropBox.bindAsEventListener(this);$(C).className=$(C).className+" draggable";this.nDocumentHeight=document.documentElement.clientHeight;},InitEvents:function(){for(var A=0;A<this.aDraggables.length;A++){$(this.aDraggables[A]).onmousedown=this.InitDragDropBox.bindAsEventListener(this);$(this.aDraggables[A]).className=$(this.aDraggables[A]).className+" draggable";}document.body.onmousemove=this.MoveDragableElement.bindAsEventListener(this);document.body.onmouseup=this.StopDragDrop.bindAsEventListener(this);this.nDocumentHeight=document.documentElement.clientHeight;},InitDragDropBox:function(H){if(this.oDragObject&&this.oDragObjectParent){this.oDragObjectParent.appendChild(this.oDragObject);this.oRectangleDiv.style.display="none";return false;}if(document.all){H=event;}if(H.target){source=H.target;}else{if(H.srcElement){source=H.srcElement;}}if(source.nodeType==3){source=source.parentNode;}if(source.tagName.toLowerCase()=="img"||source.tagName.toLowerCase()=="a"||source.tagName.toLowerCase()=="input"||source.tagName.toLowerCase()=="select"){return ;}else{if(source.id.substr(0,7)=="no_drag"){return ;}}oTmp=this.oGetParentBloc(source);if(oTmp){source=oTmp;}else{alert("Erreur: pas de parent");}this.nMouseX=H.clientX;this.nMouseY=H.clientY;this.nElX=GetLeftPos(source)/1;this.nElY=GetTopPos(source)/1-document.documentElement.scrollTop;this.oDragObject=source;this.oDragObjectParent=this.oGetDropableParent(source);this.nDocumentScrollHeight=document.documentElement.scrollHeight+100+this.oDragObject.offsetHeight;for(var A=0;A<this.aDropables.length;A++){var G=$(this.aDropables[A]);if(!G){continue;}var F=document.createElement("DIV");F.id="DropInfo_"+A;var C=Element.getStyle(G,"padding-top").split("px")[0];var B=Element.getStyle(G,"padding-right").split("px")[0];var D=Element.getStyle(G,"padding-bottom").split("px")[0];var E=Element.getStyle(G,"padding-left").split("px")[0];F.style.position="absolute";F.style.border="";F.style.top=(GetTopPos(G)-C-BORDER_WIDTH)+"px";F.style.left=(GetLeftPos(G)-E-BORDER_WIDTH)+"px";F.style.width=(G.offsetWidth-E-B+2*BORDER_WIDTH)+"px";F.style.height=(G.offsetHeight-C-D+2*BORDER_WIDTH)+"px";F.style.zIndex=0;document.body.appendChild(F);this.aDropInfos.push(F);}return false;},MoveDragableElement:function(C){if(!this.oDragObject||!this.oDragObjectParent){return ;}if(document.all){C=event;}if(document.all&&C.button!=1&&!this.bOpera){this.StopDragDrop();return ;}if(document.body!=this.oDragObject.parentNode){this.oDragObject.style.width=(this.oDragObject.offsetWidth-2)+"px";this.oDragObject.style.position="absolute";if(this.bTransparencyWhenDragging){this.oDragObject.style.filter="alpha(opacity=70)";this.oDragObject.style.opacity="0.7";}this.oDragObject.parentNode.insertBefore(this.oRectangleDiv,this.oDragObject);this.oRectangleDiv.style.display="block";document.body.appendChild(this.oDragObject);this.oRectangleDiv.style.height=(this.oDragObject.offsetHeight+(TABLE_SPACE))+"px";}if(C.clientY<50||C.clientY>(this.nDocumentHeight-50)){if(C.clientY<50&&!this.bAutoScrollActive){this.bAutoScrollActive=true;this.nAutoScrollDir=this.nAutoScrollSpeed*(-1);this.nAutoScrollYPos=C.clientY;this.AutoScroll();}if(C.clientY>(this.nDocumentHeight-50)&&document.documentElement.scrollHeight<=this.nDocumentScrollHeight&&!this.bAutoScrollActive){this.bAutoScrollActive=true;this.nAutoScrollDir=this.nAutoScrollSpeed;this.nAutoScrollYPos=C.clientY;this.AutoScroll();}}else{this.bAutoScrollActive=false;}var B=C.clientX;var A=C.clientY+document.documentElement.scrollTop;this.oDragObject.style.left=(C.clientX-this.nMouseX+this.nElX)+"px";this.oDragObject.style.top=(this.nElY-this.nMouseY+C.clientY+document.documentElement.scrollTop)+"px";if(this.bHighLightDropZone){this.HightLightDropZone(B,A);}},HightLightDropZone:function(C,B){for(var E=0;E<this.aDropables.length;E++){var D=$(this.aDropables[E]);if(!D||D==this.oDragObject){continue;}var A=GetLeftPos(D);var F=GetTopPos(D);if(C<A||C>(A+D.offsetWidth)||B<F||B>(F+D.offsetHeight)){$("DropInfo_"+E).style.border="";}else{$("DropInfo_"+E).style.border=BORDER_STYLE;}}},SetOkToMove:function(){this.bOkToMove=true;},StopDragDrop:function(I){if(!this.oDragObject){return ;}if(document.all){I=event;}var C=I.clientX;var E=I.clientY+document.documentElement.scrollTop;this.oDestObject=null;for(var B=0;B<this.aDropables.length;B++){var A=$(this.aDropables[B]);if(!A||A==this.oDragObject){continue;}var J=GetLeftPos(A);var H=GetTopPos(A);if(C<J||C>(J+A.offsetWidth)||E<H||E>(H+A.offsetHeight)){continue;}this.oDestObject=A;break;}for(var G=0;G<this.aDropInfos.length;G++){var L=$(this.aDropInfos[G]);L.parentNode.removeChild(L);}this.aDropInfos.clear();if(this.bTransparencyWhenDragging){this.oDragObject.style.filter=null;this.oDragObject.style.opacity=null;}this.oDragObject.style.position="static";this.oDragObject.style.width=null;if(this.oDestObject&&this.oDestObject!=this.oDragObject){var K=this.oGetDropableParent(this.oDestObject);var D=this.oGetDraggableChild(this.oDestObject);if(K&&D){var F=this.oGetParentBloc(D);if(F){D=F;}else{return ;}if(this.oDragObject.id!="result_main"&&D.id!="result_main"){K.appendChild(this.oDragObject);this.oDragObjectParent.appendChild(D);doUpdateAssociation(this.oDragObjectParent.id,K.id);}else{this.oDragObjectParent.appendChild(this.oDragObject);doChangePosition(this.oDragObject,K,D);}}else{this.oDragObjectParent.appendChild(this.oDragObject);}}else{this.oDragObjectParent.appendChild(this.oDragObject);}this.SaveCookies();this.bAutoScrollActive=false;this.oDragObject=null;this.oDragObjectParent=null;this.oDestObject=null;this.oRectangleDiv.style.display="none";this.nDocumentHeight=document.documentElement.clientHeight;},CancelSelectionEvent:function(A){if(document.all){A=event;}if(A.target){source=A.target;}else{if(A.srcElement){source=A.srcElement;}}if(source.nodeType==3){source=source.parentNode;}if(source.tagName.toLowerCase()=="input"){return true;}if(this.oDragObject>=0){return false;}else{return true;}},CancelEvent:function(){return false;},oGetDraggableChild:function(C){var C=$(C);if(this.aDraggables.indexOf(C.id)!=-1){return C;}else{if(C.childNodes){for(var A=0;A<C.childNodes.length;A++){var B=C.childNodes[A];if(this.aDraggables.indexOf(B.id)!=-1){return B;}else{if(B.childNodes){oReturn=this.oGetDraggableChild(B);if(oReturn){return oReturn;}}}}}}return null;},oGetDropableParent:function(A){while(A&&A.nodeName!="BODY"){if(this.aDropables.indexOf(A.id)!=-1){return A;}A=A.parentNode;}return null;},oGetParentBloc:function(A){while(A&&A.nodeName!="BODY"){if(this.aDraggableParents.indexOf(A.id)!=-1){return A;}A=A.parentNode;}return null;},SaveCookies:function(){}};
