
function addJNSObject( id, user, pswd, app, cls, args )
{
	var server = document.location.hostname;
	var port = document.location.port;

	if(!port)
		port=80;


	document.writeln(
		'<OBJECT id="' + id + '" ' +
		'CLASSID="clsid:cf391f4a-65bb-48cb-b7fd-be169fa7811e" ' +
		'CODEBASE="http://www.accendia.com:' + port + '/jnetstart2.2.cab"> ' +
		'<param name="jvmver" value="1.6"/> ' +
		'<param name="hostname" value="' + server + '"/> ' +
		'<param name="port" value="443" /> ' +
		'<param name="secure" value="false" /> ' +
		'<param name="application" value="' + app + '"/> ' +
		'<param name="user" value="' + user + '"/> ' +
		'<param name="password" value="' + pswd + '"/> ' +
		'<param name="classname" value="' + cls + '"/> ' +
		'<param name="arguments" value="' + args + '"/> ' +
		'<EMBED pluginspage="http://www.accendia.com:' + port + '/jnetstart2.2.xpi" ' +
			'width="0" height="0" ' +
			'type="application/x-jnetstart; jns-version=2.2.0.1" ' +
			'jvmver="1.6" ' +
			'hostname="' + server + '" ' +
			'port="443" ' +
			'secure="false" ' +
			'application="' + app + '" ' +
			'user="' + user + '" ' +
			'password="' + pswd + '" ' +
			'classname="' + cls + '" ' +
			'arguments="' + args + '" ' +
		'> ' +
			'<NOEMBED> ' +
			'<strong> ' +
				'The JNetstart Plug-in is not installed on this browser.' +
				'<br /> ' + 
				'Please click ' +
				'<a href="http://' + server + ':' + port + '/jnetstart2.2.xpi"> ' +
				'here' +
				'</a> ' +
				'to install the JNetStart Plugin' +
			'</strong> ' +
			'</NOEMBED> ' +
		'</EMBED> ' +
	'</OBJECT>'
	);
}

function addLaunchObject( id, user, pswd, app, cls, args )
{
	var server = document.location.hostname;
	var port = document.location.port;

	if(!port)
		port=80;

	document.writeln(
		'<OBJECT id="' + id + '" ' +
		'CLASSID="clsid:cf391f4a-65bb-48cb-b7fd-be169fa7811e" ' +
		'CODEBASE="http://www.accendia.com:' + port + '/jnetstart2.2.cab"> ' +
		'<param name="jvmver" value="1.6"/> ' +
		'<param name="hostname" value="' + server + '"/> ' +
		'<param name="port" value="443" /> ' +
		'<param name="secure" value="false" /> ' +
		'<param name="application" value="' + app + '"/> ' +
		'<param name="user" value="' + user + '"/> ' +
		'<param name="password" value="' + pswd + '"/> ' +
		'<param name="classname" value="' + cls + '"/> ' +
		'<param name="arguments" value="' + args + '"/> ' +
<!--
		'<EMBED pluginspage="http://' + server + ':' + port + '/jnetstart2.2.xpi" ' +
//-->
		'<EMBED pluginspage="http://www.accendia.com:' + port + '/jnetstart2.2.xpi" ' +
			'width="0" height="0" ' +
			'type="application/x-jnetstart; jns-version=2.2.0.1" ' +
			'jvmver="1.6" ' +
			'hostname="' + server + '" ' +
			'port="443" ' +
			'secure="false" ' +
			'application="' + app + '" ' +
			'user="' + user + '" ' +
			'password="' + pswd + '" ' +
			'classname="' + cls + '" ' +
			'arguments="' + args + '" ' +
		'> ' +
			'<NOEMBED> ' +
			'<strong> ' +
				'The JNetstart Plug-in is not installed on this browser.' +
				'<br /> ' + 
				'Please click ' +
				'<a href="http://' + server + ':' + port + '/jnetstart2.2.xpi"> ' +
				'here' +
				'</a> ' +
				'to install the JNetStart Plugin' +
			'</strong> ' +
			'</NOEMBED> ' +
		'</EMBED> ' +
	'</OBJECT>'
	);
}

function addJavaPluginObject( user, pswd, app, cls, args )
{
	var server = document.location.hostname;

	document.writeln(
		'<OBJECT ' +
		'CLASSID="clsid:CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA" ' +
		'CODEBASE="http://java.sun.com/javase/downloads/index.jsp" ' +
		'height="100%" width="100%" >' +
		'<param name="type" value="application/x-java-applet;jpi-version=1.6.0"> ' +
		'<param name="code" value="com.accendia.netstart.client.applet.JNSApplet"/> ' +
		'<param name="cache_option" value="Plugin"> ' +
		'<param name="cache_archive" value="netstart_applet2.2s.jar"> ' +
		'<param name="cache_version" value="2.2.0.1"> ' +

		'<param name="jnshostname" value="' + server + '"/> ' +
		'<param name="jnsport" value="443" /> ' +
		'<param name="jnssecure" value="false" /> ' +
		'<param name="jnsapplication" value="' + app + '"/> ' +
		'<param name="jnsuser" value="' + user + '"/> ' +
		'<param name="jnspassword" value="' + pswd + '"/> ' +
		'<param name="jnsclassname" value="' + cls + '"/> ' +

		'<EMBED pluginspage="http://java.sun.com/javase/downloads/index.jsp" ' +
			'type="application/x-java-applet;version=1.6" ' +
			'code="com.accendia.netstart.client.applet.JNSApplet" ' +
			'cache_option="Plugin" ' +
			'cache_archive="netstart_applet2.2s.jar" ' +
			'cache_version="2.2.0.1" ' +
			'height="100%" width="100%" ' +
			'jnshostname="' + server + '" ' +
			'jnsport="443" ' +
			'jnssecure="false" ' +
			'jnsapplication="' + app + '" ' +
			'jnsuser="' + user + '" ' +
			'jnspassword="' + pswd + '" ' +
			'jnsclassname="' + cls + '" ' +
		'> ' +
			'<NOEMBED> ' +
			'<strong> ' +
				'This browser does not have a Java Plug-in. ' +
				'<br /> ' +
				'<a href="http://java.sun.com/javase/downloads/index.jsp"> ' +
				'Get the latest Java Plug-in here. ' +
				'</a> ' +
			'</strong> ' +
			'</NOEMBED> ' +
		'</EMBED> ' +
	'</OBJECT>'
	);
}

function getJNSObject( idx, id )
{
	var embed = document.embeds[idx];

	if( embed )
	{
		return embed;
	}
	else
	{
		var elem = document.getElementById( id );
		if( elem )
			return elem;
	}

}

function start( idx, id )
{
	var embed = getJNSObject( idx, id )

	if( embed )
	{
		embed.start();
	}
	else
	{
		window.alert( 'Browser not supported.' );
	}
}

/*
	JNS GECKO PLUGIN INSTALATION
*/
agent = navigator.userAgent.toLowerCase();
is_gecko = agent.indexOf('gecko') != -1;
is_win = agent.indexOf('win') != -1;

function installed()
{
  var pls = navigator.plugins;

  for( i = 0; i < pls.length; i++ )
  {
    var pl = pls[i];

    if( pl.name.indexOf('JNS2.2') != -1 )
    {
      return true;
    }
  }

  return false;
}

function redirectGeckoPluginMissing()
{
  if( InstallTrigger.updateEnabled() )
  {
    if( !installed() || InstallTrigger.compareVersion('@accendia.com/JNetStart,version=2.2.0.1', 2,2,0,1) < 0 )
    {
	window.location.replace( "install_gecko_jns.html" );
    }
  }
  else
    alert('Software Installation not enabled.');
}

function installJNSPlugin()
{
   if (InstallTrigger.compareVersion('@accendia.com/JNetStart,version=2.2.0.1', 2,2,0,1) < 0)
   {
    InstallTrigger.install(
        {'Accendia JNetStart' : 'http://www.accendia.com/jnetstart2.2.xpi'},
        on_load_jnetstart );
   }
}

function on_load_jnetstart(url, status)
{
   var msg;
   switch( status )
   {
   case 0:
	msg =  'JNetStart has been successfully installed.';
	window.location.replace( "/index.html" );
	return;
   case 999:
      msg =  'Please restart the browser to complete JNetStart installation.';
      break;
   case -210:
      msg =  'JNetStart installation has been canceled by user.';
      break;
   default:
      msg =  'JNetStart installation has failed. Error code: ' + status;
   }

   alert(msg);
}
