// JavaScript Document
function getElementPosition (elem) {
	var offsetLeft = 0;
	var offsetTop = 0;
	if (elem.offsetParent) {
		while (elem.offsetParent) {
			offsetLeft += elem.offsetLeft
			offsetTop += elem.offsetTop
			elem = elem.offsetParent;
		}
	}
	offsetLeft += document.getElementsByTagName('body').item(0).offsetLeft;
	offsetTop += document.getElementsByTagName('body').item(0).offsetTop;
	return {left:offsetLeft, top:offsetTop};
}
function getWindowInnerHeight(win) {
	if (!win) win = window;
	var doc = window.document;
	var availHeight, availWidth
	if (window.innerHeight) {
		availHeight = window.innerHeight;
		availWidth = window.innerWidth;
	} else if (document.documentElement.clientHeight) {
		availHeight=document.documentElement.clientHeight;
		availWidth=document.documentElement.clientWidth;
	} else {
		availHeight=document.body.clientHeight;
		availWidth=document.body.clientWidth;
	}
	return {'width':availWidth, 'height':availHeight};
}
function getLocation (oWidth, oHeight, posx, posy) {
	var scrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft
	var scrollTop = document.body.scrollTop + document.documentElement.scrollTop
	
	var winDim = getWindowInnerHeight();
	var availHeight = winDim['height'];
	var availWidth = winDim['width'];
	
	if (oWidth>availWidth) {
		oWidth = availWidth;
		oHeight +=18;
	}
	
	if (oHeight>availHeight) {
		oHeight = availHeight;
		oWidth +=18;
	}
	
	availHeight += scrollTop;
	availWidth += scrollLeft;
	availWidth-= 25
	availHeight-= 25
	
	var leftPos; var rightPos;
	if (posx + oWidth > availWidth) {
		leftPos = availWidth - oWidth;
	} else {
		leftPos = posx;
	}
	if (posy + oHeight > availHeight) {
		topPos = availHeight - oHeight;
	} else {
		topPos = posy;
	}
	return {width:oWidth,height:oHeight,left:leftPos,top:topPos}
}
function showCIMenu (elm) {
// get location
	var m = document.getElementById('corporateDropDown');
	
	var p = getElementPosition(elm);
	var posX = p['left']// - document.body.scrollLeft + document.documentElement.scrollLeft;
	var posY = p['top'] + elm.offsetHeight// - document.body.scrollTop + document.documentElement.scrollTop;
	var loc = getLocation(m.offsetWidth,m.offsetHeight + elm.offsetHeight-25,posX,posY);
	
	m.style.top = loc['top']+'px';
	m.style.left = loc['left']+'px';
	
	m.style.visibility = 'visible';
	
}
function hideCIMenu () {
	var m = document.getElementById('corporateDropDown');
	m.style.visibility = 'hidden';
	m.style.left = '-500px';
	m.style.top = '-500px';
}
document.onclick = function () {
	setTimeout('hideCIMenu()',300);
}