// 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 PopUpImage(heading, text, imagename, width, height, description) {
	var bgcolor 		= "#D6DDE7";	
	var xwidth  		= 500;
	var yheight 		= 300;
	var width 			= width;
	var height			= height;
	var description		= description;
	var imagename 		= "../images/" + imagename
	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("<img src='" + imagename + "' width='"+ width + "' height='"+ height + "' alt='"+ description + "' border='0'>");
	vindow.document.writeln("<img src='"+ imagename + "' width='"+ width + "' height='"+ height + "' alt='"+ description + "' border='0'>");	
	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();
}

// JavaScript Document
function PopUpFile(filename) {
 var xwidth    = 800;
 var yheight   = 595;
 var scrollbars   = 1;
 vindow = window.open("../images/" + filename, "FileWindow", "resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollbars + ",copyhistory=0,width=" + xwidth + ",height=" + yheight);
 vindow.focus();
}

function PopUpthisFile(filename) {
 var xwidth    = 800;
 var yheight   = 600;
 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();
}

function PopUpResource(filename) {
 var xwidth    = 790;
 var yheight   = 590;
 var scrollbars   = 0;
 vindow = window.open(filename, "FileWindow", "resizable=1,toolbar=0,location=0,directories=0,status=0,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)) {
		ableForm(document.mcForm,true)	
		alert( "You have completed this question." );
		return;
	}
	if (curr_tries == num_tries){
		ableForm(document.mcForm,true);
	}	

	// 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;
		
		if (scorequiz){
			vscore++;
			document.cookie = "scoreval=" + vscore;  // Score is added to the Cookie Value
		}
		
		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'>");
		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("</head>");
		w.document.writeln("<body>");	
		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>");
	}
	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;
			if (scorequiz){
				vscore++;
				document.cookie = "scoreval=" + vscore;  // Score is added to the Cookie Value
			}
			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></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'>");
			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>");
			
}

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("</head>");
			w.document.writeln("<body>");	
			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'>");
				if (curr_tries == num_tries){
					ableForm(document.mcForm,true)
					//w.document.writeln(review);
					w.document.writeln("<BR>");					
				}			
			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:self.close();
}

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;
	}
	
	if (curr_tries == num_tries){
		ableForm(document.mcForm,true);
	}
	
	
	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 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();
		}
	
}


function ableForm(fRef, disable) {
  if (document.getElementById || document.all) {
    for (var i=0; i<fRef.elements.length; i++) {
      fRef.elements[i].disabled = disable;
    }
  }
}




function loadThese(){
	//GetParam('remclick');
	setBookmark(window.location);
}

function initquestion(){
	//GetParam1('returnclick');
	//setBookmark(window.location);
	readCookie(name);
	DisableRightClick ();
}

function initscore(){
	var vscore = 0;
	document.cookie = "scoreval=" + vscore; 
	//alert("vscore" + vscore);
}

function calculatescore (number,totalpages){ // Calculate the percentage score after rounding off the numbers
	var percentage = (number / totalpages) ;
	var rlength = 2; // The number of decimal places to round to
	var newnumber = Math.round(percentage*Math.pow(10,rlength))/Math.pow(10,rlength);
	percentage = newnumber * 100 ;
	//alert("you scored : " + percentage);
	return percentage ;
}

function readCookie(name){
	var start = cookies.indexOf(name +"=");
		if (start == -1){
			//alert ("cookie not found");
		}
	start = cookies.indexOf("=", start) + 1;
	var end = cookies.indexOf(";", start);
	if (end == -1){
		end = cookies.length;
	}
	var value = unescape(cookies.substring(start, end));
	if (value==null){
		alert("no cookie found");
	}else{
		//alert("cookie value is :" + value);
		vscore = value;
	}
	return vscore;
}

function initlastpage(){
	var finalscore = readCookie(name);						
	var percentscore = calculatescore (finalscore, totalquestions);
	//alert("percentscore" + percentscore);
	window.document.scoreform.scoreval.value = Math.round(percentscore*100)/100 + "%";				
	percentscore = eval(percentscore)
	if (percentscore >= "80"){
		passSCO();
	}else{
		failSCO();
	}
	
}


function DisableRightClick () {
	//Disable right click script III- By Renigade (renigade@mediaone.net)
	//For full source code, visit http://www.dynamicdrive.com

	var message="";
	///////////////////////////////////
	function clickIE() {
		if (document.all) {
			(message);
			return false;
		}
	}
	function clickNS(e) {
		if (document.layers||(document.getElementById&&!document.all)) {
			if (e.which==2||e.which==3) {
				(message);
				return false;
			}
		}
	}
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS;
	}
	else {
		document.onmouseup=clickNS;
		document.oncontextmenu=clickIE;
	}

	document.oncontextmenu=new Function("return false");
}

//FUNCTION FOR SEQUENCING FILL IN THE BLANKS ADDED ON 9/13/05////////////////////////////////////////////////////////////////
function fillBlanksCus5Ans( ) {
  if (document.mcForm.t1 == undefined) {
 
  }else{
   x1 = document.mcForm.t1.value;
   x1 = x1.toLowerCase();
  }
 
  if (document.mcForm.t2 == undefined) { // If there are more than 1 fill in the blank check if it is available
 
  }else{
   x2 = document.mcForm.t2.value;
   x2 = x2.toLowerCase();
  }
  
  if (document.mcForm.t3 == undefined) {  // If there are more than 2 fill in the blank check if it is available
 
  }else{
    x3 = document.mcForm.t3.value;
   x3 = x3.toLowerCase();
  }
  
  if (document.mcForm.t4 == undefined) {  // If there are more than 2 fill in the blank check if it is available
 
  }else{
    x4 = document.mcForm.t4.value;
   x4 = x4.toLowerCase();
  }
  
  if (document.mcForm.t5 == undefined) {  // If there are more than 2 fill in the blank check if it is available
 
  }else{
    x5 = document.mcForm.t5.value;
   x5 = x5.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." );
   alert( "You have completed this question." );
   return;
  }
  if (qDist == 4) {
   if ((CA1 == x1) && (CA2 == x2) && (CA3 == x3) && (CA4 == x4)) {
    gotCorrect();
   }else{
    gotIncorrect(); 
   } //End if qdist = 4
   return false;
  }// End If Statement Parenthesis
  
  if (qDist == 5) {
   if ((CA1 == x1) && (CA2 == x2) && (CA3 == x3)&& (CA4 == x4) && (CA5 == x5)) {
    gotCorrect();
   }else{
    gotIncorrect(); 
   } //End if qdist = 3
   return false;
  }
 
} // End function parenthesis

function runEmbeddedFscreen(nameofFile, width, height){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width='+width+' height='+height+' id="base" align="middle">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value='+nameofFile+' />\n')
	document.write('<param name="quality" value="high" />\n')
	document.write('<param name="scale" value="exactfit" />\n')
	document.write('<param name="salign" value="lt" />\n')
	document.write('<param name="bgcolor" value="#ffffff" />\n')
	document.write('<embed src='+nameofFile+' quality="high" scale="exactfit" salign="lt" bgcolor="#ffffff" width='+width+' height='+height+' name="base" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n')
	document.write('</object>\n')
}


function embedIEswf(nameofFile){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="100%" id="base" align="middle">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value='+nameofFile+' />\n')
	document.write('<param name="quality" value="high" />\n')
	document.write('<param name="scale" value="exactfit" />\n')
	document.write('<param name="salign" value="lt" />\n')
	document.write('<param name="bgcolor" value="#ffffff" />\n')
	document.write('<embed src='+nameofFile+' quality="high" scale="exactfit" salign="lt" bgcolor="#ffffff" width="100%" height="100%" name="base" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n')
	document.write('</object>\n')
}

