//---------------------------------------------------------------------------
// 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) {
	alert(e);
      return '';
      alert('*** Create H2 Obj failed');
      }

    var iret, s2;
    var s1 = SrcNS.toLowerCase();

    Max = objNSList.Count;
    if (Max == 0) {
      //alert('*** No Namespaces found');
      return ''; }

    //--------------------------------------------
    // First 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;
    }
  }



function LinkKwd(kwd){
  var s = "";
  var session = new ActiveXObject("HxDs.HxSession");
  
  var ns = NS_IsValid("MS.VSCC");
  if (ns != '')
  {
    try
    {
      ns = "ms-help://" + ns;
      session.Initialize(ns, 0);
    }
    catch(e)
    {
      ns = "";
    }
  }

  if (ns == '')
  {
    var ns = NS_IsValid("MS.MSDNVS");
    try
    {
      ns = "ms-help://" + ns;
      session.Initialize(ns, 0);
    }
    catch(e)
    {
      ns = "";
    }
  }

  if (ns == '')
  {
    var ns = NS_IsValid("MS.VSCC.2003");
    try
    {
      ns = "ms-help://" + ns;
      session.Initialize(ns, 0);
    }
    catch(e)
    {
      ns = '';
    }
  }

  if (ns != '')
  {
    //var kwd = "frlrfSystem" + linkname + "ClassTopic";

    try 
    {
      s = session.QueryForUrl(kwd, "!DefaultAssociativeIndex", 0, "");
      window.location = s;       //local document
    }
    catch(e) 
    {
     if (kwd.indexOf("eaglrf") != -1) {
      window.alert("This topic in the ESRI Component Help Collection is not available.");
     }
     else {
      window.alert("This topic from the Microsoft documentation collection not available.\nKeyword query failed."); 
     }
    }

  }
  else
    window.alert("Sorry. Can't display this Microsoft documentation collection topic.\nNamespaces containing the topic were not found or are not installed");

}






