﻿//---------------------------------------------
//	ACTIVITY FUNCTIONS
//---------------------------------------------

function validateNumber(_str)
{
    var _exp = new RegExp(/^\d+$/);
    var _test=_exp.test(_str);
    return(_test);
}

function objAct()
{
	
	// Configuration Properties
	this.width				= 685;  // Size of the SWF
	this.height				= 428;
	
	// Activity properties
	this.id					= "";	// activity ID. E.g. "ca11t1s1a1"
	this.path 				= "";	// path to the SWF file
	
	this.version            = "8.0.0";  // Version de Flash Requerida
	this.background         = "#FFFFFF"; // Color de fondo de la pelicula
	this.useExpressInstall  = true;  // Usar Express Install para actualizar la version de Flash
	this.homeURL			= ""
	
	this.lcId				= new Date().getTime();
	this.proxy              = "javascript/JavaScriptFlashGateway.swf";
	this.grabadora			= false;
	this.timeout			= 5;    // The "timeout" parameter is used to control how many seconds must wait the activity
	                                // until the recorder is loaded, before continuing with its loading.
	
	this.tieneGrabadora		= new Array(2,29,52,55,66,80,91,99,107,109,116,117,127,128)
}

/*
 * Inicialización de parámetros 
 */
objAct.prototype.init = function()
{
	var qs;
	var qs = new Querystring();
	
	url = new String(document.URL)
	this.homeURL = url.slice(0, url.indexOf("?"))
	
	this.id = qs.get("id");
	this.grabadora = this.checkRecorder();
}

/*
 * Carga de la Actividad
 */
objAct.prototype.load = function()
{
	var container = document.getElementById("flashcontent");
	
	if(this.id && validateNumber(this.id))
	{
		this.path = "actividad_" + this.id + ".swf"
		this.putFlash();
		container.style.visibility = "visible";
	}
	else
		alert("error en el paso de parámetros")
}

/**
*	Llamada para navegar a la actividad indicada
*/
objAct.prototype.abrirActividadAveteca = function(id) {
	document.location = "?id=" + id;
}

/**
*	Llamada para navegar al video indicado
*/
objAct.prototype.abrirVideo = function(video) {
	var videoFrame = document.getElementById("video")
	videoFrame.src = video;
}

/*
 * Comprobación de la grabadora
 */
objAct.prototype.checkRecorder = function()
{
	for(a in this.tieneGrabadora)
		if(parseInt(this.id) == this.tieneGrabadora[a])
			return true;

	return false;		
}

/*
*	Function to include the flash movie in the HTML page
*/
objAct.prototype.putFlash = function ()
{
    var fo = new SWFObject(this.path, "peli", this.width, this.height, this.version, this.background, this.useExpressInstall);
    
	fo.addParam("allowScriptAccess", "sameDomain")
	fo.addParam("quality", "best");
	
	//fo.addVariable("grabadora", this.grabadora);
	//fo.addVariable("lcId", this.lcId);
	//fo.addVariable("timeout", this.timeout);
	
	// Explorer. Para que el tabulador no se salga del Flash
	fo.addParam("SeamlessTabbing", "false");
	fo.addParam("menu", "false");
	fo.setAttribute('xiRedirectUrl', this.homeURL + "?id=" + this.id);
			
	fo.write("flashcontent");
}

/*
 * Funcion para incluir la grabadora
 */
objAct.prototype.putRecorder = function()
{
	if(this.checkRecorder())
	{
		str = '<div style="visibility:hidden">'
		str +=	'<applet' 
		str +=	'	id="idgrabadora"' 
		str +=	'	code="es.ua.virtua.RecorderApplet" '
		str +=	'	archive="recorder.jar, commons-logging.jar"' 
		str +=	'	width="0" height="0" mayscript>'
		str +=	'	<PARAM NAME="target" VALUE="memory" >'
		str +=	'	<PARAM NAME="showgui" VALUE="hidden" >'
		str +=	'	<PARAM NAME="enableJSCallback" VALUE="false" >'
		str +=	'</applet>'
		str +='</div>'
		
		document.write(str);
	}
}
