var flag=false;
var boxIDList;

function getElement(id)
{
	return(document.getElementById ? document.getElementById(id)
			: document.all ? document.all[id]
			: null);
}

function setFalse(){
	flag=false;
}
function setTrue(){
	flag=true;
}

function changeOpacity(id,opacity)
{
	obj=getElement(id);
	obj.style.opacity = opacity/100;
	obj.style.filter = 'alpha(opacity=' + opacity + ')';
}


function moveBlock(thisid,whereid,offX,offY) {
	obj=getElement(whereid);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
	}
	
	curleft += offX;
	curtop += offY;
	obj=getElement(thisid);
	obj.style.top = curtop + 'px';
	obj.style.left = curleft + 'px';
}





function doPageTop(border,padding,shadow,button) {
	if (border == null) border=1;
	if (padding == null) padding=8;
	if (shadow == null) shadow=8;
	shadow=0;
	
	obj=getElement('PageData');
	var pageWidth=obj.offsetWidth;
	obj=getElement('TopContainer');
	obj.style.width=pageWidth + 'px';
	pageWidth=pageWidth-2*border-shadow;

	obj=getElement('Top');
	obj.style.width=pageWidth + 'px';

	for (var i=1;i<=shadow;i++){
	obj=getElement('TopShadow' + i);
	obj.style.width=pageWidth + 'px';
	}
	var topWidth=Math.round((pageWidth-button-2)/2);
	obj=getElement('TopL');
	obj.style.width=topWidth + 'px';

	topWidth=Math.round(topWidth/2);
	obj=getElement('TopC');
	obj.style.width=topWidth + 'px';
	obj.style.left=2 * topWidth + 'px';

	obj=getElement('TopR');
	obj.style.width=topWidth - padding + 'px';
	obj.style.left=3 * topWidth + 'px';

}
function changeClass(id,classname)
{
	obj=getElement(id);
	obj.className = classname;
}
//moves object to a new position
function move(id,x,y)
{
	obj=getElement(id);
	obj.style.left=x + 'px';
	obj.style.top=y + 'px';
}	

//this is used only on the game page - WindowDisplayWidth is passed from CF
function showBox(IDList,border,padding,shadow)
{
	flag=false;
	if (border == null) border=1;
	if (padding == null) padding=8;
	if (shadow == null) shadow=8;
//get info about width of page	
	obj=getElement('PageData');
	var pageWidth=obj.offsetWidth;
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var infoWidth=pageWidth - 2 * border - 2 * padding - shadow;
//set global var to IDList
	boxIDList=IDList;
//take list of IDs and convert to an array
	var array=IDList.split(',');

	for (var i in array){
		obj=getElement(array[i]);
		obj.style.display='block';
	}

	if (array[1] == 'BoxOptn' && windowDisplayWidth > pageWidth){
		obj=getElement('WidthHelp');
		obj.style.display='block';
		boxIDList=IDList + ',WidthHelp';	
	}
	
	obj=getElement('BoxInfo');
	obj.style.width=infoWidth + 'px';
	var infoHeight=obj.offsetHeight;

	obj=getElement('BoxContainer');
	obj.style.left=curleft + 'px';
	obj.style.top=curtop + 'px';
	obj.style.width=pageWidth + 'px';
	var temp=infoHeight + shadow;
	obj.style.height=temp + 'px';

	infoHeight=infoHeight - 2 * border - 2 * padding;

	for (var i=1;i<=shadow;i++){
	obj=getElement('BoxShadow' + i);
	obj.style.width=infoWidth + 'px';
	obj.style.height=infoHeight + 'px';
	}

	obj=getElement('BoxContainer');
	obj.style.visibility='visible';	
}
function hideBox()
{
	obj=getElement('BoxContainer');
	obj.style.visibility='hidden';	

	var array=boxIDList.split(',');
	for (var i in array){
		obj=getElement(array[i]);
		obj.style.display='none';
	}
	flag=true;
	boxIDList=null;
}

function show(id)
{
	obj=getElement(id);
	if(obj != null)	obj.style.visibility='visible';
}	
function hide(id)
{
	obj=getElement(id);
	if (obj != null) obj.style.visibility='hidden';
}	



function windowData(id)
{
	var winWidth = winHeight = 0;
	if (window.innerWidth)
	{ winWidth = window.innerWidth; winHeight = window.innerHeight }
	else if (document.documentElement && document.documentElement.clientWidth)
	{ winWidth = document.documentElement.clientWidth; 
		winHeight = document.documentElement.clientHeight; }
	else if (document.body)
	{ winWidth = document.body.clientWidth;  winHeight = document.body.clientHeight;}

	var curleft = curtop = 0;
	var w = 8;
	if (id != null)
	{
	obj=getElement(id);
	w=obj.offsetWidth;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
			}
		}
	}
	var winCode=winWidth + ',' + winHeight + ',' + w + ',' + curleft + ',' + curtop ;
	return winCode;
}


