/**
 *	toolTips.js	v1.0
 * 	Coded by George Melroy D'Souza
 
 */
function initToolTip(){
	var toolTipDivs = document.myGetElementsByClassName('toolTipTag');
	var toolTipSTATDivs = document.myGetElementsByClassName('toolTipTagSTAT');
	var toolTipBtn = document.myGetElementsByClassName('toolTip');
	var toolTipSTATBtn = document.myGetElementsByClassName('toolTipSTAT');

	for(var i=0; i<toolTipDivs.length; i++) {
		var toolTipId = 'toolTip' + i;
		toolTipDivs[i].btnObj = toolTipBtn[i];
		toolTipBtn[i].id = toolTipId;
		toolTipBtn[i].leftParentPos = findPosX(toolTipDivs[i]) + toolTipDivs[i].offsetWidth;
		toolTipDivs[i].txtTitle = (toolTipBtn[i].title) ? toolTipBtn[i].title : toolTipDivs[i].txtTitle;
		
		toolTipDivs[i].onmouseover = function(e){
			if (this.txtTitle) this.btnObj.style.visibility = 'visible';
		}
		
		toolTipDivs[i].onmouseout = function(e){
			if (this.txtTitle) this.btnObj.style.visibility = 'hidden';
		}
		
		if (toolTipDivs[i].txtTitle) {
			toolTipBtn[i].onmouseover = function(e) {showToolTipBox(e,this);}
			toolTipBtn[i].onmouseout = function(e) {hideToolTipBox(e,this);}
		}
	}
	for(var i=0; i<toolTipSTATDivs.length; i++) {
		var toolTipId = 'toolTipSTAT' + i;
		toolTipSTATDivs[i].btnObj = toolTipSTATBtn[i];
		toolTipSTATBtn[i].id = toolTipId;
		toolTipSTATBtn[i].leftParentPos = findPosX(toolTipSTATDivs[i]) + toolTipSTATDivs[i].offsetWidth;
		toolTipSTATDivs[i].txtTitle = (toolTipSTATBtn[i].title) ? toolTipSTATBtn[i].title : toolTipSTATDivs[i].txtTitle;
		
		if (toolTipSTATDivs[i].txtTitle) toolTipSTATDivs[i].btnObj.style.visibility = 'visible';

		toolTipSTATBtn[i].onmouseover = function(e) {showToolTipBox(e,this);}
		toolTipSTATBtn[i].onmouseout = function(e) {hideToolTipBox(e,this);}
	}
}

function showToolTipBox(e,ttipObj) {
	var divTipId = ttipObj.id + 'TP';
	
	// if ( document.captureEvents ) {
		// ttipObj.xCord = e.pageX;
		// ttipObj.yCord = e.pageY;
	// } else if ( window.event.clientX ) {
		// ttipObj.xCord = window.event.clientX + document.documentElement.scrollLeft;
		// ttipObj.yCord = window.event.clientY + document.documentElement.scrollTop;
	// }
	
	// var scrX = Number(ttipObj.xCord);
	// var scrY = Number(ttipObj.yCord);
	// var tp = parseInt(scrY+5);
	// var lt = parseInt(scrX+5);

	if (document.getElementById(divTipId)) {
		var divTipId = ttipObj.id + 'TP';
		var divObj = document.getElementById(divTipId);
		divObj.style.visibility = 'visible';
		
		if (parseInt(ttipObj.leftParentPos) < (findPosX(ttipObj) + parseInt(divObj.offsetWidth) + 20)) {
			divObj.style.left = (parseInt(findPosX(ttipObj)) - parseInt(divObj.offsetWidth)) + 'px';
		}else{
			divObj.style.left = (findPosX(ttipObj) + 20) + 'px';
		}
	}else{
		var divObj = document.createElement("div");
		var subDivObj =  document.createElement("div");
		divObj.id = divTipId;
		divObj.className = 'abs toolTipHelp';
		divObj.style.top = (findPosY(ttipObj) +30) + 'px';
		subDivObj.className = 'brown allpad font11';
		subDivObj.innerHTML = ttipObj.title;
		ttipObj.title = '';
		ttipObj.appendChild(divObj);
		divObj.appendChild(subDivObj);
		
		// if (parseInt(ttipObj.leftParentPos) < (findPosX(ttipObj) + parseInt(divObj.offsetWidth) + 20)) {
			// divObj.style.left = parseInt(lt-(divObj.offsetWidth+15))+'px';
		// } else {
			// divObj.style.left = lt+'px';
		// }
		
		// if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(divObj.offsetHeight+tp) ) {
			// divObj.style.top = parseInt(tp-(divObj.offsetHeight+20))+'px';
		// } else {
			// divObj.style.top = tp+'px';
		// }
		
		if (parseInt(ttipObj.leftParentPos) < (findPosX(ttipObj) + parseInt(divObj.offsetWidth) + 20)) {
			divObj.style.left = (parseInt(findPosX(ttipObj)) - parseInt(divObj.offsetWidth)) + 'px';
		}else{
			divObj.style.left = (findPosX(ttipObj) + 20) + 'px';
		}
	}
}

function hideToolTipBox(e, ttipObj) {
	var divTipId = ttipObj.id + 'TP';
	var divObj = document.getElementById(divTipId);
	divObj.style.visibility = 'hidden';
}

//var oldOnload = window.onload;
//window.onload = function () { if(oldOnload) oldOnload(); initToolTip(); }