
var g_iEventCount = 0;
var g_EventArray = new Array;

var iCurrentEventCount = 0;
var iCurrentX = 0;
var iCurrentY = 0;
var scrolltimer = null;
var loop = false;
//  ########  TRACKS MOUSE POSITION FOR POPUP PLACEMENT
//var isNav = (navigator.appName.indexOf("Netscape") !=-1);
var isIE = (navigator.userAgent.indexOf("MSIE") !=-1);


function handlerMM(e)
{
	iCurrentX = (!isIE) ? e.pageX : (document.documentElement && document.documentElement.scrollLeft) ? event.clientX + document.documentElement.scrollLeft : event.clientX + document.body.scrollLeft;
	iCurrentY = (!isIE) ? e.pageY : (document.documentElement && document.documentElement.scrollTop) ? event.clientY + document.documentElement.scrollTop : event.clientY + document.body.scrollTop;

	//HidePopup();
	return true;
}

if(!isIE)
{
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;

function ShowPopup(iEvent)
{
	try
	{
		if(iEvent > 0 && iEvent <= g_iEventCount)
		{
			var eventInfo = g_EventArray[iEvent-1];	// Arrays are zero based, but the xsl numbering is 1 based.
			var popupObj = document.getElementById?document.getElementById("popupmsg"):document.all?d.all["popupmsg"]:d.layers["popupmsg"];
			var contentObj = document.getElementById?document.getElementById("pricechart"):document.all?d.all["pricechart"]:d.layers["pricechart"];

			// See if we have more than one event on the same day
			var iStartEvent = iEvent - 1;
			var iEndEvent = iEvent - 1;
			for(; iStartEvent - 1 >= 0; iStartEvent--)
			{
				var eventInfoTmp = g_EventArray[iStartEvent-1];	
				if(eventInfoTmp.sCoords != eventInfo.sCoords)
					break;
			}
	
			for(; iEndEvent + 1 < g_iEventCount; iEndEvent++)
			{
				var eventInfoTmp = g_EventArray[iEndEvent+1];	
				if(eventInfoTmp.sCoords != eventInfo.sCoords)
					break;
			}
	
			// Set up popup message
			var sTypeDesc
			var sTxt = "";
			var sLink

			iCurrentEventCount = iEndEvent - iStartEvent + 1;

			for(var i = iStartEvent; i <= iEndEvent; i++)
			{
//				if(i > iStartEvent)
	//				sTxt += '<BR>';
	
				eventInfo = g_EventArray[i];
				switch(eventInfo.sSource)
				{
					case "E":
						switch(eventInfo.sType)
						{
							case "1":
								sTypeDesc = "Split";
								break;
							case "10":
								sTypeDesc = "Spinoff";
								break;
							case "11":
								sTypeDesc = "Stock Dividend";
								break;
							case "13":
								sTypeDesc = "Cash Dividend";
								break;
							case "14":
								sTypeDesc = "IPO";
								break;
							case "15":
								sTypeDesc = "Quiet Period";
								break;
							case "16":
								sTypeDesc = "Lockup";
								break;
							case "17":
								sTypeDesc = "Insider Buy";
								break;
							case "18":
								sTypeDesc = "Insider Sale";
								break;
							case "19":
								sTypeDesc = "Insider 144";
								break;
							case "20":
								sTypeDesc = "EPS Change";
								break;
						}
	
						if(eventInfo.sLabel.length > 0)
							sTxt += '<div class="StockEventBlock">' + eventInfo.sLabel + ' ' + sTypeDesc + ' on ' + eventInfo.sDate + '</div>';
						else
							sTxt += '<div class="StockEventBlock">' + sTypeDesc + ' on ' + eventInfo.sDate + '</div>';
			
						break;
          case "S":
						switch(eventInfo.sType)
						{
							case "1":
								sTypeDesc = "News Releases";
								break;
							case "2":
								sTypeDesc = "Financial Results";
								break;
							case "3":
								sTypeDesc = "Webcasts";
								break;
							case "4":
								sTypeDesc = "Event";
								break;
						}
			
						if(eventInfo.sLabel.length > 0)
							sTxt += '<div class="StockEventBlock">' + eventInfo.sLabel + '<br />' + sTypeDesc + ' on ' + eventInfo.sDate + '</div>';
						else
							sTxt += '<div class="StockEventBlock">' + sTypeDesc + ' on ' + eventInfo.sDate + '</div>';
		
						break;
					case "P":
						switch(eventInfo.sType)
						{
							case "1":
								sTypeDesc = "10K";
								break;
							case "2":
								sTypeDesc = "10Q";
								break;
							case "9":
								sTypeDesc = "6K or 8K";
								break;
							case "11":
								sTypeDesc = "DEF";
								break;
							case "13":
								sTypeDesc = "Insider";
								break;
						}
			
						if(eventInfo.sLabel.length > 0)
						{
							if(eventInfo.sType == "13")
								sLink = 'Form ' + eventInfo.sLabel;
							else
								sLink = eventInfo.sLabel;
						}
						else
							sLink = sTypeDesc;
			
						sTxt += '<div class="StockEventBlock">' + sLink + ' on ' + eventInfo.sDate + '</div>';
		
						break;
					case "I":
						switch(eventInfo.sType)
						{
							case "1":
								sTypeDesc = "Insider Buy(s)";
								break;
							case "2":
								sTypeDesc = "Insider Sell(s)";
								break;
							case "144":
								sTypeDesc = "Insider Form 144(s)";
								break;
						}

						if(eventInfo.sLabel.length > 0)
							sTxt += '<div class="StockEventBlock">' + eventInfo.sLabel + ' ' + sTypeDesc + ' on ' + eventInfo.sDate + '</div>';
						else
							sTxt += '<div class="StockEventBlock">' + sTypeDesc + ' on ' + eventInfo.sDate + '</div>';
			
						break;
				}
			}
	
			var msgObj = document.getElementById?document.getElementById("EventDesc"):document.all?d.all["EventDesc"]:d.layers["EventDesc"];
		
			msgObj.innerHTML = sTxt;

			if(!isIE)
			{

				if(iCurrentEventCount <= 3)
				{
					msgObj.style.height = 25 * iCurrentEventCount;
				}
				else
				{
					msgObj.style.height = 90;
				}
			}
			else
			{
				if(iCurrentEventCount <= 3)
				{
					msgObj.style.height = 25 * iCurrentEventCount;
				}
				else 
				{
					msgObj.style.height = 90;
				}
			}

			// Now position the popup
			var iStart = 0;
			var rectArray = new Array(4);
		
			for(i = 0; i < 3; i++)
			{
				var iPos = eventInfo.sCoords.indexOf(',', iStart);
				if(iPos >= 0)
					rectArray[i] = parseInt(eventInfo.sCoords.substr(iStart, iPos));
		
				iStart = iPos + 1;
			}
			rectArray[3] = parseInt(eventInfo.sCoords.substr(iStart));
		
			var x = rectArray[0] + (rectArray[2] - rectArray[0]) / 2;
			var y = rectArray[1];
	
			var newx = iCurrentX - popupObj.offsetWidth/2;
			var newy = iCurrentY - popupObj.offsetHeight/2;
			var iEventHeight = rectArray[3] - rectArray[1];
			var iPopupHeight = msgObj.offsetHeight;

// Move Notification to 10,10 from the mouse	
			popupObj.style.left = (iCurrentX+10)+"px";
			popupObj.style.top = (iCurrentY+10)+"px";

			msgObj.scrollTop = 0;

//      alert("Left: "+popupObj.style.left+"; Top: "+popupObj.style.top+";");
    
      
			ShowPopup2();
		}
	}
	catch(e)
	{
		alert("ShowPopup:  " + e);
	}
}

function ShowPopup2()
{
	document.getElementById("popupmsg").style.visibility='visible';
	document.getElementById("popupmsg").style.zIndex=1000;
}

function HidePopup()
{
	
	try
	{
		if(document.getElementById("popupmsg").style.visibility != 'hidden')
		{
				document.getElementById("popupmsg").style.visibility='hidden';
				document.getElementById("popupmsg").style.zIndex=0;
		}
	}
	catch(e)
	{
		alert(e);
	}
}

function EventInfo(Coords, Source, Type, Date, CompanyId, EventId, Label) 
{
	this.sCoords = Coords;
	this.sSource = Source; 
	this.sType = Type; 
	this.sDate = Date; 
	this.sCompanyId = CompanyId; 
	this.sEventId = EventId;
	this.sLabel = Label; 
}

function wsh_AddEvent(Coords, Source, Type, Date, Label, CompanyId, EventId) 
{
	g_EventArray[g_iEventCount] = new EventInfo(Coords, Source, Type, Date, Label, CompanyId, EventId);
	g_iEventCount++;
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
