/********************************************************************************************************/ 
/************************************ GLOBAL VAR ********************************************************/
/********************************************************************************************************/
// -------------------------- DECLARE ------------------------- //
// Applet variables
//Window size
var widthWindow;
var heightWindow;	

// It's an array that contains all applet <PARAM>
var arrParams;

// It's the name of the installer main class.
var nameInstallerMainClass;
// ------------------------------------------------------------ //

// --------------------------- INIT --------------------------- //
// Get the parent <DIV>
arrParams = new Array();

//Initialize
widthWindow = computeWidthWindow();
heightWindow = computeHeightWindow();

// Don't put brakets because we replace the default function of "window.onresize" with "computeWindowSize".
window.onresize = computeWindowSize;

// Initializes the installer's name.
nameInstallerMainClass = "mcd.installer.MCDInstaller";
if (nameInstallerMainClass == "Empty")
{
	alert("Installer main class is empty.");
}
// ------------------------------------------------------------ //

/********************************************************************************************************/ 
/*************************************** INFO ***********************************************************/
/********************************************************************************************************/
// Test if it's internet explorer
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

// Test if java is activated on the browser
if (navigator.javaEnabled() == false)
{
	alert("This page requires Java to be enabled");
}

//Add java detector
document.writeln('<div style="position:absolute; left:-1px; top:-1px;" id="divJavaDetector" name="divJavaDetector" >'); 
document.writeln('<APPLET code="ci.detector.java.CIJavaDetector" codebase="./APPLET/JAVA/" archive="CIJavaDetector.jar" width="1" height="1" id="javaDetector" name="javaDetector" mayscript>');
document.writeln('</APPLET>');
document.writeln('</div>');

// Add applet cedreo.
document.writeln('<div  style="position:absolute; left:0px; top:0px;" width="1" height="1" id="divAppletCedreo" name="divAppletCedreo">');
document.writeln('</div>');

/********************************************************************************************************/ 
/************************************** CREATE **********************************************************/
/********************************************************************************************************/ 
/**
 * This function allows to make a dynamic applet creation
 */
function createApplet()
{
	// --------------------------- DELETE ------------------------- //
	removeApplet();
	// ------------------------------------------------------------ //
	
	// Java detection
	if (javaDetection()==true)
	{
		// Starts wait.
		startWaitAppletCreation();
	
		// Applet creation.	
		addApplet();
	}
}

/**
 * Allows to wait applet creation.
 */
function startWaitAppletCreation()
{
	var javaDetect;
	// --------------------------- INIT --------------------------- //
	
	javaDetect = document.getElementById("javaDetector");
	javaDetect.startWaitAppletCreation();
}

/**
 * This function allows to detect if java exists.
 */
function javaDetection()
{
	var vDivDetect;
	var textNoJava, linkJava, textDownload;
	var javaDetect, javaVersion;
	var javaExists;
	// --------------------------- INIT --------------------------- //
	
	javaDetect = document.getElementById("javaDetector");
	
	javaExists = true;
	try
	{
		javaVersion = javaDetect.getVersion();
	}
	catch(pb)
	{
		javaExists = false;
	}
	
	if(javaExists==false)
	{
		// Create a dynamic <DIV>
		vDivDetect = document.createElement("div");
		vDivDetect.id="divDetect";
		vDivDetect.name="divDetect";
		
		//Create text no Java
		textNoJava = document.createTextNode("You need Java(tm) to view this presentation.");
	
		//Create link to download Java
		linkJava = document.createElement("A");
		linkJava.href = "http://www.java.com";
	
		//Create download text
		textDownload =  document.createTextNode("Download Java");
		
		//Add text no Java to the div applet
		vDivDetect.appendChild(textNoJava);

		//Add download text to the link
		linkJava.appendChild(textDownload);
	
		//Add link  to the div applet
		vDivDetect.appendChild(linkJava);
	
		// Add the <DIV> that is associated to the applet in the main div
		document.body.appendChild(vDivDetect);	
		
		return false;
	}
	
	return true;
}

/**
 * This function allows to add a dynamic applet
 */
function addApplet()
{	  	
   	var vDivApplet, vApplet, vDivParent;
	var count, index;
	// --------------------------- INIT --------------------------- //
	// Create a dynamic <DIV>
	vDivApplet = document.createElement("div");
	vDivApplet.id="divApplet";
	vDivApplet.name="divApplet";
	
	vApplet = document.createElement("applet");
	vApplet.setAttribute("code",nameInstallerMainClass);
 	vApplet.setAttribute("codebase","./APPLET/JAVA/");
	vApplet.setAttribute("archive","CIInstaller.jar"); 
	vApplet.setAttribute("name","CIApplet");
	vApplet.setAttribute("id","CIApplet");
	vApplet.setAttribute("width","1");
	vApplet.setAttribute("height","1");
	
	//Add applet to the <DIV> for applet	
	vDivApplet.appendChild(vApplet);

	// Add the <DIV> that is associated to the applet in the main div
	vDivParent = document.getElementById("divAppletCedreo"); 
	vDivParent.appendChild(vDivApplet);
}

/**
 * Remove an applet.
 */
function removeApplet()
{
	var vDivApplet, vApplet, vDivParent;
	// --------------------------- INIT --------------------------- //
	
	// Test if the "div" that contains the applet does already exist.
	vDivApplet = document.getElementById("divApplet");
	if (vDivApplet)
	{
		// If exist then delete we must remove the applet div from the page and its child
		vApplet = document.getElementById("CIApplet");
		vDivApplet.removeChild(vApplet);
		
		vDivParent = document.getElementById("divAppletCedreo"); 
		vDivParent.removeChild(vDivApplet);
	}
}
