


/***********************************************
* Copyright 10/2008 Shivani Chamakura
***********************************************/

/* IMPORTANT: Put script after tooltip div or 
	 put tooltip div just before </BODY>. */

var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;
//declare width, height
var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

///////////////////////  CUSTOMIZE HERE   ////////////////////
// settings for tooltip 
// Do you want tip to move when mouse moves over link?
var tipFollowMouse= true;	
// Be sure to set tipWidth wide enough for widest image
var tipWidth= 100;
var offX= 0;//20;	// how far from mouse to show tip
var offY= 0;//12; 
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";
// set default text color and background color for tooltip here
// individual tooltips can have their own (set in messages arrays)
// but don't have to
var tipFontColor= "#000000";
var tipBgColor= "#DDECFF"; 
var tipBorderColor= "#cacaca";
var tipBorderWidth= 0;
var tipBorderStyle= "solid";
var tipPadding= 0;

//not used
// tooltip content goes here (image, description, optional bgColor, optional textcolor)
var messages = new Array();
//// multi-dimensional arrays containing: 
//// image and text for tooltip
//// optional: bgColor and color to be sent to tooltip
//messages[0] = new Array('red_balloon.gif');
//messages[1] = new Array('duck2.gif');
//messages[2] = new Array('test.gif');
////not used 
//////////////////////  END OF CUSTOMIZATION AREA  ///////////////////
////not used
//// preload images that are to appear in tooltip
//// from arrays above
//if (document.images) {
//	var theImgs = new Array();
//	for (var i=0; i<messages.length; i++) {
//  	theImgs[i] = new Image();
//		theImgs[i].src = messages[i][0];
//  }
//}
//not used
// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var tableStr = "<table><tr><td align='center'><img src='{0}' width='{1}' height='{2}'></td></tr></table>";
var table2Str = "<table><tr><td align='center'><img src='{0}' width='{1}'></td></tr></table>";


////////////////////////////////////////////////////////////
//  initTip	- initialization for tooltip.
//		Global variables for tooltip. 
//		Set styles
//		Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;

function initTip() {
    if (nodyn) return;
	//generate tooltip
	tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipcss.width = tipWidth+"px";
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		//tipcss.backgroundColor = tipBgColor;
		//tipcss.borderColor = tipBorderColor;
		//tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		//tipcss.borderStyle = tipBorderStyle;
	}
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}



/////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes 
//			it to tipDiv
/////////////////////////////////////////////////
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link

function doTooltipWithalt(evt,sUrl,sWidth,sHeight,sAltUrl) {
    initTip();
    //if (!tooltip) return;
	if (t1) clearTimeout(t1);	
	if (t2) clearTimeout(t2);
	tipOn = true;
	
    image_1 = new Image();
    image_1.src = sUrl;
    
    if(typeof image_1.naturalWidth != "undefined" && image_1.naturalWidth == 0)
    {
        sUrl = sAltUrl;
        image_1.src = sAltUrl
    }
    
    //if (tipWidth 200) { tipWidth = 200; }
       
    
	if (ie4||ie5||ns5) {
	    var tip = "";
	    if (sHeight > 0)
		    tip = tableStr.format(sUrl, sWidth, sHeight);
		else
		    tip = table2Str.format(sUrl, sWidth);
		
		//tipcss.backgroundColor = curBgColor;
        tipcss.width = '{0}px'.format(sWidth);
        
        if (sHeight > 0)
            tipcss.height = '{0}px'.format(sHeight);
	 	tooltip.innerHTML = tip;
	 	//alert(tipcss.width);
	 	//alert(tip);
	 	
	 	
	 	
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}

function doTooltip(evt,sUrl,sWidth,sHeight) {
    initTip();
    //if (!tooltip) return;
	if (t1) clearTimeout(t1);	
	if (t2) clearTimeout(t2);
	tipOn = true;
	
    image_1 = new Image();
    image_1.src = sUrl;
//    if ((image_1.width == 0) && (image_1.height == 0))
//    {
//        image_1.src = "../resources/images/no_image_avail.gif";
//    }
    //if (tipWidth 200) { tipWidth = 200; }
       
    
	if (ie4||ie5||ns5) {
	    var tip = "";
	    if (sHeight > 0)
		    tip = tableStr.format(sUrl, sWidth, sHeight);
		else
		    tip = table2Str.format(sUrl, sWidth);
		
		//tipcss.backgroundColor = curBgColor;
        tipcss.width = '{0}px'.format(sWidth);
        
        if (sHeight > 0)
            tipcss.height = '{0}px'.format(sHeight);
	 	tooltip.innerHTML = tip;
	 	//alert(tipcss.width);
	 	//alert(tip);
	 	
	 	
	 	
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}

var mouseX, mouseY;
function trackMouse(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (tipOn) positionTip(evt);
}

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position, 
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = mouseX-(tpWd+offX)+"px";
	else tipcss.left = mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = winHt-(tpHt+offY)+"px";
	else tipcss.top = mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}

String.prototype.format = function()
{

    var str = this;

    for(var i=0;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }

    return str;
}


