HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/JTent/tentje.com/wwwroot/2015_02_13/layout/tsg_mobile/content/js/template_form.js
var lbIsEvaluated 	= false;   
var lsPageSubType	= 'FORM';
var liTries			= 0;
var liMaxTries		= 0;
var laFormFields	= new Array();
var liOKLeft		= null;
var liOKTop			= null;
var lbOKVisible		= true;
var liFeedbackLeft	= null;
var liFeedbackTop	= null;

function initInteraction() {
	// OK- und Loesungsbutton positionieren, wenn left und top in pagesettings angegeben
	if (liOKLeft != null) {
		loOkButton.shiftTo(liOKLeft,liOKTop);
		loSolution.shiftTo(liOKLeft,liOKTop);
	} else {
		loOkButton.shiftTo(giInputOKLeft,giInputOKTop);
		loSolution.shiftTo(giInputOKLeft,giInputOKTop);
	}
	// Alle Feedbacks positionieren, wenn left und top in pagesettings angegeben
	addFeedback('FBsummary');
	if (liFeedbackLeft != null) {
		for (i=0; i<laFeedbacks.length; i++) {
			document.getElementById(laFeedbacks[i]).style.left = liFeedbackLeft;
			document.getElementById(laFeedbacks[i]).style.top = liFeedbackTop;
		}
	}
	createFormFields();
}

function evaluate() {
	// keine Auswertung, wenn bereits endgueltig ausgewertet wurde oder die Anzahl der Versuche ueberschritten wurde
	if (lbIsEvaluated == true || liTries >= liMaxTries) {
		return;
	}
	// Anzahl Versuche hochzaehlen
	liTries++;
	var lsResult = '';
	var liScore = 0;
	resetPageResult();
	// Status der Formularfelder pruefen
	for (i=0; i<laFormFields.length; i++) {
		if (laFormFields[i].lsType == 'input' || laFormFields[i].lsType == 'textarea') {
			laFormFields[i].checkCorrect();
		}
		if (!laFormFields[i].lbIsOptional && laFormFields[i].lsType != 'button') {
			if (laFormFields[i].lbIsCorrect) {
				lsResult += '2';
				liScore += laFormFields[i].liScore;
			} else {
				if (laFormFields[i].lbChanged == true){
					lsResult += '1';
				} else {
					lsResult += '0';
				}
			}
		}
	}
	// Inhalt des Result-Strings:
	// 0 = Feld ist nicht bearbeitet
	// 1 = Eingabe ist falsch
	// 2 = Eingabe ist richtig
	if (lsResult.indexOf('1') == -1 && lsResult.indexOf('2') == -1) {
		// Keine Eingabe
		liTries = liTries - 1;
	} else if (lsResult.indexOf("0") == -1 && lsResult.indexOf("1") == -1) {
		// Alles Richtig!
		lbIsEvaluated = true;
		// OK-Button ausblenden
		loOkButton.hide();
		if (parent.goPageItem.pagetype != 'tp') {
			if (gbShowSolutionOnLastEval) {
				// Loesung anzeigen
				finishExercise(lsResult, liTries, liScore);
				showSolution();
				return;
			} else {
				disableInput();
			}
		}
		// Weiter-Button freischalten
		parent.goNext.enable();
	} else if (liTries < liMaxTries) {
		// Anzahl der Versuche kleiner maximaler Anzahl der Versuche
		lbIsEvaluated = false;
	} else {
		// Anzahl der maximalen Versuche erreicht
		lbIsEvaluated = true;
		// OK-Button ausblenden
		loOkButton.hide();
		if (parent.goPageItem.pagetype != 'tp') {
			if (gbShowSolutionOnLastEval) {
				// Loesung anzeigen
				finishExercise(lsResult, liTries, liScore);
				showSolution();
				return;
			} else {
				loSolution.show();
			}
		}
		// Weiter-Button freischalten
		parent.goNext.enable();
	}
	finishExercise(lsResult, liTries, liScore);
}       

function resetPageResult() {
	parent.goPageItem.result	= '';
	parent.goPageItem.score		= 0;
	parent.goPageItem.solution	= 0;
}

function finishExercise(psResult, piTries, piScore) {
	// Feedback anzeigen
	showFeedback(psResult, piTries);
	// Score ermitteln
	var liScore = 0;
	if (laExerciseScore[piTries] != null && laExerciseScore[piTries] != '') {
		// Wenn es Punkte fuer die Bearbeitung der Aufgabe gibt
		if (psResult.indexOf("0") == -1 && psResult.indexOf("1") == -1) {
			// Wenn alles richtig
			liScore = parseInt(laExerciseScore[piTries]);
		}
	} else {
		// Sonst die Gesamtpunkte der einzelnen Felder speichern
		liScore = piScore;
	}
	// Seitenstatus setzen: 
	// 0 = nicht richtig geloest
	// 1 = richtig geloest im 1. Versuch
	// 2 = richtig geloest im n. Versuch
	var liSolution = 0;
	if (psResult.indexOf("0") == -1 && psResult.indexOf("1") == -1) {
		if (piTries > 1) {
			liSolution = 2;
		} else {
			liSolution = 1;
		}
	}
	// Seitenstatus setzen
	parent.goPageItem.vis		= true;
	parent.goPageItem.result	= psResult;
	parent.goPageItem.solution	= liSolution;
	parent.goPageItem.score		= liScore;
}

function showFeedback(psResult,piTries) {
	// Alle Feedbacks ausblenden
	for (i=0; i<laFeedbacks.length; i++) {
		getScreenTextObject(laFeedbacks[i]).hide();
	}
	// richtige und falsche zaehlen
	var liMaxTrue	= 0;
	var liTrue		= 0;
	var liFalse		= 0;
	// Status der Formularfelder pruefen
	for (i=0; i<laFormFields.length; i++) {
		if (!laFormFields[i].lbIsOptional && laFormFields[i].lsType != 'button') {
			liMaxTrue ++;
			if (laFormFields[i].lbIsCorrect) {
				liTrue ++;
			} else {
				if(laFormFields[i].lbChanged == true){
					liFalse += 1;
				}	
			}
			if (giShowCorrectAndFalse > -1 && (piTries >= giShowCorrectAndFalse || (giShowCorrectAndFalse == 99 && piTries >= liMaxTries))) {
				laFormFields[i].showFeedback();
			}
		}
	}
	if (liTrue == 0 && liFalse == 0) { 
		// Keine Eingabe des Anwenders
		lsResult = "noanswer";
		piTries = 1;
	} else if (liTrue == liMaxTrue && liFalse == 0) { 
		// Alles Richtig
		lsResult = "correct";
	} else if (liTrue == liMaxTrue && liFalse > 0) { 
		// Alle Richtigen, aber auch Falsche
		lsResult = "all_correct_and_false";
	} else if (liTrue < liMaxTrue && liTrue > 0 && liFalse > 0) { 
		// Richtige, aber nicht alle und Falsche
		lsResult = "correct_and_false";
	} else if (liTrue < liMaxTrue && liTrue > 0 && liFalse == 0) { 
		// Richtige, aber nicht alle
		lsResult = "correct_not_all";
	} else {	
		// Nur Falsche
		lsResult = "false";
	}
	if (lsResult == "all_correct_and_false") {
		if (document.getElementById('FB'+piTries.toString()+lsResult) == null) {
			lsResult = "correct_and_false";
			if (document.getElementById('FB'+piTries.toString()+lsResult) == null) {
				lsResult = "false";
			}
		}
	} else if (lsResult == 'correct_and_false' && document.getElementById('FB'+piTries.toString()+lsResult) == null) {
		lsResult = 'false';
	} else if (lsResult == "correct_not_all" && document.getElementById('FB'+piTries.toString()+lsResult) == null) {
		lsResult = 'false';
	}

	// Feedback hat selbe Position wie Anweisung; deshalb Anweisung ausblenden.
	hideObjectsOfType('TextAnweisung');
	
	// Feedback-Text anzeigen
	getScreenTextObject('FB'+piTries.toString()+lsResult).show();
	
	// Feedback-Grafik anzeigen, wenn vorhanden
	var lsFeedbackImage = 'g'+lsPageName.substr(1)+'fb'+piTries.toString()+lsResult;
	showObj(lsFeedbackImage);

	// Feedback-Audio abspielen
	var lsFeedbackAudio = 'a'+lsPageName.substr(1)+'fb'+piTries.toString()+lsResult;
	if (loAudios[lsFeedbackAudio] != null) {
		playAudio(lsFeedbackAudio, 'false');
	}
}

function disableInput() {
	for (i=0; i<laFormFields.length; i++) {
		laFormFields[i].disable();
	}
}

function showSolution() {
	if (!gbShowSolutionOnLastEval) {
		// Alle Feedbacks ausblenden
		for (i=0; i<laFeedbacks.length; i++) {
			getScreenTextObject(laFeedbacks[i]).hide();
		}
		// Summary-Feedback anzeigen
		if (document.getElementById('FBsummary') != null) {
			getScreenTextObject('FBsummary').show();
		}
	}
	// Button "Loesung" ausblenden;
	loSolution.hide();
	//
	for (i=0; i<laFormFields.length; i++) {
		if (laFormFields[i].lsType != 'button') {
			laFormFields[i].showSolution();
		}
	}
	disableInput();
}

// =================================================================================================================
// OBJEKTE
// =================================================================================================================

//
// Container (Div) fuer Formularfelder
//
function ObjContainer(psID, piLeft, piTop) {
	loDiv					= document.createElement('div');
	loDiv.id				= psID;
	loDiv.style.position	= 'absolute';
	loDiv.style.left		= piLeft;
	loDiv.style.top			= piTop;
	loDiv.style.visibility	= 'hidden';
	loDiv.style.zIndex		= 10;
	loDiv.className			= 'MarkNone';
	
	document.getElementById('ContentScreen').appendChild(loDiv);

	return loDiv;
}

//
// Container resizen auf angegebene Hoehe und Breite
//
function setContainerSize(poObj, piWidth, piHeight) {
	if (InternetExplorer) {
		piWidth += giFormMarkBorder*2;
		piHeight += giFormMarkBorder*2;
	} else {
		if (poObj.lsType == 'radio') {
			piWidth += giFormMarkBorder*2+5;
			piHeight += giFormMarkBorder*2+1;
		} else if (poObj.lsType == 'checkbox') {
			piWidth += giFormMarkBorder*2+3;
			piHeight += giFormMarkBorder*2+3;
		}
	}
	poObj.htmlobj.style.width = piWidth;
	poObj.htmlobj.style.height = piHeight;
	return;
}

//
// Standardfunktionen fuer Formular-Objekte
//
function setObjFunctions(poObj) {
	addOtherScreenObject('Formfield',poObj);
	poObj.show = function() {
		this.htmlobj.style.visibility = 'visible';
		setContainerSize(this, this.field.offsetWidth, this.field.offsetHeight);
	}
	poObj.hide = function() {
		this.htmlobj.style.visibility = 'hidden';
	}
	poObj.disable = function() {
		poObj.field.onfocus = function() {
			this.blur();
		}
		poObj.field.onclick = function() {
			this.blur();
			if (InternetExplorer && poObj.lsType == 'select') {
				// geht im IE nicht anders, da sonst das geklickte Feld bei Mehrfachauswahl auch selektiert ist
				window.setTimeout(this.obj.lsID+'.showSolution();',50);
			} else {
				if (this.obj.lsType != 'button') {
					this.obj.showSolution();
				}
			}
		}
		poObj.field.onchange = function() {
			document.getElementById('ContentScreen').focus();
		}
		poObj.htmlobj.className = 'MarkNone';
		poObj.field.className = 'FieldNormal';
		if (document.getElementById('fod'+this.lsID) != null) {
			poObj.field.style.cursor = 'help';
			poObj.htmlobj.style.cursor = 'help';
			poObj.htmlobj.onmouseover = function() {
				showFOD(this.id);
			}
			poObj.htmlobj.onmouseout = function() {
				showFOD('');
			}
		} else {
			poObj.field.style.cursor = 'default';
			poObj.htmlobj.style.cursor = 'default';
		}
	}
	poObj.showFeedback = function() {
		if (!this.lbIsOptional && this.lsType != 'button') {
			if (this.lsType == 'radio') {
				// Es wird nur der Radiobutton einer Gruppe markiert, der geklickt ist!
				if (this.lbClicked) {
					if (this.lbIsCorrect) {
						this.htmlobj.className = 'MarkCorrect';
						this.field.className = 'FieldSolution';
					} else {
						this.htmlobj.className = 'MarkFalse';
						this.field.className = 'FieldSolution';
					}
				} else {
					this.htmlobj.className = 'MarkNone';
					this.field.className = 'FieldNormal';
				}
			} else {
				if (this.lbIsCorrect) {
					this.htmlobj.className = 'MarkCorrect';
					this.field.className = 'FieldSolution';
				} else {
					this.htmlobj.className = 'MarkFalse';
					this.field.className = 'FieldSolution';
				}
			}
		}
	}
	return;
}

// Pruefen ob ein Element eines Arrays einem Vergleichsstring entspricht
// Hier zum Abpruefen der Alternativen
function arrayContains(paArray, psValue) {
	for (var i=0; i<paArray.length; i++) {
		if (paArray[i] == psValue) {
			return true;
		}
	}
	return false;
}

//
// Input-Field
//
function InputField(psID, piLeft, piTop, piWidth, pbOptional, psScore, psPreset, psCorrect, paAlternatives) {
	this.lsID					= psID;
	this.lsType					= 'input';
	this.lbIsOptional			= pbOptional;
	this.lbChanged				= false;
	this.lsCorrect				= Unicode2Str(psCorrect);
	this.liScore				= (psScore == '') ? 0 : parseInt(psScore);
	if (psPreset == psCorrect || arrayContains(paAlternatives,psCorrect)) {
		this.lbIsCorrect		= true;
	} else {
		this.lbIsCorrect		= false;
	}
	this.laAlternatives			= Unicode2Str(paAlternatives.join('#ARR#')).split('#ARR#');
	this.htmlobj				= ObjContainer(psID, piLeft, piTop, piWidth);

	loField						= document.createElement('input');
	loField.id					= 'Field'+this.lsID;
	loField.type				= 'text';
	loField.className			= 'FieldNormal';
	loField.style.width			= piWidth;
	if (giFormInputBorder > -1) {
		loField.style.borderWidth = giFormInputBorder;
	}
	loField.value				= Unicode2Str(psPreset);

	loField.obj = this;
	this.field = loField;
	this.htmlobj.appendChild(loField);
	laFormFields.push(this);
	setObjFunctions(this);

	this.checkCorrect = function() {
		if ((this.field.value != '' || this.lbIsOptional) && (this.field.value == this.lsCorrect || arrayContains(this.laAlternatives, this.field.value))) {
			this.lbIsCorrect = true;
		} else {
			this.lbIsCorrect = false;
		}
	}

	loField.onchange = function() {
		this.obj.lbChanged = true;
		this.obj.checkCorrect();
	}
	
	this.showSolution = function() {
		this.field.value = this.lsCorrect;
	}
}

//
// Textarea
//
function Textarea(psID, piLeft, piTop, piWidth, piHeight, pbOptional, psScore, psPreset, psCorrect, paAlternatives) {
	this.lsID					= psID;
	this.lsType					= 'input';
	this.lbIsOptional			= pbOptional;
	this.lbChanged				= false;
	this.lsCorrect				= Unicode2Str(psCorrect);
	this.liScore				= (psScore == '') ? 0 : parseInt(psScore);
	if (psPreset == psCorrect) {
		this.lbIsCorrect		= true;
	} else {
		this.lbIsCorrect		= false;
	}
	this.laAlternatives			= Unicode2Str(paAlternatives.join('#ARR#')).split('#ARR#');
	this.htmlobj				= ObjContainer(psID, piLeft, piTop, piWidth);

	loField						= document.createElement('textarea');
	loField.id					= 'Field'+this.lsID;
	loField.className			= 'FieldNormal';
	loField.style.width			= piWidth;
	loField.style.height		= piHeight;
	loField.style.overflow		= 'auto';
	if (giFormInputBorder > -1) {
		loField.style.borderWidth = giFormInputBorder;
	}
	loField.value				= Unicode2Str(psPreset);

	loField.obj = this;
	
	this.field = loField;
	this.htmlobj.appendChild(loField);
	laFormFields.push(this);
	setObjFunctions(this);

	this.checkCorrect = function() {
		if (this.field.value == this.psCorrect) {
			this.lbIsCorrect = true;
		} else {
			// Alternativen abpruefen
			// Alle Alternativen muessen im eigegebenen Text enthalten sein (AND-Verknuepfung)
			var liCorrect = 0;
			for (var i=0; i<this.laAlternatives.length; i++) {
				if (this.field.value.toLowerCase().indexOf(this.laAlternatives[i].toLowerCase()) != -1) {
					liCorrect++;
				}
			}
			if ((this.field.value != '' || this.lbIsOptional) && liCorrect == this.laAlternatives.length) {
				this.lbIsCorrect = true;
			} else {
				this.lbIsCorrect = false;
			}
		}
	}

	loField.onchange = function() {
		this.obj.checkCorrect();
		this.obj.lbChanged = true;
	}

	this.showSolution = function() {
		this.field.value = this.lsCorrect;
	}
}

//
// Selectbox
//
function SelectBox(psID, piLeft, piTop, piWidth, pbOptional, psScore, piSize, pbMultiple, paSelected, paCorrect, paAlternatives) {
	this.lsID				= psID;
	this.lsType				= 'select';
	this.lbIsOptional		= pbOptional;
	this.laCorrect			= paCorrect;
	this.laSelected			= paSelected;
	this.lbChanged			= false;
	this.lbIsCorrect		= false;
	this.liScore			= (psScore == '') ? 0 : parseInt(psScore);
	this.lbMultiple			= (pbMultiple == 'true') ? true : false;
	this.laAlternatives		= paAlternatives;
	this.htmlobj			= ObjContainer(psID, piLeft, piTop);

	loField					= document.createElement('select');
	loField.id				= 'Field'+this.lsID;
	loField.className		= 'FieldNormal';
	loField.style.width		= piWidth;
	loField.size			= piSize;
	loField.multiple		= this.lbMultiple;
	
	loField.obj = this;

	this.laCorrect		= Unicode2Str(this.laCorrect.join('#ARR#')).split('#ARR#');
	this.laSelected		= Unicode2Str(this.laSelected.join('#ARR#')).split('#ARR#');
	this.laAlternatives	= Unicode2Str(this.laAlternatives.join('#ARR#')).split('#ARR#');
	
	this.field = loField;
	this.htmlobj.appendChild(loField);
	laFormFields.push(this);
	setObjFunctions(this);

	// Auswertung beim Auswaehlen einer Selectbox-Option
	loField.onchange = function() {
		// this ist die Selectbox
		// this.obj ist das Objekt, zu dem die Selectbox gehoert
		this.obj.lbIsCorrect = false;
		this.obj.lbChanged = true;
		var liCorrect = 0;
		for (var i=0; i<this.options.length; i++) {
			if (this.options[i].selected == true && arrayContains(this.obj.laCorrect,this.options[i].text)) {
				liCorrect ++;
			}
		}
		if (liCorrect == this.obj.laCorrect.length || (this.obj.lbMultiple == false && liCorrect == 1)) {
			this.obj.lbIsCorrect = true;
		}
	}

	this.showSolution = function() {
		// this ist das Objekt
		// this.field ist die Selectbox
		for (var i=0; i<this.field.options.length; i++) {
			if (arrayContains(this.laCorrect, this.field.options[i].text)) {
				this.field.options[i].selected = true;
			} else {
				this.field.options[i].selected = false;
			}
		}
	}

	// Optionen hinzufuegen
	for (var i=0; i<this.laAlternatives.length; i++) {
		loOption = document.createElement('option');
		loOption.setAttribute('value',this.laAlternatives[i]);
		this.field.appendChild(loOption);
		loText = document.createTextNode(this.laAlternatives[i]);

		loOption.appendChild(loText);
	}
	this.presetSelectBox = function() {
		// Vorselektierte Eintraege setzen
		// Richtig/Falsch Status bereits am Anfang pruefen (Es kann bereits beim Anlegen auf richtig gesetzt sein)
		var liCorrect = 0;
		for (var i=0; i<this.field.options.length; i++) {
			if (arrayContains(this.laSelected, this.field.options[i].text)) {
				this.field.options[i].selected = true;
				if (arrayContains(this.laCorrect, this.field.options[i].text)) {
					liCorrect++;
				}
			} else {
				this.field.options[i].selected = false;
			}
		}
		if (liCorrect == this.laCorrect.length || (this.lbMultiple == false && liCorrect == 1)) {
			this.lbIsCorrect = true;
		}
	}
	
	window.setTimeout(this.lsID+'.presetSelectBox()',100);
}

//
// Radiobutton
//
function RadioButton(psID, psGroupID, piLeft, piTop, piWidth, pbOptional, psScore, psChecked, piCorrect, psPostText) {
	this.lsID					= psID;
	this.lsType					= 'radio';
	this.lsGroupID				= psGroupID;
	this.lbIsOptional			= pbOptional;
	this.liCorrect				= piCorrect;
	this.liScore				= (psScore == '') ? 0 : parseInt(psScore);
	this.lbChanged				= true;
	this.lbClicked				= false;
	// Richtig/Falsch Status bereits am Anfang pruefen (Es kann bereits beim Anlegen auf richtig gesetzt sein)
	if (psChecked == 'true' && piCorrect == 1) {
		this.lbIsCorrect		= true;
	} else {
		this.lbIsCorrect		= false;
	}
	this.htmlobj				= ObjContainer(psID, piLeft, piTop);

	if (InternetExplorer) {
		// Bug im IE: Eigenschaft "name" kann nicht nachtraeglich gesetzt werden
		loField					= document.createElement('<input name="Field'+psGroupID+'">');
	} else {
		loField					= document.createElement('input');
		loField.name			= 'Field'+psGroupID;
	}
	loField.className			= 'FieldNormal';
	loField.id					= 'Field'+psID;
	loField.type				= 'radio';

	loField.obj = this;
	
	this.field = loField;
	this.htmlobj.appendChild(loField);
	laFormFields.push(this);
	setObjFunctions(this);

	if (psChecked == 'true') {
		loField.checked		= psChecked;
		this.lbClicked			= true;
	}

	// Auswertung beim Klicken des Radiobuttons
	loField.onclick = function() {
		// Alle Radiobuttons der selben Gruppe durchgehen
		for (var i=0; i<document.getElementsByName('Field'+this.obj.lsGroupID).length; i++) {
			document.getElementsByName('Field'+this.obj.lsGroupID)[i].obj.lbClicked = document.getElementsByName('Field'+this.obj.lsGroupID)[i].checked;
			if (document.getElementsByName('Field'+this.obj.lsGroupID)[i].checked == true  && document.getElementsByName('Field'+this.obj.lsGroupID)[i].obj.liCorrect == 1 || 
				document.getElementsByName('Field'+this.obj.lsGroupID)[i].checked == false && document.getElementsByName('Field'+this.obj.lsGroupID)[i].obj.liCorrect == 0) {
				document.getElementsByName('Field'+this.obj.lsGroupID)[i].obj.lbIsCorrect = true;
			} else {
				document.getElementsByName('Field'+this.obj.lsGroupID)[i].obj.lbIsCorrect = false;
			}
		}
		this.obj.lbChanged = true;
	}

	this.showSolution = function() {
		// this ist das Objekt
		// Alle Radiobuttons der selben Gruppe durchgehen und setzen
		for (var i=0; i<document.getElementsByName('Field'+this.lsGroupID).length; i++) {
			if (document.getElementsByName('Field'+this.lsGroupID)[i].obj.liCorrect == 1) {
				document.getElementsByName('Field'+this.lsGroupID)[i].checked = true;
			} else {
				document.getElementsByName('Field'+this.lsGroupID)[i].checked = false;
			}
		}
	}

	loText					= document.createElement('span');
	loText.id				= 'Text'+this.lsID;
	loText.className		= 'FormText';
	loText.style.position	= 'absolute';
	loText.style.left		= giFormRadioSpace;
	loText.style.top		= 0;
	loText.innerHTML		= psPostText;
	if (piWidth > 0) {
		loText.style.width	= piWidth-giFormRadioSpace;
	} else {
		// Dummy-Text anlegen, um Textbreite zu ermitteln, wenn keine angegeben ist
		document.getElementById('ContentScreen').appendChild(loText);
		liTextWidth = loText.clientWidth+1;
		document.getElementById('ContentScreen').removeChild(loText);
		loText.style.width	= liTextWidth;
	}

	this.htmlobj.appendChild(loText);
}

//
// Checkbox
//
function CheckBox(psID, piLeft, piTop, piWidth, pbOptional, psScore, psChecked, piCorrect, psPostText) {
	this.lsID				= psID;
	this.lsType				= 'checkbox';
	this.lbIsOptional		= pbOptional;
	this.liCorrect			= piCorrect;
	this.liScore			= (psScore == '') ? 0 : parseInt(psScore);
	this.lbChanged			= false;
	// Richtig/Falsch Status bereits am Anfang pruefen (Es kann bereits beim Anlegen auf richtig gesetzt sein)
	if (psChecked == 'true' && piCorrect == 1 || psChecked != 'true' && piCorrect == 0) {
		this.lbIsCorrect	= true;
	} else {
		this.lbIsCorrect	= false;
	}
	this.htmlobj			= ObjContainer(psID, piLeft, piTop);

	loField					= document.createElement('input');
	loField.id				= 'Field'+this.lsID;
	loField.type			= 'checkbox'
	loField.className		= 'FieldNormal';
	loField.obj = this;

	this.field = loField;
	this.htmlobj.appendChild(loField);
	laFormFields.push(this);
	setObjFunctions(this);

	// "checked"-Status kann erst nach dem Anlegen der Checkbox im Div gesetzt werden
	if (psChecked == 'true') {
		loField.checked = psChecked;
	}

	// Auswertung beim Klicken der Checkbox
	loField.onclick = function() {
		// this ist die Checkbox
		// this.obj ist das Objekt, zu dem die Checkbox gehoert
		if (this.checked && this.obj.liCorrect == 1 || !this.checked && this.obj.liCorrect == 0) {
			this.obj.lbIsCorrect = true;
		} else {
			this.obj.lbIsCorrect = false;
		}
		this.obj.lbChanged = true;
	}

	this.showSolution = function() {
		// this ist das Objekt
		// this.field ist die Selectbox
		if (this.liCorrect == 1) {
			this.field.checked = true;
		} else {
			this.field.checked = false;
		}
	}

	loText					= document.createElement('span');
	loText.id				= 'Text'+this.lsID;
	loText.className		= 'FormText';
	loText.style.position	= 'absolute';
	loText.style.left		= giFormCheckboxSpace;
	loText.style.top		= 0;
	loText.innerHTML		= psPostText;
	if (piWidth > 0) {
		loText.style.width	= piWidth-giFormCheckboxSpace;
	} else {
		// Dummy-Text anlegen, um Textbreite zu ermitteln, wenn keine angegeben ist
		document.getElementById('ContentScreen').appendChild(loText);
		liTextWidth = loText.clientWidth+1;
		document.getElementById('ContentScreen').removeChild(loText);
		loText.style.width	= liTextWidth;
	}
	
	this.htmlobj.appendChild(loText);
}

//
// Button
//
function FormButton(psID, piLeft, piTop, piWidth, psPreset) {
	this.lsID				= psID;
	this.lsType				= 'button';
	this.htmlobj			= ObjContainer(psID, piLeft, piTop);

	loField					= document.createElement('input');
	loField.id				= 'Field'+this.lsID;
	loField.type			= 'button'
	loField.style.position	= 'absolute';
	loField.style.left		= 0;
	loField.style.top		= 0;
	loField.style.width		= piWidth;
	loField.value			= Unicode2Str(psPreset);
	loField.className		= 'FormButtonText';
	loField.actions			= new Array();
	loField.obj				= this;

	this.field = loField;
	this.htmlobj.appendChild(loField);
	laFormFields.push(this);
	setObjFunctions(this);
	
	this.addEvent = function(psEvent, paActions) {
		this.field.actions[psEvent] = new Array();
		this.field.actions[psEvent].push(paActions)
		if (psEvent == 'click') {
			this.field.onclick = function() {
				for (var i=0; i<this.actions['click'].length; i++) {
					for (var j=0; j<this.actions['click'][i].length; j++) {
						var lsAction = this.actions['click'][i][j][0];			// Action Name
						var lsParam1 = this.actions['click'][i][j][1];			// ObjID
						var lsParam2 = this.actions['click'][i][j][2];			// nSpeed
						eval(lsAction+'("'+lsParam1+'","'+lsParam2+'")');
					}
				}
			}
		}
	}
}