var hidecortona = false;
var cortonaversion = "";
var cortonabuild = 0;

bd=false;
ver=Math.round(parseFloat(navigator.appVersion)*100);
ie=navigator.appName.toLowerCase().indexOf('microsoft') != -1;
opera=navigator.userAgent.toLowerCase().indexOf('opera') != -1;
win = navigator.userAgent.toLowerCase().indexOf('win') != -1;
mac = navigator.userAgent.toLowerCase().indexOf('mac') != -1;
goodie = !opera && ie && ver >= 400 && win;
goodns = !opera && !ie && ver >= 450 && ver < 500 && win;
goodns67 = !opera && !ie && ver >= 500 & win;

cortbuild = 157;

c = "http://www.parallelgraphics.com";
path = c + '/bin';

function installAndShow(emb) // this func is called from scenes which are opened in a new window (Volvo, Koenigsegg, etc.)
{
	installed();
/*
	if (goodns && (cortonabuild == 0 || cortonabuild < cortbuild)) 
		{ install_cortona(); }
		
	else 
*/		
		if (goodns67 && (cortonabuild == 0 || cortonabuild < cortbuild))
		{ downloadNow(); }

	else if (!goodie) 
	{ 
		if (cortonabuild == 0 && win)
		{
			document.write("<table cellpadding=40 cellspacing=2 bgcolor=#CCCCCC><tr><td align=center bgcolor=#FFFFFF><font color=000033>This 3D scene requires Cortona<sup>&reg;</sup> VRML Client.</font><br><a href='"+c+"/products/cortona/download/'><img src='/l2/images/cortona/install-cortona.gif' border=0 vspace=10 hspace=20></a></td></tr></table>");
		}
		else if (cortonabuild < cortbuild && win)
		{
			document.write("<table cellpadding=40 cellspacing=2 bgcolor=#CCCCCC><tr><td align=center bgcolor=#FFFFFF><font color=000033>Your version of Cortona<sup>&reg;</sup> VRML Client is out of date.</font><br><a href='"+c+"/products/cortona/download/'><img src='/l2/images/cortona/install-cortona.gif' border=0 vspace=10 hspace=20></a></td></tr></table><p>");		
		}
		else 
		{
			document.write(emb); 
		}	
	}
}

function installAndShow2(emb) // this func is called from scenes which are opened in a new window (Volvo, Koenigsegg, etc.)
{
	installed();
/*
	if (goodns && (cortonabuild == 0)) 
		{ install_cortona(); }
		
	else 
*/		
	if (goodns67 && (cortonabuild == 0))
		{ downloadNow(); }
		
	else if (!goodie) 
	{ 
		if ((cortonabuild == 0) && win)
		{
			document.write("<table cellpadding=40 cellspacing=2 bgcolor=#CCCCCC><tr><td align=center bgcolor=#FFFFFF>This 3D scene requires Cortona<sup>&reg;</sup> VRML Client.<br><a href='"+c+"/products/cortona/download/'><img src='/l2/images/cortona/install-cortona.gif' border=0 vspace=10 hspace=20></a></td></tr></table>");
		}
		else 
		{
			document.write(emb); 
		}	
	}
}

function complete() {
	navigator.plugins.refresh(true);
	if (goodns) installed();
	if (goodns && cortonabuild < cortbuild) //because when upgrade, plugins collection will not be refreshed.
		alert('Cortona(R) VRML Client 5.1 installed. Please, restart your browser.');
	else window.location.reload();
}

var flag = 0;

function installed()
{
   f = false;
   for (i = 0; i < navigator.plugins.length; i++)
   {
    	pl = navigator.plugins[i];
		for (j = 0; j < pl.length; j++)
		{
    		mime = pl[j];
	 		if (mime.type.indexOf('vrml') != -1 && 
		        mime.suffixes.toLowerCase().indexOf('wrl') != -1 &&
	   		    mime.enabledPlugin.name == pl.name &&
		   	    pl.name.toLowerCase().indexOf('cortona') != -1)
			    {
					cortonaversion = pl.description.substring(pl.description.indexOf("(") + 1, pl.description.indexOf(")"));
					if (!cortonaversion.length) {
						cortonaversion = "2.2 or lower";
						cortonabuild = 40;
					} else {
						cortonabuild = cortonaversion.substring(cortonaversion.lastIndexOf(" "), cortonaversion.length);
					}
					f = true; break;
				}
		}
		if (f) break; 
	}
	return f;
}

// Automatic Installation of Cortona under Netscape Navigator 6.x, 7.x and Mozilla
function downloadNow()
{
   if (navigator.platform=='Win32')
   {
   		if (InstallTrigger.UpdateEnabled())
        {
///////////////////////CHECK THE VERSION!!!//////////////////
        	if (InstallTrigger.CompareVersion('/ParallelGraphics/Cortona/Vrml', 5, 1, 0, 157) <= 0)
/////////////////////////////////////////////////////////////			   
            {
            	InstallTrigger.install({'Cortona(R) VRML Client' : path + '/cortvrml.xpi'}, on_load_cortvrml);
            }
            else alert('Cortona(R) VRML Client has already installed.');
         } 
		 else alert('Enable Software Installation before running this script.');
   } 
   else alert('This plug-in only runs on Windows operating systems.');
}

function on_load_cortvrml(url, status)
{
   var msg;
   var flag = 0;
   switch( status )
   {
   case 0:
      msg =  'Cortona(R) VRML Client has been successfully installed.';
	  flag = 1;
      break;
   case 999:
      msg =  'Please restart the browser to complete Cortona(R) VRML Client installation.';
      break;
   case -210:
      msg =  'Cortona(R) VRML Client installation has been canceled by user.';
      break;
   default:
      msg =  'Cortona(R) VRML Client installation has failed. Error code: ' + status;
   }
   alert(msg);
   if (flag) complete();
}


