var serveur;
var leBiscuit;
var RACINE_stage;
var sysFich=null;
var FICH_PARCOURS="";
var lesson_mode="normal";
var modeTentative="";
var parcoursEnregistre=false;
var activiteUnique=false;
var SUR_CHORUS=false;
var SUR_CHORUS_ADM=false;
var RACINE_MOS;
var STYLE_INTERFACE;
var RACINE_XSL;
var RACINE_STYLES;
var RACINE_STYLE;
var LISTE_L="";
var LISTE_BL="";
var PLAN_DROIT=false;
var MENU_BAS=false;
window.onbeforeunload=LMS_veutQuitter;
var depuisFenGNR=false;

function LMS_init(version){
	serveur=new LMSLocal();
	serveur.init(version);
	try {
		// exception sur Firefox
		if (window.opener!=null&&window.opener.top.liste!=null&&window.opener.top.liste.DOMArbo!=null){
			lesson_mode="browse";
			depuisFenGNR=true;
		}
	} catch(e){}
	var strLoc=window.location.href;
	var indexD=strLoc.lastIndexOf("index.htm");
	if (indexD<0){indexD=strLoc.lastIndexOf("start.hta");}
	if (indexD<0 && strLoc.indexOf(".htm")<0 && strLoc.substring(strLoc.length-1)=="/"){
		// dossier sans index
		indexD=strLoc.length;
	}
	if (indexD>0){
		RACINE_stage=strLoc.substring(0,indexD);
		// retrouve le bon codeStage
		var refCods=RACINE_stage.substring(0,RACINE_stage.length-1);
		var indeB=refCods.lastIndexOf("/");
		serveur.codeStage=refCods.substring(indeB+1);
		RACINE_STYLE=RACINE_stage+"MosMtr/ressources/style/";
		RACINE_XSL=RACINE_STYLE+"xsl/local/";
		var depuisFen=false;
		if (!depuisFenGNR){
			try {
				if (window.opener!=null){
					depuisFen=true;
				}
			} catch(e){}
		}		
		if (depuisFenGNR||depuisFen){
			try{
				if (FEN_X!='' && FEN_Y!=''){ 
					FEN_X=Number(FEN_X);
					if (FEN_X<0){FEN_X=window.screen.width+FEN_X;} 
					FEN_Y=Number(FEN_Y);
					if (FEN_Y<0){FEN_Y=window.screen.height+FEN_Y;}	
					if (!isNaN(FEN_X)&&!isNaN(FEN_Y)){
						window.moveTo(FEN_X,FEN_Y);
					}			
				}
				if (FEN_L!=''&&FEN_H!=''){ 
					FEN_L=Number(FEN_L);
					if (FEN_L<0){FEN_L=window.screen.width+FEN_L;}
					FEN_H=Number(FEN_H);
					if (FEN_H<0){FEN_H=window.screen.height+FEN_H;}				
					if (!isNaN(FEN_L)&&!isNaN(FEN_H)&&FEN_L>0&&FEN_H>0){
						if (FEN_L>window.screen.width){FEN_L=window.screen.width;}
						if (FEN_H>window.screen.height){FEN_H=window.screen.height-25;}
						window.resizeTo(FEN_L,FEN_H);
					}
				}
				if (depuisFenGNR){
					serveur.vMos_prenom=window.opener.top.menu.prenomCMI;
					serveur.vMos_nom=window.opener.top.menu.nomCMI;
				} else {
					serveur.vMos_prenom=window.opener.prenom;
					serveur.vMos_nom=window.opener.nom;
				}			
			}catch(e){}
		}
		var cadres = document.getElementById("frame2");	
		if (cadres.cols.indexOf("*,")==0){
			PLAN_DROIT=true;
		}
	} else {
		var indSrv=strLoc.toLowerCase().lastIndexOf("/mossrv/");
		if (indSrv>0 && strLoc.indexOf("/lms")>0){
			SUR_CHORUS=true;
			var pStage;
			var echecCNX=true;
			var pId=donneParam("idk");
			if (pId!=""){
				pId=PF_decrypte(pId);
			} else {
				pId=donneParam("id");
			}
			serveur.vMos_id=pId;
			var pStage=donneParam("stk");
			if (pStage!=""){
				pStage=PF_decrypte(pStage);
			} else {
				pStage=donneParam("stg");
			}
			RACINE_MOS=strLoc.substring(0,indSrv)+"/";
			serveur.codeStage=pStage;
			serveur.vMos_lang=donneParam("lang");
			if (serveur.vMos_lang==""){serveur.vMos_lang="en";}
			STYLE_INTERFACE=donneParam("style");
			if (STYLE_INTERFACE==""){STYLE_INTERFACE="standard";}
			RACINE_STYLES=RACINE_MOS+"MosData/MosStyleMgr/styles/";
			RACINE_STYLE=RACINE_STYLES+STYLE_INTERFACE+"/";
			RACINE_XSL=RACINE_STYLE+"xsl/";
						
			if (pId=="_adminvsr" && top.opener && top.opener.top.haut && top.opener.top.serveur){
				lesson_mode="browse";
				SUR_CHORUS_ADM=true;
				serveur.vMos_nom=top.opener.top.serveur.nom;
				serveur.vMos_prenom=top.opener.top.serveur.prenom;
			} else if (pId=="_thumbnail"){
				lesson_mode="browse";
			} else {
				try {
					if (window.opener!=null){
						if (window.opener.valProfil){
							serveur.vMos_nom=window.opener.valProfil("lastName");
							serveur.vMos_prenom=window.opener.valProfil("firstName");
						} else if (window.opener.top.serveur){
							serveur.vMos_nom=window.opener.top.serveur.vMos_nom;
							serveur.vMos_prenom=window.opener.top.serveur.vMos_prenom;
						}
						if (serveur.vMos_nom!="" && window.opener.oProfil.childNodes.length>0){
							echecCNX=false;
						}
					}
				} catch(e){}
				if (echecCNX){
					if (genereIdSession().substring(3)==donneParam("atn").substring(3)){
						echecCNX=false;
					} else {
						initBiscuit();
						if (leBiscuit.mpk=="" && pId.indexOf("_u")==0){
							// depuis connexion anonym
							leBiscuit.mpk=PF_crypte("no");
							leBiscuit.idUtil="";
							leBiscuit.enregistrer();	
						}
						if (leBiscuit.mpk!=""){
							if (authentifierLMS(pId,leBiscuit.mpk)){echecCNX=false;}
						}
						if (echecCNX){
							IU_chargerLangue(serveur.vMos_lang);
							// demander le mot de passe ?
							var nlex=donneLex(402);
							nlex=nlex.replace("USER_ID",pId);
							var nMotPasse=prompt(nlex,"");
							if (nMotPasse!=null && nMotPasse!=""){
								var mpK0=PF_crypte(nMotPasse);
								if (authentifierLMS(pId,mpK0)){
									echecCNX=false;
									leBiscuit.mpk=mpK0;
									leBiscuit.enregistrer();
								}
							}
						}
					}
				}
				if (echecCNX){serveur.codeStage="";alert(donneLex(4));return false;}
				var pGroupe=donneParam("grk");
				if (pGroupe!=""){
					pGroupe=PF_decrypte(pGroupe);
				} else {
					pGroupe=donneParam("grp");
				}
				serveur.codeGroupe=pGroupe;
			}
			if (pStage.indexOf("[_MOSLCMS]")==0){
				pStage=pStage.substring(10);
				lesson_mode="browse";
				activiteUnique=true;
			}
			if (strLoc.indexOf("rv/lmsB")>0){
				MENU_BAS=true;
			}
			RACINE_stage=RACINE_MOS+"MosPub/"+pStage+"/";
			if (strLoc.indexOf("D.html?")>0){
				PLAN_DROIT=true;
			}
			var dispCdr=donneParam("dispCdr").split(",");
			if (dispCdr.length>2){
				LISTE_L=dispCdr[1];	
				LISTE_BL=dispCdr[2];
				dimCadres(dispCdr[0],LISTE_L);	
			}
		}
	}
	if (!SUR_CHORUS){
		var csync=donneParam("sync");
		if (csync!=""){
			indeB=refCods.lastIndexOf("/MosPub/");
			if (csync=="1"){
				// lien depuis mos synchro
				FICH_PARCOURS=refCods.substring(0,indeB)+"/MosData/player/parc/"+serveur.codeStage+".xml";
				FICH_PARCOURS=FICH_PARCOURS.replace(/file:\/\/\//,'');
				FICH_PARCOURS=FICH_PARCOURS.replace(/\//g,"\\");
				FICH_PARCOURS=unescape(FICH_PARCOURS);
				
				try {sysFich=window.opener.mosUTF;}catch(e){sysFich=null;}
			} 
			if (csync=="2"){
				// lien depuis mos gnr
				lesson_mode="normal";
				FICH_PARCOURS=refCods.substring(0,indeB)+"/MosData/MosGnr/parc/"+serveur.codeStage+".xml";
			}		
		}
	}
	if (tabLex==null){IU_chargerLangue(serveur.vMos_lang);}
	if (serveur.codeStage!=""){
		API_1484_11=new APIAdapter();
		if (SUR_CHORUS){
			window.planLMS.location="plan.html";
		} else {
			window.planLMS.location="MosMtr/gen/plan.html";
		}
	}
}
function LMS_quitter(){	
	if (API_1484_11==null){return ;}
	if (window.planLMS.itemCourant!=null && !serveur.parcoursEnAttente){
		window.planLMS.MODE_PREEMPTIF=false;
		// suspend que si besoin
		var req="abandonAll";
		if (planLMS.masqueSuspendre){req="exitAll";}
		if (planLMS.masqueSortie){req="suspendAll";}
		window.planLMS.overallSequencing(req);	
	}
} 
function LMS_persisteParcours(asynchrone,enrTentative){
	if (lesson_mode!="normal" && (!enrTentative || modeTentative=="aucune") && !persisteSSP){return false;}
	if ((FICH_PARCOURS!=""||(SUR_CHORUS&&!SUR_CHORUS_ADM)) && !parcoursEnregistre){
		remonterTempsTot();
		var oRacMan=planLMS.DOMManifest.documentElement;
		var oPersiste=oRacMan.cloneNode(true);
		// nettoie severe		
		oPersiste.removeAttribute("version");
		oPersiste.setAttribute("codeStage",serveur.codeStage);		
		oPersiste.setAttribute("codeInscription",serveur.codeInscription);
		oPersiste.setAttribute("idU",serveur.vMos_id);
		if (SUR_CHORUS){
			oPersiste.setAttribute("modeTentative",modeTentative);
			oPersiste.setAttribute("codeGroupe",planLMS.codeGroupeParc);
			oPersiste.setAttribute("depuisChorus","oui");
			// les evts de dates sont faits par le serveur
			oPersiste.removeAttribute("dateCompletion");
			oPersiste.removeAttribute("dateValidation");
			oPersiste.removeAttribute("dateEntre");
			oPersiste.removeAttribute("dateAcces");
			oPersiste.removeAttribute("evtCompletion");
			oPersiste.removeAttribute("evtValidation");
		}
		// alert(oPersiste.xml);
		var orga=XML_premierNoeud(oPersiste,"organization");
		var oAlocGlo=XML_fils(oPersiste,"allocationsGlobales");
		if (oAlocGlo!=null){
			if (oAlocGlo.firstChild){
				if (SUR_CHORUS){
					var oAllocV=XML_trouveNoeud(oAlocGlo,"allocation","modif","non");
					while (oAllocV!=null){
						oAllocV.parentNode.removeChild(oAllocV);
						oAllocV=XML_trouveNoeud(oAlocGlo,"allocation","modif","non");	
					}
				}
				// marquer modif sur les vrais
				var oAllocV=XML_trouveNoeud(planLMS.allocationsGlobales,"allocation","modif","oui");
				while (oAllocV!=null){
					oAllocV.setAttribute("modif","non");
					oAllocV=XML_trouveNoeud(planLMS.allocationsGlobales,"allocation","modif","oui");	
				}
			}
			if (!oAlocGlo.firstChild){oPersiste.removeChild(oAlocGlo);}
		}
		// alert(orga.xml);
		if (lesson_mode!="normal"){
			// seulement la tentative
			orga.parentNode.removeChild(orga);
			oPersiste.setAttribute("enregistreParcours","non");
		} else {
			nettoieItem(orga);
			var oSupp=XML_premierNoeudNS(orga,"imsss","minNormalizedMeasure");
			while (oSupp!=null){
				oSupp.parentNode.removeChild(oSupp);
				oSupp=XML_premierNoeudNS(orga,"imsss","minNormalizedMeasure");
			}
			oSupp=XML_premierNoeudNS(orga,"imsss","mapInfo");
			while (oSupp!=null){
				oSupp.parentNode.removeChild(oSupp);
				oSupp=XML_premierNoeudNS(orga,"imsss","mapInfo");
			}
			var ltitre=XML_fils(orga,"title");
			if (ltitre!=null){
				orga.removeChild(ltitre);	
			}
			var ressourcesTmp=XML_premierNoeud(oPersiste,"resources");
			if (ressourcesTmp!=null){
				ressourcesTmp.parentNode.removeChild(ressourcesTmp);	
			}
			var oCont=XML_fils(oPersiste,"objectifsGlobaux");
			if (oCont!=null){
				var tObj=oCont.firstChild;
				while (tObj!=null){
					var osuiv=tObj.nextSibling;
					if (SUR_CHORUS){
						if (PF_attr(tObj,"modification")!="true"){
							tObj.parentNode.removeChild(tObj);	
						}
					}
					tObj=osuiv;
				}
			}
			if (!oCont.firstChild){oPersiste.removeChild(oCont);}
		}
		var gardeReponses=XML_fils(oRacMan,"gardeReponses");
		
		
		oPersiste.removeAttribute("xmlns:adlnav");		
		oPersiste.removeAttribute("xmlns:xsi");		
		
		var resXML=serialiserXML(oPersiste);
		// alert(resXML);

		if (SUR_CHORUS){
			cibleASP=RACINE_MOS+"MosSrv/aspx/SRV_parcours.aspx";
			if (asynchrone){
				parcoursEnregistre=true;
				persisteSSP=false;
				SYS_lancerOperations(resXML,true);
			} else {			
				var oRetour=SYS_lancerOperationsRetour(resXML,"enregistrerParcours");
				if (oRetour!=null && XML_texteNoeud(oRetour)=="OK"){
					parcoursEnregistre=true;
					persisteSSP=false;
				}
			}
			if (parcoursEnregistre){
				// supprimer le garde reponses
				var gardeReponses=XML_fils(oRacMan,"gardeReponses");
				if (gardeReponses!=null){
					gardeReponses.parentNode.removeChild(gardeReponses);
				}
				var oRacRet=planLMS.DOMManifest.documentElement;				
				if ((planLMS.modeExploration=="valide" && PF_attr(oRacRet,"etatValidation")=="true") || (planLMS.modeExploration=="complete" && PF_attr(oRacRet,"etatParcours")=="completed")){
					lesson_mode="review";
				}
				try {
					if (window.opener && window.opener.oZoneContenu!=null){
						window.opener.IU_majParcoursAffiche(serveur.codeStage,PF_attr(oRacRet,"etatParcours"),PF_attr(oRacRet,"etatValidation"));
					}
				}catch(e){}
			}
		} else {
			var loca=FICH_PARCOURS;
			if (depuisFenGNR){
				window.opener.top.menu.GTR_enregistrerParcoursAuteur(resXML);
				parcoursEnregistre=true;
				persisteSSP=false;
			} else {
				if (!estMoz){
					// add loc
					if (sysFich==null){
						sysFich=new ActiveXObject("MOSUTF.ctlConvert");
					}
					if (sysFich!=null){
						sysFich.createUTF8File(resXML,loca,false);
						parcoursEnregistre=true;
						persisteSSP=false;
						try{
							window.opener.ATR_retourParc(serveur.codeStage);
						}catch(e){}
					}	
				} else {
					alert("Can't save progress information with Mozilla Firefox.");	
				}
			}
		}
		if (parcoursEnregistre && SUR_CHORUS){
			// nettoyer les objs modifi
			var oCont=XML_fils(oRacMan,"objectifsGlobaux");
			if (oCont!=null){
				var oExisteObjMod=XML_trouveNoeud(oCont,"objectif","modification","true");
				while (oExisteObjMod!=null){
					oExisteObjMod.removeAttribute("modification");
					oExisteObjMod=XML_trouveNoeud(oCont,"objectif","modification","true");
				}
			}
		}	
	}
}                      

function LMS_modePleinEcran(){
	window.moveTo(0,0);
	window.resizeTo(window.screen.width,window.screen.height);
}
function LMS_masquerCadres(){
	try {
		window.planLMS.document.getElementsByTagName("html")[0].style.display="none";
		window.haut.document.getElementsByTagName("html")[0].style.display="none";	
		window.planLMS.document.body.style.display="none";
		window.haut.document.body.style.display="none";
		if (window.opener==null){
			dimCadres(0,0);
		}		
	} catch(e){}
}
function LMS_fermer(){
	LMS_masquerCadres();
	API_1484_11=null;
	if (passeParVeutQuitter){return ;}
	if (donneParam("hrq")!=""){
		// depuis lancement direct	
		window.location=RACINE_MOS+"MosSrv/index.htm?id="+serveur.vMos_id+"#htq"+donneParam("hrq");
	} else if (window.opener!=null){
		if (SUR_CHORUS){
			try {
				if (window.opener.oFenCursus){
					window.opener.oFenCursus.location.reload();}
			}catch(e){}
		}
		window.close();
	} else {
		// hta ?
		if (SUR_CHORUS){
			parent.contenuLMS.location=window.planLMS.adrPageDefaut("quit");
		} else {
			parent.contenuLMS.location=parent.RACINE_stage+"MosMtr/gen/blanc.htm";
			window.close();
		}				
	}
}

function donneParam(nomP){
 	var res='';
 	var params=window.location.search;
 	if ((params!="")&&(params.indexOf('%26')>0)){
		params=params.replace(/%26/,'&');
	}
 	var ind=params.indexOf(nomP+'=');
 	if (ind>0){
 	 	var reste=params.substring(ind+nomP.length+1,params.length);
 	 	var indexFin=reste.indexOf('&');
 	 	if (indexFin<0){indexFin=params.length;}
 	 	res= reste.substring(0,indexFin);
 	}
 	return res;
}

function getDateServeur(mode){
	var resu='';
	var dateJS=new Date();
	var moisServeur="0";	
	var jourServeur="0";	
	var anneeServeur=dateJS.getUTCFullYear();
	if (dateJS.getUTCMonth()+1<10){moisServeur = moisServeur + (dateJS.getUTCMonth()+1).toString();}
	else{moisServeur=dateJS.getUTCMonth()+1;}
	if (dateJS.getUTCDate()<10){jourServeur = jourServeur + (dateJS.getUTCDate()).toString();}
	else{jourServeur=dateJS.getUTCDate();} 
	 if (mode=='yyyymmjj'){
		 resu=anneeServeur+ "-" + moisServeur + "-" + jourServeur;
	} else {
		var heureServeur="0";
	var minutesServeur="0";
	var secondesServeur="0";
	 if (dateJS.getUTCHours()<10){heureServeur+=(dateJS.getUTCHours()).toString();}
	else {heureServeur=dateJS.getUTCHours();}
	if (dateJS.getUTCMinutes()<10){minutesServeur+=(dateJS.getUTCMinutes()).toString();}
	else {minutesServeur=dateJS.getUTCMinutes();}
	if (dateJS.getUTCSeconds()<10){secondesServeur+=(dateJS.getUTCSeconds()).toString();}
	else{secondesServeur=dateJS.getUTCSeconds();} 
		// yyyymmjjhhmmss
	 	resu=anneeServeur+ "-" + moisServeur + "-" + jourServeur + "T" + heureServeur + ":" + minutesServeur + ":" + secondesServeur;
	}
	return resu;
}
function LMS_allerPrecedent(){
	window.haut.NAVIG_allerPrecedent();
}
function LMS_allerSuivant(){
	window.haut.NAVIG_allerSuivant();
}
function LMS_ouvrirGlossaire(){
	var largeur = 10;
	var hauteur = 10;
	var position="left="+largeur+",top="+hauteur+",screenX="+largeur+",screenY="+hauteur+",";		
	var src=RACINE_stage+"MosMtr/ressources/style/glossaire.htm?ver="+serveur.version;
	if ((window.contenuLMS!=null)&&(window.contenuLMS.oSco!=null)){
		if (window.contenuLMS.oSco.refGlo!=''){
			src=RACINE_stage+"../"+window.contenuLMS.oSco.refGlo+"/MosMtr/ressources/style/glossaire.htm?ver="+serveur.version;
		}
	}
	// on affiche en plus grand sur les hautes resolutions

	var taille="width=800,height=560";	
	if (screen.width>1000){
		taille="width=960,height=680";	
	}
	var fen=window.open(src,'Glossaire','toolbar=no,status=no,menubar=no,'+taille+','+position+'scrollbars=no,resizable=yes');
	fen.focus();
}
var passeParVeutQuitter=false;
// onbeforeunload
function LMS_veutQuitter(){
	if (API_1484_11==null){return ;}
	passeParVeutQuitter=true;
	if (API_1484_11.etatCommunication=="enCours"){
		API_1484_11.etatCommunication="";
		API_1484_11.scoEnAttente=true;
		try {
			window.contenuLMS.SCO_terminer();	
		}catch(e){}
	}
	var actionQuit="suspendAll";
	var prendActionInterface=true;
	if (window.planLMS.itemCourant!=null){
		if (planLMS.masqueSuspendre){actionQuit="exitAll";prendActionInterface=false;}
		if (planLMS.masqueSortie){actionQuit="suspendAll";prendActionInterface=false;}
	} 
	if (prendActionInterface){
		try {
			var lesliens=window.haut.document.getElementsByTagName("a");
			for (var i=0;i<lesliens.length;i++){
				if (lesliens[i].href.indexOf("NAVIG_retour('exitAll')")>=0){
					actionQuit="exitAll";
				}
			}
		}catch(e){}
	}
	window.haut.NAVIG_retour(actionQuit);
}
function nettoieItem(itemTmp){
	var filsitem=XML_fils(itemTmp,"item");
	if (filsitem==null && PF_attr(itemTmp,"activityProgressStatus")!="true"){
		itemTmp.parentNode.removeChild(itemTmp);return ;
	} 
	itemTmp.removeAttribute("nom");
	itemTmp.removeAttribute("identifierref");
	itemTmp.removeAttribute("listeRemonte");
	itemTmp.removeAttribute("planDejaFait");
	
	supprEltItm(itemTmp,"adlcp","dataFromLMS");
	supprEltItm(itemTmp,"adlcp","timeLimitAction");
	
	oSeq=XML_filsNS(itemTmp,"imsss","sequencing");
	if (PF_attr(itemTmp,"activityProgressStatus")=="true"){
		if (PF_attr(itemTmp,"activityIsActive")=="false"){
			itemTmp.removeAttribute("activityIsActive");
		}
		if (PF_attr(itemTmp,"activityIsSuspended")=="false"){
			itemTmp.removeAttribute("activityIsSuspended");
		}
		oSeq=XML_filsNS(itemTmp,"imsss","sequencing");
		if (oSeq!=null){
			var oBjs=XML_filsNS(oSeq,"imsss","objectives");
			if (oBjs!=null && oBjs.childNodes.length>0){
				for (var no=0;no<oBjs.childNodes.length;no++){
					var objtm=oBjs.childNodes[no];
					if (objtm.nodeType==1){
						objtm.removeAttribute("satisfiedByMeasure");
					}
				}
				itemTmp.appendChild(oBjs);				
			}
		}
	}
	if (oSeq!=null){itemTmp.removeChild(oSeq);}
	supprEltItm(itemTmp,"adlnav","presentation");
	while ((filsitem!=null)&&(filsitem.nodeName=="item")){
		var oSuiv=filsitem.nextSibling;
		nettoieItem(filsitem);
		filsitem=oSuiv;	
	}
}
function supprEltItm(oI,ns,nom){
	var oSeq=XML_filsNS(oI,ns,nom);
	if (oSeq!=null){oI.removeChild(oSeq);}
}
function LMSLocal() {
	this.codeStage;
	this.codeGroupe="";
	this.titreStage;
	this.parcoursEnAttente=false;
	this.vMos_id=""; // id utilisateur
	this.vMos_nom=""; // vide ou intialise par un Mos Synchro
	this.vMos_prenom="";
	this.codeInscription="";
	this.version;
	this.largeurCol=0;
	this.vMos_lang="";
	// methodes
	this.init = csLMS_init;
}

function csLMS_init(version){
	this.version=version;
}

function donneActivite(idActivite){
	if (idActivite==itemRacine.getAttribute("identifier")){
		return itemRacine;
	} else {
		return XML_trouveNoeud(itemRacine,"item","identifier",idActivite);
	}
}
// service pour ajouter le nbacc et date et der ressource sur profil
function serviceAccesMD(){
	var tabParam=new Array();
	tabParam[0]="userID##"+serveur.vMos_id;
	tabParam[1]="courseID##"+serveur.codeStage;
	tabParam[2]="resourceID##"+donneParam("sco");
	SYS_service("accesRessource",tabParam);
}

function dimCadres(haut,larg){
	if (haut.toString()!=''){
		var oFr=document.getElementById('frame1');
		var nVal=haut+",*";
		if (MENU_BAS){
			nVal="*,"+haut;
		}
		if (oFr.rows!=nVal){
			oFr.rows=nVal;
		}
	}
	if (larg.toString()!=''){
		if (larg!=0){serveur.largeurCol=larg;}
		var oFr=document.getElementById('frame2');
		var nVal=larg+",*";
		if (PLAN_DROIT){
			nVal="*,"+larg;
		}
		if (oFr.cols!=nVal){
			oFr.cols=nVal;
		}
	}
}

function authentifierLMS(idU,mpUK){
	var tabParam=new Array();
	tabParam[0]="userID##"+PF_crypte(idU);
	tabParam[1]="userPassword##"+mpUK;
	tabParam[2]="isEncrypted##true";	
	var oRetour=SYS_service("authenticateUser",tabParam);
	if (XML_texteNoeud(XML_fils(oRetour,"isAuthenticated"))=="true"){
		return true;
	}
	return false;
}

function Biscuit(){
	this.$document;
	this.$name;
	this.$domain;
	this.$path;
	this.$secure;
	
	this.idUtil=''; // identifiant util
	this.mpk='';
	this.langue=''; // langue 
	this.derSco=''; // dernier sco vu 
	this.derService=''; // id der service 
	// methodes
	this.init=BIS_init;
	this.charger=BIS_charger;
	this.enregistrer=BIS_enregistrer;
}


function BIS_init(document, name, hours, path, domain, secure) {
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}

function BIS_enregistrer(){
    var cookieval = "";
    for(var prop in this) {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}

function BIS_charger(){
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   // cookie not defined for this page.
    start += this.$name.length + 1;  // skip name and equals sign.
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    var a = cookieval.split('&'); 
    for(var i=0; i < a.length; i++) 
        a[i] = a[i].split(':');

   for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }
    return true;
}

function initBiscuit(){
	leBiscuit = new Biscuit();
	leBiscuit.init(this.document,"BiscuitIU5",57000);
	leBiscuit.charger();
}
function retourneObjetXMLParcours(codeStage0){
	var tabParam=new Array;
	ajTParam(tabParam,"userID",serveur.vMos_id);
	ajTParam(tabParam,"userTimeOffset",donneFuseauMin());
	ajTParam(tabParam,"userLanguage",serveur.vMos_lang);
	ajTParam(tabParam,"courseID",codeStage0);
	ajTParam(tabParam,"interfaceName",STYLE_INTERFACE);
	var oRetour=SYS_service("getSingleCourse",tabParam);
	return XML_noeudEgal(oRetour,"courseID",codeStage0);	
}
function openCourseLMS(codeStage0){
	if (!SUR_CHORUS){return alert("Opening the course requires to be logged to MOS Chorus.");}
	var objParcours=retourneObjetXMLParcours(codeStage0);
	if (objParcours!=null){
		objParcours=objParcours.parentNode;
		if (paramRetour(objParcours,"groupID")!=""){
			// si existe
			return lancerParcours(objParcours,"");
		}
	}	
	var msg="Sorry, the course '"+codeStage0+"' is not accessible.";
	var noAccessReason=oRetour.getAttribute("noAccessReason");
	if (noAccessReason==null){noAccessReason="";}
	if (noAccessReason!=""){
		msg=infoRefus(noAccessReason);
	}
	alert(msg);
}

function infoRefus(info){
	var lex="";
	var numR=0;
	if (info=="no_rule"){numR=462;}	
	if (info=="no_group"){numR=17;}	
	if (info=="allow_rule"){numR=18;}
	if (info=="deny_rule"){numR=222;}
	if (info=="bad_date"){numR=461;}
	if (info=="bad_date_rule"){numR=461;}
	if (info=="seq_rule"){numR=463;}
	if (numR==0){return donneLex(16);}
	return donneLex(16)+" "+donneLex(numR);
}

function lancerParcours(objLance,idSco){
	var codeStg=paramRetour(objLance,"courseID");
	var codeGrp;
	var estInscrit=false;
	if (paramRetour(objLance,"isEnrolled")=="true"){			
		estInscrit=true;
	} else {
		codeGrp=paramRetour(objLance,"groupID");
	}
	
	if (paramRetour(objLance,"accessDeniedByDate")=="true"){
		var dateDepart=paramRetour(objLance,"startDate");
		if (dateDepart!=""){
			dateDepart=IU_afficheDate(dateDepart,true);
			alert(donneLex(527).replace("DATE",dateDepart));	
		}
		var dateFin=paramRetour(objLance,"endDate");
		if (dateFin!=""){
			dateFin=IU_afficheDate(dateFin,true);
			alert(donneLex(541).replace("DATE",dateFin));	
		}
		var creneau=paramRetour(objLance,"timeWindow");
		if (creneau!=""){
			alert(donneLex(528)+"\n"+creneau);	
		}
		return ;
	}
	if (paramRetour(objLance,"accessDeniedByRule")=="true"){
		alert(donneLex(222));	
		return ;
	}
	var prm="&atn="+genereIdSession();
	prm+="&idk="+PF_crypte(serveur.vMos_id)+"&stk="+PF_crypte(codeStg);
	if (!estInscrit){prm+="&grk="+PF_crypte(codeGrp);}	
	prm+="&lang="+serveur.vMos_lang;
	if (paramRetour(objLance,"showGroup")!="true" && prm.indexOf("&vgp=")<0){
		prm+="&vgp=0";
	}
	if (idSco!=""){prm+="&sco="+idSco;}
	var ref=paramRetour(objLance,"courseURL")+prm;
	var nomFen="LMS_"+codeStg;
	nomFen=nomFen.replace(/\W/g,"_");
	// determin la position fenetre
	var styleLMS=paramRetour(objLance,"styleLMS");
	if (styleLMS==""){styleLMS=STYLE_INTERFACE;}
	
	var DOMMDStyleLms=IU_objDom();
	DOMMDStyleLms.load(RACINE_STYLES+styleLMS+"/md_style.xml");
	var oMDStyleLms=DOMMDStyleLms.documentElement;
	var fpos="";
	var vdisp=PF_attr(oMDStyleLms,"LMS_FEN_X");
	if (vdisp!=''){ 
		vdisp=Number(vdisp);
		if (vdisp<0){vdisp=window.screen.width+vdisp;}
		fpos+=",left="+vdisp;
	}
	vdisp=PF_attr(oMDStyleLms,"LMS_FEN_Y");
	if (vdisp!=""){
		vdisp=Number(vdisp);
		if (vdisp<0){vdisp=window.screen.height+vdisp;}
		fpos+=",top="+vdisp;
	}
	vdisp=PF_attr(oMDStyleLms,"LMS_FEN_L");
	if (vdisp==""){vdisp=window.screen.width-6;if (vdisp>1280){vdisp=1280;}}
	vdisp=Number(vdisp);
	if (vdisp<0){vdisp=window.screen.width+vdisp;}
	fpos+=",width="+vdisp;
	vdisp=PF_attr(oMDStyleLms,"LMS_FEN_H");
	if (vdisp==""){vdisp=window.screen.height-75;if (vdisp>1024){vdisp=1024;}}
	vdisp=Number(vdisp);
	if (vdisp<0){vdisp=window.screen.height+vdisp;}
	fpos+=",height="+vdisp;
	
	var fenl=window.open(ref,nomFen,"toolbar=no,menubar=no,location=no,scrollbar=no,resizable=yes,status=yes"+fpos);
	fenl.focus();
}
function LMS_afficherDiplome(){
	if (SUR_CHORUS){
		// remontee du temps
		if (API_1484_11!=null && API_1484_11.etatCommunication=="enCours" && !window.planLMS.SUIVI_DESACTIVE){
			var tempsTotal=PF_attr(planLMS.DOMManifest.documentElement,"tempsTotal");
			if (tempsTotal==""){		
				remonterTempsTot(API_1484_11.activite);
			}
		}
		setTimeout("ouvreFenDipl()",500);
	} else {
		alert("This feature only works in MOS Chorus.");	
	}
}
function remonterTempsTot(oPere){
	while (oPere!=null && !window.planLMS.estRacine(oPere)){
		oPere=oPere.parentNode;	
		window.planLMS.durationRollup(oPere);
	}
	/*var modifD=false;
	var lesitems=XML_listeParBalise(window.planLMS.itemRacine,"item");
   	for (var i=lesitems.length-1;i>=0;i--){
   		var oItem=lesitems[i];
   		if (PF_attr(oItem,"activityAbsoluteDuration")=="" && !window.planLMS.estFeuille(oItem) && window.planLMS.deliveryControls(oItem,"tracked")=="true"){
   			window.planLMS.durationRollup(lesitems[i]);
   			modifD=true;
   		}
   	}
   	if (modifD){
   		window.planLMS.durationRollup(window.planLMS.itemRacine);
   	}*/
	
}
function ouvreFenDipl(){
	var idStg=serveur.codeStage;	
	var nomFen=idStg.replace(/\W/g,"")+serveur.vMos_id.replace(/\W/g,"");
	var fenb=window.open(RACINE_MOS+"MosSrv/aspx/diplm.aspx?ref="+PF_crypte(serveur.vMos_id+"##"+idStg)+"&style="+STYLE_INTERFACE+"&lang="+serveur.vMos_lang,"dipl"+nomFen,"toolbar=yes,resizable=yes,menubar=yes,status=no,location=no,width=700,top=30,left=120,heigth=550");
	fenb.focus();
}
function LMS_editPgGnr(params){
	if (!SUR_CHORUS){alert("You must be logged to MOS Chorus to edit the page.");return ;}
	var site="";
	var objParcours=retourneObjetXMLParcours(serveur.codeStage);
	if (objParcours!=null){
		objParcours=objParcours.parentNode;
		var src=RACINE_MOS+"MosGnr/MosGnr.htm?lang="+serveur.vMos_lang+"&stg="+serveur.codeStage+"&site="+paramRetour(objParcours,"site")+"&id="+serveur.vMos_id+"&roleMng=0001&actionIU=editerRessource";
		var fen=window.open(src+params,"MosGnr"+serveur.codeStage,paramFenOutil());
		fen.focus();
	}
}
function paramFenOutil(){
	var ww = window.screen.availWidth-7;
	if (ww>1280){ww=1280;}
 	var hh = window.screen.availHeight-56;
 	var position="top=0,left=0";
	if (estMoz){
		position="left="+window.screen.availLeft+",top="+window.screen.availTop;
	}
	return "toolbar=no,menubar=no,scrollbar=no,resizable=yes,status=yes,width="+ww+",height="+hh+","+position;
}
