/* --- JavaScript --- */

/* --- General --- */

 

 

/* --- add functions to onload event: addLoadEvent(functionName); --- */

function addLoadEvent(func) {

  var oldonload = window.onload;

  if (typeof window.onload != 'function') {

    window.onload = func;

  } else {

    window.onload = function() {

      if (oldonload) {

        oldonload();

      }

      func();

    }

  }

}

 

/* --- createElement() --- */

function createElement(element) {

            if (typeof document.createElementNS != 'undefined') {

                        return document.createElementNS('http://www.w3.org/1999/xhtml', element);

            }

            if (typeof document.createElement != 'undefined') {

                        return document.createElement(element);

            }

            return false;

}

 

/* --- setAttributes() --- */

function setAttributes(element,attr) {      // format attr: [['class','actief'],['href','http://www.test.xx']]

            if (typeof element.setAttributeNS != 'undefined') {

                        for (a=0; a<attr.length; a++) {

                                   element.setAttributeNS('http://www.w3.org/1999/xhtml',attr[a][0],attr[a][1]);

                        }

            }

            if (typeof element.setAttribute != 'undefined') {

                        for (a=0; a<attr.length; a++) {

                                   element.setAttribute(attr[a][0],attr[a][1]);

                        }

            }

            return false;

}

 

/* --- add/remove className --- */

function addClass(thisNode,thisClass) {

            removeClass(thisNode,thisClass);         // make sure there won't be any doubles

            thisNode.className += " " + thisClass;

}

 

function removeClass(thisNode,thisClass) {

            if (thisNode.className.length == (thisClass.length)) {

                        thisNode.className = thisNode.className.replace(thisClass,"");

            }

            else {

                        thisNode.className = thisNode.className.replace(" " + thisClass,"");

            }

}

 

/* --- tell CSS JavaScript is on --- */

jsOn = function() {

            var container;

            if (!(container = document.getElementById('container'))) return false;

            addClass(container,"jsOn");

}

 

/* --- check className --- */

function hasClassName(thisNode,thisClass) {

            var nodeClass = thisNode.className;

            if (!thisClass && nodeClass != "") return true;

            if (thisClass && nodeClass.indexOf(thisClass) > -1) {     // match, but not exact

                        var nodeClasses = nodeClass.split(/\s+/);         // seperate class names (devided by one or more whitespaces)

                        for (c=0; c<nodeClasses.length; c++) {

                                   if (nodeClasses[c] == thisClass) return true

                        }

            }

            return false;

}

 

/* --- check if CSS is supported --- */

function cssSupport() {

            if (!document.styleSheets) return false; // styleSheets object is not supported

            var css = document.styleSheets;

            for (s=0; s<css.length; s++) {

                        if (s == 0) {

                                   if (!(css[0].cssRules || css[0].rules)) return false;            // both methods (cssRules/rules) are not supported

                        }

                        if (!css[s].disabled) return true;  // at least one of the stylesheets is not disabled

            }

            return false;      // stylesheets are all disabled or not supported at all

}

/* --- JavaScript --- */

/* --- FAQ --- */

 

 

/* --- initialize FAQ functionality --- */

initFAQ = function() {

            var faq, items;

            if (!(faq = document.getElementById('faq'))) return false;

            if (!(items = faq.getElementsByTagName('li'))) return false;

            for (i=0; i<items.length; i++) {

                        var parentItem = items[i];

                        var faqLink;

                        if (!(faqLink = parentItem.getElementsByTagName('a')[0])) continue;

                        removeClass(parentItem,"open");

                        faqLink.href = "#";         // make clickable;

                        addClass(faqLink,"link");

                        faqLink.onclick = function() {

                                   var openFAQ;

                                   if (openFAQ = document.getElementById('openFAQ')) openFAQ.id = null;

                                   if (hasClassName(this.parentNode,"open")) {

                                               removeClass(this.parentNode,"open");

                                   }

                                   else {

                                               this.parentNode.id = "openFAQ";

                                               addClass(this.parentNode,"open");

                                               window.location.replace("#openFAQ");

                                   }

                                   return false;

                        }

            }

}

 

 

/* --- call functions only if the used methods are supported --- */

if (document.getElementById && document.getElementsByTagName && cssSupport()) {

            addLoadEvent(initFAQ);

}

