// JavaScript Document
function wasEmpty(str) {
	if (str==null || str=="")
		return true;
	return false;
}

function checkLogin(logname,pass) {
	aUsername = new Array("Orion","hhamman","space","black");
	aPassword = new Array("belt","stars","time","hole");
	
	for (i=0; i<4; i++) 
		if (aUsername[i]==logname && aPassword[i]==pass)
			return true;
	return false;
}

function validateLogin() {
	un = document.login.username.value;
	pw = document.login.password.value;
	msg = "";
	if (wasEmpty(un)) {
		msg = "You didn't enter a username.";
	}
	if (wasEmpty(pw)) {
		msg += "\n\nYou haven't entered a password.";
	}
	if (!wasEmpty(msg)) {
		alert(msg);
	} else {
	
		// check if login is valid
		
		if (checkLogin(un,pw)) {
			alert("Welcome to Studying the Stars!");
		} else {
			alert("The Username and, or Password you entered is incorrect, please try again.");
		}
	}
	
}


function checkAnswer (formObj) {
	curr_tries++;	// increment now since it starts at zero
	// if we're past the max number of tries do NOTHING
	if (( curr_tries > num_tries ) || (gotthis == true)) {
		alert( "You alreday answered this question." );
		return;
	}
	

	// Check all the radio buttons that are called 'radioButton'
	radioObject = formObj.radiobutton;
	value = null;
	for (i= 0; i < radioObject.length; i++){
		if (radioObject[i].checked) {
			value = radioObject[i].value;
			break;
		}
	}

	if (value == CorrectChoice) {
		gotthis = true;
                gotCorrect();
	} else {
		gotthis = false;
                gotIncorrect();
	}
	return false;  
}

function gotCorrect() {
		w = window.open("","questionResponse","resizable=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,copyhistory=0,width=380,height=250");
		w.focus();
		w.document.open();
		w.document.writeln("<html><head><title>Question Response Correct</title></head>");
		w.document.writeln("<body>");	
		w.document.writeln(CorrectFeedback);
	    	w.document.writeln("<form name='form2' method='post' action='javascript:self.close()'>");
		w.document.writeln("<div align='right'>");
		w.document.writeln("<input type='submit' name='Submit' value='Close Window' />");
		w.document.writeln("</div>");
		w.document.writeln("</form>");
		w.document.writeln("</body></html>");
		if (scorequiz){
			vscore++;
			document.cookie = "scoreval=" + vscore;  // Score is added to the Cookie Value;
		}

}

function gotIncorrect() {
		w = window.open("","questionResponse","resizable=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,copyhistory=0,width=380,height=250");
		w.focus();
		w.document.open();
		w.document.writeln("<html><head><title>Question Response Incorrect</title></head>");
		w.document.writeln("<body onBeforeUnload= 'window.opener.showAns()' onunload='window.opener.showAns()'>");	
		w.document.writeln(eval("incorrectFeedback" + curr_tries));
	    w.document.writeln("<form name='form2' method='post' action='javascript:self.close()'>");
		w.document.writeln("<div align='right'>");			
		w.document.writeln("<input type='submit' name='Submit' value='Close Window' />");
		w.document.writeln("</div>");
		w.document.writeln("</form>");
		w.document.writeln("</body></html>");

}

function fillin1 () {
	curr_tries++;	// increment now since it starts at zero
	// if we're past the max number of tries do NOTHING
	if (( curr_tries > num_tries ) || (gotthis == true)) {
		alert( "You're done with this question, please go on the next question." );
		return;
	}
	
value=document.form1.Hunter.value;

	if (value == CorrectChoice) {
		gotthis = true;
                gotCorrect();
	} else {
		gotthis = false;
                gotIncorrect();
	}
	return false;  
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

