var lastItem;

function checkExpand( elem ){
	var isOpen = false;
	if( lastItem ){
		lastItem.style.display = 'none';
	}
}

function expandMenu( elem ){
	var subElem = elem.nextSibling.nextSibling;
	if( subElem.style.display){
		if( subElem.style.display == "block" ){
			subElem.style.display="none";
			return false;
		}
	}
	

	var thetop=getTop(elem);
	var theleft=getLeft(elem);
	
	subElem.style.top=(thetop+elem.offsetHeight)+"px";
	subElem.style.left = theleft+"px";
	subElem.style.display = "block";
	lastItem = subElem;
	
	
}

function makeMenu( menuId ){
	var menu = document.getElementById( menuId );
	for( i = 0; i< menu.childNodes.length; i++ ){
		ancor = menu.childNodes[i];
		if( ancor.nodeName == 'A'){
			 ancor.className = 'up';
			 ancor.onclick = function(ev){ expandMenu(this);return false;}
			 ancor.onmouseover = function(ev){ checkExpand(this); }
		}
		
	}
}



function getTop( theitem ){
	var offsetTrail = theitem;
	var offsetTop = 0;
	while (offsetTrail) {
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 
		offsetLeft += document.body.TopMargin;
	return offsetTop;
}

// This Function returns the Left position of an object
function getLeft(theitem){
	var offsetTrail = theitem;
	var offsetLeft = 0;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 
		offsetLeft += document.body.leftMargin;
	return offsetLeft;
}

var latestEx = null;

function expandSearch( elem ){
	tg = elem.parentNode.parentNode;
	
	Element.cleanWhitespace( tg );
	if( latestEx ) latestEx.style.display = 'none';
	
	sTg = elem.parentNode.nextSibling;
	sTg.style.display = sTg.style.display == 'block' ? 'none': 'block';
	latestEx = sTg;
}

function expandForm( elem ){
	tg = $(elem);
	tg.style.display = tg.style.display == 'block' ? 'none': 'block';
}
