function setHeaderText()
{
  var title = top.content.document.title;
  if (title =="")
  {
    title = "Caviidae";
  }
  
  // Set header text
  var html='';
  html += '<html>\n'
  html += '  <head>\n'
  html += '    <link rel="stylesheet" href="../support.css" type="text/css">\n'
  html += '  </head>\n'
  html += '  <body class="HEADER">\n'
  html += '    <p class="HEADER">' + title + '</p>\n'
  html += '  </body>\n'
  html += '</html>\n'
  top.header.document.close();
  top.header.document.open();
  top.header.document.write(html);
}

function fixTop(relativePath)
{
  // If this document is the top document, make frameset document the top document
  if (self == top)
  {
    // Apparently the site was not opened by index.htm
    if (relativePath == "..")
    {
      // It's a content page, so we have to make sure that the surfer
      // continues to see this very content (within the frameset off course!)
      var myURL = self.location.href;

      top.location.href = relativePath + "/index.htm?" + myURL;
    }
    else if (relativePath == ".")
    {
      // Someone clicked on a non content page, lets lead him/her the way!
      top.location.href = relativePath + "/index.htm";
    }
    else
    {
      alert ("Please use '.../caviidae/index.htm' to enter the site");
    }
  }
}

function setContentURL()
{
  var wls = window.location.search
  
  if (wls != "")
  {
    var contentURL = wls.replace("?","");

    top.content.location.href = contentURL;
  }
}

function op()
{
  //This function is used with folders that do not open pages themselves. See online docs.
}

function writeAge(birthDate)
{
  var currentDate = new Date();
  var timeDiff = currentDate - birthDate; // Age in Milliseconds
  var timeDiff = Math.floor(timeDiff/(1000*60*60*24*365.2422)); // Age in Years
  
  document.write(timeDiff);
}

function WriteWelcomeImage()
{
  image = new Array();
  imLoc = "../images/welkom/";
  number = 0;
  
  // imageArray
  image[number++] = "Mickeywelkom3.jpg"
  image[number++] = "Mickeywelkom4.jpg"
  image[number++] = "Minnie2.jpg"
  image[number++] = "Minnie3.jpg"
  image[number++] = "Minnie4.jpg"
  image[number++] = "Minniebewerkt1.jpg"
  image[number++] = "m&m1.jpg"
  image[number++] = "XM&Mwelkom.gif"
  image[number++] = "XMickey welkom1.gif"
  image[number++] = "XMickey welkom2.gif"
  image[number++] = "XMinnie.jpg"
  image[number++] = "XMinnieglitter.gif"
  image[number++] = "XWelkomglobe.jpg"
  
  increment = Math.floor(Math.random() * number);
  
  imgTag = '<IMG SRC="' + imLoc + image[increment] + '" ALT="Welkom bij Caviidae">';

  document.write(imgTag);
}

function writePictureFrame(filePath, fileName, comment)
{
  if (parent.picture.frameElement)
  {
    // There is a frameElement object, so use it to scale the pictures

    // Calculate available width for picture data
    var availableWidth = parent.picture.frameElement.clientWidth - 2 * parent.picture.frameElement.marginWidth - 2 - 17;

    // Calculate view width for picture data.
    // If orientation is landscape, set view width to available width.
    // If orientation is portait, set view height to available width.
    var myPicture = new Image();
    myPicture.src = filePath + '/' + fileName;
    if (myPicture.height <= myPicture.width)
    {
      var pictureWidth = availableWidth;
    }
    else
    {
      var pictureWidth = (myPicture.width / myPicture.height) * availableWidth;
    }

    // pictureWidth could probably be resolved
    var imgLine = '<img src="' + escape(filePath) + '/' + escape(fileName) + '" width="' + pictureWidth + '">\n';
  }
  else
  {
    // pictureWidth could not be resolved
    var imgLine = '<img src="' + escape(filePath) + '/' + escape(fileName) + '">\n';
  }

  // Make html string for picture display
  var html = '';
  html += '<html>\n';
  html += '  <head>\n';
  html += '    <link rel="stylesheet" href="../content.css" type="text/css"></link>\n';
  html += '  </head>\n';
  html += '  <body>\n';
  html += '    <h1>\n';
  html += '      ' + comment + '\n';
  html += '    </h1>\n';
  html += '      ' + imgLine;
  html += '  </body>\n';
  html += '</html>\n';

  // Close picture document frame
  parent.picture.document.close();

  // Transform XML and write to picture frame document
  parent.picture.document.write(html);
     
}

function setRowColor(objEvent)
{
  // Remove color from previously selected row
  for (var i=1; i<parent.album.table.rows.length; i++)
  {
    if (parent.album.table.rows[i].bgColor!="")
    {
      parent.album.table.rows[i].bgColor="";
      break;
    }
  }

  // Set color on selected row
  if (objEvent.srcElement.parentElement.tagName == "TR")
  {
    objEvent.srcElement.parentElement.bgColor="#F7C027";
  }
  else if (objEvent.srcElement.parentElement.parentElement.tagName == "TR")
  {
    objEvent.srcElement.parentElement.parentElement.bgColor="#F7C027";
  }
}

function props(obj)
{
  var result = "";

  for (var i in obj)
  {
    if (i.search("") != -1)
    {
      
      result += i + " = " + obj[i] + "<BR>";
    }
  }
  var propsWindow = window.open("", "dummyName");
  propsWindow.document.close();
  propsWindow.document.open();
  propsWindow.document.writeln(result);

  return result
}

function setAlbumURL()
{
  if (isIE5())
  {
    var albumFile="album_bad_xsl.xml";
  }
  else
  {
    var albumFile="album.xml";
  }

  top.content.album.location.href = albumFile;
}

function isIE5()
{
  var UA = navigator.userAgent;
  
  if (UA.indexOf("MSIE")!=-1 && UA.substr(UA.indexOf("MSIE")+5,1) == "5")
    return true;
  else
    return false;
}

function targetWindow(anchor, target) {
  window.open(anchor.href, target);
}
