var arrBlueBox = new Array("static", "auto", "", "auto", "", "", "", "", "");
var arrYellowBox = new Array("static", "auto", "", "auto", "", "", "", "", "");
var arrRedBox = new Array("static", "auto", "", "auto", "", "", "", "", "");
var arrMSIE6BoxModel = new Array("static", "auto", "", "auto", "", "", "", "", "");
var arrTreeOfNodes = new Array("static", "auto", "", "auto", "", "", "", "", "");

var arrObjectArray = new Array(arrBlueBox, arrYellowBox, arrRedBox, arrMSIE6BoxModel, arrTreeOfNodes);

function PositionAnObject()
{
var SelectedObject;
var arrElement;

for (var i = 0; i < document.forms[0].ElemToPosition.length; i++)
{
	if(document.forms[0].ElemToPosition[i].checked)
	{
	arrElement = arrObjectArray[i];
	SelectedObject = document.getElementById(document.forms[0].ElemToPosition[i].value);
	break;
	};
};

if(!SelectedObject) return;

SelectedObject.style.position = document.forms[0].PositionSelectName.options[document.forms[0].PositionSelectName.selectedIndex].value;
arrElement[0] = document.forms[0].PositionSelectName.selectedIndex;

if(document.getElementById("idInputLeft").value.toLowerCase() == "inherit")
	{
	SelectedObject.style.left = "inherit";
	document.forms[0].LeftLengthUnit.selectedIndex = 0;
	arrElement[1] = "inherit"; arrElement[2] = "";
	}
else if(isNaN(parseFloat(document.getElementById("idInputLeft").value)))
	{
	SelectedObject.style.left = "auto";
	document.getElementById("idInputLeft").value = "auto";
	document.forms[0].LeftLengthUnit.selectedIndex = 0;
	arrElement[1] = "auto"; arrElement[2] = "";
	}
else
	{
	SelectedObject.style.left = parseFloat(document.getElementById("idInputLeft").value) + document.forms[0].LeftLengthUnit.options[document.forms[0].LeftLengthUnit.selectedIndex].value;
	arrElement[1] = +parseFloat(document.getElementById("idInputLeft").value);
	arrElement[2] = document.forms[0].LeftLengthUnit.selectedIndex;
	};

if(document.getElementById("idInputTop").value.toLowerCase() == "inherit")
	{
	SelectedObject.style.top = "inherit";
	document.forms[0].TopLengthUnit.selectedIndex = 0;
	arrElement[3] = "inherit"; arrElement[4] = "";
	}
else if(isNaN(parseFloat(document.getElementById("idInputTop").value)))
	{
	SelectedObject.style.top = "auto"; document.getElementById("idInputTop").value = "auto";
	document.forms[0].TopLengthUnit.selectedIndex = 0;
	arrElement[3] = "auto"; arrElement[4] = "";
	}
else
	{
	SelectedObject.style.top = parseFloat(document.getElementById("idInputTop").value) + document.forms[0].TopLengthUnit.options[document.forms[0].TopLengthUnit.selectedIndex].value;
	arrElement[3] = +parseFloat(document.getElementById("idInputTop").value);
	arrElement[4] = document.forms[0].TopLengthUnit.selectedIndex;
	};

if(document.getElementById("idInputRight").value.toLowerCase() == "inherit")
	{
	SelectedObject.style.right = "inherit";
	document.forms[0].RightLengthUnit.selectedIndex = 0;
	arrElement[5] = "inherit"; arrElement[6] = "";
	}
else if(isNaN(parseFloat(document.getElementById("idInputRight").value)))
	{
	SelectedObject.style.right = "auto"; document.getElementById("idInputRight").value = "auto";
	document.forms[0].RightLengthUnit.selectedIndex = 0;
	arrElement[5] = "auto"; arrElement[6] = "";
	}
else
	{
	SelectedObject.style.right = parseFloat(document.getElementById("idInputRight").value) + document.forms[0].RightLengthUnit.options[document.forms[0].RightLengthUnit.selectedIndex].value;
	arrElement[5] = +parseFloat(document.getElementById("idInputRight").value);
	arrElement[6] = document.forms[0].RightLengthUnit.selectedIndex;
	};

if(document.getElementById("idInputBottom").value.toLowerCase() == "inherit")
	{
	SelectedObject.style.bottom = "inherit";
	document.forms[0].BottomLengthUnit.selectedIndex = 0;
	arrElement[7] = "inherit"; arrElement[8] = "";
	}
else if(isNaN(parseFloat(document.getElementById("idInputBottom").value)))
	{
	SelectedObject.style.bottom = "auto"; document.getElementById("idInputBottom").value = "auto";
	document.forms[0].BottomLengthUnit.selectedIndex = 0;
	arrElement[7] = "auto"; arrElement[8] = "";
	}
else
	{
	SelectedObject.style.bottom = parseFloat(document.getElementById("idInputBottom").value) + document.forms[0].BottomLengthUnit.options[document.forms[0].BottomLengthUnit.selectedIndex].value;
	arrElement[7] = +parseFloat(document.getElementById("idInputBottom").value);
	arrElement[8] = document.forms[0].BottomLengthUnit.selectedIndex;
	};
}

function PushPin(RefImage)
{
if (RefImage.src.lastIndexOf("Off") != -1)
	{
	RefImage.src = "../GRAPHICS/GIF/PushPinOn.gif";
	if(navigator.userAgent.indexOf("MSIE 8") != -1)
	{
		var FinalParentBlock = RefImage.parentNode.parentNode;
		var tempWPXO = document.documentElement.scrollLeft;
		var tempWPYO = document.documentElement.scrollTop;
		var HtmlBorderWidth = 0;
		if(document.styleSheets && document.styleSheets[0].rules)
		/* IE proprietary CSS-stylesheet model */
		HtmlBorderWidth = isNaN(parseInt(document.styleSheets[0].rules[0].style.borderWidth, 10)) ? 0 : parseInt(document.styleSheets[0].rules[0].style.borderWidth, 10);

		FinalParentBlock.style.position = "fixed";
		FinalParentBlock.style.left = FinalParentBlock.offsetLeft - tempWPXO + HtmlBorderWidth + "px";
		FinalParentBlock.style.top = FinalParentBlock.offsetTop - tempWPYO + HtmlBorderWidth + "px";

		window.scrollTo(tempWPXO, tempWPYO);

		document.getElementById("idTitlePosition").onmousedown = null;
/*
Not removing the event listener on the div allow it to be moved despite being declared position:fixed. So, this might be an interesting and complex feature.
*/

		RefImage.title = "Click to unfix this element in the viewport";
		RefImage.alt = "Click to unfix this element in the viewport";
		RefImage.parentNode.title="";
	}
	else
		{
		var FinalParentBlock = RefImage.parentNode.parentNode;
		var tempWPXO = window.pageXOffset;
		var tempWPYO = window.pageYOffset;
		var HtmlBorderWidth = 0;
		if(document.styleSheets && document.styleSheets[0].cssRules)
		/* W3C DOM 2 Stylesheets interface/implementation compliant */
		{
		HtmlBorderWidth = isNaN(parseInt(document.styleSheets[0].cssRules[0].style.borderWidth, 10)) ? 0 : parseInt(document.styleSheets[0].cssRules[0].style.borderWidth, 10);
		};

		FinalParentBlock.style.position = "fixed";
		FinalParentBlock.style.left = FinalParentBlock.offsetLeft - tempWPXO + HtmlBorderWidth + "px";
		FinalParentBlock.style.top = FinalParentBlock.offsetTop - tempWPYO + HtmlBorderWidth + "px";

		window.scrollTo(tempWPXO, tempWPYO);

		document.getElementById("idTitlePosition").removeEventListener("mousedown", Activate, false);
/*
Not removing the event listener on the div allow it to be moved despite being declared position:fixed. So, this might be an interesting and complex feature.
*/

		RefImage.title = "Click to unfix this element in the viewport";
		RefImage.alt = "Click to unfix this element in the viewport";
		RefImage.parentNode.title="";
		} // end of internal else
	} // end of external then
else
	{
	RefImage.src = "../GRAPHICS/GIF/PushPinOff.gif";

	if(navigator.userAgent.indexOf("MSIE 8") != -1)
	{
		var HtmlBorderWidth = 0;
		if(document.styleSheets && document.styleSheets[0].rules)
		/* IE proprietary CSS-stylesheet model */
		HtmlBorderWidth = isNaN(parseInt(document.styleSheets[0].rules[0].style.borderWidth, 10)) ? 0 : parseInt(document.styleSheets[0].rules[0].style.borderWidth, 10);

		var FinalParentBlock = RefImage.parentNode.parentNode;
		FinalParentBlock.style.position = "absolute";
		FinalParentBlock.style.left = FinalParentBlock.offsetLeft + document.documentElement.scrollLeft - HtmlBorderWidth + "px";
		FinalParentBlock.style.top = FinalParentBlock.offsetTop + document.documentElement.scrollTop - HtmlBorderWidth + "px";

		document.getElementById("idTitlePosition").onmousedown = Activate;
		RefImage.title = "Click to fix this element in the viewport";
		RefImage.alt = "Click to fix this element in the viewport";
		RefImage.parentNode.title="You can drag and move this box.";
	}
	else
		{
		var HtmlBorderWidth = 0;
		if(document.styleSheets && document.styleSheets[0].cssRules)
		/* W3C DOM 2 Stylesheets interface/implementation compliant */
		{
		HtmlBorderWidth = isNaN(parseInt(document.styleSheets[0].cssRules[0].style.borderWidth, 10)) ? 0 : parseInt(document.styleSheets[0].cssRules[0].style.borderWidth, 10);
		};

		var FinalParentBlock = RefImage.parentNode.parentNode;
		FinalParentBlock.style.position = "absolute";
		FinalParentBlock.style.left = FinalParentBlock.offsetLeft + window.pageXOffset - HtmlBorderWidth + "px";
		FinalParentBlock.style.top = FinalParentBlock.offsetTop + window.pageYOffset - HtmlBorderWidth + "px";

		document.getElementById("idTitlePosition").addEventListener("mousedown", Activate, false);
		RefImage.title = "Click to fix this element in the viewport";
		RefImage.alt = "Click to fix this element in the viewport";
		RefImage.parentNode.title="You can drag and move this box.";
		} // end of internal else
	}; // end of external else
}

function Drop(evt)
{
if(document.removeEventListener)
	{
	document.removeEventListener("mousemove", Drag, false);
	document.removeEventListener("mousedown", Activate, false);
	}
	else
	{
	document.onmousemove = null;
	};

	TextBoxToBeMoved.style.cursor = "url('../GRAPHICS/ICO/grab.cur'), -moz-grab";
/* Opera 9 error console complains about this line */

	TextBoxToBeMoved.style.color = "InactiveCaptionText";
	TextBoxToBeMoved.style.backgroundColor = "InactiveCaption";
}

var InternalHorizontalPositionWithinParentBlock, InternalVerticalPositionWithinParentBlock, TextBoxToBeMoved, SelectedParentBox;

function Drag(evt)
{
if(!evt) event.returnValue = false ;
	SelectedParentBox.style.left = (evt && evt.clientX ? evt.clientX : event.clientX ? event.clientX : null) + (window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft ? document.documentElement.scrollLeft : null) - InternalHorizontalPositionWithinParentBlock + "px";
	SelectedParentBox.style.top = (evt && evt.clientY ? evt.clientY : event.clientY ? event.clientY : null) + (window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : null) - InternalVerticalPositionWithinParentBlock + "px";
}

function Activate(evt)
{
	TextBoxToBeMoved = (evt) ? evt.currentTarget : window.event ? event.srcElement : null;
	TextBoxToBeMoved.style.cursor = "url('../GRAPHICS/ICO/grabbing.cur'), -moz-grabbing";
	TextBoxToBeMoved.style.color = "CaptionText";
	TextBoxToBeMoved.style.backgroundColor = "ActiveCaption";
	SelectedParentBox = TextBoxToBeMoved.parentNode;
	var ParentBorderWidth = !window.opera && document.all && document.compatMode ? 2 : 0;
	var ParentBorderHeight = !window.opera && document.all && document.compatMode ? 2 : 0;
	InternalHorizontalPositionWithinParentBlock = (evt && evt.layerX ? evt.layerX : window.event ? event.offsetX : null) + ParentBorderWidth;
	InternalVerticalPositionWithinParentBlock   = (evt && evt.layerY ? evt.layerY : window.event ? event.offsetY : null) + ParentBorderHeight;
if(evt && evt.preventDefault)
	{
	evt.preventDefault();

/* evt.preventDefault is more accurate than return false; it prevents selecting (reverse video) text-nodes */

	document.addEventListener("mousemove", Drag, false);
	document.addEventListener("mouseup", Drop, false);
	}
	else if(window.event)
	{
	document.onmouseup = Drop;
	document.onmousemove = Drag;
	}; // end of if
}

function ResettingForm()
{
document.getElementById("BlueBox").style.position = document.getElementById("YellowBox").style.position = document.getElementById("RedBox").style.position = document.getElementById("IE6BoxModel").style.position = document.getElementById("TreeNodes").style.position = "static";
arrBlueBox = ["static", "auto", "", "auto", "", "", "", "", ""];
arrYellowBox = ["static", "auto", "", "auto", "", "", "", "", ""];
arrRedBox = ["static", "auto", "", "auto", "", "", "", "", ""];
arrMSIE6BoxModel = ["static", "auto", "", "auto", "", "", "", "", ""];
arrTreeOfNodes = ["static", "auto", "", "auto", "", "", "", "", ""];
}