var tracking='NONE';
var anwendung='SAT'

// ADL-SCORM, AICC-HACP, NONE 

function doSetTrackingType()
{
	document.player.SetVariable('lms.type',  tracking);
	document.player.SetVariable('anwendung', anwendung);
}

//Modified Authorware AICC API - ADL SCORM RTI Publishing Template, based on:
// SCORM 1.1 Minimal Compliance Code Extension for Authorware
// version 1.1.3.seemedia     10.11.04
// Copyright 2000, 2001 Macromedia, Inc. All rights reserved.
// Modified by seemedia GmbH, Germany 2004 ---------------------

if ( tracking == 'ADL-SCORM' )
{
	//returns LMS API object (or null if not found)
	
	function findAPI( win )
	{
		// look in this window
		
		if ( ( typeof( win.API ) != 'undefined' ) && ( win.API != null ) )
		{
			return ( win.API );
		}
		else
		{
			// look in this window's frameset kin (except opener)
			
			if ( win.frames.length > 0 )
			{
				for ( var i = 0 ; i < win.frames.length ; i++ )
				{
					var winFrameApi = win.frames[i].API;
					
					if ( ( typeof( winFrameApi ) !=  'undefined' ) && 
					     ( win != win.opener ) && 
					     ( winFrameApi != null ) )
					{
						return ( win.frames[i].API );
					}
				}
			}
		}
		
		// check in parent window
		
		if ( ( typeof( win.parent ) != 'undefined' ) && 
		     ( win.parent != null ) && 
		     ( win.parent != win ) )
		{
			return ( findAPI( win.parent ) );
		}
		
		// not found
		
		return ( null );
	}
	
	// get the API object
	
	status = 'Looking for API object';
	
	if ( typeof( API ) == 'undefined' )
	{
		API = null;
	}
	
	// define mm_getAPI, which calls findAPI as needed
	
	function mm_getAPI()
	{
		API = findAPI( window );
		
		// check in opener once
		
		if ( ( API == null ) && 
		     ( typeof( window.opener ) != 'undefined' ) && 
		     ( window.opener != null ) )
		{
			API = findAPI( window.opener );
		}
		
		if ( API != null )
		{
			status = 'API found';
		}
		else
		{
			status = 'API not found';
		}
	}
	
	// get the API
	
	mm_getAPI();
}

function doLMSInitialize()
{
	if ( ( typeof( API ) == 'undefined' ) || ( API == null ) )
	{
		alert( 'Unable to locate the LMS\'s API.' );
		var tracking='NONE'
		document.player.SetVariable('lms.type',  tracking);
		document.player.SetVariable( 'lms.initialized', 'false' ); 
	}
	else
	{
		var result01 = API.LMSInitialize( '' );
		
		if ( result01.toString() != 'true' )
		{
			var err = ErrorHandler();
		}
		else
		{
			document.player.SetVariable( 'lms.initialized', result01.toString() );
		}
	}
}

function doGetUserData()
{
	if ( ( typeof( API ) == 'undefined' ) || ( API == null ) )
	{
		alert( 'Unable to get the UserID.' );
		document.player.SetVariable( 'lms.userid', 'false' ); 
	}
	else
	{
		var result = API.LMSGetValue( 'cmi.core.student_id' );
		document.player.SetVariable( 'lms.userid', result.toString() ); 
		
		result = API.LMSGetValue( 'cmi.core.student_name' );
		document.player.SetVariable( 'lms.username', result.toString() );
		
		result = API.LMSGetValue( 'cmi.core.lesson_status' ); 
		document.player.SetVariable( 'lms.Status', result.toString() );
		
		result= API.LMSGetValue( 'cmi.suspend_data' );
		document.player.SetVariable( 'lms.Data', result.toString() );
		
		result= API.LMSGetValue( 'cmi.core.total_time' );
		document.player.SetVariable( 'lms.time', result.toString() );
		
		result= API.LMSGetValue( 'cmi.core.lesson_mode' );
		document.player.SetVariable( 'lms.Lesson_Mode', result.toString() );
		
		result = API.LMSGetValue( 'cmi.core.lesson_location' );
		
		if ( result != 0 )
		{
			document.player.SetVariable( 'lms.location', result.toString() );
		}
		
		result= API.LMSGetValue( 'cmi.core.score.raw' );
		document.player.SetVariable( 'lms.score', result.toString() );
		
		result= API.LMSGetValue( 'cmi.student_data.mastery_score' );
		document.player.SetVariable( 'lms.mastery_score', result.toString() );
		
		result= API.LMSGetValue( 'cmi.launch_data' );
		//document.player.SetVariable( 'lms.launch_data', result.toString() );
	}
}

var status   = null;
var score    = null;
var xlocation = null;
var time     = null;
var data     = null;

function doLMSExit( status, score, xlocation, time, data )
{
	if ( ( typeof( API ) != 'undefined' ) && ( API != null ) )
	{
		try
		{
			API.LMSSetValue( 'cmi.core.lesson_status', status );
			API.LMSSetValue( 'cmi.core.score.raw', score );
			API.LMSSetValue( 'cmi.core.lesson_location', xlocation );
			API.LMSSetValue( 'cmi.core.session_time', time );
			API.LMSSetValue( 'cmi.suspend_data', data );
			//API.LMSSetValue( 'cmi.core.exit', 'logout' );
			
			var emptyString ='';
			
			API.LMSCommit( emptyString );
			API.LMSFinish( emptyString );
			
			API = null;
		}
		catch (e)
		{
			alert(e);
		}
	}
	
	top.window.close();
}

function doExit()
{
	top.window.close();
}

function doUnload()
{
	if ( ( typeof( API ) != 'undefined' ) && ( API != null ) )
	{
		// Falls die Zeit reicht, versuchen wir noch ein regulaeres Ende
		
		if ( document.player != null )
		{
			var duration = new Date() - startTime;
			
			var status   = document.player.GetVariable( 'lms.status' );
			var score    = document.player.GetVariable( 'lms.score' );
			var xlocation = document.player.GetVariable( 'lms.location' );
			
			//var time     = document.player.GetVariable( 'lms.time' );
			
			// Die Zeit kommt nicht mehr vom LMS sondern vom JavaScript
			
			var time     = convertTotalSeconds( duration / 1000 );
			
			var data     = document.player.GetVariable( 'lms.data' );
			
			doLMSExit( status, score, xlocation, time, data );
		}
	}
	
	return ( true );
}

// Neu fuer die Zeitberechnung

var startTime = new Date();

// berechnen der Zeit

function convertTotalSeconds( totalSeconds )
{	
	totalSeconds = parseInt( totalSeconds, 10 );
	
	var hours = parseInt( totalSeconds / (60*60), 10 );
	
	totalSeconds = totalSeconds - hours * 60 * 60;
	
	var mins = parseInt( totalSeconds / 60, 10 );
	
	totalSeconds = totalSeconds - mins * 60;
	
	var secs = totalSeconds;
	
	var result = '';
	
	if ( hours < 10 )
	{
		result += '0';
	}
	
	result += hours + ':';
	
	if ( mins < 10 )
	{
		result += '0';
	}
	
	result += mins + ':';
	
	if ( secs < 10 )
	{
		result += '0';
	}
	
	result += secs;
	
	return ( result );
}