var nAttempts=1;
var ContextMessage='\n<class>\n\t<school>CMU</school>\n\t<period>09-106</period>\n'
		+'\t<description>Spring 2008</description>\n</class>\n'
		+'<dataset>\n\t<name>Online Vlab Homeworks</name>\n\t<level type="Assigned Homeworks">\n'
		+'\t\t<name>Unknown Acid Assignment</name>\n\t<problem>\n'
		+'\t\t<name>Bonus: Identify Mixture of Acids</name>\n\t\t<context>AcidBase Titration</context>\n'
		+'\t</problem>\n\t</level>\n</dataset>\n';

/**
* Enters name and date and starts the problem
*/
function check_intro() {
	//check if filled
	if(document.step0.studentName.value=="" || document.step0.studentId.value=="") {
		alert("Please enter your name and university ID to start the problem.");
	} else {
		//a1.deactivate();
		var stuName=document.step0.studentName.value;
		var stuId=document.step0.studentId.value;
		stuName=stuName.replace(/<.*>/g,"");
		stuId=stuId.replace(/<.*>/g,"");		
		//document.getElementById("intro").style.display="none";

		//document.getElementById("identification").style.display="block";
		document.getElementById("description").style.display="block";
		//setInnerHTMLById("identification_date",'Loaded at '+full_time());
		//setInnerHTMLById("identification_name",'Name: '+stuName+", Student Number: "+stuId);	
		
		logLogIn(ContextMessage);
	}
	return false;
}

/**
* Enters name and date and starts the problem on PHP-enabled
*/
function check_data() {
	//check if filled
	if(isPHPworking) {
		//a1.deactivate();
		var stuName=userName;
		var stuId=userID;
		stuName=stuName.replace(/<.*>/g,"");
		stuId=stuId.replace(/<.*>/g,"");		
		//document.getElementById("intro").style.display="none";

		//document.getElementById("identification").style.display="block";
		document.getElementById("description").style.display="block";
		//setInnerHTMLById("identification_date",'Loaded at '+full_time());
		//setInnerHTMLById("identification_name",'Name: '+stuName+", Andrew ID: "+stuId);
		a2.activate();
		logLogIn(ContextMessage);
	}
}


/**
* Problem object
*/
function Problem() {

        this.p10=Math.floor(1+Math.random()*3);
        this.concS=(2+Math.random()*3)*Math.pow(10,-this.p10);
		this.concW=(2+Math.random()*4)*Math.pow(10,-this.p10);
        this.qS=this.concS/10;
        this.qW=this.concW/10;

	this.unknownString="u1,"+this.qS+",u2,"+this.qW;
}
	


	function checkAnswer() {
		
    var AttemptsLimit=3;

	// check for filled with a number
		if (isNaN(document.acidbottle3.concweak.value) || isNaN(document.acidbottle3.concstrong.value)) {
			alert("Please select an acid and enter a concentration before submitting.");		
		} else {
			var correctconcweak=thisProblem.concW;
			var correctconcstrong=thisProblem.concS;
			var subconcstrong=document.acidbottle3.concstrong.value;
			var subconcweak=document.acidbottle3.concweak.value;
			var isCorrect=(relativeError(correctconcweak,subconcweak,0.01)&&(relativeError(correctconcstrong,subconcstrong,0.01)));
			var errorType="UNKNOWN_ERROR";
			var userAnswer="Student guess is: "+subconcstrong+" M trichloroacetic acid"
					+" and "+subconcweak+" M alloxanic acid.";
			var corAnswer="The unknown bottle contains "+format_sig(correctconcstrong,3)+" M trichloroacetic acid"
					+" and "+format_sig(correctconcweak,3)+" M alloxanic acid.";
			var message="";
			
			if (relativeError(correctconcweak,subconcweak,0.01)&&(relativeError(correctconcstrong,subconcstrong,0.01))) {
				message="Your answer is CORRECT. WELL DONE.  The bottle contains "+format_sig(correctconcstrong,3)+" "; 
				message+="M trichloroacetic acid and "+format_sig(correctconcweak,3)+" M alloxanic acid.";
				a2.deactivate();
				document.getElementById("done").style.display="block";
				document.getElementById("vlab").style.display="none";
				errorType="CORRECT";
				
			} else {
			
				if (nAttempts>=3) {
					message="Your answer is WRONG. ";
					message+="The solution contains "+format_sig(correctconcstrong,3); 
					message+=" M trichloroacetic acid and "+format_sig(correctconcweak,3)+" M alloxanic acid.";
					message+=" Try to verify this result in the virtual lab and then hit the RELOAD button ";
					message+="to start over with a new problem. Good luck!";
					a2.deactivate();
					
				}	else  {
					message="Your acid concentrations are incorrect, but you still have "+(AttemptsLimit-nAttempts)+" attempts left. ";
					message+="Check your experiment and try again.";
					}
			}
				
		
			a2.setFeedback(message,(isCorrect)?1:nAttempts);
			logFormCheck("acidbottle3",nAttempts,userAnswer,corAnswer,message,isCorrect,errorType);
			nAttempts++;
		}	
		return false;
	}	

/*
* Finishes the problem
*/
function problemCompleted() {
	document.getElementById("vlab").style.display="none";
	document.getElementById("done").style.display="block";
}
