/********************************************************************************************************/ 
/************************************ 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";
}

/**
 * Allows to manage a map of parameter.
 */
function CIMapParameter()
{
    var m_arrKey = new Array();
    var m_arrValue = new Array();
    
    /**
     * Allows to add a parameter.
     * @param p_key is the parameter key.
     * @param p_value is the parameter value.
     */
    this.addParameter = function(p_key, p_value)
    {
        // -------------------------- DECLARE --------------------------//
        
        if ((typeof p_key == "string") == false || (typeof p_key == "string") == false)
        {
            return;
        }
        
        m_arrKey.push(p_key);
        m_arrValue.push(p_value);
    }
    
    /**
     * Returns a string representation of map.
     * @return Returns a string representation of map.
     */
    this.convertToString = function()
    {
        var str;
        var size, end;
        // -------------------------- DECLARE --------------------------//
        
        size = m_arrKey.length
        end = size - 1;
        for (i=0; i<size; i++)
        {
            str += m_arrKey[i] + "=" + m_arrValue[i];
           
            if (i < end)
            {
                str += "|";  
            }
        }
        
        return str;
    }
    
    /**
     * Allows to print object.
     */
    this.toString = function()
    {
        var size;
        // -------------------------- DECLARE --------------------------//
        
        size = m_arrKey.length
        for (i=0; i<size; i++)
        {
            alert("KEY= " + m_arrKey[i] + "\tVALUE: " + m_arrValue[i]);
        }
    }   
}

/**
 * Allows to manage parameters.
 */
function CIArrParameter()
{
	var m_arrParameter = new Array();
	
	/**
	 * Allows to add a parameter.
	 * @param p_parameter is the parameter to add.
	 */
	this.addParameter = function(p_parameter)
	{
		// -------------------------- DECLARE --------------------------//
		
		if ((typeof p_parameter == "string") == false)
		{
			return;
		}
		
		m_arrParameter.push(p_parameter);
	}
	
	/**
	 * Allows to print object.
	 */
	this.toString = function()
	{
		// -------------------------- DECLARE --------------------------//
		
		for (i=0; i<m_arrParameter.length; i++)
		{
			alert(m_arrParameter[i]);
		}
	}	
	
	/**
	 * Returns parameter's array.
	 * @return  Returns parameter's array.
	 */
	this.getArrParameter = function()
	{
		return m_arrParameter;
	}
}
 
/**
 * Adds array of specific parameter to applet.
 * @param p_applet is the applet to add parameter.
 * @param p_parameterObject is the array of specific parameter to add to applet.
 */
function addArrParameterSpecificToApplet(p_applet, p_parameterObject)
{
	var size;
	var arrParameter;
	// -------------------------- DECLARE --------------------------//
	
	// Tests if the parameter has the good type.
	if (obtainClass(p_parameterObject).indexOf("CIArrParameter") == -1)
	{
		alert("Invalid type of parameter into 'startAppletWithArrParameterSpecific()'");
		return
	}
	
	// Creates list of parameter.
	arrParameter = p_parameterObject.getArrParameter();
	size = arrParameter.length;
	for (i=0; i<size; i++)
	{
		if (typeof arrParameter[i] == "string")
		{
			p_applet.addParameterSpecific(arrParameter[i]);
		}
	}
}
