// nfw functions
//
//===========================================================================
// History:
// 19dec03 - revised GetHelpPathLink and GetHelpPathText to use path defined 
//	at registry key specified by localUserRegPath. If useRegPath is set 
//	to 1 the registry path is used, else the current path is used.
// 26nov03 - created "str_exercises" variable
// 17nov03 - added OpenExercise and checkTOC functions
// 04nov03 - added OpenPDF function
// 04nov03 - commented out code that operates on top nav images in setButton
// 03apr03 - added loadFrame
// 17mar03 - fixed formatting of GetHelpPathLink
// 12mar03 - added getcurpath2, GetNfwPathLink, and GetNfwPath functions
//===========================================================================
// LOCALIZATION
//
var str_onlastpage 	= "You are on the last page.";
var str_onfirstpage 	= "You are on the first page.";
var str_nextpage 	= "Next page";
var str_prevpage 	= "Previous page";
var str_exercises	= "Tutorials";
var localUserRegPath    = "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R16.1\\ACAD-301:409\\LocalRootFolder";

//===========================================================================
// GLOBAL VARIABLES
//
var useRegPath = 0;  // if == 1, the registry path defined by localUserRegPath is used
var curfile    = "";
var okbotimg   = 0;
var okWsh      = 1;

//===========================================================================
//
if( useRegPath == 1 ) {
  try { var WshShell = new ActiveXObject("WScript.Shell"); }
  catch(e) { okWsh = 0; }
}

//===========================================================================
// doBrowse - enables back and next browsing
//
// This assumes that 'browselist' is defined elsewhere
//
// <direction> = the number of pages that are skipped, use 1 for next 
//               and -1 for back.
//
function doBrowse(direction) {
  curfile = document.all.curfile.value
  var ct = 0;
  for( var num in browselist ) {
    var file = browselist[num];
    if( curfile == file ) {
      var newfile = browselist[ct+direction];
    }
    ct++;
  }
  if( newfile ) { document.all.ifrm.src=newfile; }
  else {
    //if( direction == 1 ) { alert(str_onlastpage); }
    //else { alert(str_onfirstpage); }
  }
}

//===========================================================================
// loadFrame - loads the first step of the exercise 

function loadFrame() {
  document.all.ifrm.src=browselist[1];
}

//===========================================================================
// setButton - sets the appropriate nav "button" for the lesson.
//
// This assumes that all button IMG object names are "imageN" starting with "image1"
//
// <imgnum>  = the number associated with the "image" object 
// <numbtns> = the number of buttons (lessons)

function setButton(imgnum,numbtns) {
  var ct = 0;
  if( okbotimg == 1 ) {
    var i = 1;
    while( i <= numbtns ) {
      //eval("parent.document.image"+i+".src='numoff"+i+".gif';");
      eval("parent.document.botimage"+i+".src='numoff"+i+".gif';");
      i++;
    }
    //eval("parent.document.image"+imgnum+".src='numon"+imgnum+".gif';");
    eval("parent.document.botimage"+imgnum+".src='numon"+imgnum+".gif';");
    document.all.curfile.value = browselist[imgnum]
    if( imgnum == 1 ) { 
      //parent.document.prevarrow1.src="l_arrow_off.gif";
      parent.document.prevarrow2.src="l_arrow_off.gif";
      //parent.document.prevarrow1.title=str_onfirstpage;
      parent.document.prevarrow2.title=str_onfirstpage;
    }
    else {
      //parent.document.prevarrow1.src="l_arrow.gif";
      parent.document.prevarrow2.src="l_arrow.gif";
      //parent.document.prevarrow1.title=str_prevpage;
      parent.document.prevarrow2.title=str_prevpage;
    }
    if( imgnum == numbtns ) { 
      //parent.document.nextarrow1.src="r_arrow_off.gif";
      parent.document.nextarrow2.src="r_arrow_off.gif";
      //parent.document.nextarrow1.title=str_onlastpage;
      parent.document.nextarrow2.title=str_onlastpage;
    }
    else {
      //parent.document.nextarrow1.src="r_arrow.gif";
      parent.document.nextarrow2.src="r_arrow.gif";
      //parent.document.nextarrow1.title=str_nextpage;
      parent.document.nextarrow2.title=str_nextpage;
    }
  }
}

//===========================================================================
// setsize - adjusts the size of the iframe so the scrollbars align properly
//
// add to onload and onresize events

function setsize() {
  // if botimg1 exists, set the siz to 32, else set it to 0
  try {
    zz = document.all.botimage1.src;
    var siz = 32;
    okbotimg = 1;
  }
  catch(e) {
    var siz = 0;
  }
  if( navigator.appName == "Microsoft Internet Explorer" ) {
    var ht = document.body.clientHeight - document.all.ifrm.offsetTop;
    if( ht > siz ) {
      document.all.ifrm.style.height = ht-siz;
    }
  }
}

//===========================================================================

function MakeArray(n) {
  this.length = n;
  for (var i = 1; i <= n; i++) { 
    this[i] = 0 
  }
  return this
}

//===========================================================================

function getcurpath2 () {
  var path = unescape(location.pathname);
  if( path.indexOf("@MSITStore:") == 0 ) {
    path = path.substring(11,path.length);
  }
  if( path.indexOf("/") == 0 ) {
    path = path.substring(1,path.length);
  }
  var i = path.lastIndexOf("\\");
  var j = 0;
  path = path.substring(j,i+1);
  return path;
}

function GetHelpPathLink (extra) {
  if( useRegPath == 1 ) { 
    if( okWsh == 1 ) { var path = WshShell.RegRead (localUserRegPath); }
    else { path = "LOCALROOTPREFIX - "; }
  }
  else { var path = getcurpath2(); }
  if( extra == null ) { extra = ""; }
  var ex = extra.replace(/\\/g, "/");
  var pathstr = path;
  //return "<a href='file://" + path + ex + "' class=pathlink target=path>" + pathstr + "\\" + extra + "</a>";
  return "<a href='file://" + path + ex + "' class=pathlink target=path>" + pathstr + extra + "</a>";
}

function GetHelpPathText (extra) {
  if( useRegPath == 1 ) { 
    if( okWsh == 1 ) { var path = WshShell.RegRead (localUserRegPath); }
    else { path = "LOCALROOTPREFIX - "; }
  }
  else { var path = getcurpath2(); }
  if( extra == null ) { extra = ""; }
  //return path + "\\" + extra;
  return path + extra;
}

function OLDGetHelpPathLink (extra) {
  var path = getcurpath2();
  if( extra == null ) { extra = ""; }
  var ex = extra.replace(/\\/g, "/");
  var pathstr = path;
  //var pathstr = path.replace(/\\/g, "\\ ");;
  return "<a href='file://" + path + ex + "' class=pathlink target=path>" + pathstr + extra + "</a>";
}

function OLDGetHelpPathText (extra) {
  var path = getcurpath2();
  if( extra == null ) { extra = ""; }
  return path + extra;
}

function OpenPDF (file) {
  var path = getcurpath2();
  window.open("file://"+path+file,"pdf","scrollbars=yes,resizable=yes,width=500,height=500");
}

// OpenExercise - Opens the exercise defined by the object id
//
function OpenExercise(eid) {
  eval(eid+".Click();");
}

// checkTOC - used with "noflash" file
//
function checkTOC () {
  nfwtoc = window.location.hash;
  if( nfwtoc == "#noflash" ) {
    backlink.innerHTML = str_exercises;
    backlink.href = "../noflash.html";
  }
}
