// Copyright (C) 2007 Cognos Incorporated. All Rights Reserved.
// Cognos and the Cognos logo are trademarks of Cognos Incorporated.

// htmlcontent.js

// Helper functions for getting the Content and the navigation buttons in 
// sync.

// var page; is defined by the HTML file that includes this script.
// holds the page identifier.

// Have we initialized ourselves.
var loaded = false;


function alert_obj(obj)
{
  var msg = typeof(obj) + "\n";
  msg = msg + obj + "\n";
  var name;
  for (name in obj) {
    msg = msg + name + ":" + obj[name] + "\n";
  }
  alert(msg);
}

/// Returns the Table of contents Window
function window_toc()
{
  if (parent) {
    if (parent.frames) {
      var toc = parent.frames["toc"];
      return toc;
    }
  }
  return null;
}
  



// Update the navigation frame to show what is being displayed
function update_navigation()
{
  var hash;
  var id_valid;


  win_toc = window_toc();
  if (win_toc) {
    if (win_toc.loaded) {
      hash = win_toc.current_selection_id;
      if (hash == null || hash.length == 0) {
        hash = page;
      }
      id_valid = win_toc.highlight(hash);
      if (! id_valid) {
        // Walk through the documents anchors until a valid id is found.
        var nbAnchors = document.anchors.length;
        var anchorIndex = 0;
        while (anchorIndex < nbAnchors) {
          hash = document.anchors[anchorIndex].name;
          id_valid = win_toc.highlight(hash);
          if (id_valid) {
            break;
          }
          anchorIndex++;
        }
      }
      
      // if we are in an MHT file, or if we are in a non-IE, we must call scrollToAnchor()
      if (!win_toc.useHash || navigator.userAgent.search(/msie/i) == -1) {
		win_toc.scrollToAnchor(window, hash);	
      }
    }
  }
}


function onLoad()
{
  loaded = true;
  update_navigation();
}



function content_output_iframe(fileStr,hash,width,height)
{
  var text = "<NOFRAMES>";
  text = text + "Frames must be enabled since the IFRAME tag is being used."; // TODO put this into a resource file
  text = text + fileStr + "#" + hash;
  text = text + "</NOFRAMES>";
  document.writeln(text);

  text = "<IFRAME ";
  text += "marginheight=\"0px\" marginwidth=\"0px\" ";
  text += "border=\"0px\" ";
  text += "width=\"";
  text += width;
  text += "\" height=\"";
  text += height;
  text += "\" src=\"";
  text += fileStr;
  if (hash && hash.length > 0) {
    text += "#" + hash;
  }
  text += "\" >";
  text += "</IFRAME>";
  document.writeln(text);
}



