////////////////////////////////////////////
//--  
//--  @copyright Copyright (c) 2009-2010 RetY Web Design. All rights reserved.
//--
////////////////////////////////////////////

function navigateInBrowser(strn) {
  window.location.href = strn;
  return true;
}

function sniffIE() {
	var sAgent = navigator.userAgent
	//alert(sAgent);
	var isIE = (sAgent.indexOf("MSIE 7")  > -1)
	return isIE;
	
}

function onmenuclick(obj,code) {
	hide(obj);
	eval(code);
}

function show(obj) {
 	if(typeof(obj) == "undefined")
		return;
 	obj.style.visibility = 'visible';
}

function hide(obj){
	if(typeof(obj) == "undefined")
	return;
	obj.style.visibility = 'hidden';
}

function SetColor(obj,bgcolor,fgcolor) {
	if(typeof(obj) == "undefined") return;
 obj.style.color = fgcolor;
	obj.style.backgroundColor = bgcolor;
}

function OnMouseOverBar(obj,rowid,colid,bgcolor,fgcolor) {
	SetColor(obj,bgcolor,fgcolor);
	window.status = menuArray[rowid][colid];
}

function OnMouseOutOfBar(obj,rowid,colid,bgcolor,fgcolor) {
	SetColor(obj,bgcolor,fgcolor);
	window.status = "";
}


function PositionPopUp(objId,parentId) {
	if(typeof(objId) == "undefined")
		return;

	//first get a reference to the popup menu
	obj = document.getElementById(objId)

	//next get a reference to the <tr>
	var thisParent = document.getElementById(parentId);
	
	//now walk up the DOM until the BODY element is reached.
	//along the way, add up the Left & Top offsets

	if (sniffIE()){
		//alert("MSIE 7 detected");
		//MSIE
		obj.style.top = 190;		// Had to be hardcoded because none of the computation was having any effect on IE7....
		obj.style.left = thisParent.offsetLeft;
	} else {
		var myLeft = 0;
		var myTop = 30;
		obj.style.left = myLeft + thisParent.offsetLeft+"px";
		obj.style.top = myTop + thisParent.offsetTop+"px";
	}
	show(obj);
	return false;
}

function ErasePopUp(objId,parentId)
{
	if(typeof(objId) == "undefined")
		return;

	//first get a reference to the popup menu
	obj = document.getElementById(objId)
	hide(obj);
	return false;
}

function CreateMenuBar(rowid,obj,cssClass) {
	var subMenuHTML; 
	current_id = "div_"+ rowid +"_"+ obj;
	navigationLink =  navigationArray[rowid][obj];

	subMenuHTML = "\n<div id=\""+current_id+"\" ";
	subMenuHTML += "class=\""+cssClass+"\" ";	
	subMenuHTML += " > " ;
	subMenuHTML +=  "<a href=\""+navigationLink+"\">";
	subMenuHTML +=  menuArray[rowid][obj];
	subMenuHTML += "</a>\n";
	subMenuHTML += "</div> \n";
	return subMenuHTML;
}

function CreatePopUpMenu(menuIndex,menuLength) {
	var divHTML ;

	if(!menuLength) {
		return;
	}

	divHTML = "<div id=\"popup_"+ menuIndex +"_0\"" ;
	// Give it the class by default
	divHTML += " class=\"menu\" ";
	// Make it invisible by default
	divHTML += " style=\"visibility:hidden;\"";
	// Add javascript handler for mouseOver, mouseOut
	divHTML += " onmouseover=\"show(this);\" onmouseout=\"hide(this);\" >\n";
	
	// Create submenu items
	for (obj = 1;obj < menuLength; obj++) {
		divHTML += CreateMenuBar(menuIndex,obj,"menuText");
	}  
	divHTML += "</div>";

	document.write(divHTML);
}


function createMenus() {
	for (parent_id = 0; parent_id < menuArray.length; parent_id++) {
		menuLength = menuArray[parent_id].length;
		CreatePopUpMenu(parent_id,menuLength);
	}
}
