//
// Blink3D.js
//
// Support routines for embedding Blink 3D into web pages
//


var iPosition, sTemp;

//
// 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') || sOS != 'Windows' )
	{
		alert( 'This page uses the Blink 3D Plugin from Pelican Crossing (http://www.pelicancrossing.com) which requires Microsoft Internet Explorer or Firefox running on Windows. The page can not be displayed as you are not using Internet Explorer or Firefox 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 Microsoft 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;
	}
}


//
// 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
	{
		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>' );
	}
}


