//alert('loading Javascript.js');

if (cbCounter == undefined) 
{
	var cbCounter = 0;
	// If you need more than 32 content blocks on a single page, feel free to increment the size of the array
	dimension ("contentBlockCollection", 32, 2);
}

function displayContentBlockIcons()
{
	//alert('displaying content block icons');
	if (cbCounter > 0)
	{
		for (i=1;i<=cbCounter;i++)
		{
			//alert('Moving icon for registered block ' + i);
			//alert('Content Block: ' + contentBlockCollection[i]['contentblock']);
			//alert('X : ' + (docjslib_getRealLeft(contentBlockCollection[i]['contentblock']) - 1) + "px");
			//alert('Y : ' + (docjslib_getRealTop(contentBlockCollection[i]['contentblock']) - 1) + "px");
			document.getElementById(contentBlockCollection[i]['icon']).style.left = (docjslib_getRealLeft(contentBlockCollection[i]['contentblock']) - 1) + "px";
			document.getElementById(contentBlockCollection[i]['icon']).style.top = (docjslib_getRealTop(contentBlockCollection[i]['contentblock']) - 1)  + "px";
			document.getElementById(contentBlockCollection[i]['icon']).style.display = "inline";
		}
	}
}

function registerContentBlock(cbName)
{
	cbCounter++;
	//alert("Registering " + cbName);
	contentBlockCollection[cbCounter]['contentblock'] = 'contentblock_' + cbName;
	contentBlockCollection[cbCounter]['icon'] = 'contentblockicon_' + cbName;
}

function docjslib_getRealLeft(element) {
	xPos = document.getElementById(element).offsetLeft;
	tempEl = document.getElementById(element).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(element) {
	yPos = document.getElementById(element).offsetTop;
	tempEl = document.getElementById(element).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

/* Copyright 1998 David S. Jackson. All rights reserved.
 ** You may use the code as long as this header remains intact.
 **
 ** Calling sequence for the dimension function:
 **  -- array name (a string)
 **  -- a variable-length sequence of dimensions
 **  -- the last dimension is a place holder
*/
function dimension (name_str, n0, n1, n2, n3)
  {
  var numDimens = dimension.arguments.length - 1;
  var code = name_str + " = new Array();";
  eval (code);

	  for (var i = 0; i <  n0; i++) // first index is 0
//    for (var i = 1; i <= n0; i++) // first index is 1
	  {
		 var newName = name_str + "[" + i + "]";
		 if (numDimens > 1)
		 {
			code = "dimension ('" + newName + "'";
			for (var j = 2; j <= numDimens; j++)
			   code += ", " + dimension.arguments[j];
			code += ");";
			eval (code);
		 }
	  }
   }
