//---------------------------------------------------------------------------
// 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('*** 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 ns = NS_IsValid("MS.VSCC");
  if (ns == ''){
   // window.alert(ns.length);
    var ns = NS_IsValid("MS.MSDNVS");
    }
  if (ns == ''){
    //window.alert(ns.length);
    var ns = NS_IsValid("MS.VSCC.2003");
    }
  if ((ns != '') && (kwd.indexOf('vadat') == -1)){

    var session = new ActiveXObject("HxDs.HxSession");
    ns = "ms-help://" + ns;
    session.Initialize(ns, 0);

    try {
      s = session.QueryForUrl(kwd, "!DefaultAssociativeIndex", 0, "");
      window.location = s;       //local document
      }
    catch(e) {
      window.alert("This topic from the Microsoft documentation collection is not available.\nKeyword query failed."); }
    }
  else {
    if (kwd.indexOf('Empty') != -1){
       window.open("http://msdn.microsoft.com/library/en-us/veendf98/html/defempty.asp");
    }
    else if ((kwd.indexOf('vadat') != -1) ){
      window.open("http://msdn.microsoft.com/library/en-us/vbenlr98/html/" + kwd + ".asp")
    }
    else {
      window.open("http://msdn.microsoft.com/library/en-us/cpref/html/" + kwd + ".asp")
    }
  }
}






