var DIRECTION_VERTICAL 		= 0
var DIRECTION_HORIZONTAL 	= 1

function createNavBar(oTable, arrDescription, arrURL, preview)
{
	//alert('oTable: ' + oTable.id);
	emptyNavBar(oTable);
	var cellIndex;
	var oRow;
	var oCell;
	var direction;
	var oCloneCell = document.createElement("TD");
	var sNormalColor, sLoginColor;
	//Create the template cell
	with (oCloneCell)
	{
		//<td id="mnuNavBarItemClone" nowrap style="font:bold small; color:silver;" onmouseover="this.style.color='black';" onmouseout="this.style.color='silver';" onclick=""></td>
		id 					= 'mnuNavBarItemClone';
		//className			= 'detail';
		style.fontWeight 	= 'bold';
		style.fontSize 		= 'x-small';
		style.backgroundColor = 'transparent';
		if (oTable.id=='mnuNavBarbartop') {
			sNormalColor = '#ff6600';
			sLoginColor = '#ff6600';
			noWrap = true;
		} else {
			sNormalColor	= '#ffcc00';
			sLoginColor = '#EE6600';
	  }
	}
	
	if (preview) {
	  direction = DIRECTION_VERTICAL;
	} else {
	  switch (oTable.id) {
	  case 'mnuNavBarbartop':
	    direction = DIRECTION_HORIZONTAL;
	    break;
	  case 'mnuNavBarbarbottom':
	    direction = DIRECTION_HORIZONTAL;
	    break;
	  default:
	    direction = DIRECTION_VERTICAL;
	    break;
	  }
	}
	
	// Add only 1 row if horizontal
	if (direction == DIRECTION_HORIZONTAL)
		oRow = oTable.insertRow()
	// Load navbar
	for (cellIndex = 0; cellIndex < arrURL.length; cellIndex++)
	{
		if (direction == DIRECTION_VERTICAL)
			oRow = oTable.insertRow();

		oCell = oCloneCell.cloneNode();
		//alert('oCell: ' + oCell);
		oCell.innerHTML = arrDescription[cellIndex];
		oCell.onmouseover = new Function("javascript:this.style.color='white';");

    var sUrl = arrURL[cellIndex];
    
    if (sUrl.substr(0, 1) == '!') {
      oCell.style.color = sLoginColor;
      sUrl = sUrl.substr(1);
    } else {
      oCell.style.color = sNormalColor;
    }

		oCell.onmouseout  = new Function("javascript:this.style.color='" + oCell.style.color + "';");
		
		if (preview) 
			oCell.onclick = new Function("javascript:with (parent.document.forms(0)) { fldNavigationItemId.value='" + sUrl + "'; submit();}");
		else
		{
			if (sUrl.indexOf('http') != -1)
				oCell.onclick = new Function("javascript:window.open('" + sUrl + "');");
			else
				oCell.onclick = new Function("javascript:mainframe.document.location='" + sUrl + "';");
		}
		oRow.appendChild(oCell);
		if (direction == DIRECTION_HORIZONTAL) {
			if (cellIndex < (arrURL.length - 1))
			{
				oCell = oCloneCell.cloneNode();
				oCell.style.cursor = '';
				oCell.innerHTML = '<img src="../uploads/images/frameset/dot.gif">';
				oRow.appendChild(oCell);
			}
		}
	}
}

function emptyNavBar(oTable)
{
	var i;
	var intLength = oTable.rows.length
	for (i = 0; i < intLength; i++)
		oTable.deleteRow(0);
}


