PAGETYPE_UNKNOWN = "Unknown";PAGETYPE_INFORMATION = "Information";PAGETYPE_EXERCISE = "Exercise";PAGETYPE_HIDDEN = "Hidden";PAGESTATUS_NOT_ATTEMPTED = "N";PAGESTATUS_INCOMPLETE = "I";PAGESTATUS_COMPLETED = "C";PAGESTATUS_PASSED = "P";PAGESTATUS_FAILED = "F";KEY_SEP = "#|#";/*  *  *  */UELOInteractions = function(){	this.id = "";	this.correctResponses = "";	this.time = "";	this.type = "";	this.weighting = "";	this.studentResponse = "";	this.status = "N";	this.result = "";	this.score = "";	this.question = "";	this.latency = "";}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"){		//alert(name+'::'+value);		if(value=='P') this['result']=true;		else this['result']=false;	}		if (typeof(this[name]) == "number" || typeof(this[name]) == "string" || typeof(this[name]) == "boolean"){		//alert(name+'::'+value);		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';	}else{		this.result=false;		this.status='F';	}	}/*  *  *  */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.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, score){	//alert("elementId: "+elementId+", question: "+question+", correctResponses: "+correctResponses+", score: "+score);	/*	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();		//alert('il= '+this.interactions.length);		inter.id = interId;		inter.question = question || "";		inter.score = score || "";		inter.correctResponses = correctResponses || "";		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.writeValuesList = new Array("organisation", "username", "password", "server", "percentCompleted", "pagesVisited", "pointsMax", "points", "passThreshold",  "beginTime", "endTime", "courseName", "courseDescription","keySep");}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;	}}UELO.prototype.setPageVisited = function(pageGlobalIndex){	var p = this.FindPage(pageGlobalIndex);	if(p){		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.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.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.pointsMax + "\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 += "\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 + "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];		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 + inter.id + this.keySep + inter.question + this.keySep + inter.studentResponse + this.keySep + inter.score + this.keySep + inter.status + this.keySep + "E \n";			}		}else{			//var pStatus="N";			r += uelo.scoId + this.keySep + page.pageId + this.keySep + page.globalIndex + this.keySep + this.keySep + this.keySep + this.keySep + "1" + 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.pointsMax + "\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 += "\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 + "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.score + this.keySep + inter.question + this.keySep + inter.latency + "\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.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]);			//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{						ueloPage.pageType = PAGETYPE_INFORMATION;					}					ueloPage.pageId = data[dataPageId];					ueloPage.globalIndex = data[gpi];						if(ueloPage.pageType == PAGETYPE_EXERCISE){						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]);					}				}			}		}	}}var uelo = new UELO();
