function can_I_continue(assignment_completed) {

	/* If student has correctly answered all the questions on the page he may
           continue to the next page (or stop if it is the last page).
	   Otherwise he is given a warning message and remains on the page */
	
	all_correct = true;
	if (direction == "backward") {
		return true;
	} else {
	if (no_of_questions > 0) {
		for (k=0;k<no_of_questions;k++) {
		
			all_correct = all_correct && q_correct[k];
		}
	}
	if (no_of_questions == 1) {
		warning_title = "Warning: Incorrect Answer";
		warning_message = "You must correctly answer the question on this"+
		 " page to continue.<br><br>"+
		 "Hint: Remember to push the submit button after selecting an answer.";
	} else {
		warning_title = "Warning: Incorrect or missing answers";
		warning_message = "You must correctly answer all questions on this"+
		 " page to continue.<br><br>"+
		 "Hint: Remember to push the submit button after selecting an answer.";
	} 

		
	if (all_correct) {
		if(assignment_completed) {
			window.close();
			return false;
		} else {
			return true;
		}
	} else {
		create_small_popup(warning_title," ",warning_message);
			return false;
	}
	
	}

	}
		

	function header(course_home_page) {

	/* writes header including the e-Assignment logo, LANGURE tree link, course name, module and assignment
        as well as NCSU brick link */

	 document.write("<img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/green_block.JPG' width='50' height='1030' "+
	 " align='left' alt='Research Ethics' hspace='5'>");  
	
	
	 document.write("<fieldset><legend align=right>");
	
	if (page_no == 1) {
	document.write("<a href='http://www.chass.ncsu.edu/langure/ethics/PHI816%20Fall%202007/common/e-Assignment.php'>" +
				   "<img src='http://www.chass.ncsu.edu/langure/ethics/PHI816%20Fall%202007/common/e-Assignment.png'"+
				   " alt='e-Assignment' hspace='5'></a>");
	}
	
	document.write("</legend>");
	
	/*document.write("<a href='" + course_home_page + "'>");
	document.write("<img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/research-ethics.jpg'"+
 	 " height='20' alt='Research Ethics' hspace='5'>");
	document.write("</a>"); */
	
	
	document.write("<span class='page_title'>"+ "<font color=green>"+course_title+"</font> | </span>");
	document.write("<span class='page_subtitle'>"+ "<font color=green>"+module_name + " | "+assignment_name+" | Page "+page_no+" of "+max_page_no+"</font></span>");
	
      var url = document.URL;
      var Docname =(url.substring(url.lastIndexOf("\/")+1,url.lastIndexOf("\.")))+".php"; 
      
/* <form name = "download" method="post" action="download_1.php">
<input type="hidden" name="script_name" value="<?php echo $this_script ; ?>" >
<input type="submit" value="Print the full text (including graphics) of this e_Assignment"> 
</form> */
    
    document.write("<form name = 'download' method='post' action='download_1.php'>");
    document.write("<input type='hidden' name='script_name' value='"+Docname+"' >"); 
    document.write("<input type='submit' value='Print this e_Assignment'>"); 
    document.write("</form> "); 
     
	
	document.write("</fieldset><br>");
	}
	
	
	function header_nogreenblock(course_home_page) {

	/* writes header including the e-Assignment logo, LANGURE tree link, course name, module and assignment
        as well as NCSU brick link */

	
	 document.write("<fieldset><legend align=right>");
	
	if (page_no == 1) {
	document.write("<a href='http://www.chass.ncsu.edu/langure/ethics/PHI816%20Fall%202007/common/e-Assignment.php'>" +
				   "<img src='http://www.chass.ncsu.edu/langure/ethics/PHI816%20Fall%202007/common/e-Assignment.png'"+
				   " alt='e-Assignment' hspace='5'></a>");
	}
	
	document.write("</legend>");
	
	/* document.write("<a href='" + course_home_page + "'>");
	document.write("<img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/research-ethics.jpg'"+
 	 " height='20' alt='Research Ethics' hspace='5'>");
	document.write("</a>"); */
	
	
	document.write("<span class='page_title'>"+ "<font color=green>"+course_title+"</font> | </span>");
	document.write("<span class='page_subtitle'>"+"<font color=green>"+module_name + " | "+assignment_name+" | Page "+page_no+" of "+max_page_no+"</font></span>");
	
	
	document.write("</fieldset><br>");
	
}
	
	
	
	
	function create_popup(title_text,a_string,body_text) {
	/* creates a popup window with title and text as specified in the parameters */
	/* popup  = window.open('','test',
 	left=200,top=200,width=520,height=310,toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0');
	*/
	popup = window.open();
	popup.focus();
	popup.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>");
	popup.document.write("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>");
	popup.document.write("<head><title>"+title_text+"</title>");
	popup.document.write("<link rel='stylesheet' type='text/css' href='http://www.chass.ncsu.edu/langure/ethics/php816/common/assignment_style.css'></head>");
	popup.document.write("<body><img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/green_block.JPG' width='50' height='720' align='left' alt='spacer' hspace='5'>");
	popup.document.write("<fieldset>");
	/* popup.document.write("<img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/research-ethics.jpg' width='30' align='left' alt='Research Ethics' hspace='5'>"); */
	popup.document.write("<span class='page_single_title'>"+title_text+"</span>&nbsp;&nbsp;&nbsp;&nbsp;"+a_string+"</fieldset>");
	popup.document.write("<span class='answer_review'>");
	popup.document.write(body_text+"</span>");
	popup.document.write("<br><br><input type=button value='Return' onClick='javascript:window.close();'></body></html>");
	popup.document.close();	
	}

	function create_small_popup(title_text,a_string,body_text) {
	/* creates a popup window with title and text as specified in the parameters */
	popup  = window.open('','test',
 	'left=200,top=200,width=520,height=310,toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0');
	popup.focus();
	popup.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>");
	popup.document.write("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>");
	popup.document.write("<head><title>"+title_text+"</title>");
	popup.document.write("<link rel='stylesheet' type='text/css' href='http://www.chass.ncsu.edu/langure/ethics/php816/common/assignment_style.css'></head>");
	popup.document.write("<body><img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/green_block.JPG' width='50' height='720' align='left' alt='spacer' hspace='5'>");
	popup.document.write("<fieldset>");
	/* popup.document.write("<img src='http://www.chass.ncsu.edu/langure/ethics/php816/common/research-ethics.jpg' width='30' align='left' alt='Research Ethics' hspace='5'>"); */
	popup.document.write("<span class='page_subtitle'>"+title_text+"</span>"+a_string+"</fieldset>");
	popup.document.write("<span class='answer_review'><br>");
	popup.document.write(body_text+"</span>");
	popup.document.write("<br></body></html>");
	popup.document.close();	
	}

	function answer(atext,acorrect,aresponse) {
	/*Definition of class answer*/
		this.atext = atext;
		this.acorrect = acorrect;
		this.aresponse = aresponse;
	}

	function question(qtext,qno_of_answers,qanswers) {
	/*Definition of class question*/

		this.qtext = qtext;
		this.qno_of_answers = qno_of_answers;
		this.qanswers = new Array(qno_of_answers);
		for(i=0;i<qno_of_answers;i++) {
			this.qanswers[i] = qanswers[i];
		}

	}

	function show_question(all_questions,question_no,first_q_no,popup_type) {
	/* Displays question and possible answers in radio button format */
	document.write("<fieldset><legend><span class='fieldset_legend'>Question "+
	 (question_no+first_q_no)+"</span></legend>");
	document.write("<form name='submit_answer' onsubmit='return answer_review(this);'><input name='form_qno' type='hidden' value='"+question_no+"'><input name='form_ptype' type='hidden' value='"+popup_type+"'>"+
        all_questions[question_no].qtext+"<br>");
	for (m=0;m<all_questions[question_no].qno_of_answers;m++) {
		document.write("<br><input name='qq' type ='radio' value="+m+">"+
	 	 all_questions[question_no].qanswers[m].atext);
	} 
	document.write("<br><br><input type='submit' value='submit'></form></fieldset>"); 
	}

	function show_true_false_question(all_questions,question_no,first_q_no,popup_type) {
	/* Displays question and possible answers in radio button format */
	document.write("<fieldset><legend><span class='fieldset_legend'>Question "+
	 (question_no+first_q_no)+"</span></legend>");
	document.write("<form name='submit_answer' onsubmit='return answer_review(this);'><input name='form_qno' type='hidden' value='"+question_no+"'><input name='form_ptype' type='hidden' value='"+popup_type+"'>"+
        all_questions[question_no].qtext);
	for (m=0;m<all_questions[question_no].qno_of_answers;m++) {
		document.write("&nbsp;&nbsp;&nbsp;<input name='qq' type ='radio' value="+m+">"+
	 	 all_questions[question_no].qanswers[m].atext);
	} 
	document.write("&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='submit'></form></fieldset>"); 
	}

	function show_multiple_choice_question(all_questions,question_no,first_q_no,popup_type) {
	/* Displays question and possible answers in radio button format */
	document.write("<fieldset><legend><span class='fieldset_legend'>Question "+
	 (question_no+first_q_no)+"</span></legend>");
	document.write("<form name='submit_answer' onsubmit='return answer_review(this);'><input name='form_qno' type='hidden' value='"+question_no+"'><input name='form_ptype' type='hidden' value='"+popup_type+"'>"+
        all_questions[question_no].qtext+"<br><br>");
	for (m=0;m<all_questions[question_no].qno_of_answers;m++) {
		if (m==3 || m==6) document.write("<br>");
		document.write("<input name='qq' type ='radio' value="+m+">"+
	 	 all_questions[question_no].qanswers[m].atext+"&nbsp;&nbsp;&nbsp;");
	} 
	document.write("<br><br><input type='submit' value='submit'></form></fieldset>"); 
	}

	function answer_review(answer_form) {
	/* Displays popup window which informs student if he has answered the question corectly */
	answer_selected = -1;
	answer_string = "<span class='single_title'><span class='highlight_red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your answer was incorrect.</span></span>"
	for (j=0;j<answer_form.qq.length;j++) {
		if(answer_form.qq[j].checked) {
			answer_selected = j;
			if(questions[answer_form.form_qno.value].qanswers[j].acorrect == "true") {
				 q_correct[answer_form.form_qno.value] = true;
				 answer_string = "<span class='single_title'><span class='highlight_green'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your answer was correct!</span></span>"
			}
			else q_correct[answer_form.form_qno.value] = false;		
		}
	}

	if (answer_selected > -1 && answer_form.form_ptype.value == "large") {
		create_popup(" ",answer_string,
				questions[answer_form.form_qno.value].qanswers[answer_selected].aresponse);
	} else if (answer_selected > -1 && answer_form.form_ptype.value == "small") {
		create_small_popup(" ",answer_string,
				questions[answer_form.form_qno.value].qanswers[answer_selected].aresponse);
	} else {
		create_small_popup("Warning: Question has not been answered"," ",
				"Sorry, you must select one of the answers.");
	}

	return false;			

	} 

	function show_progress_bar(p_number,p_in_assignment,a_number,a_in_module) {

	}

function save_progress(suserid,scourse_no,scourse_title,smodule_name,sassignment_name,spage_no) {
window.open ('http://www.chass.ncsu.edu/langure/ethics/PHI816%20Fall%202007/common/database.php?userid='+suserid+'&course_no='+scourse_no+'&course_title='+scourse_title+'&module_name='+smodule_name+'&assignment_name='+sassignment_name+'&page_no='+spage_no,'Save Progress Window',
'left=300,top=200,width=450,height=200,toolbar=0,resizable=0');
}

function go_next_page()
{
a = document.getElementById("direction_input");
direction = "forward";
ac = a.setAttribute("value","forward");
}

function go_prev_page()
{
a = document.getElementById("direction_input");
direction = "backward";
ac = a.setAttribute("value","backward");
}
