﻿// JScript File

function onLoad()
{
    setPosition(document.getElementById("activity2"),350,300);
	Connect(
	    document.getElementById("activity1"),
	    document.getElementById("activity2")
	    )    
}

function getAbsLeft(o) {
	oLeft = o.offsetLeft
	return oLeft
}

function getAbsTop(o) {
	oTop = o.offsetTop
	return oTop
}

function setPosition(o,oLeft,oTop) {
	o.style.top = oTop + "px"
	o.style.left = oLeft + "px"
}

function sldMouseDown(e)
{
	if (!e) {e = window.event}
	
	o=e.srcElement
	sldLeft=getAbsLeft(o)
	sldTop=getAbsTop(o)
	sldMouseLeft=e.clientX-sldLeft
	sldMouseTop=e.clientY-sldTop	
	document.onmousemove = sldMouseMove
}

function sldMouseUp(e)
{
    document.onmousemove = null
}

function sldMouseMove(e)
{
	if (!e) {e = window.event}		
	o=e.srcElement;
	if (o.className!="suspendActivity") return;
	setPosition(o,e.clientX-sldMouseLeft,e.clientY-sldMouseTop);
	Connect(
	    document.getElementById("activity1"),
	    document.getElementById("activity2")
	    )
	return false
}

function Connect(a1, a2)
{
    var designer = document.getElementById("designer");
    var c1=document.getElementById(a1.id+a2.id+"conn1");
    var c2=document.getElementById(a1.id+a2.id+"conn2");
    var c3=document.getElementById(a1.id+a2.id+"conn3");
    if (c1==null)
    {
	    c1=document.createElement("DIV");
        c1.className="connector";
	    c1.id=a1.id+a2.id+"conn1";
        designer.appendChild(c1);
    }
    if (c2==null)
    {
	    c2=document.createElement("DIV");
        c2.className="connector";
        c2.id=a1.id+a2.id+"conn2";
        designer.appendChild(c2);
    }
    if (c3==null)
    {
	    c3=document.createElement("DIV");		
        c3.className="connector";
        c3.id=a1.id+a2.id+"conn3";        
        designer.appendChild(c3);    
    }	

    var fromX = a1.offsetLeft;
    var fromY = a1.offsetTop+a1.clientHeight/2;
    var toX = a2.offsetLeft;
    var toY = a2.offsetTop+a2.clientHeight/2;

    if (fromX > toX)
    {
        var intX=toX;
        toX = fromX;
        fromX = intX;
        var intY=toY;
        toY = fromY;
        fromY = intY;
        
    }
    if (fromX+a1.clientWidth < toX) fromX=fromX+a1.clientWidth;
    var wpe = (toX-fromX)/2;	

    c1.style["left"]=fromX+"px";
    c1.style["top"]=fromY+"px";
    c1.style["width"]=wpe+"px";
    c1.style["height"]=2+"px"

    c2.style["left"]=(toX-wpe)+"px"; 
    c2.style["top"]=toY+"px";
    c2.style["width"]=wpe+"px";
    c2.style["height"]=2+"px"
    
    if (fromY<toY)
    {
        c3.style["left"]=(fromX+wpe-1)+"px";
        c3.style["top"]=fromY+"px";
        c3.style["width"]=2+"px"
        c3.style["height"]=(toY-fromY+1) + "px";
    }
    else
    {
        c3.style["left"]=(toX-wpe-1)+"px";
        c3.style["top"]=toY+"px";
        c3.style["width"]=2+"px"
        c3.style["height"]=(fromY-toY+1) + "px";
    }
}

var selected = null;
var sldValue=0
var sldTop=0
var sldLeft=0
var sldMouseLeft=0
var sldMouseTop=0