// arxref.js - JavaScript functions for Kirkland Help Files
// 
// 21mar01 - borrowed and merged two acad JavaScript files
// v.0.17: 24jan01 - added CheckForUpdates function
// v.0.16: 12jan01 - added unescape to jumpHTM function
// v.0.15: 05jan01 - updated showinfo, added strings
// v.0.14: 14dec00 - added showinfo
// v.0.13: 13nov00 - added nextpage and prevpage functions (not working yet)
// v.0.12: 24may00 - added chmpath to doComments function
// 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.";
var strprevpage     = "Previous page";
var strnextpage     = "Next page";
var hh_classid      = "clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11";
var hh_codebase     = "hhctrl.ocx#Version=4,74,8793,0";

//===========================================================================
// acOnload - placeholder for future functionality
function acOnload() {
//  autoExpand(0);
}

var mainchm = "arxdoc.chm";
var prod    = "ARX";
var lang    = "ENU";
var build   = "K025";

var release = "16";
var script = "http://www.autodesk.com/cgi-bin/achelp15.pl?type=UPDATES";
//var script = "http://www.acdocs.com/achelp/achelp15.cgi?type=UPDATES";

function CheckForUpdates () {
  var updateurl = script+"&build="+build+"&lang="+lang+"&prod="+prod+"&rel="+release;
  location.href = updateurl;
}

function doComments() {
  var stitle = document.title;
  var surl   = location.href;
  var i      = surl.indexOf("::");
  chmpath    = surl.substring(0,i+3);
  window.open(chmpath+"ac.cmtdialog.htm#"+stitle+" ["+surl+"]",null,"height=450,width=450,resizable=yes,directories=no,location=no,menubar=no,status=no,toolbar=no" );
}

function nextpage() {
  alert("not working yet!");
}

function prevpage() {
  alert("not working yet!");
}

var itext = "";
function showinfo(n) {
  if( itext == "" ) { itext = infoline.innerText; }
  if( n == 1 ) { infoline.style.visibility = "visible"; }
  else if( n == 2 ) {
    infoline.innerText = strprevpage;
    infoline.style.visibility = "visible";
  }
  else if( n == 3 ) {
    infoline.innerText = strnextpage;
    infoline.style.visibility = "visible";
  }
  else { 
    infoline.style.visibility = "hidden"; 
    infoline.innerText = itext; 
  }
}

// Jump to local non-compiled HTML file from a CHM
// jumpHTM('drivers.htm');
function jumpHTM(file) {
  var path = unescape(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 path = unescape(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='"+hh_classid+"'");
  document.writeln("  codebase='"+hh_codebase+"'>");
  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 = "../../Images/ac.chickletred.gif";
    click4more.title = strclick4more;
  }
  else {
    leadin.style.display="";
    click4more.src = "../../Images/ac.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 = "../../Images/ac.right.gif";
    procname.title = strclick4more;
  }
  else {
    procname.style.display="";
    imgname.src = "../../Images/ac.down.gif";
    procname.title = strclick2hide;
  }
}




