
// Get Mouse Position
var _mouseX = 0;
var _mouseY = 0;
function getMousePosition (event) {
	if (!Browser.nav6)
	{
		_mouseX = event.clientX + document.body.scrollLeft;
		_mouseY = event.clientY + document.body.scrollTop;
	} else {
		_mouseX = event.clientX;
		_mouseY = event.clientY;
	}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


// Show Short Description on mouseOver
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

function showSD (e, SDid, diffY) { //show Short Description (SD)
	diffY = diffY ? diffY : 0;
    var ctrl = document.getElementById(SDid);
	if (!ctrl || ctrl.style.visibility == "visible"){
		return;
	}
	var t;
	if (e.target != null)
		t = e.target.tagName;
	else
		t = e.tagName;
	if (t!='td' && t!='TD'){
		getInnerDim (); //from common.js

		getMousePosition (e);
		var _width = 350;
		var bodyWidth = document.body.clientWidth;
		var _scrollLeft = document.body.scrollLeft;
		if (_mouseX - _width/3 + 2 + _width < bodyWidth + _scrollLeft){
			var _left = _mouseX - _width/3 + 20;
			ctrl.style.left = _left - _scrollLeft < 0 ? _scrollLeft : _left; //set top-left horizontal position of SD
		}
		else 
			ctrl.style.left = bodyWidth + _scrollLeft - _width - 2; //set top-left horizontal position of SD
		ctrl.style.width = _width;  //set width of SD dynamically - need to be set here, so the heightOfSD will be calculated based on this width
		ctrl.style.overflow="visible";
		var heightOfSD = ctrl.offsetHeight - 6; // // padding *1 + border*2
		var topPositionOfSD;
		var sheeftY= -20 - diffY;
		var _scrollTop = document.body.scrollTop;
		if ( _mouseY + sheeftY - heightOfSD - _scrollTop < 0) {
			topPositionOfSD = _scrollTop; // _mouseY + sheeftY - (_mouseY + sheeftY - _scrollTop);
		} else {
			topPositionOfSD = _mouseY + sheeftY - heightOfSD;
		} 
		//alert("topPositionOfSD=" + topPositionOfSD + ";_scrollTop="+_scrollTop + "; _mouseY="+_mouseY);
		ctrl.style.height = heightOfSD;
		ctrl.style.top = topPositionOfSD;
		HideOrShowSelect('hide', e.target == null ? SDid : null); //hide all the Select Tags on the page so they don't show through the SD layer
		ctrl.style.cursor="default";
		ctrl.style.visibility = "visible";
		topPositionOfSD = '';
	}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


// Hide Short Description on mouseOver
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function hideSD (SDid) { //hide Short Description
	var ctrl = document.getElementById(SDid);
	if (ctrl)
		document.getElementById(SDid).style.visibility = "hidden";
	HideOrShowSelect('show');
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

function isOver(ctrl, sd)
{
	if (sd == null)
		return false;
	var c_t = getPositionTop(ctrl);
	var sd_t = getPositionTop(sd);
	var c_l = getPositionLeft(ctrl);
	var sd_l = getPositionLeft(sd);
	if (sd_t <= c_t  && c_t  <= sd_t + sd.offsetHeight && sd_l <= c_l  && c_l  <= sd_l + sd.offsetWidth)
	{
		return true;
	}
	if (sd_t <= c_t + ctrl.offsetHeight && c_t + ctrl.offsetHeight <= sd_t + sd.offsetHeight && 
		sd_l <= c_l + ctrl.offsetWidth && c_l + ctrl.offsetWidth <= sd_l + sd.offsetWidth)
	{
		return true;
	}
	return false;
}
// Hide Or Show Select Tags (for when displaying the short descriptions on mouseover)
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function HideOrShowSelect(action, SDid) {
	var sd = SDid !=null ? document.getElementById(SDid) : null;
	var oSelect = document.getElementsByTagName('select');
	var NrOfSelectTags =  oSelect.length; //how many select tags on the page

	for (var i=0; i < NrOfSelectTags; i++) {
		if (action == 'hide') {
			if (isOver(oSelect[i], sd))
				oSelect[i].style.visibility = 'hidden';
		} else if  (action == 'show') {
			oSelect[i].style.visibility = 'visible';
		}
	}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


// is Mouse Over the ShortDescription
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function onMouseOutSD(e,SDid) {
	getMousePosition(e);
	var sd = document.getElementById(SDid);
	if (!sd)
		return;
	var sd_t = getPositionTop(sd);
	var sd_l = getPositionLeft(sd);
	if (sd_t <= _mouseY  && _mouseY  <= sd_t + sd.offsetHeight && sd_l <= _mouseX  && _mouseX  <= sd_l + sd.offsetWidth)
		return;
	hideSD (SDid);
}


function getPositionTop (oElement){
     var retVal = 0;
     if (oElement.offsetParent) {
        retVal += getPositionTop (oElement.offsetParent);
        retVal-=oElement.scrollTop;
     }
     retVal += oElement.offsetTop;
     return retVal;
}

function getPositionLeft (oElement){
     var retVal = 0;
     if (oElement.offsetParent) {
        retVal += getPositionLeft (oElement.offsetParent);
        retVal-=oElement.scrollLeft;
     }
     retVal += oElement.offsetLeft;
     return retVal;
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<