// JavaScript Document
var contenido="";
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);
var windows;



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;
	};
}
var InternalHorizontalPositionWithinParentBlock, InternalVerticalPositionWithinParentBlock, TextBoxToBeMoved, SelectedParentBox;

function abrir(ventana,evt){
	windows="idWindow"+ventana;
	
	document.getElementById(windows).style.top = (evt && evt.clientY ? (evt.clientY-5) : window.event.clientY ? (window.event.clientY-5) : null)  + "px";
	document.getElementById(windows).style.left = (evt && evt.clientX ? (evt.clientX-5) : window.event.clientX ? (window.event.clientX-5) : null)  + "px";
	document.getElementById(windows).style.display="inline";
}

function abrir_fijo(ventana,e){
	windows="idWindow"+ventana;
	document.getElementById(windows).style.display="inline";
}

function cerrar(){
	document.getElementById("idWindow"+windows).style.display="none";
}

function ShowORHiddenChilds(parentDiv,SorH)
{
	var parent1 = document.getElementById(parentDiv);
	var thisChild = parent1.firstChild;
	while ( thisChild != parent1.lastChild )
	{
		{
			thisChild.style.display=SorH;
		}
		thisChild = thisChild.nextSibling;
	}
}
function Drop(evt)
{
	if(SelectedParentBox.style.border!="")
	ShowORHiddenChilds(SelectedParentBox.id,'block');
	SelectedParentBox.style.border="";
	SelectedParentBox.style.cursor="default";
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 */

}


function Drag(evt)
{
if(!evt) event.returnValue = false ;
	if(SelectedParentBox.style.border==""){
	ShowORHiddenChilds(SelectedParentBox.id,'none');
	SelectedParentBox.style.border="1px #000 dotted";
	SelectedParentBox.style.cursor="move";
	}
	
	
	//SelectedParentBox.innerHTML="";
	var x=((evt && evt.clientX ? evt.clientX : event.clientX ? event.clientX : null) + (window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft ? document.documentElement.scrollLeft : null) - InternalHorizontalPositionWithinParentBlock);
	var y=(evt && evt.clientY ? evt.clientY : event.clientY ? event.clientY : null) + (window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : null) - InternalVerticalPositionWithinParentBlock;
	SelectedParentBox.style.left = (x<0?0:x) + "px";
	SelectedParentBox.style.top =  (y<0?0:y) + "px";
}

function Activate(evt)
{
	TextBoxToBeMoved = (evt) ? evt.currentTarget : window.event ? event.srcElement : null;
	//TextBoxToBeMoved.style.cursor = "url('../GRAPHICS/ICO/grabbing.cur'), -moz-grabbing";
	SelectedParentBox = TextBoxToBeMoved.parentNode;
	//"idWindow"
	if(SelectedParentBox.id.indexOf("idWindow") == -1)
		SelectedParentBox = SelectedParentBox.parentNode;
	var ParentBorderWidth = !window.opera && document.all && document.compatMode ? 0 : 0;
	var ParentBorderHeight = !window.opera && document.all && document.compatMode ? 0 : 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 init_window(windows)
{
if (document.addEventListener)
	{
	document.getElementById("idCabecera"+windows).addEventListener("mousedown", Activate, false);

	}
else if (document.all && document.getElementById)
	{

	document.getElementById("idCabecera"+windows).onmousedown = Activate;
	// MSIE 6 and MSIE 7 do not support position: inherit
	};
if(document.compatMode && document.compatMode == "CSS1Compat")
{
if(document.addEventListener) // Safari or Konqueror or WebKit-based
	{
	//window.addEventListener("mousemove", MovesInWebKit, true);
	}
else if(document.all)
	{
	//document.documentElement.onmousemove = MovesInIE6 ;
	}
}
	else
	{
	//document.body.onmousemove = MovesInIE6 ;
	};
}



