function question() {
	this.q = "";
	this.id = 0;
	this.firstAnswer = null;
	this.qtype = QTEXT;
	this.mask = "";
	this.nextQuestion = null;
	this.required = false;
	this.condition = "";
	this.size = 0;
	this.errormessage = "";
	
	this.userAnswer = "";
	
	this.addAnswer = addAnswer;
	this.testCondition = testCondition;
	this.hasPotentialSkip = hasPotentialSkip;
}

function addAnswer(answerObj) {
	with (this) {
		if (firstAnswer == null)
			firstAnswer = answerObj;
		else {
			var ans = firstAnswer;
			while (ans.nextAnswer != null)
				ans = ans.nextAnswer;
			ans.nextAnswer = answerObj;
		}
	}
}

function testCondition() {
	with (this) {
		if (condition == "")
			return true;

		var testStr = condition.replace(/\{q(\d+)\} *(==|!=) *\"(.+?)\"/g, "evalStatement('$1', '$2', '$3')");
		var ret = eval(testStr);
		return ret;
	}
}

function evalStatement(qid, eq, val) {
	var que = surveyObj.firstQuestion;
	while (que != null && que.id != qid)
		que = que.nextQuestion;
		
	if (que == null)
		return false;
		
	var retval = true;
	var test = false;				
	if (que.qtype == QCHECKBOX) {
		var rx = new RegExp("\"" + val + "\"", "i");
		if (rx.test(que.userAnswer))
			test = true;
	}
	else {
		if (que.userAnswer == val)
			test = true;
	}
	
	var opBool = false;
	if (eq == "==")
		opBool = true;
	
	if (test == opBool)
		retval = true;
	else
		retval = false;
		
	return retval;
}

function hasPotentialSkip() {
	with (this) {
		var hasSkip = false;
		var ans = firstAnswer;
		while (ans != null) {
			if (ans.skipTo != 0) {
				hasSkip = true;
				break;
			}
			ans = ans.nextAnswer;
		}
		return hasSkip;
	}
}
