var DragDropState = 0 //0 == nothing, 1= moving, 2 = resizing
var DragDropSectionID = -1

var posx = 0;
var posy = 0;
var oldx = 0;
var oldy = 0;

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		posx = event.clientX + document.body.scrollLeft;
		posy = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		posx = e.pageX;
		posy = e.pageY;
	}  
	if (posx < 0){posx = 0;}
	if (posy < 0){posy = 0;} 
	if(DragDropState == 1)
	{
		document.getElementById('Section'+DragDropSectionID).style.left = (posx - 5) + 'px';
		document.getElementById('Section'+DragDropSectionID).style.top = (posy - 5) + 'px';
	} else if(DragDropState == 2)
	{
		var left = parseInt(document.getElementById('Section'+DragDropSectionID).style.left);
		var top = parseInt(document.getElementById('Section'+DragDropSectionID).style.top);
		document.getElementById('Section'+DragDropSectionID).style.width = (posx - left + 1) + 'px';
		document.getElementById('Section'+DragDropSectionID).style.height = (posy - top + 1) + 'px';
	}
	return true;
}

function PickUpBox(SectionID)
{
	if(DragDropState == 0)
	{
		DragDropState = 1;
		DragDropSectionID = SectionID;
		oldx = document.getElementById('Section'+SectionID).style.left;
		oldy = document.getElementById('Section'+SectionID).style.top;
	}
}

function StartResizeBox(SectionID)
{
	if(DragDropState == 0)
	{
		DragDropState = 2;
		DragDropSectionID = SectionID;
		oldx = document.getElementById('Section'+SectionID).style.width;
		oldy = document.getElementById('Section'+SectionID).style.height;
	}
}

function GetContainerOffset()
{
	return (GetWindowWidth() - 800)/2;
}

function GetWindowWidth()
{
	if (navigator.appName=="Netscape") {
			winW = window.innerWidth-16;
			winH = window.innerHeight-16;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		winW = document.body.offsetWidth-20;
		winH = document.body.offsetHeight-20;
	}
	return winW;
 }

function BoxClick(SectionID)
{
	if(DragDropState == 1 && SectionID == DragDropSectionID)
	{
		DragDropState = 0;
		DragDropSectionID = -1;
		var okay = true;//confirm('Would you like to keep this change?')
		if(okay)
		{
			MoveBox(SectionID,
				document.getElementById('Section'+SectionID).style.left,
				document.getElementById('Section'+SectionID).style.top);
		} else
		{
			document.getElementById('Section'+SectionID).style.left = oldx;
			document.getElementById('Section'+SectionID).style.top = oldy;
		}
	}
	if(DragDropState == 2 && SectionID == DragDropSectionID)
	{
		DragDropState = 0;
		DragDropSectionID = -1;
		var okay = true;//confirm('Would you like to keep this change?')
		if(okay)
		{
			ResizeBox(SectionID,
				document.getElementById('Section'+SectionID).style.width,
				document.getElementById('Section'+SectionID).style.height);
		} else
		{
			document.getElementById('Section'+SectionID).style.width = oldx;
			document.getElementById('Section'+SectionID).style.height = oldy;
		}
	}
}