// JavaScript Document


//debug=true;
debug=false;
		
function free_trial_get_time_remaining( uid, sid, tshow )
	{		
		if( debug )
			{
				document.getElementById( 'div_debug' ).innerHTML	+= "<br />free_trial_get_time_remaining() : uid = " + uid + ", tshow = " + tshow;
			}
		
		if( uid == 0 )
			{
				return;
			}
		
		var xml_string			= "<xml>";
		xml_string				+= "<uid>" + uid + "</uid>";
		xml_string				+= "<sid>" + sid + "</sid>";
		xml_string				+= "</xml>";
		
		//
		//    build XMLHttpRequest()
		//
		
		var http_rq = new XMLHttpRequest();
		
		if( window.location.protocol == "https:" )
			{
				var url		= 'https://www.hotlinelearning.com/alex/free_trial_timer_xml.php';
			}
		else
			{
				var url		= 'http://www.hotlinelearning.com/alex/free_trial_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 )
			{
				var t	= http_rq.responseText;
				
				document.getElementById( 't_store' ).value = t;
				
				if( debug )
					{
						document.getElementById( 'div_debug' ).innerHTML	+= "<br />http_rq.responseText = t = " + t;
						//document.getElementById( 'div_debug' ).innerHTML	+= "<br />uid = " + uid;
						//document.getElementById( 'div_debug' ).innerHTML	+= "<br />sid = " + sid;
					}
				
				var f	= "count_down( '" + uid + "', '" + sid + "', '" + tshow + "' )";
				
				if( t > 0*1 )
					{
						timer1 = setInterval( f, 1000 ); 
						return;
					}
				
			}    //  end of if( http_rq.readyState == 4 )
			
		}    //    end of http_rq.onreadystatechange function()
		
	}    //    end of function
	

function count_down( uid, sid, tshow )
	{
		var t	= document.getElementById( 't_store' ).value;
		t--;
		document.getElementById( 't_store' ).value = t;

		if( debug )
			{
				document.getElementById( 'div_debug' ).innerHTML	+= "<br />count_down() : uid = " + uid + ", tshow = " + tshow + ", t = " + t;
			}

		if( t > 0*1 )
			{
				if( t <= tshow )
					{
						document.getElementById( 'div_timer' ).innerHTML = "Free Trial time remaining: " + t + " seconds";
					}
			}
		else
			{
				document.getElementById( 'div_timer' ).innerHTML = "The Free Trial has expired.";
				
				clearInterval( timer1 );
				
				free_trial_end( uid, sid );
			}
		
	}    //    end of function
	


function free_trial_end( uid, sid )
	{
		if( debug )
			{
				document.getElementById( 'div_debug' ).innerHTML	+= "<br />free_trial_end : uid = " + uid + ", sid = " + sid;
			}
		
		var xml_string			= "<xml>";
		xml_string				+= "<uid>" + uid + "</uid>";
		xml_string				+= "<sid>" + sid + "</sid>";
		xml_string				+= "</xml>";
		
		//
		//    build XMLHttpRequest()
		//
		
		var http_rq = new XMLHttpRequest();
		
		if( window.location.protocol == "https:" )
			{
				var url		= 'https://www.hotlinelearning.com/alex/free_trial_end_xml.php';
			}
		else
			{
				var url		= 'http://www.hotlinelearning.com/alex/free_trial_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 )
			{
				//var debug=true;
				
				if( debug )
					{
						document.getElementById( 'div_debug' ).innerHTML	+= "<br />" + http_rq.responseText;
					}
				
				window.location.href= "/node/388";    //    goto this page - logged out by free_trial_end_xml.php
				
			}    //  end of if( http_rq.readyState == 4 )
			
		}    //    end of http_rq.onreadystatechange function()
		
	}    //    end of function
	
	
