/* Java Script Functies */

// ----------------------------------------------------------------------------
// Functies voor de gekleurde tekst.
// ----------------------------------------------------------------------------

// Convert one hex number into decimal form
function hexToDec(hex)
{
  var dec
  var hexVals = "0123456789ABCDEF"
  for (var i = 0; i <= 15; i++) {
    if (hex.charAt(0) == hexVals.charAt(i))
    {
      break
    }
  }
  for (var j = 0; j <= 15; j++) {
    if (hex.charAt(1) == hexVals.charAt(j))
    {
      break
    }
  }
  dec = (16 * i) + j
  return dec
}

// Convert one decimal number into hex
function decToHex(dec)
{
  var hexVals = "0123456789ABCDEF"
  var hex = hexVals.charAt(Math.floor(dec / 16)) + hexVals.charAt(dec % 16)
  return hex
}

// Calculate the increment by which to increase or decrease a color
function findStep(hexStart, hexEnd, textLength)
{
  var decStart = hexToDec(hexStart)
  var decEnd = hexToDec(hexEnd)
  var difference = decEnd - decStart
  var step = Math.round(difference / (textLength / 2) + .1)
  return step
}

// Seperate R, G, or B value from hex code
function getPart(color, colorPart)
{
  var part

  if (colorPart == "r")
    part = color.substring(1, 3)
  if (colorPart == "g")
    part = color.substring(3, 5)
  if (colorPart == "b")
    part = color.substring(5, 7)

  return part
}

// Find the color of the next letter
function findNextColor(oldHex, redStep, greenstep, blueStep)
{
  var oldRed = getPart(oldHex, "r")
  var newRed = decToHex(hexToDec(oldRed) + redStep)
  var oldGreen = getPart(oldHex, "g")
  var newGreen = decToHex(hexToDec(oldGreen) + greenstep)
  var oldBlue = getPart(oldHex, "b")
  var newBlue = decToHex(hexToDec(oldBlue) + blueStep)
  var newHex = "#" + newRed + newGreen + newBlue
  return newHex
}

function gradientText(startColor, endColor, string)
{
  var startRed = getPart(startColor, "r")
  var endRed = getPart(endColor, "r")
  var redStep = findStep(startRed, endRed, string.length)
  var startGreen = getPart(startColor, "g")
  var endGreen = getPart(endColor, "g")
  var greenstep = findStep(startGreen, endGreen, string.length)
  var startBlue = getPart(startColor, "b")
  var endBlue = getPart(endColor, "b")
  var blueStep = findStep(startBlue, endBlue, string.length)
  var oldColor = startColor
  var newColor 
  for(var i = 0; i <= Math.round((string.length / 2) - 1); i++)
  {
    if (i == 0)
    {
      newColor = oldColor
    }
    else
    {
      newColor = findNextColor(oldColor, redStep, greenstep, blueStep)            
    }
    document.write(string.charAt(i).fontcolor(newColor))
    oldColor = newColor
  }
  oldColor = endColor
  for(var i = Math.round(string.length / 2); i <= string.length; i++)
  {
    newColor = findNextColor(oldColor, -redStep, -greenstep, -blueStep)            
    document.write(string.charAt(i).fontcolor(newColor))
    oldColor = newColor
  }
}

// ----------------------------------------------------------------------------
// Funkties voor de datum en tijd.
// ----------------------------------------------------------------------------

function deTijd()
{

  var datum     = new Date()
  var uren      = datum.getHours()
  var minuten   = datum.getMinutes()
  var seconden  = datum.getSeconds()
  var deTijd

  // Eventuele 0 toevoegen bij de minuten en seconden.
  if (minuten < 10)
    minuten  = "0" + minuten
  if (seconden < 10)
    seconden = "0" + seconden

  // String van de tijd opbouwen.
  deTijd = uren + ":" + minuten + ":" + seconden

  return deTijd

}

// ----------------------------------------------------------------------------
// Funkties voor het laden van frames.
// ----------------------------------------------------------------------------


function laadnavigator(nav_href)
{
  parent.nav.location.href=nav_href;
}

function laadsite(titel_href, links_href, body_href, nav_href)
{
  parent.titel.location.href=titel_href;
  parent.links.location.href=links_href;
  parent.body.location.href=body_href;
  parent.nav.location.href=nav_href;
}


// ----------------------------------------------------------------------------
// Funkties voor het opmaken van de site.
// ----------------------------------------------------------------------------

function titel(titel)
{
  document.write("<center><font size=5>" + titel + "</font></center>")
}
