
//  ----------------  EON_FUNCTIONS.JS  ----------------
//  eon_functions.js is an external javascript file used to 
//  produce one set of commands that work in both browsers.
//             Last modified Oct 10th, 2003




//	  10	------------  CONTENTS  ------------
//	  30	GET PLATFORM AND BROWSER VERSIONS
//	  70	CHECKING IF EONX IS INSTALLED
//	 260	HANDLE EONX STATUS
//	 400	INSERT EON OBJECT
//	 500	EONX METHODS (Start, Stop, Pause, ShowSettingsDialog, FullSize, SaveSnapshot)
//	 580	OLD EONX PROPERTIES (Toolbar, ProgressBar, SettingsButton, AutoPlay)  
//			(SimulationFile, Background, Codebase, Height, Width) 
//	 775	NEW EONX PROPERTIES (Version, PrototypebaseURL, SchemeValues, ConfigurationScheme)			
//	 825	SENDING and RECIEVING EVENTS 
//	 975	METHODS FOR GETTING IN/OUT EVENT INFORMATION
//	1065	WEBEON TOOL related code
//	1125	BACKWARD COMPATIBILITY CODE
//	1135	END






//  --- GET PLATFORM AND BROWSER VERSIONS ---

// The following code detects the users platform, browser and browser versions
// convert all characters to lowercase to simplify testing 
	var agt = navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion); 
	var is_minor = parseFloat(navigator.appVersion); 
	
	// --- PLATFORM ---
	var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
	var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
	var is_win32 = (is_win95 || is_winnt || is_win98 || 
			((is_major >= 4) && (navigator.platform == "Win32")) ||
			(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

// --- BROWSER & VERSION --- 
	// Netscape
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var NN = is_nav;
	var is_nav4up=((is_nav)&&(is_major>=4)); 
	var is_nav4_51up=(is_nav4up && (is_minor>=4.51));
	var is_nav6=(is_nav && (is_major==5));
	var is_nav6up=(is_nav && (is_major>=5));
	var is_nav6_2up=false;
	var posStart=agt.indexOf('netscape6/')+10;
	if (posStart > 0) is_nav6_2up=(agt.substring(posStart,posStart + 3)>='6.2');

	// Internet Explorer
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera")==-1));
	var is_ie4up = (is_ie && (is_major >= 4));




	
	

//	--- CHECKING IF EONX IS INSTALLED ---

//  The variable EonXStatus will be set by CheckEonXStatus() to one of:
//  -1 => Computer platform or browser is not supported
//   0 => EonX is not installed
//   1 => EonX is installed but lower version than required
//   2 => EonX is installed with equal or higher version than required.
var EonXStatus = -2;	// means not checked yet.
var InstalledVersion = "nothing";	// until proven otherwise
if (NN) navigator.plugins.refresh(true);// in case plugin just installed and refreshing page.

function CheckEonXStatus()
{
	EonXStatus=-1;
	if ( (!is_win32) || ((!is_ie) && (!is_nav)) || ((!is_nav4_51up) && (!is_ie4up)) ) return;
	EonXStatus= 0;
	
	if (NN)	// Check EonX status for Netscape
	{
		// Problem: In Netscape there's currently no way to check when Eon Runtime has been
		// UNinstalled and the Netscape plugin is still in the plugins folder.
		
		var eonPlugin = navigator.plugins["EonX Plug-In"];
		if ( ((is_nav6up)&&((typeof eonPlugin)!="undefined")) || ((is_nav4_51up)&&(eonPlugin)) )
		{
			EonXStatus = 1;		// plugin exists since eonPlugin exists, assume old version.
			InstalledVersion="unknown";
			var userVersion=eonPlugin.description.substring(26) // extract from 26th characater onwards.
			if (userVersion=="") userVersion="3,0,1,75";
			else InstalledVersion=userVersion;
			if (VersionOK(userVersion, ",")) EonXStatus=2;
		}
		return;
	}
	else	//  Check EonXStatus for IE.
	{
		if (location.href.indexOf('?eonxstatus=')!=-1)
		{
			if (location.href.indexOf('?eonxstatus=1')!=-1) 
			{
				EonXStatus=1;
				InstalledVersion = location.href.substring(location.href.indexOf('eonxver=')+8);
			}
			else EonXStatus=0;
		}
		else
		{
			EonXStatus=2;
			InstalledVersion = LatestEONVersion;
			// this is later changed by getting the body attribute called "eonxversioninstalled"
		}
	}
}

function VersionOK(VersionToCheck, SplitCharacter)
{
	var strVersionToCheck = String (VersionToCheck);

	var a = strVersionToCheck.split(SplitCharacter); // a = EON version installed on users computer
	var b = LatestEONVersion.split(',');			 // b = EON version required by this web page
	
	for (var i = 0; i < 4; i++)
	{
		a[i] = parseInt(a[i],10);
		b[i] = parseInt(b[i],10);
		if (a[i]>b[i]) return true; // checked version higher than required
		if (a[i]<b[i]) return false;// checked version lower than required
	}
	return true; // eon versions are the same.
}

function EONReady()
{
	if (CheckingWindow) return;
	if (NN)
	{
		navigator.plugins.refresh(true);
		if (EonXStatus==-2) CheckEonXStatus();
	}
	return (EonXStatus==2);
}
function EONAlertPluginStatus()
{
	if (CheckingWindow) return;
	if (NN)
	{
		navigator.plugins.refresh(true);
		if (EonXStatus==-2) CheckEonXStatus();
	}
	else
	{
		if (EonXStatus==2)
		{
			if (document.body.getAttribute("eonxversioninstalled")==null)
			{
				setTimeout('EONAlertPluginStatus()', 1000);
				return;
			}
			else InstalledVersion = document.body.getAttribute("eonxversioninstalled")
		}
	}
	var t='';
	if (EonXStatus==-1)t+='The EonX Plug-in is NOT supported!\nWrong platform or browser!';
	if (EonXStatus==0) t+='The EonX Plug-in is NOT installed!';
	if (EonXStatus==1) t+='An old EonX Plug-in is installed!';
	if (EonXStatus==2) t+='The EonX Plug-in is installed!';
	t+='\n\nInstalled version: ' + InstalledVersion + '\n\nRequired version: ' + LatestEONVersion;
	alert(t);
}
function EONWritePluginStatus()
{
	if (CheckingWindow) return;
	if (NN)
	{
		navigator.plugins.refresh(true);
		if (EonXStatus==-2) CheckEonXStatus();
	}
	else
	{
		if (EonXStatus==2)
		{
			if (document.body.getAttribute("eonxversioninstalled")==null)
			{
				setTimeout('EONWritePluginStatus()', 2000);
				InstalledVersion = '<span id="installedversion">? ? ? ?</span>';
			}
			else
			{
				InstalledVersion = document.body.getAttribute("eonxversioninstalled")
				if (document.all('installedversion'))
				{
					document.all('installedversion').innerHTML = InstalledVersion + "*";
					return;
				}
			}
		}
	}
	var t='<table border="0" cellpadding="10" bgcolor="#000099"><tr><td><font face="Verdana, Arial, Helvetica" size=2 color="#ffffff">';
	if (EonXStatus==-1) t+='The EonX Plug-in is <b>NOT</b> supported!<br>Wrong platform or browser!';
	if (EonXStatus==0) t+='The EonX Plug-in is <b>NOT</b> installed!';
	if (EonXStatus==1) t+='An old EonX Plug-in is installed!';
	if (EonXStatus==2) t+='The EonX Plug-in is installed!';
	t+='<br>Installed version: ' + InstalledVersion + '<br>Required version: ' + LatestEONVersion + '<br></font></td></tr></table>';
	document.write(t);
}

function errorHandler()
{
	// ignore error messages for the hidden window.
	return true;
}
var EonXTestWin = false;
function OpenCheckingWindow(nr)
{
	EonXTestWin = open(location.href+'?eonxtest'+nr,"TestEonXWin","resizable=no,scrollbars=no,status=0,width=10,height=10,top=2000,left=2000");
}

var CheckingWindow = false;
if (NN) CheckAndHandleEonXStatus = CheckAndHandleEonXStatusNN;
if (CheckAndHandleEonXStatus>0)
{
	CheckEonXStatus();
	if (!NN)
	{
		// Send info to eon_functions.vbs via body attributes
		document.write('<body eonxversion="' + LatestEONVersion+'" eonxstatus1=' +EonXStatus+' eonxcreateobject="' +eonxCreateObject+ '">');
		// Check in hidden window.
		if ((location.href.indexOf('?eonxtest')!=-1))
		{
			CheckingWindow=true;	//document has been opened as a hidden window for checking eonx.
			window.onerror = errorHandler;
		}
		else OpenCheckingWindow(1);
	}
}















//	--- HANDLE EONX STATUS  ---

//	What happens when EonXStatus<>2 depends on the variable CheckAndHandleEonXStatus
	// 0 - Do nothing. (IE will auto install. NN will have link to PP)
	//*1 - Auto popup PP, TB with link. (PP=plugin page, TB=table box with info and links)
	// 1.1 - same as 1 but PP has stardard browser toolbar, locationbar etc
	// 2 - TB with link to popup PP.
	// 2.1 - same as 2 but PP with standard browser toolbar, locationbar etc
	// 3 - TB with link to PP in same window.
	// 4 - Auto send to PP in same window.
	// 5 - Alert, send to PP in same window.
	// 6 - Alert(Go to PP?) OK, Cancel. Ok: PP in same window. Cancel: TB like 3
	// 7 - Check but do nothing. (IE will auto install. NN will have link to PP)
	// 8 - Get plugin here. IE:auto download & alert. NN4: alert, trigger download, TB with refresh link. NN6: TB link to EXE.
	// 9 - Cancel EonInsert. 
	// 10- Call CustomEonXStatusHandler() and cancel EONInsert - Use to show alternative content.
	// 11- Call CustomEonXStatusHandler() but don't cancel EONInsert - For example: Use own code to check
	//		and handle different browsers and versions or redirect to plugin or alternative content page.
	// 12- TB with link to download now. Link reloads using method 8.
	// 13- TB reports version required, version installed, link to PP in same window.
//	*WE RECOMMEND method 1.

function HandleEonXStatus()
{
	if (EonXStatus==2) return;
	if (EonXStatus==-1){document.write(InsertTextBox(-1));return;}	
		
	if (location.href.indexOf('installnow=true')>0) CheckAndHandleEonXStatus=8;
	var n = CheckAndHandleEonXStatus;
	
	if ((n==0)|(n==7)) return;
	if ((n>=1)&&(n<=3))
	{
		if ((n==1)|(n==1.1)) setTimeout('OpenEonXPluginPage()', 1500);
		document.write(InsertTextBox(n));
	}
	if (n==4) GoToEonXPluginPage();
	if ((n==5)|(n==6)) // redirect to plugin page in current window
	{
		var msg = "The latest version of EonX Plug-in is required to view 3D content on this page.\n\n";
		msg = msg + "When you press OK, you will be redirected to a plug-in download page.\n\n";
		msg = msg + "When installation is complete, press the back button to return to this page."
		if (n==5){alert(msg);GoToEonXPluginPage();}
		if ( (n==6)&&(confirm(msg)) ) GoToEonXPluginPage();
		document.write(InsertTextBox(3));
	}
	if (n==8)
	{
		if (NN)
		{
			if (is_nav6up){document.write(InsertTextBox(8.1));return;}
			
			// trigger download of Netscape plugin
			var trigger = netscape.softupdate.Trigger;
			trigger.StartSoftwareUpdate(eonxCodebaseNN, trigger.DEFAULT_MODE);
			
			// alert user that plugin is downloading
			alert(GetPluginMessage());
			document.write(InsertTextBox(n));
		}
		else setTimeout('IEDownloadingPluginMsg()', 1000);
	}
	if (n==9) DoEONInsert = false;
	if (n==10) {CustomEonXStatusHandler(); DoEONInsert = false;}
	if (n==11) CustomEonXStatusHandler();
	if (n==12) document.write(InsertTextBox(n));
	if (n==13) document.write(InsertTextBox(n));
}

function InsertTextBox(n)
{
	if (eonxWidth<240) eonxWidth=240;
	var t = '<table width=' + eonxWidth + ' height=' + eonxHeight + ' border=0 cellspacing=0 cellpadding=3 bgcolor="#ccccff"><tr><td><div ';
	if (!NN) t+='style="position:relative;overflow:auto;height:100%"';
	t+='><table width=' + (parseInt(eonxWidth)-6) + ' height=' + (parseInt(eonxHeight)-6) + ' border=0 cellspacing=0 cellpadding=3 bgcolor="#eeeeff"><tr><td align="center"><font size=1 color="#000066" face="Verdana,Arial,Helvetica,san-serif"><font size=2><b>';
	t+='EonX Plug-in Required!</b></font><br>To view the 3D EON content in this page,<br>';
	if (n==12)t+='you need to download and install the plug-in.<br><a href="javascript:InstallEonXNow()"><font color="#000099"><b>INSTALL NOW</b></font></a><br>';
	if (n==13){t+='the required version is ' + LatestEONVersion + '.<br>The installed version is ' + InstalledVersion + '. If you want,<br>';n=3}
	if ((n==1)|(n==1.1)) t+='the EonX Plug-in is required.<br><br>A window called "EON Download Center"<br>has been opened. To get the Plug-in,<br>please follow its instructions.<br>';
	if ((n==2)|(n==2.1)) t+='you need to open the <a href="javascript:OpenEonXPluginPage()"><font color="#000099"><b>Plug-in Download</b></font></a> page.<br>';
	if (n==3) t+='you can go to the <a href="javascript:GoToEonXPluginPage()"><font color="#000099"><b>Plug-in Download</b></font></a> page.<br>';
	if (n==8.1)t+='you need to <a href="' + LatestEONDirectory + 'EonForNetscape6.exe"><font color="#000099"><b>Download and Install EonForNetscape6.exe</b></font></a>.<br>';
	if (n==8) t+='the EON for Netscape plug-in is being downloaded.<br>When the security warning appears, click on <b>Grant</b> to continue.<br>';
	if (n==-1) t+='you need to have a windows platform with at least<br>Internet Explorer 4.0 or Netscape 4.51 or later.';
	if ( ((n!=-1)&&(n!=12)) | ((n==12)&&(is_nav6up)) )
	{	if (!NN) t+='<div id="clickhere" style="position:relative;visibility:hidden">';
		t+='<br>When the installation of<br>the EonX Plug-in is complete,<br><a href="javascript:RefreshPage()"><font size=3 color="#ff0000"><b>CLICK HERE</b></font></a> to refresh this page.<br>The EON content will then appear here.<br><br>Enjoy the 3D experience!';
		if (!NN) t+='</div>'
		if (!NN) setTimeout('document.all("clickhere").style.visibility = "visible"', 10000);}
	t+='</font></td></tr></table></div></td></tr></table>';
	DoEONInsert = false; // TextBox replaces Eon object.
	return t;
}

function OpenEonXPluginPage()
{
	var winsettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=496,height=390';
	var n=CheckAndHandleEonXStatus;
	if ((n==1.1)|(n==2.1)) winsettings='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=496,height=390';
	var PPwin = open(eonxPluginsPage, 'PluginPageWindow', winsettings);
	PPwin.focus();
}
function RefreshPage()
{
	if (location.href.indexOf("?eonxstatus")==-1) location.reload();
	else location.replace(location.href.substring(0, location.href.indexOf("?eonxstatus")));
}
function GoToEonXPluginPage()
{
	location.href = eonxPluginsPage;
}
function IEDownloadingPluginMsg()
{
	alert(GetPluginMessage());
}
function GetPluginMessage()
{
	var msg = 'EonX Plug-in Required!\n\nTo view the 3D EON content in this page, you need the EonX Plug-in.\nDownloading has begun...\n\nWhen the security warning dialog appears, click on ';
	if (NN) msg = msg + '"GRANT"';
	else msg = msg + '"YES"';
	msg = msg + ' to continue.'
	if (NN) msg = msg + '\n\nOnce installation is complete, refresh this page.';
	return msg;
}
function InstallEonXNow()
{
	if (is_nav6up) location.href=LatestEONDirectory + "EonForNetscape.exe";
	else
	{
		if (NN) location.href = location.href + "?installnow=true";
		else
		{
			var pos = location.href.substring(location.href.indexOf('?eonxstatus='))
			location.href = location.href.substring(location.href, 0, pos)+'?installnow=true';
		}
	}
}



//  --- INSERT EON OBJECT ---

//  This function will insert the embed or the object tag which displays 
//  the EON simulation. The reasons for doing this are:
//  1. In Netscape, EONX will only look in the codebase given. It doesn't look
//     where this web page is like IE does. This function dynamically writes the
//     EONX object/embed tag and calculates the directory this file is in whether
//     it be on the Internet, a CD or local harddisk. It's called the documentbase.
//     Now if we move the webpage we don't have to update the path to the simulation.
//  2. Saves time for the programmer to write down one set of values instead of two.
//  3. Forces the use of names or id that are used in all the functions of this file.
//  4. Reduces space in the webpage file. ( Write just EONInsert() instead of all below.)

var DoEONInsert = true;
function EONInsert()
{
	if (CheckingWindow) return;
	HandleEonXStatus();
	if (DoEONInsert) document.write(EONInsertText());
	if (eonxAutoPlay==1) isEONrunning = true;
}
function EONInsertText()
{
	if (NN)
	{	
		var t= '<EMBED\n NAME="EONControl"\n TYPE="application/x-eonx"\n';
		t+=' HEIGHT="' + eonxHeight + '"\n';
		t+=' WIDTH="' + eonxWidth + '"\n';
		t+=' CODEBASE="' + eonxCodebaseNN + '"\n';
		t+=' PLUGINSPAGE="' + eonxPluginsPage + '"\n';
		t+=' PARAM_Codebase="' + eonxCodebase2 + '"\n';
		t+=' PARAM_AutoPlay="' + eonxAutoPlay + '"\n';
		t+=' PARAM_Toolbar="' + eonxToolbar + '"\n';
		t+=' PARAM_Progressbar="' + eonxProgressbar + '"\n';
		t+=' PARAM_SettingsButton="' + eonxSettingsButton + '"\n';
		t+=' PARAM_Background="' + eonxBackground + '"\n';
		t+=' PARAM_SimulationFile="' + eonxSimulationFile + '"\n';
		t+=' PARAM_PrototypebaseURL="' + eonxPrototypebaseURL + eonxServerURL + '"\n';
		t+=' PARAM_SchemeValues="' + eonxSchemeValues + '"\n';
		t+=' PARAM_ConfigurationScheme="' + eonxConfigurationScheme + '">';
	}
	else
	{
		var t='<OBJECT ID="EONControl"';
		t+=' TITLE="EonX ActiveX Control"';
		t+=' CLASSID="' + eonxClassid + '"';
		t+=' HEIGHT="' + eonxHeight + '"';
		t+=' WIDTH="' + eonxWidth + '"';
		t+=' CODEBASE="' + eonxCodebaseIE + '">';
		t+=' <PARAM NAME="Codebase" Value="' + eonxCodebase2 + '">';
		t+=' <PARAM NAME="AutoPlay" Value="' + eonxAutoPlay + '">';
		t+=' <PARAM NAME="Toolbar" Value="' + eonxToolbar + '">';
		t+=' <PARAM NAME="Progressbar" Value="' + eonxProgressbar + '">';
		t+=' <PARAM NAME="SettingsButton" Value="' + eonxSettingsButton + '">';
		t+=' <PARAM NAME="Background" Value="' + eonxBackground + '">';
		t+=' <PARAM NAME="SimulationFile" Value="' + eonxSimulationFile + '">';
		t+=' <PARAM NAME="PrototypebaseURL" Value="' + eonxPrototypebaseURL + eonxServerURL + '">';
		t+=' <PARAM NAME="SchemeValues" Value="' + eonxSchemeValues + '">';
		t+=' <PARAM NAME="ConfigurationScheme" Value="' + eonxConfigurationScheme + '">';
		t+='</OBJECT>';
		
		// The following code will insert hidden form fields which are neccessary 
		// to allow communication between vbscript and javascript and vice versa;
		// The tags should never be a problem becuase they are in a hidden div far
		// to the left of the page. (It hasn't been tested yet on early browsers.)
		// These fields allow all events from EON to be handled by one javascript 
		// function called EON_OnEvent(e,v) and they allow all events to EON to be 
		// sent using javascript only. (eon_functions.vbs external script is required.)
		t+='<div style="position:absolute;visibility:hidden; left:-1000 px;">';
		t+='<form name="eonhiddenfields">';
		t+='<input type="hidden" name="EONInEventType">';
		t+='<input type="hidden" name="EONInEventName">';
		t+='<input type="hidden" name="EONInEventV1">';
		t+='<input type="hidden" name="EONInEventV2">';
		t+='<input type="hidden" name="EONInEventV3">';
		t+='<input type="hidden" name="EONInEventV4">';
		t+='<input type="hidden" name="EONOutEventType">';
		t+='<input type="hidden" name="EONOutEventName" onclick="EONOutEventName_OnClick()">';
		t+='<input type="hidden" name="EONOutEventV1">';
		t+='<input type="hidden" name="EONOutEventV2">';
		t+='<input type="hidden" name="EONOutEventV3">';
		t+='<input type="hidden" name="EONOutEventV4">';
		t+='</form></div>';
	}
	return t;
}



	










// --- EONX METHODS --- (Start, Stop, Pause, ShowSettingsDialog, Fullsize)

//  This variable is used in the SimulationFile function to determine 
//  if the simulation should be stopped and restarted. 
var isEONrunning = false;

// This function starts a simulation
function EONStart()
{
	(NN) ? document.EONControl.Start() : EONControl.Start();
	isEONrunning = true;
	setTimeout("if (ToolOpen) WEBEON.focus()", 1000); // for WEBEON Tool's purpose
}
// This function stops a simulation
function EONStop()
{
	(NN) ? document.EONControl.Stop() : EONControl.Stop();
	isEONrunning = false;
	EONBackground(eonxBackground);
}

// This function pauses and unpauses a simulation.
function EONPause(v)
{
	(NN) ? document.EONControl.Pause(v) : EONControl.Pause(v);
}

// This function will show the EON Configuration dialog
function EONShowSettingsDialog()
{
	(NN) ? document.EONControl.ShowSettingsDialog() : EONControl.ShowSettingsDialog()
}

// This function can both set the FullSize Mode and get its value
function EONFullsize(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)
		{
			if (document.EONControl.GetFullsize()) return 1;
			return 0;
		}
		else
		{	
			return EONControl.GetFullsize();
		}
	}
	else		// setting the FullSize mode
	{
		if (NN)	{document.EONControl.SetFullsize(v);}
		else {EONControl.SetFullsize(v);}
	}
}

// This function saves a picture of the running simulation to a specific location
function EONSaveSnapshot(v)
{
	if (v==null)	// Press 444 to automatically call this function
	{		// use this to see the file: '<img src="file:///c://eonx.png">'
		if (NN) document.EONControl.SaveSnapshot("C://eonx.png");
		else EONControl.SaveSnapshot("C://eonx.png");
	}
	else
	{
		if (NN) document.EONControl.SaveSnapshot(v);
		else EONControl.SaveSnapshot(v);
	}
}











//  --- OLD EONX PROPERTIES --- (Toolbar, ProgressBar, SettingsButton, AutoPlay)  
//       				(SimulationFile, Background, Codebase, Height, Width) 

// This function can both set or get the value of the Toolbar
function EONToolbar(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)
		{
			if (document.EONControl.GetToolbar()) return 1;
			return 0;
		}
		else
		{
			 if (EONControl.Toolbar == -1) return 1;
			 return EONControl.Toolbar ;
		}
	}
	else		// setting the Toolbar
	{
		if (NN)	{document.EONControl.SetToolbar(v);}
		else {EONControl.Toolbar = v;}
	}
}

// This function can both set or get the value of the progressbar
function EONProgressbar(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)
		{
			if (document.EONControl.GetProgressbar()) return 1;
			return 0;
		}
		else
		{
			 if (EONControl.Progressbar == -1) return 1;
			 return EONControl.Progressbar ;
		}
	}
	else		// setting the Progressbar
	{
		if (NN) {document.EONControl.SetProgressbar(v)}
		else {EONControl.Progressbar = v}
	}
}

// This function can both set or get the value of the Settingsbutton
function EONSettingsButton(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)
		{
			if (document.EONControl.GetSettingsButton()) return 1;
			return 0;
		}
		else
		{
			 if (EONControl.SettingsButton == -1) return 1;
			 return EONControl.SettingsButton ;
		}
	}
	else		// setting the SettingsButton
	{
		if (NN)	{document.EONControl.SetSettingsButton(v)}
		else {EONControl.SettingsButton = v}
	}
}

// This function can both set or get the value of the Autoplay property.
// Setting the autoplay property will have no effect though since then it wouldn't be automatic!
function EONAutoPlay(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)
		{
			if (document.EONControl.GetAutoPlay()) return 1;
			return 0;
		}
		else
		{
			 if (EONControl.AutoPlay == -1) return 1;
			 return EONControl.AutoPlay ;
		}
	}
	else		// setting the value
	{
		if (NN) {document.EONControl.SetAutoPlay(v)}
		else {EONControl.AutoPlay = v}
	}
}

// This function can both set or get the value of the SimulationFile
// When setting it checks that the simulation file is different from the existing
// file and if the simulation is running it will stop it, change files and restart it.
// If it isn't running it will only change the file.
function EONSimulationFile(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)	{return document.EONControl.GetSimulationFile();}
		else {return EONControl.SimulationFile;}
	}
	else	// Setting the value of the Simulation file
	{
		if (v != (EONSimulationFile()))
		{
			var s = false;
			if (isEONrunning) 
			{
				EONStop();
				var s = true;
			}
			if (NN)	{document.EONControl.SetSimulationFile(v)}
			else {EONControl.SimulationFile = v;}
			if (s) EONStart();
		}
	}
}

// This function can both set or get the value of the Background
function EONBackground(v)
{
	if (v == null)	// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)	{return document.EONControl.GetBackground();}
		else {return EONControl.Background;}
	}
	else	// Setting the background
	{
		if (isEONrunning)
		{
			eonxBackground = v;
			return;
		}
		if (NN)	{document.EONControl.SetBackground(v);}
		else {EONControl.Background = v;}
	}
}

// This function can both set or get the value of the Codebase
// This codebase is where the simulation files and background files are kept.
function EONCodebase(v)
{
	if (v == null)		// if no v was sent then we are getting it instead of setting it.
	{
		if (NN)	{return document.EONControl.GetCodebase()}
		else {return EONControl.Codebase;}
	}
	else
	{
		if (isEONrunning) return;
		if (NN)	{document.EONControl.SetCodebase(v)}
		else {EONControl.Codebase = v}
	}
}

// This function will get or set the width of the simulation.
function EONWidth(v)
{
	if (v == null)
	{
		if (NN){return eonxWidth;}
		else {return EONControl.width;}
	}
	else	// setting the width (IE only)
	{
		if (!NN) {EONControl.width = v;}
	}
}
// This function will get or set the height of the simulation.
function EONHeight(v)
{
	if (v == null)
	{
		if (NN)	{return eonxHeight;}
		else {return EONControl.height;}
	}
	else
	{
		if (!NN){EONControl.height = v;}
	}
}









//  --- NEW EONX PROPERTIES ---  (Version, PrototypebaseURL, SchemeValues, ConfigurationScheme)

//  This function will return, as an array, which version of EON is installed.
function EONGetVersionArray()
{
	if(NN)
	{
		return document.EONControl.Version();
	}
	else
	{
		var verArray = EONControl.Version;
		if(verArray==null) {return new Array("not available");}
		else {return verArray.toArray();}
	}
}
//  This function will return a string stating which version of EON is installed.
function EONGetVersion()
{
	var verArray = EONGetVersionArray()
	if (verArray[0] == "not available")	{return "EonX version not available";}
	else {return "EonX version " + verArray[0] + "." + verArray[1] + "." + verArray[2]+ "." + verArray[3];}
}

//  This function will get the PrototypebaseURL property
function EONPrototypebaseURL()
{
	if (NN) {return document.EONControl.GetPrototypebaseURL();}
	else {return EONControl.PrototypebaseURL;}
}

//  This function will get the SchemeValues property
function EONSchemeValues()
{
	if (NN)	{return document.EONControl.GetSchemeValues();}
	else {return EONControl.SchemeValues;}
}

// This function will get the ConfigurationScheme property
function EONConfigurationScheme()
{
	if (NN) {return document.EONControl.GetConfigurationScheme();}
	else {return EONControl.ConfigurationScheme;}
}






//  --- SENDING and RECIEVING EVENTS ---

//	This function will send events to EON. In the case of IE the data will 
//  first be sent to HTML Elements to then be picked up by vbscript and then 
//  sent to EON. (See the EONInEventName_OnClick subroutine in eon_functions.vbs)
function EONSendEvent(type, e, v1, v2, v3, v4)
{
	// Send error if type is not recognized
		type=type.toUpperCase()
		datatypes = "SFBOOL, SFCOLOR, SFFLOAT, SFIMAGE, SFINT32, SFNODE, SFROTATION, SFSTRING, SFTIME, SFVEC2F, SFVEC3F";
		if (datatypes.indexOf(type)==-1) 
		{
			alert("Unrecognized EON datatype '" + type + "'");
		}

	
	if (NN)
	{
		if ((typeof(v1)=="string")&&(v2==null))
		{
			var simpletypes = "SFBOOL, SFFLOAT, SFIMAGE, SFINT32, SFNODE, SFSTRING, SFTIME"
			if (simpletypes.indexOf(type)!=-1)
			{
				if (type=="SFBOOL")
				{
					if ((v1=="true")||(v1=="True")||(v1=="TRUE")) {v1=true}else{v1=false}
				}
				if ((type=="SFFLOAT")||(type=="SFINT32")||(type=="SFTIME")){v1=Number(v1)}
			}
			else
			{
				var b = v1.split(" ");
				if ((b.length>=2)&&(b.length<=4))
				{
					v1=Number(b[0]);
					v2=Number(b[1]);
					if ((b.length==3)&&((type=="SFCOLOR")||(type=="SFVEC3F"))) v3=Number(b[2]);
					if ((b.length==4)&&(type=="SFROTATION")) {v3=Number(b[2]);v4=Number(b[3]);} 
				}
			}
		}
		var args = new Array(type, v1, v2, v3, v4);
		document.EONControl.SendEvent(e, args);
	}
	else
	{
		document.eonhiddenfields.EONInEventType.value = type;
		document.eonhiddenfields.EONInEventName.value = e;
		document.eonhiddenfields.EONInEventV1.value = v1;
		document.eonhiddenfields.EONInEventV2.value = v2;
		document.eonhiddenfields.EONInEventV3.value = v3;
		document.eonhiddenfields.EONInEventV4.value = v4;
			// Logging for WEB-EON TOOL's purpose
			Logcount ++
			if (LogActive) WEBEON.LogEONEvent(Logcount, "in", e, v1, v2, v3, v4)
		document.eonhiddenfields.EONInEventName.click();
	}
}

// This next function is for receiving events from EON when using IE.
// The event has already been accepted by VBScript and put into the hidden field
// This function gets the values and sends them to a common function for both
// Netscape and IE browsers called EON_OnEvent(e,v).
function EONOutEventName_OnClick()
{
	var t = document.eonhiddenfields.EONOutEventType.value;
	var e = document.eonhiddenfields.EONOutEventName.value;
	
	if (t == 0) 
	{
		var v = document.eonhiddenfields.EONOutEventV1.value;
			// Logging for WEB-EON TOOL's purpose.
			Logcount ++
			if (LogActive) WEBEON.LogEONEvent(Logcount, "out", e, v)
		EON_OnEvent(e,v);
	}
	else
	{
		// Logging for WEB-EON TOOL's purpose.
			Logcount ++
		var v = new Array(t + 1);
		if (t == 1)
		{
			v[0] = document.eonhiddenfields.EONOutEventV1.value
			v[1] = document.eonhiddenfields.EONOutEventV2.value
			// Logging for WEB-EON TOOL's purpose.
				if (LogActive)  WEBEON.LogEONEvent(Logcount, "out", e, v[0],v[1])
		}
		if (t == 2)
		{
			v[0] = document.eonhiddenfields.EONOutEventV1.value
			v[1] = document.eonhiddenfields.EONOutEventV2.value
			v[2] = document.eonhiddenfields.EONOutEventV3.value
			// Logging for WEB-EON TOOL's purpose.
				if (LogActive) WEBEON.LogEONEvent(Logcount, "out", e, v[0],v[1],v[2])
		} 
		if (t == 3) 
		{
			v[0] = document.eonhiddenfields.EONOutEventV1.value
			v[1] = document.eonhiddenfields.EONOutEventV2.value
			v[2] = document.eonhiddenfields.EONOutEventV3.value
			v[3] = document.eonhiddenfields.EONOutEventV4.value
			// Logging for WEB-EON TOOL's purpose.
				if (LogActive) WEBEON.LogEONEvent(Logcount, "out", e, v[0],v[1],v[2],v[3])
		}
		EON_OnEvent(e, v);
	}
}

// This function recieves events directly from EON when using Netscape
// It will send the event on to the common function for both Netscape and IE
// called EON_OnEvent(e,v). (No logging because the WEBEON tool is not designed for NN)
function EONControl_OnEvent(e,v)
{
	var ev = String(e);
	var arraytypes = " SFCOLOR, SFROTATION, SFVEC2F, SFVEC3F ";
	if (arraytypes.indexOf(EONGetDataType(e))!=-1)
	{
		var arrlen = v.length;
		var v1 = v[0];
		var v2 = v[1];
		TheArray = new Array(arrlen);
		TheArray[0] = v1;
		TheArray[1] = v2;
		if (arrlen >= 3)
		{
			var v3 = v[2];
			TheArray[2] = v3;
			if (arrlen == 4) 
			{
				var v4 = v[3];
				TheArray[3] = v4;
			}
		}
		EON_OnEvent(ev,TheArray);
	}
	else
	{
		var v1 = String(v);		// this is to make the value of the same type as it is in IE.
		EON_OnEvent(ev, v1);
	}
}







// --- METHODS FOR GETTING IN/OUT EVENT INFORMATION ---

// This returns the number of IN events for the running simulation.
function EONGetNumberOfInEvents()
{
	if (NN)	{return document.EONControl.GetNumberOfInEvents();}
	else {return EONControl.GetNumberOfInEvents();}
}

// This returns the number of OUT events for the running simulation.
function EONGetNumberOfOutEvents()
{
	if (NN)	{return document.EONControl.GetNumberOfOutEvents();}
	else {return EONControl.GetNumberofOutEvents();}
}

// This function gets the name of an inevent given its position in the list of inevents.
function EONGetInEventName(i)
{
	if (NN)	{return document.EONControl.GetInEventName(i);}
	else {return EONControl.GetInEventName(i);}
}

// This function gets the name of an outevent given its position in the list of outevents.
function EONGetOutEventName(i)
{
	if (NN)	{return document.EONControl.GetOutEventName(i);}
	else {return EONControl.GetOutEventName(i);}
}

// Given the events position in the list of inevents, this function gets 
// an integer of an inevent which represents its datatype.
function EONGetInEventType(i)
{
	if (NN)	{return document.EONControl.GetInEventType(i);}
	else {return EONControl.GetInEventType(i);}
}

// Given the events position in the list of outevents, this function gets 
// an integer of an outevent which represents its datatype.
function EONGetOutEventType(i)
{
	if (NN)	{return document.EONControl.GetOutEventType(i);}
	else {return EONControl.GetOutEventType(i);}
}

// There are 22 EON datatypes. Other functions will give you an integer 
// representing a datatype. By using that integer in this function you will 
// return a string like "SFBOOL" or "SFVEC3F".
// HOWEVER this function will also accept a string representing the name of the
// inevent or outevent and still return a string like "SFBOOL" or "SFVEC3F".
function EONGetDataType(p)
{
	var EONdatatypes = new Array("SFBOOL", "SFCOLOR", "SFFLOAT", "SFIMAGE", "SFINT32", "SFNODE", "SFROTATION", "SFSTRING", "SFTIME", "SFVEC2F", "SFVEC3F", "MFBOOL", "MFCOLOR", "MFFLOAT", "MFIMAGE", "MFINT32", "MFNODE", "MFROTATION", "MFSTRING", "MFTIME", "MFVEC2F", "MFVEC3F");
	if ((p >= 0) && (p <= 21)) // p is integer
	{
		return EONdatatypes[p];
	}
	else // p is probably an inevent name or an outevent name
	{
		p=String(p)
		var n = EONGetNumberOfInEvents();
		for (var i=0 ; i<n ; i++ )
		{
			if ((p.toUpperCase()) == (String((EONGetInEventName(i)).toUpperCase())))
			{
				return EONdatatypes[EONGetInEventType(i)];
			}
		}
		n = EONGetNumberOfOutEvents();
		for (var i=0 ; i<n ; i++ )
		{
			if ((p.toUpperCase()) == (String((EONGetOutEventName(i)).toUpperCase())))
			{
				return EONdatatypes[EONGetOutEventType(i)];
			}
		}
		return "not found";
	}
}










// ---  WEBEON TOOL CODE  ---
// This next code is designed to open the WEB-EON Tool when the user
// presses 3 times on the number 5 key. 
document.onkeypress = KeyPressed;
var sixcount = 0;
var fourcount = 0;
function KeyPressed(e)
{
	if (NN)
	{
		if (e.which == 52) {fourcount ++;}
		else {fourcount = 0;}
	}
	else
	{
		e = window.event;
		if (e.keyCode == 53) {sixcount ++;}
		else {sixcount = 0;}
		if (e.keyCode == 52) {fourcount ++;}
		else {fourcount = 0;}
	}
	if ((sixcount == 3)&&(!NN))
	{
		sixcount=0;
		if (EnableWEBEON_Tool) OpenWEBEON();
	}
	if (fourcount==3)
	{
		fourcount=0;
		EONSaveSnapshot();
	}
}

var WEBEON = "nothin";
var ToolOpen = false;
function OpenWEBEON()
{
	if (!NN) WEBEON = open("WEBEON_Tool.html","webeon", "resizable=yes,scrollbars=no,status=0,width=470,height=320");
}
window.onunload = ClosingPage;
function ClosingPage()
{
	if (ToolOpen) WEBEON.PageOpen = false;
	if (ToolOpen) WEBEON.close();
}
// The LogActive variable will be set to true by the WEB-EON tool.
var Logcount = 0;
var LogActive = false;












// BACKWARD COMPATIBILTY
// These functions, variables, are here for backwards compatibility.
// If they are removed some older web pages will NOT work.
function DownloadEONforNetscapeSmartUpdateUsers() {}
function ShowUserInfoWhenEONIsNotSupported() {}
var eonxServerURL = '';




//End of file