  //拖动
  function tableDrag(scrollCon,table,tableCon,moveCon,tableT){
    var scrollC = document.getElementById(scrollCon),
		ochek=document.getElementById(tableCon),
        otable=document.getElementById(table),
		othead=document.getElementById(tableT),
        otody=otable.tBodies[0],
        oth=otable.getElementsByTagName("th"),
        otd=otody.getElementsByTagName("td"),
        box=document.getElementById(moveCon),
        arrn=[]; 
        for (var i = 0; i < oth.length; i++) {
          oth[i].onmousedown=function(e){ //以前是oth    
              var e=e||window.event,
                  target = e.target||e.srcElement,
                  thW = target.offsetWidth,
                  maxl=otable.offsetWidth-thW,
                  rows=otable.rows,
                  ckL=ochek.offsetLeft,
                  disX=target.offsetLeft,
                  _this=this,
                  cdisX=e.clientX-ckL-disX-scrollC.offsetLeft;
                   //console.log(target);
                  if(target.nodeName=="SPAN" || target.nodeName=="IMG"){
                     return false;
                  }

                  for (var i = 0; i < rows.length; i++) {
                      var op=document.createElement("p");
                      op.innerHTML=rows[i].cells[this.cellIndex].innerHTML;  
                      box.appendChild(op);
                  };  
                  for (var i = 0; i < oth.length; i++) { 
                    /*  var self=$("#thShow li .checkBox").eq(i);                    
                      if(self.checked){
                          arrn.push(oth[i].offsetLeft);  
                      } */
                     arrn.push(oth[i].offsetLeft);          
                  }; 
                  console.log(arrn);
                  box.style.display="block";
                  box.style.width=thW+"px";
                  box.style.left=disX+"px";
                  //未完成 还有事件没写。
                  document.onmousemove=function(e){
                      var e=e||window.event,
                      target = e.target||e.srcElement,
                      thW = target.offsetWidth;
                      box.style.top=0;
                      box.style.left=e.clientX-ckL-cdisX-scrollC.offsetLeft+"px";
                      if(box.offsetLeft>maxl){
                           box.style.left=maxl+"px";
                      }else if(box.offsetLeft<0){
                           box.style.left=0;
                      }        
                      document.onselectstart=function(){return false};     
                    window.getSelection ? window.getSelection().removeAllRanges() : doc.selection.empty();              
                  }
                  document.onmouseup=function(e){
                     var e=e||window.event,
                         opr=box.getElementsByTagName("p"),
						 scrollL = ochek.scrollLeft || 0;
                         oboxl=box.offsetLeft+cdisX+scrollL;
                        for (var i = 0; i < arrn.length; i++) {
                           if(arrn[i]<oboxl){
                            var index=i;
                           }
                        };
                       for (var i = 0; i < rows.length; i++) {
                          rows[i].cells[_this.cellIndex].innerHTML="";
                          rows[i].cells[_this.cellIndex].innerHTML=rows[i].cells[index].innerHTML;
                          rows[i].cells[index].innerHTML="";
                          rows[i].cells[index].innerHTML=opr[i].innerHTML;
                       };
                       box.innerHTML="";
                       arrn.splice(0,arrn.length);
                       box.style.display="none";
                       document.onmousemove=null; 
                       document.onmouseup=null;
                       document.onselectstart=function(){return false};     
                  }

             }
        };
        
  }
  _.MessageManager.on("tableDrag",function(){
    var scrollC = document.getElementById("graphToTable"),
    ochek=document.getElementById("tableDiv"),
        otable=document.getElementById("tableCon"),
    othead=document.getElementById("tableThead"),
        otody=otable.tBodies[0],
       othh=otable.getElementsByTagName("th"),
        otdd=otody.getElementsByTagName("td"),
        box=document.getElementById("tableBox"),
        arrn=[],oth=[],otd=[];
        for(var i=0;i<othh.length;i++){
          console.log(othh[i].style.display!="none");
          if(othh[i].style.display!="none"){
            oth.push(othh[i]);
          }
        }
        for(var i=0;i<otdd.length;i++){
          if(otdd[i].style.display!="none"){
            otd.push(otdd[i]);
          }
        }
        for (var i = 0; i < oth.length; i++) {
          oth[i].onmousedown=function(e){ //以前是oth 
             /* oth=[];  
              var thshow=$("#thShow li .checkBox");
              for(var i=0;i<thshow.length;i++){
                if(thshow[i].checked){
                  oth.push($("#tableThead tr th")[i]);
                }
              }*/
              var e=e||window.event,
                  target = e.target||e.srcElement,
                  thW = target.offsetWidth,
                  maxl=otable.offsetWidth-thW,
                  rows=otable.rows,
                  ckL=ochek.offsetLeft,
                  disX=target.offsetLeft,
                  _this=this,
                  cdisX=e.clientX-ckL-disX-scrollC.offsetLeft;
                   console.log(target);
                  if(target.nodeName=="SPAN" || target.nodeName=="IMG"){
                     return false;
                  }

                  for (var i = 0; i < rows.length; i++) {
                      var op=document.createElement("p");
                      op.innerHTML=rows[i].cells[this.cellIndex].innerHTML;  
                      box.appendChild(op);
                  };  
                  for (var i = 0; i < oth.length; i++) { 
                      /*var self=$("#thShow li .checkBox").eq(i);                    
                      if(self.checked){
                          arrn.push(oth[i].offsetLeft);  
                      } */
                      arrn.push(oth[i].offsetLeft);        
                  }; 
                  console.log(arrn);
                  box.style.display="block";
                  box.style.width=thW+"px";
                  box.style.left=disX+"px";
                  //未完成 还有事件没写。
                  document.onmousemove=function(e){
                      var e=e||window.event,
                      target = e.target||e.srcElement,
                      thW = target.offsetWidth;
                      box.style.top=0;
                      box.style.left=e.clientX-ckL-cdisX-scrollC.offsetLeft+"px";
                      if(box.offsetLeft>maxl){
                           box.style.left=maxl+"px";
                      }else if(box.offsetLeft<0){
                           box.style.left=0;
                      }        
                      document.onselectstart=function(){return false};     
                    window.getSelection ? window.getSelection().removeAllRanges() : doc.selection.empty();              
                  }
                  document.onmouseup=function(e){
                     var e=e||window.event,
                         opr=box.getElementsByTagName("p"),
             scrollL = ochek.scrollLeft || 0;
                         oboxl=box.offsetLeft+cdisX+scrollL;
                        for (var i = 0; i < arrn.length; i++) {
                           if(arrn[i]<oboxl){
                            var index=i;
                           }
                        };
                       for (var i = 0; i < rows.length; i++) {
                          rows[i].cells[_this.cellIndex].innerHTML="";
                          rows[i].cells[_this.cellIndex].innerHTML=rows[i].cells[index].innerHTML;
                          rows[i].cells[index].innerHTML="";
                          rows[i].cells[index].innerHTML=opr[i].innerHTML;
                       };
                       box.innerHTML="";
                       arrn.splice(0,arrn.length);
                       box.style.display="none";
                       document.onmousemove=null; 
                       document.onmouseup=null;
                       document.onselectstart=function(){return false};     
                  }

             }
        };
  });