// popup menu functions
// SecureCottage Ecommerce Systems 
// Copyright 2005


function dn()
{
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function popUp(evt,currElem,obj)
{
  var popUpWin = document.getElementById(currElem).style;
  
  if(document.all)
  {
//    popUpWin.top = parseInt(evt.y)-1;
//  	popUpWin.left = Math.max(2,parseInt(evt.x)+2)-50;
    popUpWin.top = findPosY(obj)+obj.offsetHeight-1;
  	popUpWin.left = findPosX(obj);

  }
  else
  {
//   popUpWin.top = parseInt(evt.pageY)-1 + "px";
//   popUpWin.left = parseInt(evt.pageX)+2-50 + "px";
   popUpWin.top = (findPosY(obj)+obj.offsetHeight-1) + "px";
   popUpWin.left =(findPosX(obj)) + "px";

  }
  
  
  
  popUpWin.visibility = "visible";
}
function keepWinUp(currElem)
{
  var popUpWin = document.getElementById(currElem).style;
  popUpWin.visibility = "visible";
}
function popDown(currElem)
{
  var popUpWin = document.getElementById(currElem).style;
  popUpWin.visibility = "hidden";
}
function isArray(a)
{
	return (a && typeof a == 'object' && 
			a.constructor == Array);
}
function IssueSubMenus(menu)
{
	var i;
	var ii;
	// print out submenus
    for(i=0,ii=1;i<menu.length;i+=2)
	{
		if(isArray(menu[i+1]))
		{
			printarray(menu[i+1],"popup" + ii);
			ii++;
		}
	}

}
function IssueMenu(menu)
{
	var i;
	var ii;
	
	for(i=0,ii=1;i<menu.length;i+=2)
	{
		if(isArray(menu[i+1]))
		{
			printarrayitem(menu[i],"popup" + ii);
			ii++;
		}
		else printmenuitem(menu[i],menu[i+1]);
	}

}
var menuitemcounter = 0;
function printarrayitem(name,id)
{
	menuitemcounter++;
	var linkid = "alink" + menuitemcounter;
	document.write(
   
	'<a href="javascript:dn()" '  + 'name="' + linkid + '" ' +
'onMouseover="popUp(event,\'' + id + '\',this)"' +
'onMouseOut="popDown(\'' + id + '\')"' +
'>' + name +'&nbsp;</a>');

}
function printmenuitem(name,thelink)
{
    document.write('<a href="' + thelink + '">' +
				   name + '&nbsp;</a>');
}
function printarray(a,name)
{
	var i;
	document.write(
'<span class="popupStyle" id="' + name + '"' + 
'onMouseOver="keepWinUp(\'' + name + '\')"' + 
'onMouseOut="popDown(\'' + name + '\')">');
	for(i=0;i<a.length;i+=2)
	{ document.write(
       '<a href="' + a[i] + '">' + a[i+1] + '</a>');
	//   if(i <= a.length-2)
	//     document.write('<br>');
	}
	document.write('</span>');
}


