// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub boutonsFSC_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call boutonsFSC_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

// FS SCORM - fscommand adapter for ADL SCORM
// version 1.1.1    11/25/01      
// Copyright 2002 Pathlore Software Corporation All Rights Reserved
// Copyright 2002 Macromedia Inc. All rights reserved.
// Copyright 2003 ONLINEFORMAPRO. All rights reserved.
// Developed by Tom King, Macromedia and Leonard Greenberg, Pathlore
// Modified by Jeff Burton and Andrew Chemey, Macromedia (01/09/02)
// Modified by Damien MOREL, Onlineformapro
// Adapted for AICC conform by Damien MOREL, ONLINEFORMAPRO
// -----------------------------------------------------------------

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var findAPITries = 0;
function findAPI(win)
{
   // Check to see if the window (win) contains the API
   // if the window (win) does not contain the API and
   // the window (win) has a parent window and the parent window  
   // is not the same as the window (win)
   while ( (win.API == null) && 
           (win.parent != null) && 
           (win.parent != win) )
   {	
      // increment the number of findAPITries
      findAPITries++;
      // Note: 7 is an arbitrary number, but should be more than sufficient
      if (findAPITries > 7) 
      {
         alert("Error finding API -- too deeply nested.");
         return null;
      }
      
      // set the variable that represents the window being 
      // being searched to be the parent of the current window
      // then search for the API again
      win = win.parent;
   }
   return win.API;
}
function getAPI()
{
   // start by looking for the API in the current window
   var theAPI = findAPI(window);
   // if the API is null (could not be found in the current window)
   // and the current window has an opener window
   if ( (theAPI == null) && 
        (window.opener != null) && 
        (typeof(window.opener) != "undefined") )
   {
	
      // try to find the API in the current window's opener
      theAPI = findAPI(window.opener);
   }
   // if the API has not been found
   if (theAPI == null)
   {
      // Alert the user that the API Adapter could not be found
      //alert("Unable to find an API adapter");
   }
   return theAPI;
}
var mm_API = getAPI();
//var mm_API = null;
// make sure status conforms to scorm standards
function normalizeStatus(status)
	{
	switch (status.toUpperCase().charAt(0))
		{
		case 'C':	return "completed";
		case 'I':	return "incomplete";
		case 'N':	return "not attempted";
		case 'F':	return "failed";
		case 'P':	return "passed";
		}
	return status;
	}
// make sure the question type conforms to scorm standards
function normalizeType(theType)
	{
	switch (theType.toUpperCase().charAt(0))
		{
		case 'T':	return "true-false";
		case 'C':	return "choice";
		case 'F':	return "fill-in";
		case 'M':	return "matching";
		case 'P':	return "peformance";
		case 'S':	return "sequencing";
		case 'L':	return "likert";
		case 'N':	return "numeric";
		}
	return theType;
	}
// make sure the question result conforms to scorm standards
function normalizeResult(result)
	{
	switch (result.toUpperCase().charAt(0))
		{
		case 'C':	return "correct";
		case 'W':	return "wrong";
		case 'U':	return "unanticipated";
		case 'N':	return "neutral";
		}
	return result;
	}
	
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function boutonsFSC_DoFSCommand(command, args) 
	{
        
  var boutonsFSCObj = InternetExplorer ? boutonsFSC : document.boutonsFSC;
  
	var tabArg = args.split("|");
	
	
	//ouverture de popup pour les ressouces swf d'Excel 2000
	//rubrique - file - nom
	//alert("ca marche = :"+tabArg[1]+": fin");
    	if(command == "openWindow"){
      	  window.open(tabArg[1],'newwindow','height=600,width=800,toolbar=no');
       	 return;
    	}

	if (command == "callTutor") {
		location.href="callto:" + tabArg[0];
		return;
	}

	if (command == "email") {
		lien="http://www.onlineformapro.com/formations/formulaire.asp?emailde=" + escape(tabArg[0]);
		window.open(lien,'EMAIL','width=550,height=321');
		return;
	}

	if (command == "contact_tuteur") {
		alert("Veuillez contacter votre tuteur.")
		return;
	}

        
	args 				= String(args);
	command 			= String(command);
	var F_intData 	= args.split(";");
	
	// check for existence of scorm api
	if (mm_API == null)
		return;
	
	switch (command)
		{
                
		case "MM_StartSession" :
			break;
		
		case "MM_cmiSendInteractionInfo" :
			//MM_cmiSendInteractionInfo(date, time, intid, objid, intrtype, correct, student, result, weight, latency)
			var	n	= mm_API.LMSGetValue("cmi.interactions._count");
			mm_API.LMSSetValue("cmi.interactions." + n + ".id", F_intData[2]);
			mm_API.LMSSetValue("cmi.interactions." + n + ".objectives.0.id", F_intData[3]);
			mm_API.LMSSetValue("cmi.interactions." + n + ".time", F_intData[1]);
			mm_API.LMSSetValue("cmi.interactions." + n + ".type", normalizeType(F_intData[4]));
			mm_API.LMSSetValue("cmi.interactions." + n + ".correct_responses.0.pattern", F_intData[5]);
			mm_API.LMSSetValue("cmi.interactions." + n + ".weighting", F_intData[8]);
			mm_API.LMSSetValue("cmi.interactions." + n + ".student_response", F_intData[6]);
			mm_API.LMSSetValue("cmi.interactions." + n + ".result", normalizeResult(F_intData[7]));
			mm_API.LMSSetValue("cmi.interactions." + n + ".latency", F_intData[9]);
			break;
			
		case "MM_cmiSendObjectiveInfo" :
			//MM_cmiSendObjectiveInfo(index, objid, score, status)
			var	n	= mm_API.LMSGetValue("cmi.objectives._count");
			mm_API.LMSSetValue("cmi.objectives." + n + ".id", F_intData[1]);
			mm_API.LMSSetValue("cmi.objectives." + n + ".score.raw", F_intData[2]);
			mm_API.LMSSetValue("cmi.objectives." + n + ".status", normalizeStatus(F_intData[3]));
			break;
			
		case "CMISetScore":
		case "MM_cmiSendScore" :
			//MM_cmiSendScore(theScore)
			mm_API.LMSSetValue("cmi.core.score.raw", F_intData[0]);
			break;
			
		case "CMISetStatus":
		case "MM_cmiSetLessonStatus" :
			//MM_cmiSetLessonStatus(theStatus)
			mm_API.LMSSetValue("cmi.core.lesson_status", normalizeStatus(F_intData[0]));
			break;
			
		case "CMISetTime" :
			//CMISetTime(t)
			mm_API.LMSSetValue("cmi.core.session_time", F_intData[0]);
			break;
		
		case "CMISetCompleted" :
			//CMISetCompleted()
			mm_API.LMSSetValue("cmi.core.lesson_status", "completed");
			break;
		
		case "CMISetStarted" :
			//CMISetCompleted()
			mm_API.LMSSetValue("cmi.core.lesson_status", "incomplete");
			break;
			
		case "CMISetPassed":
			//CMISetCompleted()
			mm_API.LMSSetValue("cmi.core.lesson_status", "passed");
			break;
			
		case "CMISetFailed":
			//CMISetCompleted()
			mm_API.LMSSetValue("cmi.core.lesson_status", "failed");
			break;
			
		case "CMISetData":
			//CMISetData(data)
			mm_API.LMSSetValue("cmi.suspend_data", F_intData[0]);
			break;
			
		case "CMISetLocation":
			//CMISetLocation(loc)
			mm_API.LMSSetValue("cmi.core.lesson_location", F_intData[0]);
			break;
			
		case "CMISetTimedOut":
			//CMISetTimedOut()
			mm_API.LMSSetValue("cmi.core.exit", "time-out");
			break;
			
		case "LMSGetValue" :
			boutonsFSCObj.SetVariable(F_intData[1], mm_API.LMSGetValue(F_intData[0]));
			break;
		
		case "CMIInitialize":
			//CMIInitialize()
			mm_API.LMSInitialize(args);
			break;
		
		case "CMIFinish":
			break;
			
		case "CMIExitAU":
			mm_API.LMSFinish(args);
			break;
		}
	// END OF CMI FUNCTION MAPPING
	}
	
	//-------- Norme AICC---------
	// fonction de réception des variables AICC
	function getStringVar(st){
	  var temp = self.document.location.search;
	  if(temp.indexOf(st) >= 0){
	    temp = temp.substring((temp.indexOf(st)+(st.length+1)),	temp.length);
	    temp = temp.substring(0, (((temp.indexOf('&')>=0)?temp.indexOf('&'):temp.length)));
	  }else{ temp = '';
	  } return unescape(temp);
	}
	
	// cherche les variable AICC
	var aicc_sid=getStringVar('aicc_sid');
	var aicc_url=getStringVar('aicc_url');
	
	if (aicc_sid == ""){
		aicc_sid=getStringVar('AICC_SID');
	}
	if (aicc_url == ""){
		aicc_url=getStringVar('AICC_URL');
	}
	
	// initialize le tps de session
	NavName = navigator.appName.substring(0,3);
	NavVersion = navigator.appVersion.substring(0,1);
	if (NavName != "Mic" || NavVersion>=4)
		{
		entree = new Date;
		entree = entree.getTime();
		}
	
	var data;
	var lien;
	data="";
	if (mm_API != null){ //SCORM
		mm_API.LMSInitialize("");
		data=mm_API.LMSGetValue("cmi.suspend_data");
	}
	

	//chemin du fichier ŕ charger
	lien=fichier + "?entree=" + entree + "&susdata=" + data + "&aicc_sid=" + aicc_sid + "&aicc_url=" + aicc_url;
	//alert(lien);
	
	function fin(){ //fonction de fin
		if (mm_API != null){ //SCORM
			mm_API.LMSFinish("");
		}
		if (aicc_sid!="" && aicc_url != ""){ //AICC HACP
			chemin_exit="./aicc_exit.htm?aicc_sid=" + aicc_sid + "&aicc_url=" + aicc_url;
			window.open(chemin_exit,'aicc_exit','WIDTH=20,HEIGHT=20,scrollbars=no');
		}
	}
	
	function quitter() { //bouton quitter des formations
		if (parent.window.opener != null){ //si ouverture formation plein ecran
			parent.close(); //fermeture de la fenetre
		}else{ //si dans le frameset
			if (mm_API == null){ // si non scorm
				document.location.href=history.go(-1);
			}else{
				document.location.href=history.go(-3);
			}	
		}
	}
	
