function validateform(form) {
	// make sure there is an answer for each question
	var s = "";
	var n = 0;
	var msg = "";
	var k = 0;
	var j = 0;
	var f = aForms[step].split(",");
	var c = new Array(f.length); 
	for (j=0; j < f.length; j++) {
		var i = parseInt(f[j]);
		for (r=0; r < aQ[i].options.length; r++) {
			if (aQ[i].options[r].Type == "radio") {
				if (eval("form.q" + i + "[" + r + "].checked") == true) {
					c[n] = aQ[i].options[r].Value;
					break;
				}
			} else if (aQ[i].options[r].Type == "ntext") {
				var txt = eval("form.q" + i + "[" + r + "].value");
				if (txt != "")
					c[n] = txt;
			}
		}
		n++;
	}	

	//check that all q's answered
	var qall = 1;
	for (i=0; i < c.length; i++) {
		if (c[i] == undefined)
			qall = 0;
	}
	if (qall == 0) {
		msg += "Please answer all questions.";
		alert(msg);
		}
	else {
		var flat_c = "";
		for (i=0; i < c.length; i++) {
			flat_c += ",";
			flat_c += c[i];
		}
		if (step == 0) 
			window.location.href = sourceURL + '?ans=' + (parseInt(step) + 1) + flat_c + "&rnd=" + Math.random()
		else
			window.location.href = sourceURL + '?ans=' + (parseInt(step) + 1) + "," + getPrevAns() + flat_c + "&rnd=" +Math.random();
	}
	return false;
}

function getPrevAns() {
	// compile previous answers
	var s = "";
	for (i=1; i < values.length; i++) {
		s += values[i] + ","
	}
	return (s.substring(0, s.length-1));
}

function cQuestion(question) {
	this.question = question;
	this.options = new Array();
	this.addOption = addOption;
	this.renderQuestion = renderQuestion;
	function addOption(optText, optType, optName, optValue) {
		this.options[this.options.length] = new cOption(optText, optType, optName, optValue);
	}
	function renderQuestion() {
		var s = "";
		var i = 0;
		s += "<b>" + this.question + "</b><BR>";
		for (i=0; i < this.options.length; i++) {
			s += this.options[i].renderOption();
		}
		return s;
	}
}

function cOption(optText, optType, optName, optValue) {
	this.Text = optText;
	this.Type = optType;
	this.Name = optName;
	this.Value = optValue;
	this.renderOption = renderOption;
	function renderOption() {
		var s = "";
		if (this.Type == "radio") 
			s += "<input type='radio' name='" + this.Name + "' value='" + this.Value + "'>" + this.Text + "<BR>"
		else if (this.Type == "ntext") 
			s += "<input type='text' name='" + this.Name + "' value='" + this.Value + "' onchange='validatenum(this)'>" + this.Text + "<BR>";
		return s;
	}
}

function validatenum(s) {
	if (isNaN(s.value)) {
		alert("Please enter a numeric value.");
		s.value = "";
		s.focus();
	}
}
