/*/* * Copyright (C) 2003,2004 by 4system Polska Sp. z o.o. * All Rights Reserved. */var PAGETYPE_UNKNOWN = "Unknown";var PAGETYPE_INFORMATION = "Information";var PAGETYPE_EXERCISE = "Exercise";var PAGETYPE_HIDDEN = "Hidden";var PAGETYPE_POLL = "Poll";var PAGESTATUS_NOT_ATTEMPTED = "N";var PAGESTATUS_INCOMPLETE = "I";var PAGESTATUS_COMPLETED = "C";var PAGESTATUS_PASSED = "P";var PAGESTATUS_FAILED = "F";var KEY_SEP = "#|#";var CHAR_A_CODE = 97;

UELODDCalculator = function()
{
	var namesList = new Array();
}

UELODDCalculator.prototype.setNamesList = function(s)
{
	this.namesList = new Array();
	var list = s.split(":");
	for (var i = 0; i < list.length; i++)
	{
		var items = list[i].split("|");
		for (var j = 0; j < items.length; j++) 
		{
			var ex = false;
			for (var k = 0; k < this.namesList.length; k++)
			{
				if (this.namesList[k] == items[j])
				{
					ex = true;
					break;
				}
			}
			if (!ex) 
			{
				this.namesList[this.namesList.length] = items[j];
			}
		}
	}
}

UELODDCalculator.prototype.getNameCode = function(name)
{
	for (var i = 0; i < this.namesList.length; i++)
	{
		if (this.namesList[i] == name)
		{
			return String.fromCharCode(CHAR_A_CODE + i);
		}
	}
	return "";
}
UELODDCalculator.prototype.transform = function(ss, s){	this.setNamesList(ss);
	var r = "{";	if (s.length != 0)	{		var sr = s.split(":");		for (var i = 0; i < sr.length; i++)
		{			if (r.length > 1) r += ",";			r += String.fromCharCode(CHAR_A_CODE + i) + ".";			r += this.getNameCode(sr[i]);
		}	}	r += "}";	return r;
}

UELODDCalculator.prototype.transformToPermutation = function(ss, s)
{
	this.setNamesList(ss);
	var g = new Array();
	var list = s.split(":");
	for (var i = 0; i < list.length; i++)
	{
		g[i] = new Array();
		var items = list[i].split("|");
		if (i == 0) {
			for (var k = 0; k < items.length; k++) 
			{
				g[i][g[i].length] = {"index":items[k],"parent":-1};
			}
		} else {
			for (var j = 0; j < g[i - 1].length; j++)
			{
				for (var k = 0; k < items.length; k++) 
				{
					g[i][g[i].length] = {"index":items[k],"parent":j};
				}
			}
		}
	}
	var res = "";
	for (var i = 0; i < g[g.length - 1].length; i++)
	{
		var p = g.length - 1;
		var mod = "";
		if (res.length > 0) res += ";"
		res += "{";
		var item = g[g.length - 1][i];
		mod += String.fromCharCode(CHAR_A_CODE + p) + "." + this.getNameCode(item["index"]);
		p--;
		var parent = item["parent"];
		for (var j = g.length - 2; j >= 0; j--)
		{
			mod = String.fromCharCode(CHAR_A_CODE + p) + "." + this.getNameCode(g[j][parent]["index"]) + "," + mod;
			parent = g[j][parent]["parent"]
			p--;
		}
		res += mod + "}";
	}	
	return (res);
}
/*  *  *  */UELOInteractions = function(){	this.id = "";	this.correctResponses = "";	this.time = "";	this.type = "";	this.weighting = "";	this.studentResponse = "";	this.status = "N";	this.result = "";	this.maxScore = 0;	this.score = 0;	this.question = "";	this.latency = null;	this.tryNumber=0;	this.maxTryNumber=0;};UELOInteractions.prototype.AddCorrectResponses = function(pattern){	var p = this.FindCorrectResponses(pattern);	if (p == null)	{		p = this.correctResponses[this.correctResponses.length] = pattern; 	}	return p;};UELOInteractions.prototype.FindCorrectResponses = function(pattern){	for (var i = 0; i < this.correctResponses.length; i++)	{		if (this.correctResponses[i] == pattern)		{			return this.correctResponses[i];		}	}	return null;};UELOInteractions.prototype.setValue = function(name, value){	// wyjatki do poprawinie i ujednolicenia	if (name == "answers") name = "studentResponse";	if (name == "group") name = "id";		if (typeof(this[name]) == "undefined") return;		if (name == "status"){		if(value=='P') this['result']=true;		else this['result']=false;	}		if (typeof(this[name]) == "number" || typeof(this[name]) == "string" || typeof(this[name]) == "boolean"){		this[name] = value;	}};UELOInteractions.prototype.getValue = function(name){	return (typeof(this[name] != "undefined")) ? this[name] : null;}UELOInteractions.prototype.setResult = function(value){	if(value==true){		this.result=true;		this.status='P';		this.score=1;	}else{		this.result=false;		this.status='F';		this.score=0;	}	};/*  *  *  */UELOPage = function(){	this.pageId = "";	this.scoId = "";	this.type = -1;	this.pageType = PAGETYPE_UNKNOWN;	this.status = PAGESTATUS_NOT_ATTEMPTED;	this.title = "";	this.globalIndex = -1;	this.pageVisited = 0;	this.chapterName = "";	this.correctResponses = new Array();	this.interactions = new Array();};UELOPage.prototype.setValue = function(name, value){	// wyjatki do poprawinie i ujednolicenia	if (typeof(this[name]) == "undefined") return;			if (typeof(this[name]) == "number" || typeof(this[name]) == "string" || typeof(this[name]) == "boolean"){				this[name] = value;	}};UELOPage.prototype.AddInteraction = function(elementId, question, correctResponses, maxScore, tryNumber, maxTryNumber, type){	/*	if (elementType.indexOf('Light',0) > 0){		elementType=elementType.substring(0,elementType.indexOf('Light',0));	}	*/	var interId = this.FormatInteractionId(elementId, this.globalIndex);	var inter = this.FindInteraction(interId);	if (inter == null)	{			var inter = this.interactions[this.interactions.length] = new UELOInteractions();		inter.id = interId;		inter.question = question || "";		inter.maxScore = maxScore || "";		inter.maxTryNumber = maxTryNumber || "";		inter.correctResponses = correctResponses || "";		inter.type = type || "";		return  inter;	} else {		return inter;	}};UELOPage.prototype.FindInteraction = function(interId){	//alert('1:'+interId+', il= '+this.interactions.length);	for (var i = 0; i < this.interactions.length; i++)	{		var inter = this.interactions[i];		if (inter.id == interId)		{			return inter;		}	}	return null;}UELOPage.prototype.FormatInteractionId = function(elementId, pageGlobalIndex){	return elementId + "_" + pageGlobalIndex;}/*  *  *  */UELO = function(){	this.pages = new Array();	this.keySep = KEY_SEP;		this.scoId = "";	this.courseName = "";	this.courseDescription = "";		this.username = "";	this.password = "";	this.organisation = "";	this.server = "";	this.percentCompleted = "";	this.pagesCount = 0;	this.exercisePagesCount = 0;	this.pagesVisited = 0;	this.pointsMax = 100;	this.points = 0;	this.passThreshold = 100;	this.beginTime = new Date();	this.endTime = new Date();	this.sessionTime = 0;	this.userVars = "";	this.lastVisitedPage = 0;	this.saveUelo = 0;	this.showUserAnswers = true;		this.writeValuesList = new Array("organisation", "username", "password", "server", "percentCompleted", "pagesVisited", "pointsMax", "points", "passThreshold",  "beginTime", "endTime", "courseName", "courseDescription","keySep","userVars","lastVisitedPage","score");}UELO.prototype.AddPage = function(){	var p = new UELOPage();	this.pages[this.pages.length] = p;	this.pagesCount++;	return p;}//parent.UELO.LoadFromForm(string textAreaName) - wczytuje wartosci z TextArea na formularzuUELO.prototype.LoadFromForm = function(textAreaName){}//String parent.UELO.getHeaderString(String Name) - daje text z naglowka UELO.prototype.GetHeaderString = function(name){	for (var k in this)	{		var type = typeof(this[k]);		if (type == "number" || type == "string" || type == "boolean" || type == "object")		{			return this[k];		}	}	return null;}UELO.prototype.setHeaderString = function(name, value){	///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	/// wyjatki do poprawinie i ujednolicenia	if (name == "Server_for_check_Answers") name = "server";		var f = new RegExp("^" + name + "$", "gi");	for (var k in this)	{		if (k.match(f))		{			for (var j = 0; j < this.writeValuesList.length; j++)			{				if (this.writeValuesList[j].toLowerCase() == k.toLowerCase())				{					if (typeof(this[k]) == "number" || typeof(this[k]) == "string" || typeof(this[k]) == "boolean")					{						this[k] = value;						return;					}					if (typeof(this[k]) == "object" && (k == "beginTime" || k == "endTime")) 					{						this[k] = this.stringToDate(value);						return;					}				}			}		}	}}//String parent.UELO.getDataStringByID(int PageId;String ColumnName) - daje text z danych linia szukajac po PageIdUELO.prototype.GetDataStringByID = function(pageId, name){}//String parent.UELO.getDataStringByIdx(int RowIdx;String ColumnName) - daje text z danych linia RowIdxUELO.prototype.GetDataStringByIdx = function(rowIdx, columnName){}//String parent.UELO.getDataStringByName(String PageName;String ColumnName) - daje text z danych linia szukajac po PageIdUELO.prototype.GetDataStringByName = function(pageName, columnName){}//int parent.UELO.getDataRowCount() - daje ilosc liniiUELO.prototype.GetDataRowCount = function(){}//String parent.UELO.setDataStringByID(int PageID;String ColumnName,String value)UELO.prototype.SetDataStringByID = function(pageID, columnName, value){}UELO.prototype.setPageStatus = function(pageGlobalIndex,newPageStatus){	var p = this.FindPage(pageGlobalIndex);	if(p){		p.status = newPageStatus;		for (var i = 0; i < p.interactions.length; i++)		{			var inter = p.interactions[i];			if (inter.status == 'N') inter.status = newPageStatus;		}					}}UELO.prototype.updateUELOFromSD = function(statusString){	var arr = statusString.split(",");
	for (var i = 0; i < arr.length; i++) {
			this.setPageStatus(struct.getGIX(i+2),arr[i]);
	}}UELO.prototype.getLastVisitedPage = function(){	if (this.lastVisitedPage != 0) return this.lastVisitedPage	var lastPage = null;	for (var i = 0; i < this.pages.length; i++) {		if(this.pages[i].status == 'I'){			this.pages[i].globalIndex;		}else if(this.pages[i].status == 'N'){			return lastPage;		}		lastPage = this.pages[i].globalIndex;	}	return lastPage;}UELO.prototype.setLastVisitedPage = function(pageNo){	this.lastVisitedPage = pageNo;}UELO.prototype.getPageIndexInStruct = function(pageGlobalIndex){	for (var i = 0; i < this.pages.length; i++) {		if(this.pages[i].globalIndex == pageGlobalIndex) return i;	}}UELO.prototype.getPageStatus = function(pageGlobalIndex){	var p = this.FindPage(pageGlobalIndex);	if(p){		return p.status;	}}UELO.prototype.setPageVisited = function(pageGlobalIndex){	var p = this.FindPage(pageGlobalIndex);	if(p){		this.setLastVisitedPage(pageGlobalIndex);		p.pageVisited = 1;	}	this.setPercentCompleted();}UELO.prototype.setPercentCompleted = function(){	var allPages=this.getPagesCount(null);	var visitedPages=this.getPagesVisitedCount('VISITED');	var pagesC=''+((visitedPages*100)/allPages);	if(pagesC.indexOf('.')>0) pagesC=pagesC.substr(0,pagesC.indexOf('.')+3);	//alert(allPages+', '+visitedPages+', '+pagesC);	this.percentCompleted = pagesC;	}UELO.prototype.getPagesCount = function(pageType){	var exCnt = 0;	var infCnt = 0;	var fullCnt = 0;	var visCnt = 0;	//if(!pageType) return this.pages.length;		for (var i = 0; i < this.pages.length; i++) {				if(this.pages[i].pageType==PAGETYPE_HIDDEN) continue;		if (this.pages[i].pageType == PAGETYPE_EXERCISE) exCnt++;		else infCnt++;		fullCnt++;	}		if(!pageType) return fullCnt; 	if (pageType=PAGETYPE_EXERCISE) return exCnt;	else return infCnt;}UELO.prototype.getPointsMax = function(){	var retScore=0;	for (var i = 0; i < this.pages.length; i++)	{				var page = this.pages[i];		if(page.pageType==PAGETYPE_HIDDEN) continue;		if(page.pageType==PAGETYPE_EXERCISE){			for (var j = 0; j < page.interactions.length; j++)			{				var inter = page.interactions[j];				retScore += parseInt(inter.maxScore);			}		}	}	return retScore;}UELO.prototype.getPagesVisitedCount = function(){	var visCnt = 0;		for (var i = 0; i < this.pages.length; i++) {				if(this.pages[i].pageType==PAGETYPE_HIDDEN) continue;		if (this.pages[i].pageVisited == 1) visCnt++;	}	return visCnt;}UELO.prototype.getCourseScore = function(){	var retScore=0;	for (var i = 0; i < this.pages.length; i++)	{				var page = this.pages[i];		if(page.pageType==PAGETYPE_HIDDEN) continue;		if(page.pageType==PAGETYPE_EXERCISE){			for (var j = 0; j < page.interactions.length; j++)			{				var inter = page.interactions[j];				if(inter.status=="P") retScore += parseInt(inter.score);			}		}	}	return retScore;}UELO.prototype.getCourseStatus = function(){	if(this.getPagesCount()!=this.getPagesVisitedCount()) return 1;	else return 0;}UELO.prototype.FindPage = function(pageGlobalIndex){	for (var i = 0; i < this.pages.length; i++) {				if (this.pages[i].globalIndex == pageGlobalIndex) {			return this.pages[i]		}			}	return null;}UELO.prototype.AddInteractionToPage = function(pageGlobalIndex,elementId){	var iterPage=this.FindPage(pageGlobalIndex);	if(iterPage==null) return null;	return iterPage.AddInteraction(elementId);}UELO.prototype.findInteraction = function(pageGlobalIndex, elementId){	var iterPage = this.FindPage(pageGlobalIndex);	if(iterPage == null) return null;		return iterPage.FindInteraction(elementId);}//String parent.UELO.setDataStringByID(int PageID;String ColumnName,String value)UELO.prototype.GetStudentAnswer = function(pageGlobalIndex, elementId){	var iterPage=this.FindPage(pageGlobalIndex);	if(iterPage==null) return null;	var interId = iterPage.FormatInteractionId(elementId, iterPage.globalIndex);	var iter=iterPage.FindInteraction(interId);	if(iter==null) return null;	return iter.studentResponse;}UELO.prototype.setUELOData = function(){	this.endTime = new Date();	this.sessionTime = this.calculateTimeToString(this.beginTime, new Date());	}UELO.prototype.toWBTSString = function(){	var r = "";	r += "[UniversalElearningDataObjectHeader]\n";	r += "Organisation=" + this.organisation + "\n";	r += "Username=" + this.username + "\n";	r += "Password=" + this.password + "\n";	r += "ServerForCheckAnswers=" + this.server + "\n";	r += "PercentCompleted=" + this.percentCompleted + "\n";	r += "PagesCount=" + this.getPagesCount(null) + "\n";	r += "ExercisePagesCount=" + this.getPagesCount(PAGETYPE_EXERCISE) + "\n";	r += "PagesVisited=" + this.getPagesVisitedCount() + "\n";	r += "PointsMax=" + this.getPointsMax() + "\n";	r += "Points=" + this.points + "\n";	r += "PassThreshold=" + this.passThreshold + "\n";	r += "BeginTime=" + this.dateTimeToString(this.beginTime) + "\n";	r += "EndTime=" + this.dateTimeToString(this.endTime) + "\n";	r += "SessionTime=" + this.calculateTimeToString(this.beginTime, this.endTime) + "\n";	r += "KeySep=" + this.keySep + "\n";	r += "userVars=" + this.getUserVars() + "\n";	r += "lastVisitedPage=" + this.getLastVisitedPage() + "\n";		r += "\n";	r += "[UniversalElearningDataObjectDataFormat]" + "\n";	r += "sco_identifier" + this.keySep + "page_identifier" + this.keySep + "globalPageIndex"+ this.keySep + "chapterName" + this.keySep + "group" + this.keySep + "question" + this.keySep + "answers"+ this.keySep + "maxScore" + this.keySep + "score" + this.keySep + "tryNumber" + this.keySep + "maxTryNumber" + this.keySep + "status" + this.keySep + "pageType" + "\n";	r += "\n";	r += "[UniversalElearningDataObjectData]" + "\n";		for (var i = 0; i < this.pages.length; i++)	{		var page = this.pages[i];		if(page.pageType==PAGETYPE_HIDDEN) continue;		if(page.pageType==PAGETYPE_EXERCISE){			for (var j = 0; j < page.interactions.length; j++)			{				var inter = page.interactions[j];				r += uelo.scoId + this.keySep + page.pageId + this.keySep + page.globalIndex + this.keySep + page.chapterName + this.keySep + inter.id + this.keySep + inter.question + this.keySep + inter.studentResponse + this.keySep + inter.maxScore  + this.keySep + inter.score + this.keySep + inter.tryNumber + this.keySep + inter.maxTryNumber + this.keySep + inter.status + this.keySep + "E \n";			}		}else if(page.pageType==PAGETYPE_POLL){			for (var j = 0; j < page.interactions.length; j++)			{				var inter = page.interactions[j];				r += uelo.scoId + this.keySep + page.pageId + this.keySep + page.globalIndex + this.keySep + page.chapterName + this.keySep + inter.id + this.keySep + inter.question + this.keySep + inter.studentResponse + this.keySep + inter.maxScore  + this.keySep + inter.score + this.keySep + inter.tryNumber + this.keySep + inter.maxTryNumber + this.keySep + inter.status + this.keySep + "P \n";			}					}else{			//var pStatus="N";			r += uelo.scoId + this.keySep + page.pageId + this.keySep + page.globalIndex + this.keySep + page.chapterName + this.keySep + this.keySep + this.keySep + this.keySep+ "1" + this.keySep + "0" + this.keySep + "0" + this.keySep + "0" + this.keySep + page.status + this.keySep + "I \n";		}	}		return r;}UELO.prototype.toFullString = function(){	var r = "";	r += "[UniversalElearningDataObjectHeader]\n";	r += "ScoId=" + this.scoId + "\n";	r += "CourseName=" + this.courseName + "\n";	r += "CourseDescription=" + this.courseDescription + "\n";	r += "Organisation=" + this.organisation + "\n";	r += "Username=" + this.username + "\n";	r += "Password=" + this.password + "\n";	r += "ServerForCheckAnswers=" + this.server + "\n";	r += "PercentCompleted=" + this.percentCompleted + "\n";	r += "PagesCount=" + this.getPagesCount(null) + "\n";	r += "ExercisePagesCount=" + this.getPagesCount(PAGETYPE_EXERCISE) + "\n";	r += "PagesVisited=" + this.getPagesVisitedCount() + "\n";	r += "PointsMax=" + this.getPointsMax() + "\n";	r += "Points=" + this.points + "\n";	r += "PassThreshold=" + this.passThreshold + "\n";	r += "BeginTime=" + this.dateTimeToString(this.beginTime) + "\n";	r += "EndTime=" + this.dateTimeToString(this.endTime) + "\n";	r += "SessionTime=" + this.calculateTimeToString(this.beginTime, this.endTime) + "\n";	r += "KeySep=" + this.keySep + "\n";	r += "userVars=" + this.getUserVars() + "\n";	r += "lastVisitedPage=" + this.getLastVisitedPage() + "\n";		r += "\n";	r += "[UniversalElearningDataObjectDataFormat]" + "\n";	r += "sco_identifier" + this.keySep + "page_identifier" + this.keySep + "globalPageIndex" + this.keySep + "group" + this.keySep + "question" + this.keySep + "answers" + this.keySep + "maxScore" + this.keySep + "score" + this.keySep + "status" + this.keySep + "pageType" + "\n";	r += "\n";	r += "[UniversalElearningDataObjectData]" + "\n";		for (var i = 0; i < this.pages.length; i++)	{		var page = this.pages[i];		r += "\n";		r += "[UniversalElearningDataObjectDataPage]" + "\n";		r += page.pageId + this.keySep + page.scoId+ this.keySep + page.type+ this.keySep + page.pageType+ this.keySep + page.status+ this.keySep + page.title+ this.keySep + page.globalIndex+ "\n";		for (var j = 0; j < page.interactions.length; j++)		{			var inter = page.interactions[j];			r += "    [UniversalElearningDataObjectDataPageInteraction]" + "\n";			r += "    "+inter.id + this.keySep + inter.correctResponses + this.keySep + inter.studentResponse + this.keySep + inter.time + this.keySep + inter.type + this.keySep + inter.weighting + this.keySep + inter.status + this.keySep + inter.result + this.keySep + inter.maxScore + this.keySep + inter.score + this.keySep + inter.question + this.keySep + inter.latency + "\n";		}	}		return r;}// To jest metoda która tłumaczy z formatu UELO do normy HACP// generalnie CUDA na KIJU ;) tam sie dziejavar _CORRECT_RESPONSES = 1;var _STUDENT_RESPONSE = 2;UELO.prototype.formatResponseToHACPFormat = function(mode, inter){	var s = "";	if (mode == _CORRECT_RESPONSES)	{		s = inter.correctResponses;	}	else if (mode == _STUDENT_RESPONSE)	{		s = inter.studentResponse;	}	else	{		return null;	}		var type = inter.type.toLowerCase();	if (typeof(s) == "string" && type == "choice")	{		var r = s;		var arr = s.split(":");		if (arr.length > 1)		{			var r = "{";			for (var i = 0; i < arr.length; i++)			{				if (arr[i] == "1")				{					if (r.length > 1) r += ",";					r += String.fromCharCode(97 + i);				}			}			r += "}";		}		return r;	} 	else if (type == "numeric")	{		// sa takie przypadki ze komponent przedstawia sie jako "numeric"		// a dane dostaracza takie jak "choice" - aw		if (typeof(s) == "string")		{			var arr = s.split(":");			if (arr.length > 0)			{				var r = "";				for (var i = 0; i < arr.length; i++)				{					if (arr[i] == "1")					{						return i;					}				}			}			return s;		}		return s.toString();	}	else if (type == "fill-in")	{		s = s.replace(/\|\|/gi, "; ");		return s;
	}	else if (type == "matching")	{//		var list = inter.correctResponses.split(":");		var calc = new UELODDCalculator();		if (mode == _CORRECT_RESPONSES)		{			return calc.transformToPermutation(inter.correctResponses, inter.correctResponses);		}		else if (mode == _STUDENT_RESPONSE)		{			return calc.transform(inter.correctResponses, inter.studentResponse);		}		return r;	}	return s;}UELO.prototype.toHACPInteractionsString = function(course_id, student_id, lesson_id){	var r = "";	var d = new Date();	r += '"course_id","student_id","lesson_id","date","time","interaction_id","objective_id","type_interaction","correct_response","student_response","result","weighting","latency"\n';	for (var i = 0; i < this.pages.length; i++)	{		var page = this.pages[i];		for (var j = 0; j < page.interactions.length; j++)		{			var inter = page.interactions[j];			r += '"' + course_id + '"'; //course_id			r += ',"'+ student_id +'"'; //student_id			r += ',"0"'; //lesson_id			r += ',"'+this.dateToString(d, "/")+'"'; // date			r += ',"'+this.timeToString(d)+'"'; // time			r += ',"p_' + i + '_e_' + j + '"'; // interaction_id  -> r += ',"'+inter.id+'"'; // interaction_id			r += ',""'; // objective_id			r += ',"'+inter.type+'"'; // type_interaction			r += ',"'+this.formatResponseToHACPFormat(_CORRECT_RESPONSES, inter)+'"'; // correct_response			r += ',"'+this.formatResponseToHACPFormat(_STUDENT_RESPONSE, inter)+'"'; // student_response			r += ',"'+((inter.result == true)?"c":"w")+'"'; // result			r += ',"1.0"'; // weighting			r += ',"'+((inter.latency == null)?"00:00:00":inter.latency)+'"'; // latency			r += '\n';		}	}	return r;}UELO.prototype.calculateTimeToString = function(dateStart, dateEnd){  var dd = Math.abs( dateEnd.getTime() - dateStart.getTime() );  var ts = Math.floor( ( ( (dd % (60 * 60 * 1000 * 24) ) % (60 * 60 * 1000) ) % ( 60 * 1000 ) ) / 1000 * 1 );  var tm = Math.floor( (dd % (60 * 60 * 1000 * 24)) % ((60 * 60 * 1000)) / (60 * 1000) );  var th = Math.floor( (dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) );  var sh = ((th < 10) ? "0" : "") + th;  var sm = ((tm < 10) ? "0" : "") + tm;  var ss = ((ts < 10) ? "0" : "") + ts;  return ("" + sh + ":" + sm + ":" + ss);};UELO.prototype.dateToString = function(date, separator){	if (typeof(separator) == "undefined")	{		separator = "-";	}	var day = date.getDate();	var month = date.getMonth() + 1;	var year = date.getFullYear();	var day = ((day < 10) ? "0" : "") + day;	var month = ((month < 10) ? "0" : "") + month;	return (year + separator + month + separator + day);};UELO.prototype.timeToString = function(date){  var ts = date.getSeconds();  var tm = date.getMinutes();  var th = date.getHours();  var th = ((th < 10) ? "0" : "") + th;  var tm = ((tm < 10) ? "0" : "") + tm;  var ts = ((ts < 10) ? "0" : "") + ts;  return ("" + th + ":" + tm + ":" + ts);};UELO.prototype.dateTimeToString = function(date){  var ts = date.getSeconds();  var tm = date.getMinutes();  var th = date.getHours();  var th = ((th < 10) ? "0" : "") + th;  var tm = ((tm < 10) ? "0" : "") + tm;  var ts = ((ts < 10) ? "0" : "") + ts;    var day = date.getDate();  var month = date.getMonth() + 1;  var year = date.getFullYear();  var day = ((day < 10) ? "0" : "") + day;  var month = ((month < 10) ? "0" : "") + month;  var year = ((year < 10) ? "0" : "") + year;  return (year + "-" + month + "-" + day + " " + th + ":" + tm + ":" + ts);};UELO.prototype.stringToDate = function(s){	var r = new RegExp("(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})");	var a = s.match(r);	return (a.length == 7) ? new Date(a[1], parseInt(a[2]) - 1, a[3], a[4], a[5], a[6]) : new Date();}UELO.prototype.toString = function(){	return this.toFullString();}UELO.prototype.__parseFindGroup = function(a, name){	var key = new RegExp("^\\[" + name + "\\]$", "i");	for (var i = 0; i < a.length; i++)	{		if (a[i].match(key)) 		{			return i;		}	}	return null;}UELO.prototype.loadFromString = function(s){	s = s.replace(new RegExp("\r", "g"), "");	var lines = s.split("\n");	//header	var index = this.__parseFindGroup(lines, "UniversalElearningDataObjectHeader");	if (index == null) 	{		return;	}		var i = index;	while (i++ < lines.length - 1)	{		var p = lines[i].indexOf("=");		if (p > 0)		{			var key = lines[i].slice(0, p);			var value = lines[i].slice(p + 1);			this.setHeaderString(key, value);		} else {			break;		}	}	var index = this.__parseFindGroup(lines, "UniversalElearningDataObjectDataFormat");	if (index == null) 	{		return;	}	var keyMatrix = lines[index + 1].split(this.keySep);	var gpi = -1; // globalPageIndex	var eii = -1;  // elementIdIndex	var dataPageType = -1; // pageType	var dataPageId = -1; // pageId	for (var j = 0; j < keyMatrix.length; j++)	{		//alert(keyMatrix[j]);		if (keyMatrix[j].match(new RegExp("^globalPageIndex$", "gi")))		{			gpi = j;		}		if (keyMatrix[j].match(new RegExp("^group$", "gi")))		{			eii = j;		}		if (keyMatrix[j].match(new RegExp("^pageType$", "gi")))		{			dataPageType = j;		}		if (keyMatrix[j].match(new RegExp("^page_identifier$", "gi")))		{			dataPageId = j;		}			}	//alert('dataPageType='+dataPageType);	if (gpi == -1 || eii == -1)	{		return;	}	var index = this.__parseFindGroup(lines, "UniversalElearningDataObjectData");	if (index == null) 	{		return;	}	var i = index;		while (i++ < lines.length - 1)	{		var data = lines[i].split(this.keySep);				//if (data.length != keyMatrix.length) alert(data+'::'+data.length+'::'+keyMatrix.length+'::'+i);		if (data.length == keyMatrix.length)		{			var o = this.findInteraction(data[gpi], data[eii]);			var ueloPage = this.FindPage(data[gpi]);			//alert(data[gpi]+", "+data[eii]);			if(!o){ 				//var ueloPage = this.FindPage(data[gpi]);								if(!ueloPage){ 					//alert('0::'+data[dataPageType]+'::'+data[dataPageType].indexOf('E'));					ueloPage= this.AddPage();					ueloPage.type = 0;					if(data[dataPageType].indexOf('E')>=0){						ueloPage.pageType = PAGETYPE_EXERCISE;					}else if(data[dataPageType].indexOf('P')>=0){						ueloPage.pageType = PAGETYPE_POLL;					}else{						ueloPage.pageType = PAGETYPE_INFORMATION;					}					ueloPage.pageId = data[dataPageId];					ueloPage.globalIndex = data[gpi];						if((ueloPage.pageType == PAGETYPE_EXERCISE) || (ueloPage.pageType == PAGETYPE_POLL)){						o = ueloPage.interactions[ueloPage.interactions.length] = new UELOInteractions();					}else{						//					}				}				if(ueloPage){					//o = ueloPage.interactions[ueloPage.interactions.length] = new UELOInteractions();				}			}else{				//alert('Wrong data!!!: '+data);			}						if (ueloPage){				for (var j = 0; j < keyMatrix.length; j++){					if (j != gpi && j != eii && j != dataPageType){						//alert(keyMatrix[j]+"::"+data[j]);						ueloPage.setValue(keyMatrix[j], data[j]);					}				}						}						if (o){				for (var j = 0; j < keyMatrix.length; j++){					if (j != gpi){						//alert(keyMatrix[j]+"::"+data[j]);						o.setValue(keyMatrix[j], data[j]);					}				}			}		}	}}UELO.prototype.getChapters = function(){	var chapters = new Array();	var chapterPageName = "";	for (var i = 0; i < this.pages.length; i++) {		var p = this.pages[i];		if (chapterPageName != p.chapterName){			if (this.courseName != p.chapterName){					chapters[chapters.length] = p.chapterName;			}			chapterPageName = p.chapterName;		}	}	return chapters;}UELO.prototype.getPagesInChapter = function(chName){	var chapterPages = new Array();	for (var i = 0; i < this.pages.length; i++) {		var p = this.pages[i];		if (p.chapterName == chName){			if (this.courseName != p.chapterName){					chapterPages[chapterPages.length] = p.globalIndex;			}		}	}	return chapterPages;}UELO.prototype.getUserVars = function(){	return this.userVars;}UELO.prototype.setUserVars = function(uVars){	this.userVars = uVars;}var uelo = new UELO();
