// JavaScript Document


function chapter_id_drop_down_menu( course_id, i )
	{
		//alert( 'course_id = ' + course_id + ', i = ' + i );
		
		var html	= "\r\n\r\n<select id='select_chapter_" + i + "' >";
		
		html	+= '\r\n<option>Select</option>';

		//
		//    get the chapter_id's for this course_id
		//
		
		var xml_string			= "<xml>";
		xml_string				+= "<course_id>" + course_id + "</course_id>";
		xml_string				+= "</xml>";
		
		//alert( 'xml_string = ' + xml_string );
		
		//
		//    build XMLHttpRequest()
		//
		
		var http_rq = new XMLHttpRequest();
		
		if( window.location.protocol == "https:" )
			{
				var url		= 'https://www.hotlinelearning.com/alex/courses_get_chapter_ids_xml.php';
			}
		else
			{
				var url		= 'http://www.hotlinelearning.com/alex/courses_get_chapter_ids_xml.php';
			}
		
		http_rq.open( 'POST', url, true );    //    'true' is for asynchronous
		
		//    Send the proper header information along with the request
		
		http_rq.setRequestHeader( 'MessageType', 'Call' );
		http_rq.setRequestHeader( 'Content-type', 'text/xml' );
		http_rq.setRequestHeader( 'Content-length', xml_string.length );
		http_rq.setRequestHeader( 'Connection', 'close' );
		
		http_rq.send( xml_string );
		
		//    wait for response
		
		http_rq.onreadystatechange	= function() { if( http_rq.readyState == 4 )
			{
				//alert( 'http_rq.responseText = ' + http_rq.responseText );  //  for debug
				
				var ch_str		= http_rq.responseText;    //    chapter_id's string
				
				//var ch_arr		= new Array();
				
				ch_arr			= ch_str.split( "::::" );
				
				for( x = 0; x < ch_arr.length; x++ )
					{
						"html	+= '<option>" +  ch_arr[x]  + "</option>';";
					}
				
				html	+= '\r\n</select>';
			
				document.getElementById( 'td_chapter_id_' + i ).innerHTML = html;

			}    //  end of if( http_rq.readyState == 4 )
			
		}    //    end of http_rq.onreadystatechange function()

				/*
						<?php
						
						for( $i = 0; $i <sizeof( $ca ); $i++ )
							{
								echo "html	+= '<option>" . $ca[$i]['chapter_id'] . "</option>';";
							}
						
						?>
				*/
	
	}    //    end of function


function obsolete_scorm_zip( i )
	{
		//alert( "obsolete_scorm_zip: i = " + i );
	
		var course_id	= encodeURIComponent( document.getElementById( "select_course_" + i ).value );
		var chapter_id	= encodeURIComponent( document.getElementById( "select_chapter_" + i ).value );
		var filename	= encodeURIComponent( document.getElementById( "td_filename_" + i ).innerHTML );
		
		//alert( "course_id = " + course_id );
		//alert( "chapter_id = " + chapter_id );
		//alert( "filename = " + filename );
		alert( "obsolete_scorm_zip: i = " + i + ", course_id = " + course_id + ", chapter_id = " + chapter_id + ", filename = " + filename );
		
		//window.location.href	= "?function=obsolete_scorm_zip&course_id=" + course_id + "&chapter_id=" + chapter_id + "&filename=" + filename;
	
	}    //    end of function


function install_scorm_zip( i )
	{
		//alert( "install_scorm_zip: i = " + i );
	
		var course_id	= encodeURIComponent( document.getElementById( "select_course_" + i ).value );
		var chapter_id	= encodeURIComponent( document.getElementById( "select_chapter_" + i ).value );
		var filename	= encodeURIComponent( document.getElementById( "td_filename_" + i ).innerHTML );
		
		//alert( "course_id = " + course_id );
		//alert( "chapter_id = " + chapter_id );
		//alert( "filename = " + filename );
		alert( "install_scorm_zip: i = " + i + ", course_id = " + course_id + ", chapter_id = " + chapter_id + ", filename = " + filename );
		
		//window.location.href	= "?function=install_scorm_zip&course_id=" + course_id + "&chapter_id=" + chapter_id + "&filename=" + filename;
	
	}    //    end of function


function final_exam_timer( uid, final_minutes_max, start_time, final_timer_display_minutes )
	{
		//alert( "final_exam_timer() : " + final_minutes_max + " : " + start_time );
		
		var xml_string			= "<xml>";
		xml_string				+= "<uid>" + uid + "</uid>";
		xml_string				+= "</xml>";
		
		//alert( 'xml_string = ' + xml_string );
		
		//
		//    build XMLHttpRequest()
		//
		
		var http_rq = new XMLHttpRequest();
		
		if( window.location.protocol == "https:" )
			{
				var url		= 'https://www.hotlinelearning.com/alex/courses_final_exam_timer_xml.php';
			}
		else
			{
				var url		= 'http://www.hotlinelearning.com/alex/courses_final_exam_timer_xml.php';
			}
		
		http_rq.open( 'POST', url, true );    //    'true' is for asynchronous
		
		//    Send the proper header information along with the request
		
		http_rq.setRequestHeader( 'MessageType', 'Call' );
		http_rq.setRequestHeader( 'Content-type', 'text/xml' );
		http_rq.setRequestHeader( 'Content-length', xml_string.length );
		http_rq.setRequestHeader( 'Connection', 'close' );
		
		http_rq.send( xml_string );
		
		//    wait for response
		
		http_rq.onreadystatechange	= function() { if( http_rq.readyState == 4 )
			{
				//alert( 'http_rq.responseText = ' + http_rq.responseText );  //  for debug
				
				var ts		= http_rq.responseText;    //    current server Unix time
				
				if( start_time + final_minutes_max * 60 < ts - final_timer_display_minutes * 60 )
					{
						var tr	= ts - start_time;
				
						var f	= "final_exam_count_down( '" + tr + "' )";
						
						timer2 = setInterval( f, 1000 ); 
					}
				
			}    //  end of if( http_rq.readyState == 4 )
			
		}    //    end of http_rq.onreadystatechange function()
		
	}    //    end of function
	

function final_exam_count_down( tr )
	{
		//alert( "final_exam_count_down() : tr = " + tr );
		
		t	= tr - 1;
		
		if( t > 0*1 )
			{
				if( t < 31 )
					{
						document.getElementById( 'div_timer' ).innerHTML = "Final Exam time remaining: " + t + " seconds";
					}
			}
		else
			{
				document.getElementById( 'div_timer' ).innerHTML = "The Final Exam is over.";
				
				clearInterval( timer2 );
				
				final_exam_end( uid );
			}
		
	}    //    end of function
		
	
function final_exam_end( uid )
	{
		//alert( "final_exam_end() : " + uid );
		
		var xml_string			= "<xml>";
		xml_string				+= "<uid>" + uid + "</uid>";
		xml_string				+= "</xml>";
		
		alert( 'xml_string = ' + xml_string );
		
		//
		//    build XMLHttpRequest()
		//
		
		var http_rq = new XMLHttpRequest();
		
		if( window.location.protocol == "https:" )
			{
				var url		= 'https://www.hotlinelearning.com/alex/courses_final_exam_end_xml.php';
			}
		else
			{
				var url		= 'http://www.hotlinelearning.com/alex/courses_final_exam_end_xml.php';
			}
		
		http_rq.open( 'POST', url, true );    //    'true' is for asynchronous
		
		//    Send the proper header information along with the request
		
		http_rq.setRequestHeader( 'MessageType', 'Call' );
		http_rq.setRequestHeader( 'Content-type', 'text/xml' );
		http_rq.setRequestHeader( 'Content-length', xml_string.length );
		http_rq.setRequestHeader( 'Connection', 'close' );
		
		http_rq.send( xml_string );
		
		//    wait for response
		
		http_rq.onreadystatechange	= function() { if( http_rq.readyState == 4 )
			{
				alert( 'http_rq.responseText = ' + http_rq.responseText );  //  for debug
				
				//
				//    take the user to a page to explain that the final exam is over
				//
				
				//window.location.href= "/node/388";
				
			}    //  end of if( http_rq.readyState == 4 )
			
		}    //    end of http_rq.onreadystatechange function()
		
	}    //    end of function


function enter_final_exam_score( group_id, course_id, uid )
	{
		//alert( "group_id = " + group_id + ", course_id = " + course_id + ", uid =  " + uid );
		
		var n = "fes_" + course_id + "_" + uid;
		
		var nd = "fes_date_" +    group_id + "_" + course_id + "_" + uid;
		var ns = "fes_score_" +   group_id + "_" + course_id + "_" + uid;
		var np = "fes_pf_" +      group_id + "_" + course_id + "_" + uid;
		var nx = "fes_submit_" +  group_id + "_" + course_id + "_" + uid;
		
		var now = new Date();
		var vd  = ( now.getMonth() + 1*1 ) + "/" + now.getDate() + "/" + now.getFullYear();
		
		var f = "<form method='post' action=''><div style='text-align: center; background-color: yellow;'>";
		
		f     = f + "<table>";
		
		f     = f + "<tr>";
		f     = f + "<td align='right'>";
		
		f     = f + "Final Exam Date</td><td><input type='text' id='" + nd + "' name='" + nd + "' value='" + vd + "' />";
		
		f     = f + "</td>";
		f     = f + "</tr>";

		f     = f + "<tr>";
		f     = f + "<td align='right'>";
		
		f 	  = f + "Final Exam Score (0-100)</td><td><input type='text' id='" + ns + "' name='" + ns + "' value='' />";
		
		f     = f + "</td>";
		f     = f + "</tr>";

		f     = f + "<tr>";
		f     = f + "<td align='right'>";

		//f 	  = f + "Final Exam Pass/Fail</td><td><input type='text' id='" + ns + "' name='" + ns + "' value='' />";
		f 	  = f + "Final Exam Pass/Fail</td>";
		f 	  = f + "<td>";
		f 	  = f + "Pass <input type='radio' id='" + np + "' name='" + np + "' value='Pass' checked />";
		f 	  = f + "&nbsp;&nbsp;&nbsp;&nbsp;";
		f 	  = f + "Fail <input type='radio' id='" + np + "' name='" + np + "' value='Fail' />";
		
		f     = f + "</td>";
		f     = f + "</tr>";


		f     = f + "<tr>";
		f     = f + "<td colspan='2' align='center'>";

		f     = f + "<input type='submit' id='" + nx + "' name='" + nx + "' value='Submit' />";

		f     = f + "</td>";
		f     = f + "</tr>";

		f     = f + "</table>";
		
		f     = f + "</div></form>";
		
		document.getElementById( n ).innerHTML = f;
		
	}    //    end of function
	
