/*****************************************************************************************
 *
 *	 Alias functions for tooltips using "wztooltip-js" library.
 *
 *  Highly customizable with various parameters.
 *  See reference documentation http://www.walterzorn.com/tooltip/tooltip_e.htm#docu
 *
 *  General usage: onmouseover="Tip('text for tooltip')" onmouseout="Untip()" parameters on tags.
 *
 *  Alternative usage using an HTML element for tooltip content: onmouseover="TagToTip('SpanIdName')" onmouseout="Untip()"
 *
 *****************************************************************************************/


/*****************************************************************************************
 *  Alias functions for "wztooltip-js" for some standardized customizations.
 *****************************************************************************************/

/**
 * This is to display tip text for the right side Help icon in MPA.
 */
function TipForHelp() {

	if (arguments.length < 1 || ! arguments[0] || arguments[0].length < 1) {
		//
		// empty tip text, do nothing.
		//
		return true;
	} else if (arguments.length > 1) {
		//
		// tip text with custom arguments.
		//
		Tip(arguments);
	} else {
		//
		// tip text with default look.
		//
		Tip(arguments[0], SHADOW, true, LEFT, true, WIDTH, -300);
	}
}

/**
 * This is to display a standard balloon tip text in MPA.
 *
 * NOTE: for tip text with custom arguments use Tip(..).
 */
function TipBalloon() {

	if (arguments.length < 1 || ! arguments[0] || arguments[0].length < 1) {
		//
		// empty tip text, do nothing.
		//
		return true;
	} else {
		//
		// tip text with default look.
		//
		Tip(arguments[0], BALLOON, true, ABOVE, true, OFFSETX, -17, WIDTH, -300);
	}
}



/*****************************************************************************************
 *  DEPRECATED
 *
 *  Functions to support tooltips in both old and new UI.
 *
 *    Callers should use: onmouseover="showToolTip(event, 'text for tooltip')" onmouseout="scheduleHideToolTip()"
 *    parameters on tags.  Somewhere on the page there should be a div with id="tooltip".
 *
 *****************************************************************************************/

var timeoutId;

/*****************************************************************************************
 *  Functions for "tooltip". OLD UI only.
 *****************************************************************************************/

// no longer referenced
function scheduleHideToolTip() {
	scheduleHideToolTipById("tooltip");
}

// only referenced in old UI pages.
function hideToolTip() {
	hideToolTipById("tooltip");
}

// no longer referenced
function showToolTip(evt, text) {
	showToolTipParams(evt, text, "tooltip", 5, 20);
}

// no longer referenced
function showToolTipWithCloseButton(evt, text) {
	showToolTipParams(evt, text, "tooltip", null, null, "closebutton");
}

// only referenced in old UI pages.
function toggleToolTipWithCloseButton(evt, text) {
	showToolTipParams(evt, text, "tooltip", null, null, "closebutton", "true");
}


/*****************************************************************************************
 *  Functions for "contexthelptip". OLD UI only.
 *****************************************************************************************/

// only referenced in old UI pages.
function scheduleHideContextHelp() {
	scheduleHideToolTipById("contexthelptip");
}

// only referenced in old UI pages.
function showContextHelp(evt, text) {
	var styleId = "contexthelptip";
	var offsettop = 15;
	var offsetleft = -320;
	var tooltip = getElement(styleId);

	if (text && tooltip && tooltip.style.visibility != "visible") {
		var top;
		var left;
		if (evt.pageX) { // DOM event model
			left = evt.pageX;
			top = evt.pageY;
		} else { // IE event model
			evt = window.event;
			if (ie7) {
				left = evt.clientX + document.documentElement.scrollLeft;
				top = evt.clientY + document.documentElement.scrollTop;
			} else {
				left = evt.clientX + document.body.scrollLeft;
				top = evt.clientY + document.body.scrollTop;
			}
		}
		if (tooltip.style.visibility.toString() != "visible") {

			tooltip.innerHTML = text;
			if (offsettop) {
				tooltip.style.top = (top + offsettop) + "px";
			} else {
				tooltip.style.top = "50%";
			}
			if (offsetleft) {
				tooltip.style.left = (left + offsetleft) + "px";
			} else {
				tooltip.style.left = "50%";
			}
			tooltip.style.visibility = "visible";
		}
	}
}


/*****************************************************************************************
 *  Functions for "leveltip". OLD UI only.
 *****************************************************************************************/

// only referenced in old UI pages.
function scheduleHideLevelTip() {
	hideToolTipById("leveltip");
}

// only referenced in old UI pages.
function showLevelTip(evt, text) {
	showToolTipParams(evt, text, "leveltip", 40, 20);
}

// no longer referenced.
function showLevelTipAbove(evt, text) {
	var tooltip = getElement("leveltip");

	if (text && tooltip && tooltip.style.visibility != "visible") {
		var top;
		var left;
		if (evt.pageX) { // DOM event model
			left = evt.pageX;
	        top = evt.pageY;
		} else { // IE event model
			evt = window.event;
			if (ie7) {
				left = evt.clientX + document.documentElement.scrollLeft;
				top = evt.clientY + document.documentElement.scrollTop;
			} else {
				left = evt.clientX + document.body.scrollLeft;
		        top = evt.clientY + document.body.scrollTop;
	        }
		}

	    if (tooltip.style.visibility.toString() != "visible") {
        	tooltip.innerHTML = text;
        	if (tooltip.offsetHeight) {
        		tooltip.style.top = (top - 30 - tooltip.offsetHeight) + "px";
        	} else {
        		// offsetHeight not supported, revert to putting tip below cursor
        		tooltip.style.top = (top + 40) + "px";
        	}
        	tooltip.style.left = (left + 20) + "px";
	        tooltip.style.visibility = "visible";
	    }
    }
}

/*****************************************************************************************
 *  Functions for "levelselecttip".  China Autos only.
 *****************************************************************************************/

// no longer referenced.
function showLevelSelectTip(evt, text, offsettop, offsetleft) {
	var offsettopdefault = 15;
	var offsetleftdefault = 20;

	if (! offsettop) {
		offsettop = offsettopdefault;
	}
	if (! offsetleft) {
		offsetleft = offsetleftdefault;
	}
	showToolTipParams(evt, text, "levelselecttip", offsettop, offsetleft);
}

// no longer referenced.
function scheduleHideLevelSelectTip() {
	hideToolTipById("levelselecttip");
}


/*****************************************************************************************
 *  Common functions:
 *****************************************************************************************/

function scheduleHideToolTipById(styleId) {
	window.clearTimeout(timeoutId);
    timeoutId = window.setTimeout("hideToolTipById('" + styleId + "')", 0);
}

function showToolTipParams(evt, text, styleId, offsettop, offsetleft, closeButtonStyleId, toggle) {
	var tooltip = getElement(styleId);

	if (text && tooltip && tooltip.style.visibility != "visible") {
		var top;
		var left;
		if (evt.pageX) { // DOM event model
			left = evt.pageX;
	        top = evt.pageY;
		} else { // IE event model
			evt = window.event;
			if (ie7) {
				left = evt.clientX + document.documentElement.scrollLeft;
				top = evt.clientY + document.documentElement.scrollTop;
			} else {
				left = evt.clientX + document.body.scrollLeft;
		        top = evt.clientY + document.body.scrollTop;
	        }
		}

	    if (tooltip.style.visibility.toString() != "visible") {
	    	if (closeButtonStyleId) {
	    		var closeButton = getElement(closeButtonStyleId);
	        	tooltip.innerHTML = closeButton.innerHTML + text;
	        } else {
	        	tooltip.innerHTML = text;
	        }
	        if (offsettop) {
	        	tooltip.style.top = (top + offsettop) + "px";
	        } else {
	        	tooltip.style.top = "50%";
	        }
	        if (offsetleft) {
	        	tooltip.style.left = (left + offsetleft) + "px";
	        } else {
	        	tooltip.style.left = "50%";
	        }
	        tooltip.style.visibility = "visible";
	    }
    } else if (toggle == "true" && tooltip && tooltip.style.visibility == "visible") {
    	tooltip.style.visibility = "hidden";
    	tooltip.style.left = "-1000px";
    	tooltip.style.top = "-1000px";
    }
}


function hideToolTipById(styleId) {
	var tooltip = getElement(styleId);
	if (tooltip) {
	    tooltip.style.visibility = "hidden";
	    tooltip.left = "-1000px";
	    tooltip.top = "-1000px";
	    tooltip.innerHTML = "";
    }
}
