//
// Blink3D.js
//
// Support routines for embedding Blink 3D into web pages
//


var iPosition, sTemp, gsBrowserName;

//
// validateBrowserOS()
//
function validateBrowserOS()
{
	var sDetect = navigator.userAgent.toLowerCase();
	var sOS, sBrowser, sVersion;

	if ( checkIt( sDetect, 'konqueror' ))
	{
		sBrowser = 'Konqueror';
		sOS = 'Linux';
	}
	else if ( checkIt( sDetect, 'safari' ))
		sBrowser = 'Safari';
	else if ( checkIt( sDetect, 'omniweb' ))
		sBrowser = 'OmniWeb';
	else if ( checkIt( sDetect, 'opera' ))
		sBrowser = 'Opera';
	else if ( checkIt( sDetect, 'webtv' ))
		sBrowser = 'WebTV';
	else if ( checkIt( sDetect, 'icab' ))
		sBrowser = 'iCab';
	else if ( checkIt( sDetect, 'msie' ))
		sBrowser = 'Internet Explorer';
	else if ( !checkIt( sDetect, 'compatible' ))
	{
		sBrowser = 'Netscape Navigator';
		sVersion = sDetect.charAt( 8 );
	}
	else
		sBrowser = 'An unknown browser';

	if ( !sVersion )
		sVersion = sDetect.charAt( iPosition + sTemp.length );

	if ( !sOS )
	{
		if ( checkIt( sDetect, 'linux' ))
			sOS = 'Linux';
		else if ( checkIt( sDetect, 'x11' ))
			sOS = 'Unix';
		else if ( checkIt( sDetect, 'mac' ))
			sOS = 'Mac';
		else if ( checkIt(  sDetect,'win' ))
			sOS = 'Windows';
		else 
			sOS = 'an unknown operating system';
	}

	if ( (sBrowser != 'Internet Explorer' && sBrowser != 'Netscape Navigator' && sBrowser != 'Opera') || sOS != 'Windows' )
	{
		alert( 'This page uses the Blink 3D Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Internet Explorer, Firefox or Opera running on Windows. The page can not be displayed as you are not using Internet Explorer, Firefox or Opera on Windows.' );
		location = document.referer;
	}
	else if ( sBrowser == 'Internet Explorer' && sOS == 'Windows' && parseInt( sVersion ) < 6 )
	{
		alert( 'This page uses the Blink 3D Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Internet Explorer Version 5.0 or above. The page can not be displayed as you are using version '+sVersion+' of Internet Explorer.' );
		location = document.referer;
	}
	else if ( sBrowser == 'Netscape Navigator' && sOS == 'Windows' && parseInt( sVersion ) < 1 )
	{
		alert( 'This page uses the Blink 3D Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Firefox Version 1.0 or above. The page can not be displayed as you are using version '+sVersion+' of Firefox.' );
		location = document.referer;
	}
	else if ( sBrowser == 'Opera' && sOS == 'Windows' && parseInt( sVersion ) < 9 )
	{
		alert( 'This page uses the Blink 3D Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Opera Version 9.0 or above. The page can not be displayed as you are using version '+sVersion+' of Opera.' );
		location = document.referer;
	}

	gsBrowserName = sBrowser;
}


//
// checkIt()
//
function checkIt( sDetect, sParam )
{
	iPosition = sDetect.indexOf( sParam ) + 1;
	sTemp = sParam;
	return ( iPosition );
}


//
// createBlink3DControl()
//
function createBlink3DControl( sPluginVersion, sWidth, sHeight, sEnvURL, sChatPaneVisible, sChatPaneLocked,
	sToolbarVisible, sToolbarLocked, sContextMenuVisible, sSplitPercentage, sUIVisible, sRenderSystem,
	sSceneManager, sDownloadProgressBarStyle, sLoadProgressBarStyle, sForceDownload, sResourceGroupName,
	sAntiAlias, sRenderToTexture, sAllowNvPrefHUD )
{
	if ( window.ActiveXObject )
	{
		document.write( '<object ID="Blink3DCtl" classid="CLSID:65A0276F-A5C2-4BA2-82DA-BC4AF3250F9E"' );
		document.write( ' CODEBASE="http://www.pelicancrossing.com/install/blink3dplugin/blink3dplugin.cab#version='+sPluginVersion+'"' );
		document.write( ' width = "'+sWidth+'"' );
		document.write( ' height = "'+sHeight+'">' );
		document.write( ' <PARAM name="FileName" value="'+sEnvURL+'">' );
		document.write( ' <PARAM name="ChatPaneVisible" value="'+sChatPaneVisible+'">' );
		document.write( ' <PARAM name="ChatPaneLocked" value="'+sChatPaneLocked+'">' );
		document.write( ' <PARAM name="ToolbarVisible" value="'+sToolbarVisible+'">' );
		document.write( ' <PARAM name="ToolbarLocked" value="'+sToolbarLocked+'">' );
		document.write( ' <PARAM name="ContextMenuVisible" value="'+sContextMenuVisible+'">' );
		document.write( ' <PARAM name="SplitPercentage" value="'+sSplitPercentage+'">' );
		document.write( ' <PARAM name="UIVisible" value="'+sUIVisible+'">' );
		document.write( ' <PARAM name="RenderSystem" value="'+sRenderSystem+'">' );
		document.write( ' <PARAM name="SceneManager" value="'+sSceneManager+'">' );
		document.write( ' <PARAM name="DownloadProgressBarStyle" value="'+sDownloadProgressBarStyle+'">' );
		document.write( ' <PARAM name="LoadProgressBarStyle" value="'+sLoadProgressBarStyle+'">' );
		document.write( ' <PARAM name="ForceDownload" value="'+sForceDownload+'">' );
		document.write( ' <PARAM name="ResourceGroupName" value="'+sResourceGroupName+'">' );
		document.write( ' <PARAM name="AntiAlias" value="'+sAntiAlias+'">' );
		document.write( ' <PARAM name="RenderToTexture" value="'+sRTT+'">' );
		document.write( ' <PARAM name="AllowNvPrefHUD" value="'+sNvPrefHUD+'">' );
		document.write( '</object>' );
	}
	else
	{
		if ( gsBrowserName == 'Netscape Navigator' )		
{	
			document.write( '<object ID="Blink3DCtl"' );
			document.write( ' TYPE = "application/x-blink3d"' );
			document.write( ' CODEBASE = "http://www.pelicancrossing.com/install/blink3dplugin/blink3dinstall.xpi"' );
			document.write( ' width = "'+sWidth+'"' );
			document.write( ' height = "'+sHeight+'">' );
			document.write( ' <PARAM name="FileName" value="'+sEnvURL+'">' );
			document.write( ' <PARAM name="ChatPaneVisible" value="'+sChatPaneVisible+'">' );
			document.write( ' <PARAM name="ChatPaneLocked" value="'+sChatPaneLocked+'">' );
			document.write( ' <PARAM name="ToolbarVisible" value="'+sToolbarVisible+'">' );
			document.write( ' <PARAM name="ToolbarLocked" value="'+sToolbarLocked+'">' );
			document.write( ' <PARAM name="ContextMenuVisible" value="'+sContextMenuVisible+'">' );
			document.write( ' <PARAM name="SplitPercentage" value="'+sSplitPercentage+'">' );
			document.write( ' <PARAM name="UIVisible" value="'+sUIVisible+'">' );
			document.write( ' <PARAM name="RenderSystem" value="'+sRenderSystem+'">' );
			document.write( ' <PARAM name="SceneManager" value="'+sSceneManager+'">' );
			document.write( ' <PARAM name="DownloadProgressBarStyle" value="'+sDownloadProgressBarStyle+'">' );
			document.write( ' <PARAM name="LoadProgressBarStyle" value="'+sLoadProgressBarStyle+'">' );
			document.write( ' <PARAM name="ForceDownload" value="'+sForceDownload+'">' );
			document.write( ' <PARAM name="ResourceGroupName" value="'+sResourceGroupName+'">' );
			document.write( ' <PARAM name="AntiAlias" value="'+sAntiAlias+'">' );
			document.write( ' <PARAM name="RenderToTexture" value="'+sRTT+'">' );
			document.write( ' <PARAM name="AllowNvPrefHUD" value="'+sNvPrefHUD+'">' );
			document.write( '</object>' );
		}
		else
		{
			document.write( '<embed name="Blink3DCtl"' );
			document.write( ' type="application/x-blink3d"' );
			document.write( ' PluginsPage="http://www.pelicancrossing.com/install.htm"' );
			document.write( ' width="'+sWidth+'"' );
			document.write( ' height="'+sHeight+'"' );
			document.write( ' FileName="'+sEnvURL+'"' );
			document.write( ' ChatPaneVisible="'+sChatPaneVisible+'"' );
			document.write( ' ChatPaneLocked="'+sChatPaneLocked+'"' );
			document.write( ' ToolbarVisible="'+sToolbarVisible+'"' );
			document.write( ' ToolbarLocked="'+sToolbarLocked+'"' );
			document.write( ' ContextMenuVisible="'+sContextMenuVisible+'"' );
			document.write( ' SplitPercentage="'+sSplitPercentage+'"' );
			document.write( ' UIVisible="'+sUIVisible+'"' );
			document.write( ' RenderSystem="'+sRenderSystem+'"' );
			document.write( ' SceneManager="'+sSceneManager+'"' );
			document.write( ' DownloadProgressBarStyle="'+sDownloadProgressBarStyle+'"' );
			document.write( ' LoadProgressBarStyle="'+sLoadProgressBarStyle+'"' );
			document.write( ' ForceDownload="'+sForceDownload+'"' );
			document.write( ' ResourceGroupName="'+sResourceGroupName+'"' );
			document.write( ' AntiAlias="'+sAntiAlias+'"' );
			document.write( ' RenderToTexture="'+sRTT+'"' );
			document.write( ' AllowNvPrefHUD="'+sNvPrefHUD+'">' );
			document.write( '</embed>' );
		}
	}
}



