var num_clicks=0;
var submit_form=true;






function showCalc() {
								 newwin_show_calc=window.open("../html/calculator.htm","remotewin2","scrollbars=1,width=310,height=210,resizable=yes,left=400,top=300,screenX=400,screenY=300");

				}

//displays alert box if the user tries to "go on" on the last question
function checkLastQuestion(){
   if (document.questions.goto_question.value == document.questions.question_count.value && !allow_last_justification){
      alert("You are currently at the last question.\n Please double check your answers or submit the exam for scoring.");  
   }
}
				
				

function CheckQuestionNumber() {

				 // first we check that all characters are in range 0-9

				 all_ok = 0;

				 s = document.questions.goto_question.value;

				 for (i=0;i<s.length;i++) {

						 if (s.charAt(i) < '0' || s.charAt(i) > '9') all_ok = 1;

				 }



				 if (all_ok == 1) {

				 		document.questions.goto_question.value = document.questions.previous_question_number.value;

						alert ('The value you entered is invalid, please try again.');

						return false;

				 } 

				 

				 if (parseInt(s) < 0 || parseInt(s) > document.questions.question_count.value) { 

				 		document.questions.goto_question.value = document.questions.previous_question_number.value;

						alert ('The value you entered is either too large or small, please try again.');

						return false;

				 } 

				 

				 if (s.length == 0) {

				 		document.questions.goto_question.value = document.questions.previous_question_number.value;

						alert ('The goto field was blank, please try again.');

						return false;

				 }

				 

				 return true;

}				 


/*****checkclicks*****

This function gets called when the form 
gets submitted to ensure that the person using
the system does not try to submit the question
twice (or more).  If they are trying
to submit this form more than once, a pop
up message is displayed asking the user to wait.

*/

function checkclicks(){

   num_clicks++;

	 if(num_clicks==1){

	    submit_form=true;

	 }else{

	    alert("Please click OK, then wait for next page to load before navigating again");
        setTimeout("resetNumClicks()", 3000);
    	submit_form=false;

	 }

	 return submit_form;

}

//Should be called after some amount of time to reset the number 
//of times that the user has clicked a navigation button
//in IE, a candidate can get "stuck" on a problem since this variable is never reset.
function resetNumClicks(){
   num_clicks=0;
}











/*****showAttachment*****
This needs work.  Generates javascript error, need to check on it.
*/				



function showAttachment(page_to_open) {
   //added screen coordinates for the open window
  newwin_att=window.open(page_to_open,"remotewin2","width=600, height=600,toolbar=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0");
}



function showAttachments(questionId, language) {
   //added screen coordinates for the open window
  newwin_att=window.open("pass_multiple_attachments.asp?question_id=" + questionId + "&language=" + language,"remotewin2","width=600, height=600,toolbar=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0");
}







			



/*****closeAttachment*****



pretty sure this isn't the problem



This function gets called onSubmit, this 



ensures that all previous attachments are closed



before the next window(question) shows up



with its own attachment.



*/



function closeAttachment() {



   if (typeof newwin_att != 'undefined') newwin_att.close();
   if (typeof newwin_show_calc != 'undefined') newwin_show_calc.close();
	 



}



	



	



/*****showHelp*****



This function gets called when the HELP button is pressed. 



This function displays the help page(s) in a separate



windows without toolbars.  



*/				



function showHelp() {

 var options='width=600,height=600,screenX=0,screenY=0,left=0,top=0,'+
             'toolbar=0,scrollbars=1,resizable=yes';
 newwin_help=window.open("/tds_v5/help/help_v2.asp?DisplaySidebar=false",
                          "help",options);
 newwin_help.focus();

}




function showSpecificHelp(type) {

 var options='width=750,height=560,screenX=0,screenY=0,left=0,top=0,'+
             'toolbar=0,scrollbars=yes,resizable=yes';
 newwin_help=window.open("../help/help.asp?DisplaySidebar=false&questiontype="+type,
                          "help",options);
 newwin_help.focus();

}










/*****confirmSubmit*****

This function gets called when the SUBMIT button
is clicked.  This is a prompt to confirm that the user
indeed wants to submit the form for scoring.  

*/



function confirmSubmit() {
  var msg="To submit your exam, type 'Yes' and click 'OK', otherwise click 'Cancel' to return to the exam.";
	if(unanswered_questions > 0 || marked_questions > 0){
	   msg="You have ";
		 
		 if(unanswered_questions > 0) msg=msg +unanswered_questions+" unanswered ";
		 if(unanswered_questions > 0 && marked_questions > 0) msg=msg+"and ";
		 if(marked_questions > 0) msg=msg+marked_questions+" bookmarked ";
		 
		 msg=msg+"question(s).\nTo submit your exam, type 'Yes' and click 'OK', otherwise click 'Cancel' to return to the exam.";
	}

	 var confirmation = prompt(msg,"");
	 document.questions.hidden.value=confirmation;
	 document.questions.submit();

}



function extendedConfirmSubmit() {
  var msg="To submit your exam, type 'Yes' and click 'OK', otherwise click 'Cancel' to return to the exam.";
	 var confirmation = 'EXTENDED CONFIRMATION'; // prompt(msg,"");
	 document.questions.hidden.value=confirmation;
	 document.questions.submit();

}



function confirmLogout() {
  var msg="To submit your exam, type 'Yes' and click 'OK', otherwise click 'Cancel' to return to the exam.";
	 var confirmation = 'LOGOUT CONFIRMATION'; // prompt(msg,"");
	 document.questions.hidden.value=confirmation;
	 document.questions.submit();
}







/*****confirmStore*****



This function gets called when the STORE button



is clicked.  This is a prompt to confirm that the user



indeed wants to submit the form for storing, for use 



at a later date.  



*/



function confirmStore() {



     alert('Your progress will be saved.');



	 document.questions.hidden.value='Store=Yes';



	 document.questions.submit();



}







/*****erase_answer*****



This function is used to erase the currently checked



radio button.  







Note: This isn't used, maybe later



*/



function erase_answer(){



   for(x=0;x<document.questions.option_button.length;x++){



	    if(document.questions.option_button[x].checked==true){



			   document.questions.option_button[x].checked=false;



		 }



	 }  



}



/*****callkeepgoing*****

This function is kind of an error checker to make 

sure that the top frame had fully loaded.  If it's not

fully loaded, the keepgoing function will not exist,

so it will not get called.  If it's there, it gets called.

*/

function callkeepgoing(){

   try { 

      if(typeof(parent.frames[0].keepgoing)=="function")

	       parent.frames[0].keepgoing(); 


   } 

   catch(er) {



   } 

}









///////////////////////////////////////////



//stuff below is used only in untimed test



///////////////////////////////////////////







var start,end;



/*****starttime*****



this function is to enable us to keep



track of the number of seconds spent



on a particular question.  we needed



to be able to keep track of time



of untimed test, but without the use



of a timer.



This is just in case...wasn't part of specs  







get called onload



*/



function starttime(){



   start = new Date();



}







/*****stoptime*****



this function is to enable us to keep



track of the number of seconds spent



on a particular question.  we needed



to be able to keep track of time



of untimed test, but without the use



of a timer.



  



Note: 



Does not actually stop time as we know it :)







This calculates the difference



between the time ended and time started on



a question, then will change the (hidden) 'jstimetook'



variable in the form to reflect this.







get called onsubmit



*/



function stoptime(){



   end = new Date();



	 /*



	 browsers use milliseconds



	 instead of seconds, so



	 we divide by 1000, then 



	 round because the 



	 DB field is integer



	 */



	 var secstook=Math.round((end-start)/1000);



	 document.forms[0].jstimetook.value=secstook;



}








