/* This script differentiates between a normal web browser and
 * the ICE-browser used for the help inside Matlab.
 * 
 * We assume that the ICE-browser implies that the documentation is
 * viewed from Matlab's help-browser, so we can execute Matlab
 * instructions directly.
 *
 * Also, the ICE-browser is a horrible browser in some respects, and
 * we can use an appropiate hack. For other browsers, we assume a
 * support for standards created after the dinosaurs became extinct.
 *
 * Copyright (C) 2004-2005, Esben Høgh-Rasmussen
 */
var isIceBrowser=(navigator.userAgent.toLowerCase().indexOf('icebrowser')>=0);

/* Select one of two alternatives, depending on the browser.
 */
function writealt(icestring,otherstring) {
  if (isIceBrowser)
    document.write(icestring);
  else
    document.write(otherstring);
}

/* Insert a weblink the ICE-browser opens in
 * the normal webbrowser.
 * 
 * Example:
 *  <script type="text/javascript">weblink('http://nru.dk','NRU site')</script>
 */
function weblink(linkstr,str) {
  if (isIceBrowser)
    document.write('<a href="matlab:web(\'' + linkstr + '\',\'-browser\');">' + str + '<\/a>');
  else
    document.write('<a href="' + linkstr + '">' + str + '<\/a>');
}


/* Insert a reference to a matlab-function, i.e. one the ICE-browser
 * can acces using the DOC-command. Normal browsers will underline instead.
 *
 * Example:
 *  <script type="text/javascript">docref('svd','<code>svd<\/code>')</script>
 */
function docref(doc,str1) {
  if (isIceBrowser)
    document.write('<a href="matlab:doc(\'' + doc + '\');">' + str1 + '<\/a>');
  else
    document.write('<u>' + str1 + '<\/u>');
}

/* Same as docref, except a string can be appended to the end.
 * This is intended for chaining:
 *  <script type="text/javascript">
 *    docrefs('svd','<code>svd<\/code>',', '.)
 *    docrefs('svds','<code>svds<\/code>','.')
 *  </script>
 */ 
function docrefs(doc,str1,str2) {
  if (isIceBrowser)
    document.write('<a href="matlab:doc(\'' + doc + '\');">' + str1 + '<\/a>' + str2);
  else
    document.write('<u>' + str1 + '<\/u>' + str2);
}

/* Generate a link to the framed page (with the
 * contents-menu) if:
 * 1) we are not in the frameset
 * 2) we are not in the ICE-browser
 */
function contentslink() {
  if (isIceBrowser) return;
  var DOM=(document.createElement && document.getElementsByTagName);
  if (!DOM || parent.frames['toc_frame']) return;
  var ref=location.href;
  var pos=ref.lastIndexOf("/");
  if (pos>=0) ref=ref.substring(pos+1);
  document.write(
    '&nbsp;|&nbsp;<a href="index.html?'+ref+'">Contents (frames)</a>'
  );
}
