/********************************************************************************************************/ 
/************************************ FUNCTIONS *********************************************************/
/********************************************************************************************************/
/**
 * Get relative "X" position of an object in the browser.
 * @param obj is the object's name that we want the position.
 */
function obtainAbsoluteX(nameObject)
{
	return obtainAbsoluteObjectPosition(nameObject, 'offsetLeft');
}

/**
 * Get relative "Y" position of an object in the browser.
 * @param nameObject is the object's name that we want the position.
 */
function obtainAbsoluteY(nameObject)
{
	return obtainAbsoluteObjectPosition(nameObject, 'offsetTop');
}

/**
 * Compute the window's width.
 */
function computeWidthWindow()
{
	if (window.innerWidth) 
	{
		if(document.documentElement.clientWidth != 0)
		{
			return document.documentElement.clientWidth;
		}		
		else
		{
			return  document.body.clientWidth;
		}
	}
 	else 
	{
		return document.documentElement.clientWidth;
	}

	return 0;
}

/**
 * Compute the window's height.
 */
function computeHeightWindow()
{
	if (window.innerWidth) 
	{
		if(document.documentElement.clientHeight != 0)
		{
			return document.documentElement.clientHeight;
		}		
		else
		{
			return  document.body.clientHeight;
		}
	}
 	else 
	{
		return document.documentElement.clientHeight;
	}

 	return 0;
}

/**
 * Compute the window's size.
 */
function computeWindowSize()
{
	var x, y, div;
	// --------------------------- INIT --------------------------- //
	
	widthWindow = computeWidthWindow();
	heightWindow = computeHeightWindow();
	
	try
	{
		x = obtainAbsoluteX("appletPosition");
		y = obtainAbsoluteY("appletPosition");
		div = document.getElementById(idDivApplet);
		
		div.style.left = x + "px";
		div.style.top = y + "px";
	}
	catch(pb)
	{
		
	}
}

/**
 * Obtain the x position of an object in order to be centered.
 * @param widthObj the object's width
 */
function obtainCenteredX(widthObj)
{
	return (computeWidthWindow() - widthObj) / 2;
}

/**
 * Obtain the y position of an object in order to be centered.
 * @param heightObj the object's height
 */
function obtainCenteredY(heightObj)
{
	return (computeHeightWindow() - heightObj) / 2;
}

/**
 * Get the relative position of an object compared with the top left corner of the browser.
 * @param nameObject is the object's name that we want to know the relative position.
 * @param offset is the type of position: Top, Left, Right, Bottom
 */
function obtainAbsoluteObjectPosition(nameObject, offset)
{
	var val;
	var obj;
	// --------------------------- INIT --------------------------- //
	
	val = 0;
	obj = document.getElementById(nameObject);
	
	// Get the oldest parent (So, the browser) in order to have the absolute position of the object.
	while (obj && (obj.tagName != 'BODY'))
	{
		val += eval('obj.' + offset);
		obj = obj.offsetParent;
	}
	
	return val;
}

/**
 * Add a <PARAM> in an array of param.
 * @param arrParams is the array of param.
 * @param name is the pram's name.
 * @param value is the value of the param markup.
 */
function putParam(arrParams, name, value) 
{
	arrParams[arrParams.length] = name;
	arrParams[arrParams.length] = value;
}

/**
 * Write all parameters of an array of param.
 * @param arrParams is the array that contains allf <PARAM> that we want to write.
 */ 
function printParameters(arrParams) 
{
	for (var i=0; i < arrParams.length; i=i+2) 
	{
		document.writeln('<param name="' + arrParams[i] + '" value="' + arrParams[i+1] + '">');
	}
}

/**
 * This function allows to add an attribute to a <PARAM ...> markup.
 * @param param is the param markup that we want to add the attribute.
 * @param nameAttribute is the attribute's name.
 * @param valueAttribute is the attribute's value.
 */
 function addAttribute(param, nameAttribute, valueAttribute)
 {
 	param.setAttribute("name", nameAttribute);
	param.setAttribute("value", valueAttribute);
 }

/**
 * Put the applet at the  correct position.
 * @param divAppletName is the name of the div that contains the applet.
 * @param nameObjRef is the name of object that is the reference for the applet position.
 */
function doLayout(nameDivApplet, nameObjRef)
{
	var vDivApplet;
	// --------------------------- INIT --------------------------- //
	
	// Create a dynamic <DIV> that contains the applet
	vDivApplet = document.getElementById(nameDivApplet);
	vDivApplet.style.position="absolute";
	vDivApplet.style.left=obtainAbsoluteX(nameObjRef) + "px";
	vDivApplet.style.top=obtainAbsoluteY(nameObjRef) + "px";
}
