// functions.js - function library
// (c) 2005 Q42 BV

var userAgent    = navigator.userAgent.toLowerCase();
var appVersion   = navigator.appVersion.toLowerCase();
var appName      = navigator.appName.toLowerCase();

// operating system and browser information
var isWin        = (appVersion.indexOf('windows') != -1);
var isOpera      = (userAgent.indexOf('opera') != -1);
var isIE         = (appName.indexOf('internet explorer') != -1) && !isOpera;
var isSafari     = (userAgent.indexOf('applewebkit') != -1);
var isMozilla    = (appName.indexOf('netscape') != -1) && !isSafari;

// build versionString
if (isSafari)
  var versionString = appVersion.substr(v.lastIndexOf("safari/") + 7, 3);
else if (isIE || isOpera)
  var versionString = appVersion.substring(appVersion.indexOf('msie') + 5);
else if (isMozilla)
  var versionString = userAgent.substring(userAgent.indexOf('rv:')+3, userAgent.indexOf('rv:') + 6);
else
  var versionString = appVersion;

// cast version to numeric
var version = parseFloat(versionString);
var ie50 = isWin && isIE && (version <= 5.01);


// crossPlatform attachEvent
function attachEventHandler(theEl, theEvent, theHandler, theScope)
{
  if (theScope)
    theHandler = theHandler.closure(theScope);
  if(typeof(theEl) == 'string')
    theEl = document.getElementById(el);

  theEvent = theEvent.toLowerCase();
  if (isIE)
    theEl.attachEvent(theEvent, theHandler);
  else
  {
    if (theEl == document.body)
      theEl = document;
    if (theEvent == "ondragstart")
      theEvent = "ondraggesture";

    theEl.addEventListener(theEvent.substring(2), theHandler, true);
  }
};

// gets an array of elements
function getElementsByTagNameAttributeValue(ancestorEl, tagName, attrName, attrValue)
{
  attrName = attrName.toLowerCase();
  if (typeof(attrValue) == 'undefined')
    attrValue = null;
  var els = [];
  var a = ancestorEl.getElementsByTagName(tagName);
  for (var i=0; i<a.length; i++)
  {
    var el = a[i];
    if (attrName == "classname" && isIE)
      var val = el.className;
    else if (attrName == "classname")
      var val = el.getAttribute("class");
    else
      var val = el.getAttribute(attrName);
    if (
      (val != null)
      &&
      (
        (attrValue == null)
        ||
        (
          (
            (attrName.indexOf("class") == 0)
            &&
            (val.indexOf(attrValue) != -1)
          )
          ||
          (val == attrValue)
        )
      )
    )
      els.push(el);
  }
  return els;
};

function printOpdracht()
{
  var form = document.getElementById("vragenformulier");
  newAction = form.getAttribute("action").replace(/nakijken\.html/, "print.html");
  form.setAttribute("action", newAction);
  form.setAttribute("target", "extraframe");
  form.submit();
};

function printAntwoordFrame()
{
  this.focus();
  this.print();
};

function doPopup(src)
{
  document.getElementById("popup-img").setAttribute("src", "/Image.aspx?img=" + src + "&w=800");
};
