//Instanciation du service
scServices.assmntMgr = {

/** Réponse de l'utilisateur par champs et session. */
getResponse: function(pId, pSession, pField){
	return scServices.dataMgr.getVal("assmnt."+(pSession || "#default")+"."+pId+".resp."+pField);
},
setResponse: function(pId, pSession, pField, pValue){
	scServices.dataMgr.setVal("assmnt."+(pSession || "#default")+"."+pId+".resp."+pField, pValue);
},


/** Score sous forme de points. */
getMinPts: function(pId, pSession){
	return scServices.dataMgr.getVal("assmnt."+(pSession || "#default")+"."+pId+".minPts");
},
getScorePts: function(pId, pSession){
	return scServices.dataMgr.getVal("assmnt."+(pSession || "#default")+"."+pId+".scorePts");
},
getMaxPts: function(pId, pSession){
	return scServices.dataMgr.getVal("assmnt."+(pSession || "#default")+"."+pId+".maxPts");
},
setPts: function(pId, pSession, pMin, pScore, pMax){
	scServices.dataMgr.setVal("assmnt."+(pSession || "#default")+"."+pId+".minPts", pMin);
	scServices.dataMgr.setVal("assmnt."+(pSession || "#default")+"."+pId+".scorePts", pScore);
	scServices.dataMgr.setVal("assmnt."+(pSession || "#default")+"."+pId+".maxPts", pMax);
},


/** Statut de cette assmnt : "notAttempt", "attempt", "complete". */
getCompletionStatus: function(pId, pSession){
	return scServices.dataMgr.getVal("assmnt."+(pSession || "#default")+"."+pId+".status") || "notAttempt";
},
setCompletionStatus: function(pId, pSession, pStatus){
	switch(pStatus) {
		case "attempt" : 
		case "complete" : 
		case "notAttempt" : 
			break;
		default :
			pStatus = "notAttempt";
	}
	scServices.dataMgr.setVal("assmnt."+(pSession || "#default")+"."+pId+".status", pStatus);
	return pStatus;
},


/** Indices consultés (format de la liste des indices consultés spécifiques à l'assmnt). */
getHintsShown: function(pId, pSession){
	return scServices.dataMgr.getVal("assmnt."+(pSession || "#default")+"."+pId+".hints");
},
setHintsShown: function(pId, pSession, pHintsShown){
	scServices.dataMgr.setVal("assmnt."+(pSession || "#default")+"."+pId+".hints", pHintsShown);
},

commit: function(){
},


/* interne */
onLoad: function(){
	//alert("initDataMgr");
},
loadSortKey: "E",

onUnload: function(){
	//alert("closeDataMgr");
},
unloadSortKey: "E"

};

//Abonnements aux events onLoad et onUnload.
scOnLoads[scOnLoads.length] = scServices.assmntMgr;
scOnUnloads[scOnUnloads.length] = scServices.assmntMgr;



//######################################### service dataMgr ################################"

//Instanciation du service
scServices.dataMgr = {

/* Lecture d'une variable de l'instance. Retourne null si la variable n'existe pas. */
getVal: function(pCd) {
	var vFields = pCd.split(".");
	var vCur = this.fFields;
	for(var i=0, imax=vFields.length; i<imax; i++) {
		var vF = vCur[vFields[i]];
		if(vF == null) return null;
		vCur = vF;
	}
	return vCur;
},

/* Stockage d'une variable dans l'instance. 
 * Retourne true si la valeur a été modifiée, false sinon.
 */
setVal : function (pCd,pVal) {
	var vFields = pCd.split(".");
	var vCur = this.fFields;
	var imax = vFields.length-1;
	for(var i=0; i<imax; i++) {
		var vF = vCur[vFields[i]];
		if(vF == null) vCur = vCur[vFields[i]] = {}; else vCur = vF;
	}
	if( ! (vFields[imax] in vCur) || vCur[vFields[imax]] != pVal) {
		vCur[vFields[imax]] = pVal;
		this.fModif = true;
		return true;
	}
	return false;
},

/* Suppression d'une variable dans l'instance. 
 * Retourne true si la valeur a été supprimée, false si pCd n'existait pas.
 */
removeVal : function (pCd) {
	var vFields = pCd.split(".");
	var vCur = this.fFields;
	var imax = vFields.length-1;
	for(var i=0; i<imax; i++) {
		var vF = vCur[vFields[i]];
		if(vF == null) return false;
		vCur = vF;
	}
	if(vCur[vFields[imax]]) {
		this.fModif = true;
		return delete vCur[vFields[imax]];
	}
	return false;
},

/* interne */
fFields: {},
//Serialize un objet comportant des données au format JS
xSaveObjJs : function(pObj){
	var vBuf="";
	for (var vKey in pObj){
		if(vBuf!="") vBuf+=",";
		var vObj = pObj[vKey];
		if(vObj instanceof Object){
			vBuf+=vKey+":{"+this.xSaveObjJs(vObj)+"}";
		} else {
			var vVal = escape(vObj);
			if(vVal==vObj) {
				vBuf+=vKey+":'"+vVal+"'";
			} else {
				vBuf+=vKey+":unescape('"+vVal+"')";
			}
		}
	}
	return vBuf;
},
onLoad: function(){
	//alert("initDataMgr");
},
loadSortKey: "D",

onUnload: function(){
	//alert("closeDataMgr");
},
unloadSortKey: "D"

};

//Abonnements aux events onLoad et onUnload.
scOnLoads[scOnLoads.length] = scServices.dataMgr;
scOnUnloads[scOnUnloads.length] = scServices.dataMgr;


