// JavaScript Document

function PopUp(heading, text) {
	var bgcolor 		= "#D6DDE7";	
	var xwidth  		= 400;
	var yheight 		= 300;
	var xyscrollbars  	= 1;
	
	// open  window
	vindow = window.open("", "Window", "resizable=0,toolbar=0,location=0,status=1,menubar=0,scrollbars=" + xyscrollbars + ",copyhistory=0,width=" + xwidth + ",height=" + yheight);
   	vindow.moveTo(((screen.width/2)-170),((screen.height/2)-150))
	vindow.document.open();
	vindow.document.writeln("<html><head><title>" + heading + "</title>");
	vindow.document.writeln("</head><body>");
	vindow.document.writeln("<style>");
	vindow.document.writeln(".heading {font-family: Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: bold;   color: #000000;}");
	vindow.document.writeln(".text  {font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: normal; color: #000000;}");
	vindow.document.writeln("</style>");
	vindow.document.writeln("<div class='heading'><p>" + heading + "</p></div>");	
	vindow.document.writeln("<div class='text' ><p>" + text + "</p><p><a href='javascript:self.close()'>Close Window</a></p></div></body></html>");
	vindow.document.close();
	// bring it to the front
	vindow.focus();
}


function PopUpFile(filename) {
	var xwidth  		= 750;
	var yheight 		= 520;
	var scrollbars  	= 1;
	vindow = window.open("../images/" + filename, "FileWindow", "resizable=1,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=" + scrollbars + ",copyhistory=0,width=" + xwidth + ",height=" + yheight);
	vindow.focus();
}



// JavaScript Document



function checkAnswer (formObj) {
	curr_tries++;	// increment now since it starts at zero
	//alert(num_tries);
	// if we're past the max number of tries do NOTHING
	if (( curr_tries > num_tries ) || (gotthis == true)) {
		alert( "You have completed 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;
		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.moveTo(((screen.width/2)-170),((screen.height/2)-150));
		w.focus();
		w.document.open();
		w.document.writeln("<html><head><title>Question Response Correct</title>");
		w.document.writeln("<style>");			
		w.document.writeln(".word {font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: normal;   color: #000000;}");
		w.document.writeln("</style></head>");
		w.document.writeln("<body>");	
		w.document.writeln("<div class='word'><p>" + CorrectFeedback + "</p></div>");
	    w.document.writeln("<form name='form2' method='post' action='javascript:self.close()'>");
		w.document.writeln("<div align='right'>");
		//ableForm(document.mcForm,true)
		w.document.writeln("<input type='submit' name='Submit' value='Close Window'>");
		w.document.writeln("</div>");
		w.document.writeln("</form>");
		w.document.writeln("</body></html>");

	} else {
		gotthis = false;
		w = window.open("about:blank","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>");
		w.document.writeln("<style>");			
		w.document.writeln(".word {font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: normal;   color: #000000;}");
		w.document.writeln("</style></head>");
		w.document.writeln("<body>");	
		w.document.writeln("<div class='word'>");
		w.document.writeln(eval("incorrectFeedback" + curr_tries ));
		w.document.writeln("</div>");
	    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>");
	}
	return false;  
}


function fillBlanks( ) {
	var ns = navigator.appName;
	var bVer = parseInt(navigator.appVersion);
//=================================CONDITIONS FOR NETSCAPE==================================	
	if ((ns == "Netscape") &&(bVer == 4)){
			x1 = document.questionMC.document.form1.t1.value;
			x1 = x1.toLowerCase();
			
		if (document.questionMC.document.form1.t2 == undefined){
		}else{
			x2 = document.questionMC.document.form1.t2.value;
			x2 = x2.toLowerCase();	
		}
		
		if (document.questionMC.document.form1.t3 == undefined){
		}else{
			x3 = document.questionMC.document.form1.t3.value;
			x3 = x3.toLowerCase();	
		}
	}else{
//=================================CONDITIONS FOR NETSCAPE==================================		
	
		if (document.form1.t1 == undefined) {
	
		}else{
			x1 = document.form1.t1.value;
			x1 = x1.toLowerCase();
		}
	
		if (document.form1.t2 == undefined) { // If there are more than 1 fill in the blank check if it is available
	
		}else{
			x2 = document.form1.t2.value;
			x2 = x2.toLowerCase();
		}
		
		if (document.form1.t3 == undefined) {  // If there are more than 2 fill in the blank check if it is available
	
		}else{
	 		x3 = document.form1.t3.value;
			x3 = x3.toLowerCase();
		}
	}
	
	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 have completed this question." );
		return;
	}
	
	if (qDist == 1) {
		if (CA1 == x1) {
			gotCorrect();
		}else{
			gotIncorrect();
		}
		return false;		
	}
	
	if (qDist == 2) {
		if ((CA1 == x1) && (CA2 == x2)) {
			gotCorrect();
		}else{
			gotIncorrect();
		}
		return false;		
	}
	
	if (qDist == 3) {
		if ((CA1 == x1) && (CA2 == x2) && (CA3 == x3)) {
			gotCorrect();
		}else{
			gotIncorrect();	
		} //End if qdist = 3
		return false;
	}// End If Statement Parenthesis	
} // End function parenthesis
	
	
	
function gotCorrect() {
			gotthis = true;
			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.moveTo(((screen.width/2)-170),((screen.height/2)-150));
			w.focus();
			w.document.open();
			w.document.writeln("<html><head><title>Question Response Correct</title>");
			w.document.writeln("<style>");			
			w.document.writeln(".word {font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: normal;   color: #000000;}");
			w.document.writeln("</style></head>");
			w.document.writeln("<body>");	
			w.document.writeln("<div class='word'><p>" + CorrectFeedback + "</p></div>");
			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 gotIncorrect() {
			gotthis = false;
			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.moveTo(((screen.width/2)-170),((screen.height/2)-150));
			w.focus();
			w.document.open();
			w.document.writeln("<html><head><title>Question Response Incorrect</title>");
			w.document.writeln("<style>");			
			w.document.writeln(".word {font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: normal;   color: #000000;}");
			w.document.writeln("</style></head>");
			w.document.writeln("<body>");	
			w.document.writeln("<div class='word'>");
			w.document.writeln(eval("incorrectFeedback" + curr_tries ));
			w.document.writeln("</div>");
			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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function set_thisfocus() {
	var ns = navigator.appName;
	var bVer = parseInt(navigator.appVersion);
	if ((ns == "Netscape") &&(bVer == 4)){
		document.questionMC.document.form1.t1.focus();
	}else{
		document.form1.t1.focus();
	}
}

function goToMenu(){
	var ns = navigator.appName;
	var bVer = parseInt(navigator.appVersion);
	javascript:parent.courseviewer_child_api.doProperExit();
}

function openCenter(myurl,winName,features){
   windowNavi = window.open(myurl,"IMS","toolbar=no,width=430,height=300,menubar=no,status=no,scrollbars=yes,resizable=no");
   windowNavi.moveTo(((screen.width/2)-170),((screen.height/2)-150))
   windowNavi.location = myurl;
   windowNavi.focus();
}


//Multiple Answer Functions
function MA_toggleChoice( number, id ) {
	
	var current = userArray[number];
	
	if ( current == 'true' ) {
		current = 'false';
	} else {
		current = 'true';
	}
	//alert( "Setting " + number + " to " + current );
	userArray[number] = current;
}







function checkAnswerMa (formObj) {
curr_tries++;
	if (( curr_tries > num_tries ) || (gotthis == true)) {
		alert( "You have completed this question." );
		return;
	}
	
	var score = 0;
	for ( var i=1; i<num_questions+1; i++ ) {
	
		//alert ("[ " + i + "] Comparing answer " + answerArray[i] + " to " +  userArray[i] );
	
		if ( answerArray[i] == userArray[i] ) {
		score++;
		} 
	}// End For Loop
	
		if ( score == num_questions ) {		
			curr_tries += 10;
			gotCorrect();			
		} else {
			gotIncorrect();
		}
		
}

function MA_toggleOrder( number, id, order ) {
	var ans = ansUser.push(order);
	//alert(ansUser);
	var current = userArray[number];
	
	if ( current == 'true' ) {
		current = 'false';
	} else {
		current = 'true';
	}
	//alert( "Setting " + number + " to " + current );
	userArray[number] = current;
	return ansUser;
	//alert(userArray[id]);
}




function checkAnswerOrder(formObj){
	curr_tries++;
	if (( curr_tries > num_tries ) || (gotthis == true)) {
		alert( "You have completed this question." );
		return;
	}
	//a = ansOrder.toString();
	b = ansUser.toString();
	
	alert("ansOrder " + ansOrder);
	alert("ansUser " + ansUser);

		if ( ansOrder == b ){
			gotCorrect();
		}else{
			for ( var i=0; i<num_questions; i++ ) {
					formObj.elements[i].checked = false;
					ansUser.pop();
				}	
				gotIncorrect();
		}
	
}


