// common TLPLib Javascript

//==========================================================================
// openAnswerWin opens a new window displaying the answer or hint for a question
function openAnswerWin(button) {
	var vwidth = 600;
	var vheight = 400;
	var features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
	// get question number and type
	var question = button.form.question.value;
	var type = button.form.type.value;
	if (type == '1') {
		// quick multichoice question
		vwidth = 300;
		vheight = 200;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		var response = '';
		for (var i = 0; i < button.form.response.length; i++) {
			if (button.form.response[i].checked) {
				response = button.form.response[i].value;
			}
		}
		var w = window.open('answer.php?question='+question+'&response='+response,'',features);
	}
	else if (type == '2') {
		// long multichoice question with hint and explanatory answers
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		if (button.value == 'Hint') {
			// Hint button clicked
			var win = window.open('answer.php?question='+question+'&button=hint','',features);
		}
		else {
			// Answer button clicked
			var response = '';
			var radio = button.form.response;
			for (var i = 0; i < radio.length; i++) {
				if (radio[i].checked) {
					response = radio[i].value;
				}
			}
			var win = window.open('answer.php?question='+question+'&button=answer&response='+response,'',features);
		}
	}
	else if (type == '3') {
		// long question with numerical and worked answers
		vwidth = 600;
		vheight = 400;
		if (button.value == 'Worked answer') {
			vwidth = 700;
			vheight = 500;
		}
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		if (button.value == 'Answer') {
			var w = window.open('answer.php?question='+question+'&button=answer','',features);
		}
		else {
			var win = window.open('answer.php?question='+question+'&button=worked','',features);
		}
	}
	else if (type == '4') {
		// long multichoice question with _no_ hint and explantory answers
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		var response = '';
		var radio = button.form.response;
		for (var i = 0; i < radio.length; i++) {
			if (radio[i].checked) {
				response = radio[i].value;
			}
		}
		var win = window.open('answer.php?question='+question+'&response='+response,'',features);
	}
	else if (type == '5') {
		// long yes/no question displayed with checkboxes, with no hint and explantory answers
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		var response = '';
		var checkArray = button.form.response;
		for (var i = 0; i < checkArray.length; i++) {
			if (checkArray[i].checked) {
				response = response + checkArray[i].value;
			}
		}
		var win = window.open('answer.php?question='+question+'&response='+response,'',features);
	}
	else if (type == '7') {
		// quick multichoice question with hint
		if (button.value == 'Hint') {
			// Hint button clicked
			vwidth = 600;
			vheight = 400;
			features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
			var win = window.open('answer.php?question='+question+'&button=hint','',features);
		}
		else {
			vwidth = 300;
			vheight = 200;
			features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
			var response = '';
			for (var i = 0; i < button.form.response.length; i++) {
				if (button.form.response[i].checked) {
					response = button.form.response[i].value;
				}
			}
			var w = window.open('answer.php?question='+question+'&button=answer'+'&response='+response,'answerwin',features);
		}
	}
	else if (type == '8') {
		// long question with hint and answer
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		if (button.value == 'Hint') {
			var w = window.open('answer.php?question='+question+'&button=hint','',features);
		}
		else {
			var win = window.open('answer.php?question='+question+'&button=answer','',features);
		}
	}
	else if (type == '9') {
		// long yes/no question displayed with radio button pairs, with no hint and explantory answers
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		var response = '';
		var totRadio = button.form.elements.length - 3;
		for (var i = 0; i < totRadio; i = i + 2) {
			if (button.form.elements[2 + i].checked) {
				response = response + 'y';
			}
			else if (button.form.elements[3 + i].checked) {
				response = response + 'n';
			}
			else {
				response = response + '+';
			}
		}
		var win = window.open('answer.php?question='+question+'&response='+response,'',features);
	}
	else if (type == '10') {
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		// long question with hint and answer and worked answer
		if (button.value == 'Hint') {
			var w = window.open('answer.php?question='+question+'&button=hint','',features);
		}
		else if (button.value == 'Answer') {
			var win = window.open('answer.php?question='+question+'&button=answer','',features);
		}
		else {
			var win = window.open('answer.php?question='+question+'&button=worked','',features);
		}
	}
	else if (type == '11') {
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		// long question with answer
		var win = window.open('answer.php?question='+question+'&button=answer','',features);
	}
	else if (type == '12') {
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		// open ended question with hint
		var win = window.open('answer.php?question='+question+'&button=hint','',features);
	}
	else if (type == '13') {
		// quick question with hint and answer
		vwidth = 600;
		vheight = 400;
		features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
		if (button.value == 'Hint') {
			var w = window.open('answer.php?question='+question+'&button=hint','',features);
		}
		else {
			var win = window.open('answer.php?question='+question+'&button=answer','',features);
		}
	}
}
//==========================================================================

