selectedItem = ""
SELECTEDCLASS	=	"currentnofocus"
function HideFooter(Hide){
	 if(BrowserType == 'ie' && browserV > 4.01){
	   if(parent.frames[3].document.getElementById('hide1')){
	  	if(Hide){
		top.frames[3].document.getElementById('hide1').style.display='none';
		top.frames[3].document.getElementById('hide2').style.display='none';
		parent.frames[3].document.getElementById('hide3').style.display='none'
		}else{
		parent.frames[3].document.getElementById('hide1').style.display='';
		parent.frames[3].document.getElementById('hide2').style.display='';
		parent.frames[3].document.getElementById('hide3').style.display=''
		}
	   }
	  }
 }
 

function DoNext(){
	for (var i=0; i < arrItemObject.length; i++){
		if (parseInt(arrItemObject[i].identifier) == parseInt(selectedItem)){
			if (i+1 < arrItemObject.length){
				changeStyle(arrItemObject[i + 1].identifier)
				selectedItem = arrItemObject[i + 1].identifier
				document.frames.contenu.location = document.frames.contenu.location + "/../../" + arrItemObject[i + 1].href
				break;
			}else{
                var winSide = document.frames.side
                winSide.completedLesson();
				changeStyle(arrItemObject[i].identifier)
				selectedItem = arrItemObject[i].identifier
				document.frames.contenu.location = document.frames.contenu.location + "/../../" + arrItemObject[i].href
				break;
			}
		}
	}
}


function changeStyle(ident){
	var winSide = document.frames.side
	var srcElement    = winSide.Browser.Element('span' + ident)
	
	if (srcElement != null){
		MouseClick(ident)
	}else{
	    srcElement    = winSide.Browser.Element('hrefFlv' + ident)
		srcElement.focus()
		winSide.clickOnFlv(srcElement, false)
	}
	
}

function MouseClick(identifier){
	var winSide = document.frames.side
	var srcElement    = winSide.Browser.Element('span' + identifier)
	var targetElement = winSide.Browser.Elements("Title")
	
	if (srcElement == null || targetElement == null) return false;
	
	if (srcElement.classbackup != SELECTEDCLASS){
		for(i=0; i < targetElement.length; i++) {
			targetElement[i].parentElement.className = srcElement.classbackup
	    }
		var loopElement = srcElement.parentNode.parentNode
		while (loopElement.id != 'root'){
			winSide.expand(loopElement)
			loopElement = loopElement.parentNode
		}
		winSide.clickOnFlv(loopElement.childNodes(2), false)
		srcElement.className 	= 	SELECTEDCLASS;
		srcElement.classbackup  =   SELECTEDCLASS;
		srcElement.childNodes[0].className = "sideyes"
	}
}	

function DoPrevious(){
	
	for (var i=0; i < arrItemObject.length; i++){
		if (parseInt(arrItemObject[i].identifier) == parseInt(selectedItem)){
			if (i-1 >= 0){
				changeStyle(arrItemObject[i - 1].identifier)
				selectedItem = arrItemObject[i - 1].identifier
				document.frames.contenu.location = document.frames.contenu.location + "/../../" + arrItemObject[i - 1].href
				break;
			}else{
				changeStyle(arrItemObject[i].identifier)
				selectedItem = arrItemObject[i].identifier
				document.frames.contenu.location = document.frames.contenu.location + "/../../" + arrItemObject[i].href
				break;
			}
		}
	}
}

var SESSION_TIME_IN	   =  TimeToSec()

function DoLoadFinish(){
	try {
		parent.StayIN = true
		if (API) {
			API.LMSSetValue("cmi.core.session_time", TimeDiff(SESSION_TIME_IN, TimeToSec()));
			API.LMSCommit("");
			API.LMSFinish("");
		}
		
		if (parent.ONLINE_COURSE == true)
			parent.document.location.href = parent.PATH_SERVER + "formation/LoadFinish.asp?HoraireID=" + parent.HoraireID + "&UserID=" + parent.UserID + "&Lang=" + parent.Lang + "&ManifestID=" + parent.ManifestID + "&PageRef=" + parent.PageRef + "&UserTimeIN=" + parent.UserTimeIn
		else
			top.close()
	}
	catch (e) {
		top.close()
	}
}

function DoSwapTOC(){
 	var arrCOL = (typeof(TOC) == "object") ? TOC.cols.split(",") : "";
	if (arrCOL.length == "2"){
  		TOC_COLS_BACKUP = (arrCOL[0] == "0") ? TOC_COLS_BACKUP : TOC.cols
  		TOC.cols = (arrCOL[0] == "0") ? TOC_COLS_BACKUP : "0,*"
 	}
}

function swapImage(img){
	img.src = (img.src.toLowerCase().indexOf("hide") > -1) ? "../course-img/toc-show.gif" : "../course-img/toc-hide.gif"
}

function DoOpenHelp(){ openwin('../layout/M-Aide.html') }
function DoHelp(){     window.frames.contenu.document.location.href = '../layout/M-Aide.html' }
function DoOpenTool(){ openwin("about:blank")}
function DoTool(){     window.frames.contenu.document.location.href = "about:blank"}
function DoOpenGlossary(){ openwin("../layout/f-glossary.html")}
function DoGlossary(){ window.frames.contenu.document.location.href = "../layout/f-glossary.html"}

function StayINval(valeur){ StayIN	= valeur }
function openwin(URL){ aWindow=window.open(URL,"remote","scrollbars=yes,resizable=yes,menubar=no,location=no,toolbar=no,status=YES,width=500,height=400")}


function FindAPI() {
    //Is it in the current window?
    if (window.document.API != null) 	return window.document.API;
	
	// Is it in the window's opener?
	if (window.opener != null){
	    if (window.opener.API != null){
			return window.opener.API;
	    }else{
			// look in the openers window's frames...
			if (window.opener.parent != null){
				for (i=0; i<window.opener.parent.frames.length; i++) {
					if (window.opener.parent.frames[i].API != null)
						return window.opener.parent.frames[i].API;
				}
			}
		}
	}

	// Is it in the current window's parent?
	if (window.parent != null){
		if (window.parent.API != null){
			return window.parent.API;
		}else{
			// look in the parent window's frames...
			for (i=0; i<window.parent.frames.length; i++){
				if (window.parent.frames[i].API != null)
					return window.parent.frames[i].API;
			}
		  
		}
	}

	// Is it in the current window's parent?
	if (window.parent.parent != null){
		if (window.parent.parent.API != null){
			return window.parent.parent.API;
		}else{
			// look in the parent window's frames...
			// this is probably the most likely place for it to be...
			for (i=0; i<window.parent.parent.frames.length; i++){
				if (window.parent.parent.frames[i].API != null)
					return window.parent.parent.frames[i].API;
			}
		}
	}
	// The API was not found
	return null;	
}

/******************************************************************************************
** Function TimeToSec()
** Inputs:
** Output: time in seconds elapsed since 01/01/1970 from now.
** Description: 
******************************************************************************************/
function TimeToSec(){	
	var second = new Date();
	return Math.round(second/1000);
}

/******************************************************************************************
** Function TimeDiff(startTime,endTime)
** Inputs: startTime and endTime in seconds since 01/01/1970.
** Output: time string as "HH:MM:SS"
** Description: 
******************************************************************************************/
function TimeDiff(start,end){
	var startTime = "",
		diff = end - start,
		hh = Math.floor(diff/3600),
		mm = Math.floor(diff/60) - hh*60,
		ss = diff % 60;

	if(hh<10)
		startTime+= "0"; 
	startTime+= (hh +":");
	if(mm<10)
		startTime+= "0"; 
	startTime+= mm + ":";
	if(ss<10)
		startTime+= "0"; 
	startTime+= ss;

	return startTime;
}
