var nAttempt=1;

/**
* 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",stuName+", ID: "+stuId);

		logLogIn();
	}
	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",stuName+", ID: "+stuId);
		
		logLogIn();
	}
}

/**
* Problem object
*/
function Problem() {    
	this.deltaS=doubleRandom(80,90);
	this.unknownString="u1,"+this.deltaS;
}

/**
* Finish the lab
*/
function check_lab() {
	var message="";
	
	//check if filled
	if(document.step2.bind.value=="") {
		alert("Please enter your results before submitting.");
	} else if(isNaN(document.step2.bind.value)) {
		// skip submit
		return false;
	} else {
		var submbind=document.step2.bind.value;
		var corK=Math.exp((thisProblem.deltaS)/8.3145);
		var userAnswer="RESULT: "+submbind+".";
		
		if(relativeError(submbind,corK,0.02)) {
			logFormCheck('lab',nAttempt,userAnswer,format_sig(corK,3)+" binding constant for ligand L"+
					" &nbsp; Well done! You did a good job!",true,"CORRECT");
			problemCompleted();
		} else {
			var errorType="UNKNOWN_ERROR";
			if(relativeError(submbind,corK,0.02)&&number_sig(submbind)!=3) {
				message="Your result is not expressed with the correct number of significant figures. ";
				message+="Please check it and submit again.";
				errorType="SIGNIFICANT_FIGURES_ERROR";
			} else  {
    	        message+="Your answer is not correct, please try again and take a closer look at your calculations.";
			}

			
			if (nAttempt==3) {
    	    	message="Your answer is not correct. The correct solution is "+format_sig(corK,3)+
				        " for the binding constant of the ligand to silver";
	    		message+=". Use the Virtual Lab to make sense of this result and hit the RELOAD/REFRESH button ";
   	    		message+="to start over with a new solution. Keep going!";
				a3.deactivate();
			        }
					
			logFormCheck('lab',nAttempt,userAnswer,format_sig(corK,3)+" for the binding constant of ligand L "+
					message,false,errorType);
			a3.setFeedback(message,nAttempt);
			nAttempt++;		
		}
	}
	return false;
}

/*
* Finishes the problem
*/
function problemCompleted() {
	a3.deactivate();
	document.getElementById("vlab").style.display="none";
	document.getElementById("done").style.display="block";
	setInnerHTMLById("done_answer2",document.step2.bind.value+' binding constant for the ligand ');
}


