/* This notice must be untouched at all times.

cvs_livelecture_lib1.js    v. 1.00		01-07-2007

Copyright (c) 2007 Clear Voice Systems Ltd. All rights reserved.

Provides: main functions for livelecture.html.
This library is not generic because many function in it reference object that are instantiated
in the livelecture.html file

Depends on livelecture.html.
*/


function Play(e) {

  // If media is playing, being prepared or seeking, don't allow any action on play button
  if ( playstate == 'Playing' || playstate == 'Preparing' || playstate == 'Seeking') return(false);

  if (!e) var e = window.event;

  PlayHandler(e.type);
  
  return(false);
}	// End of Play()


function Play2(e) {

  // If media is playing, being prepared or seeking, don't allow any action on play button
  if ( playstate == 'Playing' || playstate == 'Preparing' || playstate == 'Seeking') return(false);

  if (!e) var e = window.event;

  switch (e.type) {
	  
	case 'click':
      PlayHandler(e.type);	
	  break;
	  
	case 'mouseover':
	  MM_nbGroup('over','play2','images/play2hover.jpg','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}	// End of Play2()


function PlayHandler(etype) {
	
  switch (etype) {

    case 'click':

	  if ( loadstate ) {
	  	movie1.Play();
		playstate = 'Playing';
	  }else {
		if ( QUERYSTRING['starttimecode'] && (connection.isstreamed || !connection.isonline) ) {
		  // start movie from startposition if starttimecode is set
		  loadmovie.startposition = time2int(QUERYSTRING['starttimecode']);
		}
	    loadmovie.start();
	    playstate = 'Preparing';
	  }
	  MM_nbGroup('down','group1','play','images/playactive.gif',1);
	  break;
      
	case 'mouseover':
	  MM_nbGroup('over','play','images/playhover.gif','images/playactive.gif',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}	// End of PlayHander()
	
	
function Pause(e) {

  // If not currently playing or already paused don't allow any action on pause button
  if ( playstate != 'Playing' || playstate == 'Paused' ) return(false);
  
  if (!e) var e = window.event;

  PauseHandler(e.type)
  
  return(false);
}		// End of Pause()


function PauseHandler(etype) {

  switch (etype) {

    case 'click' :
      movie1.Pause();

	  playstate = 'Paused';
	  MM_nbGroup('down','group1','pause','images/pauseactive.gif',1);
	  break;

	case 'mouseover' :
	  MM_nbGroup('over','pause','images/pausehover.gif','images/pauseactive.gif',1);
	  break;

	case 'mouseout' : 
	  MM_nbGroup('out');

	default:
	  ;
  }
  return(false);
}		// End of PauseHandler()


function Stop(e) {
  
  // If not currently playing or paused, don't allow any action on stop button  
  if ( !(playstate == 'Playing' || playstate == 'Paused') )  return(false);
  
  if (!e) var e = window.event;

  StopHandler(e.type);

  return(false);
}		// End of Stop()


function StopHandler(etype) {
  
  switch (etype) {
     case 'click':
		indexer.stop();			// Stop the indexer
	    captioner.stop();		// Stop the captioner 
		movie1.Stop();
	    window.setTimeout("indexer.start();",100);		// Restart the indexer after 0.1s 
		captioner.start(1);		//Restart the captioner at caption 1
		playstate = 'Stopped';	//Stop the player
		//MM_nbGroup('down','group1','stop','',1);
	    MM_nbGroup('down','group1','stop','images/stopactive.gif',1);
		break;
	case 'mouseover' :
		//MM_nbGroup('over','stop','images/stophover.gif','',1);
	    MM_nbGroup('over','stop','images/stophover.gif','images/stopactive.gif',1);
		break;
	case 'mouseout' :
		MM_nbGroup('out');

	default:
	  ;
  }
  return(false);
}		// End of StopHandler



function Close(e) {

  if (!e) var e = window.event;
  
  switch (e.type) {

    case 'click':
     //Stop movie play
      bttnstop.click();
  
      //Close the window after .75 seconds
      window.setTimeout("self.close();", 750);	  break;
      
	case 'mouseover':
	  MM_nbGroup('over','close','images/bttnplayerclose_hover.gif','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}



function TabBar(e) {
	
  if (!e) var e = window.event;

  id = this;

  TabBarHandler(e.type, id);

  return(false);
}		// TabBar


function TabBarHandler(etype, id) {
	
  switch (etype) {

    case 'click':
      if ( id.name=="tabcl" ) {
	    MM_nbGroup('down','group2','cltab','images/tabcl_active.jpg',2);
		document.getElementById('searchindexcontainer').style.visibility='visible';
		document.getElementById('glossarycontainer').style.visibility='hidden';
	  }
      if ( id.name=="tabdl" ) {
	    MM_nbGroup('down','group2','dltab','images/tabdl_active.jpg',2);
		document.getElementById('searchindexcontainer').style.visibility='hidden';
		document.getElementById('glossarycontainer').style.visibility='visible';
	  }
	  break;
      
	case 'mouseover':
      if ( id.name=="tabcl" )
	    MM_nbGroup('over','cltab','images/tabcl_active.jpg','',1);
      if ( id.name=="tabdl" )
	    MM_nbGroup('over','dltab','images/tabdl_active.jpg','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}	// End of TabBarHandler()



function dummyeventhandler(e) {
// Use this event handler to do nothing
  if (!e) var e = window.event;
  return (false);
}


function LoadIndex() {
  var isIndexOpened = index.openIndex();

  // if player in viewclip mode of playmode is set to clip just open the index and do nothing else.
  if ( QUERYSTRING['viewclip']=='true' || playmode=='clip' )
    return(false);
	
  if ( isIndexOpened == -1 ) {
	document.getElementById('searchindexcontainer').style.visibility='hidden';
	return(false);
  }else {
	document.getElementById('searchindexcontainer').style.visibility='visible';
    return(false);
  }
}


var isIndexVisible = true;

function SeekIndex(e) {

  if (!e) var e = window.event;
  var id = this;
  
  switch (e.type) {

    case 'click':
	  // If media is being prepared or seeking, don't allow click action on search list
      if ( playstate == 'Preparing' || playstate == 'Seeking') return(false);
	  field = this.innerHTML.split(' ');
	  tVal = field[0];
      iVal = time2int(tVal);
      // Not a valid time value
	  if ( iVal == -1 )
	    return false;
		
	  indexer.stop();		// Stop the indexer
	  captioner.stop();		// Stop the captioner  
	  seekmovie.start(iVal);		
	  index.seekIndex(iVal);
	  caption.seekCaption(iVal);
	  window.setTimeout("indexer.start();",100);		// Restart the indexer after 0.1s 
	  captioner.start();		// Restart the captioner 
	  break;

    case 'mouseover':
	  this.currentbkcolor = rgbcolor.toHex(this.style.backgroundColor);
	  if ( this.currentbkcolor.toUpperCase() == index.bknormal.toUpperCase() ) {
		// Only change bkcolor if link is normal
        this.style.backgroundColor = index.bkhighlight;
	  }
	  break;
		  
    case 'mouseout':
	  this.currentbkcolor = rgbcolor.toHex(this.style.backgroundColor);
	  if ( this.currentbkcolor.toUpperCase() == index.bkactive.toUpperCase() ) { 
	  	this.style.backgroundColor = index.bkactive;
	  }
      else {
	    this.style.backgroundColor = index.bknormal;
	  }
	  // Force tip text to off
	  tiptext.removetiptext();
      break;
	
    }
  return false;
}


function mouseover(e) {

  var id = this.name;

  switch(id) {
    case 'bttnvolume':
	MM_nbGroup('over','volume','images/sliderbttnhover.gif','',1);
    break;
	
	case 'bttnseek':
	MM_nbGroup('over','seek','images/sliderbttnhover.gif','',1);
    break;
  }
  return (false);
}


function mouseout(e) {
	
  var id = this.name;
	
  switch(id) {
    case 'bttnvolume':
	MM_nbGroup('out');
    break;
	
    case 'bttnseek':
	MM_nbGroup('out');
    break;
  }
  return (false);
}


function IncRate(e) {
	
  // If playing media not playing or greater then max tsmrate do not allow action
  if ( playstate != 'Playing' || movie1.playrate >= movie1.PLAYRATEMAX ) {
	MM_nbGroup('out');    
	return(false);
  }
  
  if (!e) var e = window.event;
  
  switch (e.type) {

    case 'click':
  	  if ( !(movie1.version >= 9) ) {
        opengetwmp9plus();
		break;
	  }	  
	  playrateindex++;
	  movie1.setRate(playrateindex);
	  break;
      
	case 'mouseover':
	  MM_nbGroup('over','tsminc','images/tsminchover.gif','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}


function DecRate(e) {
	
  // If playing media not playing or less then min tsmrate do not allow action
  if ( playstate != 'Playing' || movie1.playrate <= movie1.PLAYRATEMIN ) {
	MM_nbGroup('out');    
	return(false);
  }
    
  if (!e) var e = window.event;
  
  switch (e.type) {

    case 'click':
	  if ( !(movie1.version >= 9) ) {
        opengetwmp9plus();
		break;
	  }	  
	  playrateindex--;
	  movie1.setRate(playrateindex);
	  break;
      
	case 'mouseover':
	  MM_nbGroup('over','tsmdec','images/tsmdechover.gif','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}


function Rewind(e) {

  var pos;
  // If playing media not playing or paused do not allow action
  if ( playstate != 'Playing' && playstate != 'Paused' ) return(false);
  
  if (!e) var e = window.event;
  id = this;

  if ( id.name == 'bttnrewind05' ) REWINDVAL = 5;
  else if ( id.name == 'bttnrewind30' ) REWINDVAL = 30;
  else REWINDVAL = 30;  
  
  switch (e.type) {

    case 'click':
	  pos = movie1.getCurrentPosition() - REWINDVAL;
	  if (pos < 0 )		// Clamp playhead to position zero if rewind would  take us past beginning of movie
	    pos = 0;

	  indexer.stop();		// Stop the indexer
	  captioner.stop();		// Stop the captioner
      movie1.setCurrentPosition(pos);	//Rewind	  
	  index.seekIndex(pos);
	  caption.seekCaption(pos);
	  window.setTimeout("indexer.start();",100);		// Restart the indexer after 0.1s
	  window.setTimeout("captioner.start();",100);		// Restart the captioner after 0.1s
	  break;

	case 'mouseover':
	  MM_nbGroup('over','rewind','images/rewindhover.gif','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}


function Forward(e) {
  var pos;
  // If playing media not playing or paused do not allow action
  if ( playstate != 'Playing' && playstate != 'Paused' ) return(false);
  
  if (!e) var e = window.event;
  id = this;
  
  if ( id.name == 'bttnforward05' ) FORWARDWINDVAL = 05;
  else if( id.name == 'bttnforward30' ) FORWARDWINDVAL = 30;
  else  FORWARDWINDVAL = 30;
  
  switch (e.type) {

    case 'click':
	  pos = movie1.getCurrentPosition() + FORWARDWINDVAL;
	  if (pos >= movie1.getDuration() )	// If forward wind would take us to end of movie or past it, do nothing
	    return(false);

	  indexer.stop();		// Stop the indexer
	  captioner.stop();		// Stop the captioner
      movie1.setCurrentPosition(pos);	//Forward  
	  index.seekIndex(pos);
	  caption.seekCaption(pos);
	  window.setTimeout("indexer.start();",100);		// Restart the indexer after 0.1s
	  window.setTimeout("captioner.start();",100);		// Restart the captioner after 0.1s
	  break;

	case 'mouseover':
	  MM_nbGroup('over','forward','images/forwardhover.gif','',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	default:
	  ;
  }
  return(false);
}


function RunIQuiz(e) {

  if (!e) var e = window.event;

  switch (e.type) {
	case 'click':
	  if (!quizdataloaded) {
	    alert('There is no Multi-Choice Quiz in this Video Lecture Pack.\n');
	  }
	  else if (iquizflag) {
	    if ( confirm("The In-line Quiz is already running.\n\nSelect 'OK' to start the Multi-Choice Quiz or 'Cancel' to close this message.\n\n(Starting the Multi-Choice Quiz will stop the In-line quiz)") ) {
		  // Raise press the Iquiz control stop button
		  IQuizControl('click', 'bttniquizctrlStop');
		  
		  // Start the MCQ
		  openwindow(iquizurl + '?quiz_id='+ iquiz.quiz_id,'top=30,left=100,width=760,height=560,resizable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=1');
		} else {
		  ;	//Dummy statement do nothing
		}
	  }
	  // Detect if stand-alone quiz is running. Code to be provided.
	  else if ( false ) {
		alert("The Multi-Choice Quiz is already running.\n\n. Press 'OK' to close this message.\n");
	  }else{
	    if ( confirm("Start the Multi-Choice Quiz now?\n\nSelect 'OK' to start the quiz or 'Cancel' to close this message.\n") )
		  
		  // Start the MCQ
		  openwindow(iquizurl + '?quiz_id='+ iquiz.quiz_id,'top=30,left=100,width=760,height=560,resizable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=1');
		else
		  ;	//Dummy statement do nothing
	  }
	  break; 
  }
  return false;	  
}


function evtH_IQuizControl(e) {

  if (!e) var e = window.event;
  id = this.name;
  
  IQuizControl(e.type, id);
  
  return(false);
}		// End of evtH_IQuizControl


function IQuizControl(etype, id) {
  
  switch (etype) {

    case 'click':
	  i_quizstatus = WM_readCookie('iquizstatus');
	  i_quizstatus = i_quizstatus.split('|');
	  
	  // Send stop command to IQuiz if it is running
	  if ( id == 'bttniquizctrlStop' && iquizflag ) {
		i_quizstatus[1] = 'false';	i_quizstatus[3] = 'stop';
		i_quizstatus = i_quizstatus[0]+'|'+i_quizstatus[1]+'|'+i_quizstatus[2]+'|'+i_quizstatus[3];
		WM_setCookie ('iquizstatus', i_quizstatus, '', '/', connection.domainname, '');
		
	  // Send start command to IQuiz if it is stopped
	  }else if ( id == 'bttniquizctrlStart' && !iquizflag ){
		if ( i_quizstatus[0] == i_quizstatus[2] ) {
		  alert ('You have answered all questions in the In-line Quiz.\n');
		  break;
		}
	    // XMLHttpRequest mode: checkresultid
		getDataReturnText(iquizmanifesturl+'?quizidstring='+iquiz.quiz_id+'&mode=checkresultid', checkresultid);	
	  }
	break;
    
	case 'mouseover':
	  if ( id == 'bttniquizctrlStop' )				// IQuiz running
	    MM_nbGroup('over','iquizctrlStop','images/iquizstophover.gif','images/iquizstopactive.gif',1);
	  else if ( id == 'bttniquizctrlStart' )
	  	MM_nbGroup('over','iquizctrlStart','images/iquizstarthover.gif','images/iquizstartactive.gif',1);
	  break;
      
	case 'mouseout':
	  MM_nbGroup('out');
	  
	default:
	  ;
  }
  return(false);
}		// End of IQuizControl


// 
// Get number of questions in quiz and display it
//
function getnumquestions(responsetext) {
	numquestions = responsetext;
    document.getElementById('iquizquizinfo').innerHTML='The Quiz has ' + numquestions + ' questions';	
	if ( !inlineinfo ) 
		return;
	
	// Show additional inline quiz info and the start quiz popup( if inlineinfo = true)
	document.getElementById('IQuizindicator').style.visibility='visible';
	if ( WM_readCookie('preferences') == 'disablequizpopup' ) {
	   ; // Do nothing
	}else {
	   refRunIquizPopup = openwindow(connection.dirname+'runiquiz.html?iquizcount='+numquestions,'top=80,left=120,width=487,height=316,resizable=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=0'); 
	}		
	return;
}

// 
// Start a new quiz
//
function startnewquiz(responsetext) {
  // Getting a result record starts the quiz on the remote system
  var regpositiveinteger = /\w+#/; var regactivestring = /active#/;

  var result_id = responsetext;

  if ( regpositiveinteger.test(result_id) ) {
    iquiz.r_id = result_id.match(/\w+/);
  } else if ( regactivestring.test(result_id) ) {
    iquiz.r_id = result_id.match('active');
  }

  if (iquiz.r_id == 'active' ) {
    alert("The Multi-Choice Quiz (MCQ) is already running.\n\nYou can not start the In-line Quiz while it is running.\n\nPress 'OK' to close this message.\n");
    return false;
  }
  
  return false;

}


//Check result ID
function checkresultid(responsetext) {
  // Getting a result record starts the quiz on the remote system
  var regactivestring = /active#/;

  var result_id = responsetext;

  if ( regactivestring.test(result_id) ) {
    iquiz.r_id = result_id.match('active');
  }

  if (iquiz.r_id == 'active' ) {
    alert("The Multi-Choice Quiz (MCQ) is already running.\n\nYou can not start the In-line Quiz while it is running.\n\nPress 'OK' to close this message.\n");
    return false;
  }

  i_quizstatus[1] = 'true';
  i_quizstatus = i_quizstatus[0]+'|'+i_quizstatus[1]+'|'+i_quizstatus[2];
  WM_setCookie ('iquizstatus', i_quizstatus, '', '/', connection.domainname, '');
  return true;

}


var refRunIquizPopup = null;

function getresultinfo(responsetext) {
  
  var fs = /[ \t]*\|[ \t]*/; var regint= /\d+/; 
  var quizresultinfo = responsetext; 
  var fields = quizresultinfo.split(fs); var score = fields[0], numattempted = fields[2].match(regint), numquestions = fields[3].match(regint);
  
  var displaymsg = "In-line Quiz Results:\n\nYou answered: " + numattempted + " of " + numquestions + " questions.";
  var displaymsg =  displaymsg + "\n\nYour score is: "+ score;  
  var displaymsg =  displaymsg + "\n\nPress 'OK' to continue.";
  alert(displaymsg);

  return false;
}


function isRunIQuiz() {
  iquizstatus = WM_readCookie('iquizstatus');
  iquizstatus = iquizstatus.split('|');

  // Start the In-line Quiz
  if ( !iquizflag  && iquizstatus[1] == 'true' ) {
	iquizflag = true;	//We're running
	MM_nbGroup('down','group2','iquizctrlStart','images/iquizstartactive.gif',1);
	document.getElementById('IQuizindicator').innerHTML = 'In-line Quiz Running';	
	
	// Create new instance of IQuizPopup (only once)
	if ( !iquizpopup ) {
		// Source the quizmanifest file with mode: getresultid (Getting a result ID effectively starts the quiz)
  		getDataReturnText(iquizmanifesturl+'?quizidstring='+iquiz.quiz_id+'&mode=getresultid', startnewquiz);	
		iquizpopup = new IQuizPopup;
	}

	// Check if we've answered the last question
	if ( iquizstatus[2] == iquizstatus[0] ) {	// We've answered the last quiz
	  window.clearInterval(isruniquizthread);
	  return;
	}
	// Do these if there are remaining questions
		
    // If not last, get the first question, or next available question
	( iquizstatus[2] == 'null' ) ? nextquestion = 1 : nextquestion = parseInt(iquizstatus[2])+1;
	iquiz.next(nextquestion);
	// Start the IQuizPopup
    iquizpopup.start();

  // Stop the In-line Quiz
  } else if  ( iquizflag && iquizstatus[1] == 'false' ) {
	iquizflag = false;
	// Close the Quiz Popup window if it's open
    try {
	  iquizpopup.winref.focus();
	  iquizpopup.winref.close();
	  iquizpopup.winref = null;
	}catch(e){
	  iquizpopup.winref = null; 	// Just set winref to null
	}
	// Stop the IQuizPopup
	iquizpopup.stop();
	MM_nbGroup('down','group2','iquizctrlStop','images/iquizstopactive.gif',1);
	document.getElementById('IQuizindicator').innerHTML = 'In-line Quiz Stopped';
	// Show the score
	if ( !(iquizstatus[2] == 'null') )
	  // XMLHttpRequest mode: getresultinfo
  	  getDataReturnText(iquizmanifesturl+'?resultid='+iquiz.r_id+'&mode=getresultinfo',getresultinfo);
  }
}


var quizdataloaded = false;

function LoadIQuiz(responsetext) {
  if ( QUERYSTRING['viewclip']=='true' )
    // Don't load IQuiz if player in viewclip mode.
    return;

  // Test if quiz manifest file returned any IQuiz data
  if ( responsetext.length < 1 )
  	// No data available, do nothing
    return(false);

  // IQuiz data available
  quizdataloaded = true;
  
  // Register functions for onMouseover, onMouseout and onClick events for quiz 'Run MCQ' button 
  registerhandlers('bttnrunmcq', 'RunIQuiz', 'onmouseover,onmouseout,onclick');
  // Display the 'Run MCQ' button
  document.getElementById('bttnrunmcq_greyed').style.display = 'none';
  document.getElementById('bttnrunmcq').style.display = 'block';
  
  //Stuff quiz data into iquiz.text property
  iquiz.text = responsetext;
  // Parse the quiz data
  iquiz.open();
  
  if ( iquiz.n == 0 ) {
	// No IQuiz data containing time-codes
	inlineinfo = false;
    // Source the quizmanifest file with mode: getnumquestions
    getDataReturnText(iquizmanifesturl+'?quizidstring='+iquiz.quiz_id+'&mode=getnumquestions', getnumquestions);
  }else {
    // Quiz data with time-codes available
    inlineinfo = true;	
    // Source the quizmanifest file with mode: getnumquestions
    getDataReturnText(iquizmanifesturl+'?quizidstring='+iquiz.quiz_id+'&mode=getnumquestions', getnumquestions);
  
    iquizstatus = iquiz.n +'|null|null';
    // Display quiz control and info panels
    document.getElementById('iquizpanel').style.visibility='visible';
    document.getElementById('IQuizindicator').innerHTML = 'In-line Quiz Stopped';
    WM_setCookie ('iquizstatus', iquizstatus, '', '/', connection.domainname, '');

    // Register functions for onMouseover, onMouseout and onClick events for quiz INLINE control buttons 
    registerhandlers('bttniquizctrlStart', 'evtH_IQuizControl', 'onmouseover,onmouseout,onclick');
    registerhandlers('bttniquizctrlStop', 'evtH_IQuizControl', 'onmouseover,onmouseout,onclick');
  }
  
  // Monitor the state of the start of the iquizstatus cookie
  isruniquizthread = window.setInterval('isRunIQuiz();',250);
  return(true);

}


function openforumwindow() {
  openwindow(forum.uri,'top=80,left=162,width=700,height=300,resizable=1,toolbar=1,location=1,status=1,menubar=0,scrollbars=1');
}

function LoadForum() {
  forum.open();
  if ( forum.available ) {
    //Set up the URI for the forum open button
    bttnopenforum.onclick=openforumwindow;
    //Make the button visible
    document.getElementById('forumbttn').style.visibility="visible";
    document.getElementById('forumcaption').style.visibility="visible";
  }
}


function clipStatuswindow() {

  var strDuration, strElapsed, strPlay1state, strPlay2state, strOpenstate, strDownloadprogress;

  var objDPBar=document.getElementById('timelineprogressbar');  
  var DPBarLength = (loadmovie.movie1_DP / 100)* 216;
  objDPBar.style.clip = "rect(0px, " + DPBarLength + "px, 4px, 0px)";
  
  // Get total movie play time
  strDuration=int2time(loadmovie.playduration);

  // Get Elapsed play time
  if ( QUERYSTRING['viewclip'] == 'true' )
    strElapsed=int2time(movie1.getCurrentPosition() - loadmovie.startposition);
  else
    strElapsed=int2time(movie1.getCurrentPosition());

  // Get Player Status
  strPlay1state=movie1.getPlayState()
  if (strPlay1state)
    strPlay1state='lecture: ' + strPlay1state;

  // Only update streaming progress if isMediaonline is true and downloadstate is downloading
  if (connection.isonline && loadmovie.downloadstate == 0) {
    strDownloadprogress = 'Download Progress ' + Math.round(loadmovie.movie1_DP) + '%';
    document.getElementById('idStreamingprogress').innerHTML=strDownloadprogress;
  }
  document.getElementById('idClipelapsed').innerHTML=strElapsed;
  document.getElementById('idClipduration').innerHTML=strDuration;
  document.getElementById('idClipplaystate').innerHTML=playstate;
  document.getElementById('idClipplaystate2').innerHTML=playstate;
  document.getElementById('idCliprate').innerHTML=movie1.getRate(1);
  document.getElementById('idClip1openstatus').innerHTML=strPlay1state;
}

// Debugger functions
function dbg_openwindow() {
  if ( !debug ) return;
  var winopenparam='top=10,left=400,width=450,height=600,resizeable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=1';
  if (!dbgwinref) {
    dbgwinref=window.open('','',winopenparam);
  }else {
    try {	//Catch any errors that may occur attempting to set the focus on the child window
      dbgwinref.focus();
	}
	catch(e) {		// If user closes the child window and we attempt to set the focus on it we simply call openwindow() again
	  dbgwinref=null;
	  dbg_openwindow();
	}
  } 
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    
   try {	// Catch any errors that may occur accessing MM_nbOver.length 
      if ( document.MM_nbOver.length )
	   null;
	}
	catch(e) {	
	  return;		// Do nothing
	}
	
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

