// acad.js - JavaScript functions for Banff Help Files
// 
// v.0.11: 04may00 - fixed "display/collapse" all hidden text message so 
//		     it changes when clicked
// v.0.10: 03may00 - adjusted the height of the Comments dialog
// v.0.09: 26apr00 - added control of 'click4more' image in toggleLeadin
//		     added control of 'click4more' image in toggleProc
//		     deleted csJump function
//		     added localizable constants
// v.0.08: 06apr00 - updated autoExpand so it really works!
// v.0.07: 27mar00 - added doComments function
// v.0.06: 22mar00 - added build_hhrun_object
// v.0.05: 01mar00 - added extra "/" to jumpHTM
// v.0.04: 29feb00 - updated jumpCHM
// v.0.03: 09dec99 - added autoExpand
// v.0.02: 08dec99 - added jumpHTM and jumpCHM
// v.0.01: 30nov99 - the beginning
//
//===========================================================================
// Constants:

var strclick4more   = "Click for more...";
var strclick2hide   = "Click to hide...";
var strcollapsetext = "Collapse all hidden text on this page.";

//===========================================================================
// acOnload - placeholder for future functionality
function acOnload() {
//  autoExpand(0);
}

function doComments() {
  var stitle = document.title;
  var surl   = location.href;
  window.open("comments.htm#"+stitle,null,"height=450,width=450,resizable=yes,directories=no,location=no,menubar=no,status=no,toolbar=no" );
}

// Jump to local non-compiled HTML file from a CHM
// jumpHTM('drivers.htm');
function jumpHTM(file) {
  var path = location.pathname;
  var i = path.lastIndexOf("\\");
  var j = path.indexOf(":", 3);
  path = path.substring(j+1,i+1);
  location.href = "file:///" + path + file;
}

// Jump to a local CHM file from a non-compiled HTML file
// jumpCHM('acad_acr.chm::/acr_l30.html');
function jumpCHM(file_topic) {
  var path = location.pathname;
  var i = path.lastIndexOf("\\");
  path = path.substring(1,i+1);
  location.href = "ms-its:" + path + file_topic;
}

// Builds a ShortCut object to launch a CHM (with local path)
// build_hhrun_object - 
//
function build_hhrun_object(file) {
  var path = location.pathname;
  var i = path.lastIndexOf("\\");
  var j = path.indexOf(":", 3);
  path = path.substring(j+1,i+1);
  document.writeln("<OBJECT id=hhrun type='application/x-oleobject'");
  document.writeln("  classid='clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11'");
  document.writeln("  codebase='hhctrl.ocx#Version=4,73,8561,0'>");
  document.writeln(" <PARAM name='Command' value='ShortCut'>");
  document.writeln(" <PARAM name='Item1' value=',hh.exe," + path + file + "'>");
  document.writeln(" <PARAM name='Window'  value='bogus.html'>");
  document.writeln("</OBJECT>");
}

function getpath() {
  var path = location.pathname;
  var i = path.lastIndexOf("\\");
  var j = path.indexOf(":", 3);
  path = path.substring(j+1,i+1);
  return path;
}

function MakeArray(n) {
  this.length = n;
  for (var i = 1; i <= n; i++) { 
    this[i] = 0;
  }
  return this;
}

function toggleLeadin() {
  if( leadin.style.display == "" ) {
    leadin.style.display = "none";
    click4more.src = "chickletred.gif";
    click4more.title = strclick4more;
  }
  else {
    leadin.style.display="";
    click4more.src = "chickletred2.gif";
    click4more.title = strclick2hide;
  }
}

var lastspan = new MakeArray(5);
var lastlink = new MakeArray(5);
function togglespan( level, spanname, linkname ) {
  if( spanname.style.display == "" ) {
    spanname.style.display = "none";
    lastspan[level] = 0;
    lastlink[level] = 0;
    if( linkname != null ) {
      linkname.style.fontWeight = "";
    }
  }
  else {
    spanname.style.display="";
    if( lastspan[level] != 0 ) { 
      lastspan[level].style.display = "none"; 
      lastlink[level].style.fontWeight = "";
    }
    lastspan[level] = spanname;
    if( linkname != null ) {
      lastlink[level] = linkname;
      linkname.style.fontWeight = "bold";
    }
  }
}

var allon = 0;
//var showall1 = 0;
function showAll() {
  if( allon == 1 ) {
    document.location.href = document.location.href;
  }
  else {
    for ( i=0; i < document.all.length; i++ ) {
      document.all.item(i).style.display = "";
    }
    allon = 1;
    //if( showall1 != 0 ) {
      document.all.showall1.innerText = strcollapsetext;
    //  showall2.innerText = "";
    //}
  }
}

function autoExpand( exp ) {
  if( exp == 1 ) { showAll(); }
}

function toggleproc( procname, imgname, anchor ){
  var i = document.location.href.lastIndexOf("#");
  var cur_href = "";
  if( i > 0 ) { cur_href = document.location.href.substring(0,i); }
  if( procname.style.display == "" ) {
    procname.style.display = "none";
    imgname.src = "right.gif";
    procmore.title = strclick4more;
  }
  else {
    procname.style.display="";
    imgname.src = "down.gif";
    procmore.title = strclick2hide;
  }
}




