var canmove=false;
var scaleFactor=10.26;

var tempOffsetX=0;
var tempOffsetY=0;

var mapOffsetX=0;
var mapOffsetY=0;
var Starline;
var activeConcept;
var thisobj=null   //为了完成各种基本编辑功能，如“置前”“复制”“删除”等
var StartPointX;
var StartPointY;
var MaxID=1;

function MoveStart()
{
if(event.srcElement.className!="WorkFlowItem") return;
	if (event.srcElement.className=="WorkFlowItem")
	{
	event.srcElement.parentElement.style.position="absolute";
	activeConcept=event.srcElement.parentElement;
	canmove=true;
	}
	tempOffsetX = event.offsetX;
	tempOffsetY = event.offsetY;

	mapOffsetX = GetMapOffsetY();
	mapOffsetY = GetMapOffsetX();
	Chart.attachEvent('onmousemove',Moving);
}

function Moving()
{
	if (event.button !=1) return;
	if(canmove)
	{
		//document.selection.empty();
		activeConcept.style.pixelLeft = (event.x  - tempOffsetX -mapOffsetX + document.body.scrollLeft ) * scaleFactor;
		activeConcept.style.pixelTop = (event.y - tempOffsetY - mapOffsetY + document.body.scrollTop ) * scaleFactor;
        }
}
//包图形化双击
function ondblclick()
{      var tempOnclick=event.srcElement;
       if(tempOnclick.className=="WorkFlowItem")
       {
        parent.location.href="../FlowProcess/openIs.jsp?ID="+tempOnclick.id;
       }
}
//流程图形化双击
function ondblclick1()
{      var tempOnclick=event.srcElement;
       if(tempOnclick.className=="WorkFlowItem")
       {
        parent.location.href="FlowDesign.jsp?SelectedItems="+tempOnclick.id;
       }
}
function UpdateOneLinePos(line)
{
	var beginShape;
	var endShape;
	beginShape = document.all.item(line.getAttribute("BeginShape")).parentElement;
	endShape = document.all.item(line.getAttribute("EndShape")).parentElement;
	SetJoinLine(beginShape,endShape,line);
}

function GetCenterX(shape)
{
	 return shape.style.pixelLeft + shape.style.pixelWidth / 2;
}

function GetCenterY(shape)
{
	return shape.style.pixelTop + shape.style.pixelHeight / 2;
}

function EndMove()
{
	canmove=false;
	//document.selection.empty();
}

function GetMapOffsetY()
{
	var tempMap = Chart;
	var tempY = 0;
	while (tempMap.tagName!="BODY")
	{
		tempY = tempY + tempMap.offsetTop;
		tempMap = tempMap.offsetParent;
	}
	return 	tempY + document.body.topMargin ;
}

function GetMapOffsetX()
{
	var tempMap = Chart;
	var tempX=0;
	while (tempMap.tagName!="BODY")
	{
		tempX = tempX + tempMap.offsetLeft;
		tempMap = tempMap.offsetParent;
	}
	return 	tempX + document.body.leftMargin ;
}

function MouseUP()
{
   var tempEnd=event.srcElement;
   WorkFlowItemMenu.style.display='none';
   if(tempEnd.className=="WorkFlowItem" && event.button==2)
   {
    WorkFlowItemMenu.style.left=event.x;
    WorkFlowItemMenu.style.top=event.y;
    WorkFlowItemMenu.style.display='';
    thisobj=event.srcElement;
   }
}
//设置包属性
function SetupProperty(WorkFlowItemobj)
{
      OpenSetup("PackageEdit.jsp?SelectedItems="+WorkFlowItemobj);
}
//删除流程包
function DeletePackage(WorkFlowItemobj)
{
      if (confirm("确定要删除吗？"))
      {
      OpenDelete("DeletePackage.jsp?PackageID="+WorkFlowItemobj);
      }
}
//删除流程
function DeleteFlow(WorkFlowItemobj)
{
      if (confirm("将删除流程及流程下的相关配置，确定要删除吗？"))
      {
      OpenDelete("DeleteFlow.jsp?FlowID="+WorkFlowItemobj);
      }
}
//设置流程属性
function SetupProperty1(WorkFlowItemobj)
{
      OpenSetup1("EditFrm.jsp?SelectedItems="+WorkFlowItemobj);
}
//打开流程
function OpenFlow(WorkFlowItemobj)
{
      parent.location.href="../FlowProcess/FlowShowDesign.jsp?PackageID="+WorkFlowItemobj;
}
//打开子包
function OpenSubPackage(WorkFlowItemobj)
{
      parent.location.href="../FlowProcess/PackageDesign.jsp?FID="+WorkFlowItemobj;
}
//打开复制流程包
function OpenFlowPackageCopy(WorkFlowItemobj)
{
      if (confirm("将复制包及包下的所有流程，确定要复制吗？"))
      {
      parent.location.href="../Other/FlowPackageCopy.jsp?PackageID="+WorkFlowItemobj;
      }
}
//打开移动流程包
function OpenFlowPackageMove(WorkFlowItemobj,PackageID,type)
{

        var strURL = "../FlowProcess/selectPackage.jsp";
        var strValue = window.showModalDialog(strURL,window,"status:no;help:no;dialogHeight:385px;dialogWidth:280px");
        if (strValue!=null && strValue!="" && strValue!="undefined")
        {
          parent.location.href="../Other/PackageMove.jsp?FID="+PackageID+"&PackageID="+WorkFlowItemobj+"&MovePackageID="+strValue;
        }

}


//打开复制流程
function OpenFlowCopy(WorkFlowItemobj,PackageID)
{
      if (confirm("将复制流程及流程下的所有配置，确定要复制吗？"))
      {
      parent.location.href="../FlowProcess/FlowCopy.jsp?PackageID="+PackageID+"&FlowID="+WorkFlowItemobj;
      }
}
//打开移动流程
function OpenFlowMove(WorkFlowItemobj,PackageID)
{
      var strURL = "../FlowProcess/selectPackage.jsp";
      var strValue = window.showModalDialog(strURL,window,"status:no;help:no;dialogHeight:385px;dialogWidth:280px");
      if (strValue!=null && strValue!="" && strValue!="undefined")
      {
        parent.location.href="../FlowProcess/FlowMove.jsp?PackageID="+PackageID+"&FlowID="+WorkFlowItemobj+"&MovePackageID="+strValue;
      }
}
//打开流程配置
function OpenFlowConfig(WorkFlowItemobj){
      parent.location.href="FlowDesign.jsp?SelectedItems="+WorkFlowItemobj;
}
function AddPackage(FID){
    var url="../Other/PackageAdd.jsp?FID="+FID;
    OpenSetup(url);
}
function EditPackage(){
    var url="PackageEdit.jsp?SelectedItems="+grid.getCellValue(grid.getCurrentLine(),1);
    OpenSetup(url);
}
function EditPackage1(){
    var strID = grid.getCellValue(grid.getCurrentLine(),1);
    if (strID.length==0)
    {alert("请先选择记录！");}
    var url="../Other/PackageEdit.jsp?SelectedItems="+grid.getCellValue(grid.getCurrentLine(),1);
    OpenSetup(url);
}
//弹出新窗体(属性设置)
function OpenSetup(url){

  var csstype = document.all.item('CSSTYPE').value;
  if (csstype=="6")
  {
    OpenSetupHtml(url);
  }else
  {
    var name="PopWindow";
    var ShowPopWindow = null;
    var status="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=500,height=300";
    ShowPopWindow = window.open(url,name,status);
    ShowPopWindow.moveTo(280,200);
    ShowPopWindow.focus();
  }

}

function OpenSetupHtml(mFileUrl){
	var index =layer.open({
        type: 2,
        title: "",
        area: ['500px', '300px'],
        fix: false, //不固定
        maxmin: false,
        content: mFileUrl
    });
}

//弹出新窗体1(属性设置)
function OpenSetup1(url){
  var csstype = document.all.item('CSSTYPE').value;

  if (csstype=="6")
  {
    OpenSetupHtmlA(url);
  }else
  {
  var name="PopWindow";
  var ShowPopWindow = null;
  var status="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=600,height=520";
  ShowPopWindow = window.open(url,name,status);
  ShowPopWindow.moveTo(200,50);
  ShowPopWindow.focus();
  }
}
function OpenSetupHtmlA(mFileUrl){
	var index =parent.layer.open({
        type: 2,
        title: "",
        area: ['600px', '530px'],
        fix: false, //不固定
        maxmin: false,
        content: mFileUrl
    });
}

//弹出新窗体(删除提示)
function OpenDelete(url){

var csstype = document.all.item('CSSTYPE').value;
  if (csstype=="6")
  {
    OpenSetupHtml(url);
  }else
  {
  var name="PopWindow";
  var ShowPopWindow = null;
  var status="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=350,height=200";
  ShowPopWindow = window.open(url,name,status);
  ShowPopWindow.moveTo(260,280);
  ShowPopWindow.focus();
  }
}
document.onclick = EndMove;
Chart.onmousedown = MoveStart;
Chart.onmouseup=MouseUP;
