
function newWindow(page) {
  window.open(page, "popup",
    "height=550,width=700,left=10,top=10,menubar=no,toolbar=no,scrollbars=yes,resizable=yes");
};

function open_newWindow(page) {
  window.open(root + page, "",
    "height=600,width=1000,left=10,top=10,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes");
};

//function open_newPage(page,class,pname) {
// var html_str = '<a href="' +root+page+ '" class="' +class+ '">' +pname+ '</' + 'a>';
//  var html_str = root+page;
//window.alert('open_newPage: html_str = ' + html_str);
//  document.write(html_str);
//};

function open_hbcFile(filename) {
    theLocation=filename;
	readFileViaApplet();
	document.write(document.HbcToHtml_applet.fileContent);
};

//var tested_first_paragraph_for_voice_over = 0;
// To overcome an error in finding java program set variable to 1
var tested_first_paragraph_for_voice_over = 1;
var insert_voice_over = 0;
function insert_paragraph_audio(paragraph_number) {
audio_file = audio_dir+paragraph_number +'.swf';
//  if (new File(audio_file).exists()) {
  //document.write(audio_file);  // debug
  // It takes too long to test whether each paragraph has a voice-over.
  // So change the code so that testing the first paragraph decides whether there are 
  // voice-overs for all paragraphs
  if (!tested_first_paragraph_for_voice_over) {
	current_file = document.URL;
	current_dir = current_file.replace(/\/[^\\\/]*html/,"/"); // Unix path separator
	current_dir = current_dir.replace(/\\[^\\\/]*html/,"\\"); // DOS path separator
	document.file_exists_applet.check(current_dir+audio_file);	
	status = document.file_exists_applet.status;
	//document.write(" dir = " + current_dir + " "); 
	//document.write('status = '+status+'  ');
	// status is a string finishing with a "1' and possibly some spaces if sucessful
	insert_voice_over = status.match(/1 *$/) != null;
	tested_first_paragraph_for_voice_over = 1;
  }
  if (insert_voice_over) {
	AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','50','height','20','src',root+'load_audio/loadAudio_white_v2','flashvars','voiceFile='+audio_file,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',root+'load_audio/loadAudio_white_v2' );
  }
}

function insert_specific_audio(name) {
     audio_file = audio_dir +name+'.swf';

	AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','50','height','20','src',root+'load_audio/loadAudio_white_v2','flashvars','voiceFile='+audio_file,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',root+'load_audio/loadAudio_white_v2' );
}


function check_flash_audio() {
    audio_file = audio_dir +'check.swf';

	AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','50','height','20','src',root+'load_audio/loadAudio_white_v2','flashvars','voiceFile='+audio_file,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',root+'load_audio/loadAudio_white_v2' );
}
function check_flash_audio1() {
    audio_file = audio_dir +'check.swf';

	AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','50','height','20','src',root+'load_audio/loadAudio_lighter_grey_v2','flashvars','voiceFile='+audio_file,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',root+'load_audio/loadAudio_lighter_grey_v2' );
}

function insert_specific_movie(name) {
     movie_file = movie_dir +name+'.swf';

AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','640','height','480','src',root+'movies/load_movie_white','flashvars','movieFile='+movie_file,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',root+'movies/load_movie_white' ); //end AC code
}

function insert_specific_movie_org(name) {
     movie_file = movie_dir +name+'.swf';

AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','640','height','480','src',root+'movies/load_movie','flashvars','movieFile='+movie_file,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',root+'movies/load_movie' ); //end AC code
}


function fixDoubleDots(path) {
// Shrinks double dot notation "../" in path names so that relative paths can be used in a file and
//   they will work both locally and remotely.  Note that IE uses backslashes for local paths.
//

  currentPath = document.location.pathname;
  re = new RegExp('\\\\', 'gi');
  temp = currentPath.replace(re, '/');
  currentDir = temp.substring(0, temp.lastIndexOf("/") + 1);
  currentPath = document.location.pathname.substring(0, document.location.pathname.lastIndexOf("/") + 1);
  path = currentDir + path;

  while ( (i = path.indexOf('../')) != -1 ) {
    left=path.substring(0, i);
    right=path.substring(i + 3, path.length);
    j=left.substring(0, left.length - 1).lastIndexOf('/') + 1;
    newLeft=left.substring(0, j);
    path = newLeft + right;
  };
  return path;
};

function loadPage(page) {
  window.location.href=fixDoubleDots(page +  '.html');
};

function loadRE(page) {
  window.location.href=fixDoubleDots(page);
};
