Source: unknownacid1.js

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>Identify 1st Unknown Acid</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.acidType=1+Math.floor(Math.random()*5);
        this.pC=2-Math.random()*2;
        this.conc=Math.pow(10,-this.pC);
		this.q=this.conc/10;
		this.AcidId=41;
		
    if (this.acidType==1) {
        this.AcidHo=-616.21;
		this.AcidName="Crotonic acid";
    } else if(this.acidType==2) {
        this.AcidHo=-606.96;
		this.AcidName="Methylmalonic acid";
    } else if(this.acidType==3) {
        this.AcidHo=-611.93;
		this.AcidName="Diphenylacetic acid";
    } else if(this.acidType==4) {
        this.AcidHo=-627.336;
		this.AcidName="Alloxanic acid";
    } else if(this.acidType==5) {
        this.AcidHo=-618.55;
		this.AcidName="Methyl-m-aminobenzoic acid";
    } else if(this.acidType==6) {
        this.AcidHo=-591.6;
		this.AcidName="Picric acid";
    }
        
    this.Ka=Math.exp(-((-627.3-this.AcidHo)*1000-298.15*(-127))/(8.3145*298.15));     
    this.pKa=-Math.log(this.Ka)/Math.log(10); 
	
	this.unknownString="u1,"+this.AcidId+",u2,"+this.q+",u3,"+this.AcidHo;
}
	


	function checkAnswer() {
		
    var AttemptsLimit=3;

	// check for filled with a number
		if (document.acidbottle1.acid.selectedIndex=="" || isNaN(document.acidbottle1.conc.value)) {
			alert("Please select an acid and enter a concentration before submitting.");		
		} else {
			var correctconc=thisProblem.conc;
			var correctName=thisProblem.AcidName;
			var subconc=document.acidbottle1.conc.value;
			var subAcidName=document.acidbottle1.acid.selectedIndex;
			var corAcidName=thisProblem.acidType;
			var isCorrect=(relativeError(subconc,correctconc,0.01)&&(subAcidName==corAcidName));
			var errorType="UNKNOWN_ERROR";
			var userAnswer="Student guess for the acid is: "+document.acidbottle1.acid.options[document.acidbottle1.acid.selectedIndex].text+
					", the estimated concentration is "+ document.acidbottle1.conc.value+" M";
			var corAnswer="The unknown contains "+correctName+" at a concentration of "+format_sig(correctconc,3)+" M";
			
			var message="";
			if (relativeError(subconc,correctconc,0.01)&&(subAcidName==corAcidName)) {
				message="Your answer is CORRECT. The unknown bottle contained "+thisProblem.AcidName+" at a concentration of "
				message+=format_sig(correctconc,3) +" M" ;
				a2.deactivate();
				document.getElementById("done").style.display="block";
				document.getElementById("labframe").style.display="none";
				errorType="CORRECT";
				
			} else {
			
				if (subAcidName==corAcidName) {
                    message="You have the correct acid, but your concentration is wrong. ";
					message+="Try working it again with smaller additions of base.";
					errorType="Concentration error";
					} 
					else {
					message="Your acid choice and concentration are incorrect, but you have still "+(AttemptsLimit-nAttempts)+" attempts left. ";
					message+="Check your experiment and try again.";
						  }
			
				if (nAttempts>=3) {
					message="Your answer is WRONG. ";
					message+="The solution is "+ format_sig(correctconc,3) +" M of "+thisProblem.AcidName+". ";
					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();
				}
			}
			a2.setFeedback(message,(isCorrect)?1:nAttempts);
			logFormCheck("acidbottle1",nAttempts,userAnswer,corAnswer,message,isCorrect,errorType);
			nAttempts++;
		}
		return false;
	}	

/*
* Finishes the problem
*/
function problemCompleted() {
	document.getElementById("labframe").style.display="none";
	document.getElementById("done").style.display="block";
}