//---------------------------------------------------------------------------
// Requires IE5.0 same as MS Help 2 runtime min requirement
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// NS = NS_IsValid(SrcNS)
//---------------------------------------------------------------------------
// SrcNS: Is a namespace xyz you want to validate.
// Returns:
//   Namespace case corrected if found
//   or empty string if no match found or MS H2 not installed
//---------------------------------------------------------------------------
function NS_IsValid(SrcNS) {
  var Max, i, e;
  var objWalker, objNSList, objNS, nsName;

  try
    {
    //--- This will fail if H2 Runtime not installed --
    try {
      objWalker = new ActiveXObject("HxDs.HxRegistryWalker");
      objNSList = objWalker.RegisteredNamespaceList(undefined); }
    catch(e) {
      return '';
      alert('*** MS Help 2 runtime not found ***');
      }

    var iret, s2;
    var s1 = SrcNS.toLowerCase();

    Max = objNSList.Count;
    if (Max == 0) {
      //alert('*** No Namespaces found');
      return ''; }

    //--------------------------------------------
    // Check for exact match
    //--------------------------------------------
    for (i = 1; i <= Max; i++) {
      objNS = objNSList.ItemAt(i);
      nsName = objNS.Name;
      //document.writeln(nsName+'<br>');

      s2 = nsName.toLowerCase();
      if (s1 == s2) {
        //document.writeln('Exact Match found: ' + nsName+'<br>');
        return nsName;
        }
      }

    //No result found
    return '';
    }
  finally {
    //Done with objects
    objWalker = null;
    objNSList = null;
    objNs = null;
    }
  }


//---------------------------------------------------------------------------
// Path = H2OpenWin_Wksp('path/filename.htm')
//---------------------------------------------------------------------------
//   Expands the given relative path to include the corect vshik NS and Wkshop title
//   then opens the URL in a secondary window.
//   EG. Given "mshlpwrk/html/hxgrffilelisthxf.htm"
//       Opens Returns "ms-help://ms.vshik/mshlpwrk/html/hxgrffilelisthxf.htm"
//   Uses whatever vshik collection is found
//      MS.VSHIK.2003/dv_mshlpwrk
//      MS.VSHIK/mshlpwrk
//---------------------------------------------------------------------------
function H2OpenWin_Wksp(aPartialPath) {
var path;
  if (NS_IsValid('ms.vshik.2003') != "")
    path = 'ms-help://ms.vshik.2003/dv_mshlpwrk/'+aPartialPath;
  else
    path = 'ms-help://ms.vshik/mshlpwrk/'+aPartialPath;
  window.open(path,"_blank","");  //height=450,width=600,status=1,toolbar=0,menubar=0,location=1,resizable=1
  }

function H2OpenWin_VSHIK2003(aPartialPath) {
var path = 'ms-help://ms.vshik.2003/'+aPartialPath;
  if (NS_IsValid('ms.vshik.2003') != "")
    window.open(path,"_blank","");  //height=450,width=600,status=1,toolbar=0,menubar=0,location=1,resizable=1
  else
    alert('MS Help 2 Namespace "ms.vshik.2003" not found.');
  }

