/*ardoraPaquete.js, created by ARDORA www.webardora.net

Copyright (C) <2011>  <José Manuel Bouzán M.>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

var indice, indiceMul, taboaContidos, maxIndice, menuLateral, menuActividades, anchoContidoIni,horaInicio, taboaIntentos;
var startDate;
function inicia(){
   var data=new Date();
   if (data.getMinutes()<10){horaInicio=data.getHours() +":0"+data.getMinutes()+" h";}
   else{horaInicio=data.getHours() +":"+data.getMinutes()+" h";}
   taboaIntentos=new Array();
   menuLateral='';
   menuActividades='';
   if (window.opener == null){
      indice=0;
      }else{
      if (window.opener.indice == null){
         indice=0;
      }else{
         indice=window.opener.indice;
      }
   }
   maxIndice=5;
	taboaContidos=new Array();
taboaContidos[0]=new act("Relaciona imaxes-reino1","Relaciona imaxes-reino1","<b>Tes que clasificar o ser vivo que aparece na imaxe nalg&#250;n dos tres reinos que aparecen. Para iso clica no recadro do reino ao que pertence",'<APPLET code="ArdoraCImaxes.class" archive = "Clasific5reinos_1.jar"  width=730 height=330 MAYSCRIPT></APPLET>',false,"",true,false,false);
taboaContidos[1]=new act("Relaciona imaxes-reino2","Relaciona imaxes-reino2","<b>Clasifica as imaxes nalg&#250;n dos tres Reinos que aparecen. Para iso clica no recadro do reino &#225; que pertence. Coidado pois s&#243; tes permitidos 2 fallos",'<APPLET code="ArdoraCImaxes.class" archive = "Clasific5reinos_2.jar"  width=730 height=330 MAYSCRIPT></APPLET>',false,"",true,false,false);
taboaContidos[2]=new act("Relaciona imaxes-reino3","Relaciona imaxes-reino3","<b>Clasifica as imaxes nalg&#250;n dos tres Reinos que aparecen. Para iso, clica no recadro do reino &#225; que pertence. Coidadado, s&#243; tes permitidos dous fallos",'<APPLET code="ArdoraCImaxes.class" archive = "Clasific5reinos_3.jar"  width=730 height=330 MAYSCRIPT></APPLET>',false,"",true,false,false);
taboaContidos[3]=new act("Clasifica imaxes-reino xral.","Clasifica imaxes-reino xral.","<b>Mo ve o texto ata a imaxe que lle corresponda",'<APPLET code="ArdoraAlbum.class" archive = "repaso5reinos.jar"  width=712 height=320 MAYSCRIPT></APPLET>',false,"",true,false,false);
taboaContidos[4]=new act("Partes dos bri&#243;ns","Partes dos bri\u00F3ns","<b>Escribe as partes dun bri&#243;n",'<APPLET code="ArdoraPanelE.class" archive = "panelgrafico_musgos.jar"  width=900 height=585 MAYSCRIPT></APPLET>',false,"",true,false,false);
taboaContidos[5]=new act("Caracter&#237;sticas dos 5 Reinos","Caracter\u00EDsticas dos 5 Reinos","Relaciona cada Reino coas s&#250;as caracter&#237;sticas. Para iso tes que ir elixindo reino ou caracter&#237;sticas coas frechas superiores ou inferiores. Cando esteades seguros clicada na interrogaci&#243;n.<br>Tam&#233;n aparece a opci&#243;n das excepci&#243;ns, as&#237; que tes que relacionar con alg&#250;n ser cunha estrutura que non encaixa na clasificaci&#243;n dos 5 Reinos dos seres vivos",'<APPLET code="ArdoraRFrases.class" archive = "relaciona_caract_5reinos.jar"  width=720 height=330 MAYSCRIPT></APPLET>',false,"",true,false,false);
document.getElementById("botonAdiante").href="javascript:avanza()";
document.getElementById("botonAtras").href="javascript:retrocede()";
document.getElementById("botonAxuda").target="_blank";
anchoContidoIni=document.getElementById("areaContido").style.width;
if (doLMSGetValue( "cmi.core.lesson_status" ) == "not attempted"){
   doLMSSetValue( "cmi.core.lesson_status" , "incomplete");
   startDate = new Date().getTime();
   doLMSCommit();
}
   actualiza();
}
function actualiza(){
   document.getElementById("tituloAct").innerHTML=taboaContidos[indice].descricion;
   document.getElementById("enunciadoAct").innerHTML=taboaContidos[indice].enunciado;
   document.getElementById("contidoAct").innerHTML=taboaContidos[indice].areaContido;
   document.getElementById("botonAdiante").style.visibility="hidden";
   document.getElementById("botonAtras").style.visibility="hidden";
   document.getElementById("botonAxuda").style.visibility="hidden";
   if (eval(document.getElementById("menu")) != null){document.getElementById("menu").style.visibility="hidden";}
   if (taboaContidos[indice].seg_ant){
      if (indice>0){
         document.getElementById("botonAtras").title=taboaContidos[indice-1].descricionUTF8;
         document.getElementById("botonAtras").style.visibility="visible";
      }
      if (indice<maxIndice){
         document.getElementById("botonAdiante").title=taboaContidos[indice+1].descricionUTF8;
         document.getElementById("botonAdiante").style.visibility="visible";
      }
   }
   if (taboaContidos[indice].mp){
      document.getElementById("menuPrincipal").style.visibility="visible";
   }
   else{
      document.getElementById("menuPrincipal").style.visibility="hidden";
   }
   if (taboaContidos[indice].bAxuda.length>0){
      document.getElementById("botonAxuda").href=taboaContidos[indice].bAxuda;
      document.getElementById("botonAxuda").style.visibility="visible";
   }
   if ((taboaContidos[indice].ml) || (taboaContidos[indice].ma)){
	   contido="";
	   document.getElementById("menu").style.height="auto";
      document.getElementById("areaContido").style.width=anchoContidoIni;
	   if (taboaContidos[indice].ml){ contido=menuLateral;}
	   if (taboaContidos[indice].ma){ contido=contido+menuActividades;}
	   document.getElementById("menu").innerHTML=contido;
	   document.getElementById("menu").style.visibility="visible";
   }
   else{
        if (eval(document.getElementById("menu")) != null){document.getElementById("menu").style.height="0px";}
        document.getElementById("areaContido").style.width="100%";
   }
doLMSSetValue( "cmi.core.lesson_location" , taboaContidos[indice].descricion);
var puntos=dameTotal();
if (puntos>10) {doLMSSetValue( "cmi.core.lesson_status" , "passed");}
else{doLMSSetValue( "cmi.core.lesson_status" , "failed");}
doLMSSetValue( "cmi.core.score.raw",puntos+"");
doLMSCommit();
}
function avanza(){
   if (indice<maxIndice){
      indice++; actualiza();
   };
}
function irA(num){
      indice=num; actualiza();
}
function recarga(){
      irA(indice);
}
function retrocede(){indice--; actualiza();}
function act( descricion, descricionUTF8, enunciado, areaContido,ma, bAxuda, seg_ant, mp, ml ) {
   this.descricion=descricion;
   this.descricionUTF8=descricionUTF8;
   this.enunciado=enunciado;
   this.areaContido=areaContido;
   this.mp=mp;
   this.ml=ml;
   this.ma=ma;
   this.seg_ant=seg_ant;
   this.bAxuda=bAxuda;
   }
function iniciaActividade(){
   var data=new Date();
   if (data.getMinutes()<10){var hI=data.getHours() +":0"+data.getMinutes();}
   else{var hI=data.getHours() +":"+data.getMinutes();}
   var x=taboaIntentos.length;
   taboaIntentos[x]=new infoAct(indice,hI,0,"exec","xx:xx",0);
}
function iniciaActividadeMul(){
   indiceMul=indice;
   var data=new Date();
   if (data.getMinutes()<10){var hI=data.getHours() +":0"+data.getMinutes();}
   else{var hI=data.getHours() +":"+data.getMinutes();}
   var x=taboaIntentos.length;
   taboaIntentos[x]=new infoAct(indice,hI,0,"exec","xx:xx",0);
}
function infoAct( ind, hinicio, intentos, estado, hfin, puntos){
	this.ind=ind;
	this.hinicio=hinicio;
	this.intentos=intentos;
	this.estado=estado;
	this.hfin=hfin;
	this.puntos=puntos;
}
function actualizaInfoAct(puntos,intentos,estado){
	var data=new Date();
   if (data.getMinutes()<10){var hF=data.getHours() +":0"+data.getMinutes();}
   else{var hF=data.getHours() +":"+data.getMinutes();}
	var x=taboaIntentos.length-1;
	var hI=taboaIntentos[x].hinicio;
	taboaIntentos[x]=new infoAct(indice,hI,intentos,estado,hF,puntos);
}
function actualizaInfoActMul(){
	var data=new Date();
   if (data.getMinutes()<10){var hF=data.getHours() +":0"+data.getMinutes();}
   else{var hF=data.getHours() +":"+data.getMinutes();}
	var x=taboaIntentos.length-1;
	var hI=taboaIntentos[x].hinicio;
	taboaIntentos[x]=new infoAct(indiceMul,hI,0,"--",hF,0);
}
function PechaVentana(){window.close()}
function AbreCentrada(theURL,winName,features, myWidth, myHeight, isCenter,aNume) {
	if(window.screen)if(isCenter)if(isCenter=="true"){
      var myLeft = (screen.width-myWidth)/2;
      var myTop = (screen.height-myHeight)/2;
      features+=(features!='')?',':'';
      features+=',left='+myLeft+',top='+myTop;
    }
    window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
    indice=aNume;
}
function mostrar(capa){
var obj = document.getElementById(capa)
if(obj.style.display == "block"){
   obj.style.display = "none"
   document.getElementById("contenido").style.width="95%";
}else{
   obj.style.display = "block";
   document.getElementById("contenido").style.width="75%";
}}
function MM_preloadImages() {
   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() {var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
function MM_findObj(n, d) { //v4.01
   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
window.onunload = function() {
   var formattedTime = "00:00:00.0";
   if ( startDate != 0 ){
      var currentDate = new Date().getTime();
      var elapsedSeconds = ( (currentDate - startDate) / 1000 );
      formattedTime = convertTotalSeconds( elapsedSeconds );
   }
   var puntos=dameTotal();
if (puntos>10) {doLMSSetValue( "cmi.core.lesson_status" , "passed");}
else{doLMSSetValue( "cmi.core.lesson_status" , "failed");}
   doLMSSetValue( "cmi.core.score.raw",puntos+"");
   doLMSSetValue("cmi.core.session_time",formattedTime);
   doLMSFinish();
}
function convertTotalSeconds(ts){
   var Sec = (ts % 60); ts -= Sec; var tmp = (ts % 3600); ts -= tmp;
   if ( (ts % 3600) != 0 ) var Hour = "00" ;
   else var Hour = ""+ (ts / 3600);
   if ( (tmp % 60) != 0 ) var Min = "00";
   else var Min = ""+(tmp / 60);
   Sec=""+Sec
   Sec=Sec.substring(0,Sec.indexOf("."))
   if (Hour.length < 2)Hour = "0"+Hour;
      if (Min.length < 2)Min = "0"+Min;
      if (Sec.length <2)Sec = "0"+Sec;
         var rtnVal = Hour+":"+Min+":"+Sec;
         return rtnVal;
}
function dameTotal(){
  var cantos=0;
  for (z=0;z<6;z++){
     cantos=cantos+parseInt(damePuntuacion(z));
}
return cantos;
}
function damePuntuacion(num){
   var cantos=0;
   for (i=0;i<taboaIntentos.length;i++){
      if (parseInt(taboaIntentos[i].ind)==num){cantos=taboaIntentos[i].puntos;}
   }
   return cantos;
}
