	function ExerciseObj() {
		this.exerciseId 	  = -1;
		this.exerciseType 	  = 0;
		this.evaluationPassed = 0;
		this.nrOfContentFills = 0;
		this.currentContent   = -1;
		this.tool			  = "";
		this.result 		  = 0;
		this.selectedAnswers  = new Array();
		this.responses  	  = new Array();
		this.responsesEval 	  = new Array();
		this.spanLengthArray  = new Array(); 
	}
	function getExerciseType1ForEvaluation()
	{
		for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
			exerciseObj.responses[spanId] = document.getElementById("toFill_" + spanId).innerHTML;	
		}
	}
	function getExerciseType2ForEvaluation()
	{
		for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
			exerciseObj.responses[spanId] = document.getElementById("check_" + spanId).checked;	
		}
	}
	function getExerciseType4ForEvaluation()
	{
		for(spanId = 0; spanId < 3; spanId++ ){
			control = document.getElementById("radioSelect_" + spanId);
			if(control.checked){
				exerciseObj.responses = control.value; 	
			}
		}
		//alert(dump(radioSelect));
		exerciseObj.tool = document.getElementById("inputTool").value;
	}	
	function getExerciseType5ForEvaluation()
	{
		exerciseObj.tool = document.getElementById("inputTool").value;
	}	
	function prelucrateResultsForExerciseType1(ajaxResponse)
	{
		document.getElementById("exerciseScore").value = ajaxResponse.points;	
		if(ajaxResponse.goodResponse || exerciseObj.evaluationPassed == 2){
			document.getElementById("buttonEvaluate").style.display = "none";
			document.getElementById("nextExercise").style.display = "inline";
			currentTotalScore = parseInt(document.getElementById("totalScore").value);
			currentTotalScore += parseInt(ajaxResponse.points);
			document.getElementById("totalScore").value = currentTotalScore;
			if(ajaxResponse.goodResponse){
				alert(ajaxResponse.messages.goodResponse);
			} else {
				if(exerciseObj.evaluationPassed == 2){
					//Highlight correct answer(s)
					for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
						if(ajaxResponse.responsesEval[spanId]){
							document.getElementById("toFill_" + spanId).className = "goodResponse";
						} else {
							document.getElementById("toFill_" + spanId).className = "badResponse";
							//alert(document.getElementById("toFill_" + spanId).className);
							//alert("Schimb " + document.getElementById("toFill_" + spanId).innerHTML + " cu " + ajaxResponse.goodResponses[spanId].text);
							
							document.getElementById("toFill_" + spanId).innerHTML = ajaxResponse.goodResponses[spanId].text;
						}							
					}
				}
				alert(ajaxResponse.messages.secondFailure);
			}
			document.getElementById("nextExercise").focus();					
		} else {
			alert(ajaxResponse.messages.badResponse);
			document.getElementById("buttonEvaluate").focus();					
		}
		if(exerciseObj.evaluationPassed < 2){
			for(spanId = 0; spanId < exerciseObj.responsesEval.length; spanId++ ){
				if(exerciseObj.responsesEval[spanId]){
					document.getElementById("toFill_" + spanId).className = "goodResponse";
				} else {
					document.getElementById("toFill_" + spanId).className = "badResponse";
				}
			}
		}	
		
	}
	function prelucrateResultsForExerciseType2(ajaxResponse)
	{
		document.getElementById("exerciseScore").value = ajaxResponse.points;
		
		if(ajaxResponse.goodResponse || exerciseObj.evaluationPassed == 2){
			document.getElementById("buttonEvaluate").style.display = "none";
			document.getElementById("nextExercise").style.display = "inline";
			currentTotalScore = parseInt(document.getElementById("totalScore").value);
			currentTotalScore += parseInt(ajaxResponse.points);
			document.getElementById("totalScore").value = currentTotalScore;
			if(ajaxResponse.goodResponse){
				for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
					if(document.getElementById("check_" + spanId).checked){
						document.getElementById("toSelect_" + spanId).className = "selectGood";
					} else {
						document.getElementById("toSelect_" + spanId).className = "selectNormal";
					}
				}
				alert(ajaxResponse.messages.goodResponse);
			} else {
				if(exerciseObj.evaluationPassed == 2){
					//Highlight correct answer(s)
					for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
						if(ajaxResponse.correctResponse[spanId]){
							document.getElementById("toSelect_" + spanId).className = "selectHighlightGood";
						} else {
							document.getElementById("toSelect_" + spanId).className = "selectNormal";
						}							
					}
				}
				alert(ajaxResponse.messages.secondFailure);
			}
			document.getElementById("nextExercise").focus();					
		} else {
			alert(ajaxResponse.messages.badResponse);
			document.getElementById("buttonEvaluate").focus();					
		}
	}

	function prelucrateResultsForExerciseType4(ajaxResponse)
	{
		document.getElementById("exerciseScore").value = ajaxResponse.points;		
		if(ajaxResponse.goodResponse || exerciseObj.evaluationPassed == 2){
			document.getElementById("buttonEvaluate").style.display = "none";
			document.getElementById("finalScore").style.display = "inline";
			currentTotalScore = parseInt(document.getElementById("totalScore").value);
			currentTotalScore += parseInt(ajaxResponse.points);
			document.getElementById("totalScore").value = currentTotalScore;
			if(ajaxResponse.goodResponse){
				//alert(ajaxResponse.messages.goodResponse);
				alert(ajaxResponse.messages.pleaseEvaluate);
			} else {
				if(exerciseObj.evaluationPassed == 2){
					//Highlight correct answer(s)
					//document.getElementById("inputTool").value = ajaxResponse.tool;
					/*for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
						if(ajaxResponse.correctResponse[spanId]){
							document.getElementById("toSelect_" + spanId).className = "selectHighlightGood";
						} else {
							document.getElementById("toSelect_" + spanId).className = "selectNormal";
						}							
					}*/
				}
				alert(ajaxResponse.messages.secondFailure);
			}
			document.getElementById("comment").innerHTML = ajaxResponse.comment;
			document.getElementById("comment").focus();
			document.getElementById("ownEvaluation").focus();					
		} else {
			alert(ajaxResponse.messages.badResponse);
			document.getElementById("buttonEvaluate").focus();					
		}
	}
	function prelucrateResultsForExerciseType5(ajaxResponse)
	{
		document.getElementById("exerciseScore").value = ajaxResponse.points;		
		if(ajaxResponse.goodResponse || exerciseObj.evaluationPassed == 2){
			document.getElementById("buttonEvaluate").style.display = "none";
			document.getElementById("finalScore").style.display = "inline";
			currentTotalScore = parseInt(document.getElementById("totalScore").value);
			currentTotalScore += parseInt(ajaxResponse.points);
			document.getElementById("totalScore").value = currentTotalScore;
			if(ajaxResponse.goodResponse){
				//alert(ajaxResponse.messages.goodResponse);
				alert(ajaxResponse.messages.pleaseEvaluate);
			} else {
				if(exerciseObj.evaluationPassed == 2){
					//Highlight correct answer(s)
					//document.getElementById("inputTool").value = ajaxResponse.tool;
					/*for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
						if(ajaxResponse.correctResponse[spanId]){
							document.getElementById("toSelect_" + spanId).className = "selectHighlightGood";
						} else {
							document.getElementById("toSelect_" + spanId).className = "selectNormal";
						}							
					}*/
				}
				alert(ajaxResponse.messages.secondFailure);
			}
			document.getElementById("comment").innerHTML = ajaxResponse.comment;
			document.getElementById("comment").focus();
			document.getElementById("ownEvaluation").focus();					
		} else {
			alert(ajaxResponse.messages.badResponse);
			document.getElementById("buttonEvaluate").focus();					
		}
	}	
	function verifyOwnEvaluation()
	{
		
		ownEvaluation = parseInt(document.getElementById("ownEvaluation").value);
		if(document.getElementById("ownEvaluation").value.length == 0 || ownEvaluation < 0 || ownEvaluation > 15){
			alert(ownEvalution[0]);
			return false;
		}
		return true;
	}
	function finalScoreForExerciseType4and5()
	{
		document.getElementById("totalScore").value = parseInt(document.getElementById("totalScore").value) + 
													  parseInt(document.getElementById("ownEvaluation").value);
		sUrl = "ajax/finalScoreForExerciseType4And5.ajax.php?ownEvaluation=" + document.getElementById("ownEvaluation").value;
		var callback = {
			//if our XHR call is successful, we want to make use
			//of the returned data and create child nodes.
			success: function(oResponse) {
				YAHOO.log("XHR transaction was successful.", "info", "example");
				YAHOO.log(oResponse.responseText);
				YAHOO.log("Response object dump: " + dump(oResponse.responseText));
				document.getElementById("finalScore").style.display = "none";
				document.getElementById("nextExercise").style.display = "inline";				
			},
			
			//if our XHR call is not successful, we want to
			//fire the TreeView callback and let the Tree
			//proceed with its business.
			failure: function(oResponse) {
				YAHOO.log("Failed to process XHR transaction.", "info", "example");
			},
			
			//our handlers for the XHR response will need the same
			//argument information we got to loadNodeData, so
			//we'll pass those along:
			argument: {
			},
			
			//timeout -- if more than 7 seconds go by, we'll abort
			//the transaction and assume there are no children:
			timeout: 7000
		};
		
		//With our callback object ready, it's now time to 
		//make our XHR call using Connection Manager's
		//asyncRequest method:
		YAHOO.util.Connect.initHeader("Content-Type", "application/json; charset=utf-8");
		YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);	
	}			
	function evaluateExercise()
	{
		switch(exerciseObj.exerciseType){
			case 1:
				getExerciseType1ForEvaluation();
				YAHOO.log("Exercise1 object dump: " + dump(YAHOO.lang.JSON.stringify(exerciseObj)), "info", "exercise1");
				break;
			case 2: 
				getExerciseType2ForEvaluation();
				YAHOO.log("Exercise2 object dump: " + dump(YAHOO.lang.JSON.stringify(exerciseObj)), "info", "exercise2");
				break;
			case 4:
				getExerciseType4ForEvaluation();
				YAHOO.log("Exercise2 object dump: " + dump(YAHOO.lang.JSON.stringify(exerciseObj)), "info", "exercise4");
				break;
			case 5:
				getExerciseType5ForEvaluation();
				YAHOO.log("Exercise2 object dump: " + dump(YAHOO.lang.JSON.stringify(exerciseObj)), "info", "exercise4");
				break;				
			
		}
		sUrl = "ajax/evaluateExerciseResponse.ajax.php?exerciseResponse=" + YAHOO.lang.JSON.stringify(exerciseObj);
		var callback = {
			//if our XHR call is successful, we want to make use
			//of the returned data and create child nodes.
			success: function(oResponse) {
				YAHOO.log("XHR transaction was successful.", "info", "example");
				YAHOO.log(oResponse.responseText);
				//alert(oResponse.responseText);
				var oResults = YAHOO.lang.JSON.parse(oResponse.responseText);
				YAHOO.log("Response object dump: " + dump(oResponse.responseText));
				//alert(dump(oResults));
				switch(exerciseObj.exerciseType){
					case 1:
						exerciseObj.responsesEval = oResults.responsesEval;
						exerciseObj.result = oResults.result;
						exerciseObj.evaluationPassed++;
						prelucrateResultsForExerciseType1(oResults);	
					break;
					case 2:
						exerciseObj.result = oResults.result;
						exerciseObj.evaluationPassed++;
						prelucrateResultsForExerciseType2(oResults);						
					break;						
					case 4:
						exerciseObj.result = oResults.result;
						exerciseObj.evaluationPassed++;
						prelucrateResultsForExerciseType4(oResults);						
					break;
					case 5:
						exerciseObj.result = oResults.result;
						exerciseObj.evaluationPassed++;
						prelucrateResultsForExerciseType5(oResults);						
					break;							
				}							
			},
			
			//if our XHR call is not successful, we want to
			//fire the TreeView callback and let the Tree
			//proceed with its business.
			failure: function(oResponse) {
				YAHOO.log("Failed to process XHR transaction.", "info", "example");
			},
			
			//our handlers for the XHR response will need the same
			//argument information we got to loadNodeData, so
			//we'll pass those along:
			argument: {
			},
			
			//timeout -- if more than 7 seconds go by, we'll abort
			//the transaction and assume there are no children:
			timeout: 7000
		};
		
		//With our callback object ready, it's now time to 
		//make our XHR call using Connection Manager's
		//asyncRequest method:
		YAHOO.util.Connect.initHeader("Content-Type", "application/json; charset=utf-8");
		YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
	}

	function buildSpansLengthArrays()
	{
		for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
			exerciseObj.spanLengthArray[spanId] = document.getElementById("toFill_" + spanId).innerHTML.length;	
		}	
	}
	function nextContent()
	{
		input = document.getElementById("inputTextToFill");				
		if(exerciseObj.currentContent == -1){
			document.getElementById("buttonStartNext").value = buttonNext;
			input.style.display = "inline";
		}
		exerciseObj.currentContent++;
		YAHOO.log("Current span: " + exerciseObj.currentContent);
		if(exerciseObj.currentContent == 1){
			document.getElementById("buttonPrevious").disabled =  false;
		}
		if(exerciseObj.currentContent > 0){
			document.getElementById("toFill_" + (exerciseObj.currentContent - 1) ).className = "alreadyModified";
		}
		
		currentSpan = document.getElementById("toFill_" + exerciseObj.currentContent);
		currentSpan.className = "fillNow";
		textFilled = currentSpan.innerHTML;			
		//YAHOO.log("Replace: " + textFilled.replace( /\./g, ""));
		textFilled = textFilled.replace( /\./g, "");
		input.value = textFilled;
		YAHOO.log("Set maxlength " + exerciseObj.spanLengthArray[exerciseObj.currentContent]);		
		input.maxLength = exerciseObj.spanLengthArray[exerciseObj.currentContent];
		input.focus();
		if(exerciseObj.currentContent == exerciseObj.nrOfContentFills - 1){
			document.getElementById("buttonStartNext").disabled =  true;
			document.getElementById("buttonEvaluate").disabled  =  false;
		}	
	}
	function previousContent(input)
	{
		if(exerciseObj.currentContent == exerciseObj.nrOfContentFills - 1){
			document.getElementById("buttonStartNext").disabled =  false;
		}
		exerciseObj.currentContent--;
		if(exerciseObj.currentContent < exerciseObj.nrOfContentFills - 1){
			document.getElementById("toFill_" + (exerciseObj.currentContent + 1) ).className = "alreadyModified";
		}		
		YAHOO.log("Current span: " + exerciseObj.currentContent);
		if(exerciseObj.currentContent == 0){
			document.getElementById("buttonPrevious").disabled =  true;
		} 
		currentSpan = document.getElementById("toFill_" + exerciseObj.currentContent);
		currentSpan.className = "fillNow";
		textFilled = currentSpan.innerHTML;			
		textFilled = textFilled.replace( /\./g, "");
		input = document.getElementById("inputTextToFill");				
		input.value = textFilled;
		YAHOO.log("Set maxlength " + exerciseObj.spanLengthArray[exerciseObj.currentContent]);
		input.maxLength = exerciseObj.spanLengthArray[exerciseObj.currentContent];
		input.focus();
	}
	function copyContent(elem)
	{
		document.getElementById("toFill_" + exerciseObj.currentContent).innerHTML = elem.value;				
		if(exerciseObj.currentContent == exerciseObj.nrOfContentFills - 1){
			document.getElementById("buttonEvaluate").disabled  =  false;
		}	
	}
	function selectSpan(spanNo)
	{
		if(document.getElementById("check_" + spanNo).checked){
			document.getElementById("toSelect_" + spanNo ).className = "selectSelected";	
		} else {
			document.getElementById("toSelect_" + spanNo ).className = "selectNormal";
		}
		checkEvaluateButtonStatus();
	}
	function checkEvaluateButtonStatus()
	{
		for(spanId = 0; spanId < exerciseObj.nrOfContentFills; spanId++ ){
			if(document.getElementById("check_" + spanId).checked){
				document.getElementById("buttonEvaluate").disabled  =  false;
				return;	
			}
		}
		document.getElementById("buttonEvaluate").disabled  =  true;
	}

	function enableEvaluationType4()
	{
		if(!((document.getElementById("inputTool").value.length == 0) || (document.getElementById("inputTool").value == null))){
			for(spanId = 0; spanId < 3; spanId++ ){
				if(document.getElementsByName("radioSelect")[spanId].checked){
					document.getElementById("buttonEvaluate").disabled  =  false;
					return;	
				}
			}
		}
		document.getElementById("buttonEvaluate").disabled  =  true;
	}
	function enableEvaluationType5()
	{
		if(!((document.getElementById("inputTool").value.length == 0) || (document.getElementById("inputTool").value == null))){
			document.getElementById("buttonEvaluate").disabled  =  false;
			return;	
		}
		document.getElementById("buttonEvaluate").disabled  =  true;
	}			
