//
//
// Copyright 2000-2001 SolidWorks Corporation.  All rights reserved.
//
// No part of these files may be reproduced or used outside of the 3D Instant Website product
// for any purpose, without the express written permission of SolidWorks Corporation.
//
//
//

var isIE4 = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.substring(0,1)) >= 4;
var ns4 = (document.layers)?true:false;

var tipWidth = 200;
var cursorHt = 16;
var lineHeight = 15;			// Approx line height for medium font

function showIt(theEvent, theStr)
{
	if (isIE4)
		return false;		// Do not use for IE due to Viewpoint control hiding tooltip in IE. Solution below flashes. 2/4/2002
				
	var strLen = theStr.length
	var numLines = strLen/30;		// 200 pixels holds approx 30 medium size characters 
	var divHeight = lineHeight*numLines;	// Approx height of the DIV

	
	var showText = "<span style='position:absolute; border-width:1;border-style: solid; z-index:100;layer-background-color: #FFFFE7;'>";
	showText += "<table cellspacing='0' cellpadding='2' border='0' width='" + tipWidth + "px' bgcolor='#FFFFE7'><tr><td>"
	showText += "<font face='Verdana,Arial,Helvetica' size='1' color='#800080'>";
	showText += theStr;
	showText += "</font></td></tr></table></span>";

	if(isIE4)
	{
		var objToshow = document.all['theModelDesc'];
 	    if (!objToshow)
		   return;

		var objToshowStyle = objToshow.style;
		if (!objToshowStyle)						// V3 template had SPAN which doesn't support .style in IE.
			return;
					
		if(objToshowStyle.visibility == "visible")
  		   return;

		var theBody = document.body;
		if (!theBody)
			return false;

   for(var i=1; i <= document.applets.length; i++)
   {
    if(document.applets[i-1].id.indexOf('MetaStreamCtl') != -1)
    {
      	var targetObj = 'MetaStreamCtl' +  i ;
 	var metaStrmObj = document.all[targetObj];
	if(metaStrmObj)
      		metaStrmObj.PluginCommand("ForceHostLayering(1)()",0,0);
   }
   }

		if (objToshow.clientHeight > lineHeight)	// Make sure the DIV measures at least one line. Sometimes this is zero.
			divHeight = objToshow.clientHeight;
			
		objToshow.innerHTML = showText;
		var xMouse = theEvent.clientX + theBody.scrollLeft;
		var yMouse = theEvent.clientY + theBody.scrollTop;
					
		var rightOfWindow = theBody.clientWidth + theBody.scrollLeft;
		var bottomOfWindow = theBody.clientHeight + theBody.scrollTop;
		
		if ((xMouse + tipWidth) > rightOfWindow)
			xMouse = xMouse - tipWidth;
		
		if ((yMouse + divHeight + cursorHt) > bottomOfWindow)
			yMouse = yMouse - divHeight;
		else
			yMouse += cursorHt;

		objToshowStyle.left = xMouse;
		objToshowStyle.top = yMouse;
		
		objToshowStyle.visibility = "visible";
		objToshowStyle.zindex = 100;
		
	}
	else
	{
		var objToshow = eval("document.theModelDesc");
 	    if (!objToshow)
		   return;

  		if(objToshow.visibility == "show")
  		   return;

  objToshow.zIndex = 100 +1;//we need to set this in order to keep it above the 
                            //ILAYERs. should be one more than what has been set in 'themodelDesc' DIV/Span.
		var xMouse = theEvent.pageX;
		var yMouse = theEvent.pageY;
		var rightOfWindow = window.innerWidth + window.pageXOffset;
		var bottomOfWindow = window.innerHeight + window.pageYOffset;
		
		if ((xMouse + tipWidth) > rightOfWindow)
			xMouse = xMouse - tipWidth;
			
		if ((yMouse + divHeight + cursorHt) > bottomOfWindow)	// Use the approx. DIV height with the 'divHeight' variable.
			yMouse = yMouse - divHeight;
		else
			yMouse += cursorHt;
		
		objToshow.left = xMouse;
		objToshow.top = yMouse;

        objToshow.document.open();
		objToshow.document.write(showText);
		objToshow.document.close();

		objToshow.visibility = "show";

	}
	

}

function hideIt(theEvent, theElemName)
{
	if(isIE4)
	{
		return false;	// Do not use for IE.

  	    var objToshow = eval("document.all['" + theElemName + "']");
	    if (objToshow)
	    {
			var objToshowStyle = objToshow.style;
			if (!objToshowStyle)					// Must check this! SP01 template had SPAN which doesn't support .style in IE.
				return;

			objToshowStyle.visibility = "hidden"

   //Remove Host layering. Required. If not removed the models seem to be moving.
   for(var i=1; i <= document.applets.length; i++)
   {
    if(document.applets[i-1].id.indexOf('MetaStreamCtl') != -1)
    {
      var targetObj = 'MetaStreamCtl' +  i ;
	var metaStrmObj = document.all[targetObj];
	if(metaStrmObj)
      		metaStrmObj.PluginCommand("ForceHostLayering(0)()",0,0);
    }
   }

		}
		
	}
	else
	{	
        var objToshow = eval("document." + theElemName);

 	    if (objToshow)
	    {	
    	    objToshow.document.open();
   	    	objToshow.document.write("");
	    	objToshow.document.close();

	    	objToshow.visibility = "hide";
	    }
	}
}

function mtspluginfunction() 
{
	var count = mtspluginfunction.arguments.length;

	if(count == 0)			return false;
	var argstr = mtspluginfunction.arguments[0] + '(';
	var last = count-1;
	
	for(i = 1; i < count; i++)
	{
		argstr+= mtspluginfunction.arguments[i];
		if(i < last)	argstr+= ',';
	}
	argstr+= ')';
	
	if (isIE4)	return document.all.MetaStreamCtl.PluginCommand(argstr, 0, 0);
	else		return document.MetaStreamCtl.DoCommand(argstr);
}

