  // action en comment worden getoond bij een fout in JavaScript. Gebruik het verstandig...
  var action = '';
  var comment = '';
  var promptError = false;
  var req;

  function err(msg, url, linenumber) {
    // "kleine dingetjes"
    if ((msg.indexOf('hoverStart') > -1) || (msg.indexOf('hoverEnd') > -1)) {
      return true;
    }

    // stuur melding naar server
    var prep = ys_baseurl() + 'ys/javascript_log/' + sid + '/' + pid + '/' + escape(msg) + '/' + linenumber;

    // voor nu sturen we bij elke logregel een sms naar systeembeheer
    // if (promptError) {
      prep += '/1';
    // }

    sendRequest(prep);

    // geef foutmelding
    if (promptError) {
      var a = "Bij " + action + " is helaas een fout opgetreden\n";
      if ('' != comment) {
        a += comment + "\n\n";
      }

      // a += url + " (" + linenumber + ")";
      alert(a);
    }

    prep = null; a = null;
    return true;
  }

  function ys_baseurl() {
    var u = location.href.split('/');
    return u[0] + '//' + u[2] + '/';
  }

	function trigger_xml_post() {
    var url = ys_baseurl() + 'ys/xml';
    sendRequest(url);
    return true;
  }

  function sendRequest(uri, callback) {
    req = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
      try {
        req = new XMLHttpRequest();
        if (arguments.length > 1) {
          req.onreadystatechange = callback;
        } else {
          req.onreadystatechange = processReqChange;
        }
        req.open('GET', uri, true);
        req.send(null);
      } catch(e) {
        req = false;
      }
    } else if (window.ActiveXObject) {
      // branch for IE/Windows ActiveX version
      try {
        req = new ActiveXObject('Msxml2.XMLHTTP');
      } catch(e) {
        try {
          req = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
          req = false;
        }
      }
      if (req) {
        if (arguments.length > 1) {
          req.onreadystatechange = callback;
        } else {
          req.onreadystatechange = processReqChange;
        }
        req.open('GET', uri, true);
        req.send();
      }
    }
  }

  function processReqChange() {
    // this standard callback function can be overridden by calling
    // sendRequest(uri, callback) with your own function
    return;
  }
	
	function addToArray(haystack, newFriend) {
    if (!isArray(haystack)) {
    	return false;
    }

  	// haystack.push(newFriend) werkt niet in IE 5.x
  	if (!inArray(newFriend, haystack)) {
  	  haystack[haystack.length] = newFriend;
  	}

  	return true;
  }

  function $(id) {
    return document.getElementById(id);
  }

  function getQuestionId(elementId) {
    var m = elementId.match(/[\d\.]+/g);
    return m[0];
  }

  function getFormElement(qid) {
    var elem = $('question_' + qid);
    return (elem) ? elem : false;
  }
  
  function removeFromArray(haystack, forgetFriend) {
    // rewritten as array.splice() is not supported by IE 5.x where x < 5
    // function now returns the adjusted array
    
    if (!isArray(haystack)) {
    	return haystack;
    }

  	var i, newArray;
  	newArray = new Array();
  	for (i in haystack) {
      if (!(haystack[i] == forgetFriend)) {
      	newArray[newArray.length] = haystack[i];
      }
    }

    return newArray;
  }
	
	function inArray(needle, haystack) {
    if (!isArray(haystack)) {
    	return false;
    }

    var i;
    for (i in haystack) {
  	  if (haystack[i] == needle) {
  		  return true;
  	  }
    }
    
    return false;
  }

	function arrayKeyExists(needle, haystack) {
    if (!isArray(haystack)) {
    	return false;
    }

    var i;
    for (i in haystack) {
  	  if (i == needle) {
  		  return true;
  	  }
    }
    
    return false;
  }
  
  function isArray() {
    // thx to http://www.planetpdf.com/developer/article.asp?ContentID=6383

    // Return a boolean value telling whether the first argument is an Array object.
  	if (typeof arguments[0] == 'object') {
      return (arguments[0].constructor.toString().match(/array/i) != null);
    }
    return false;
  }

  // thx to http://simon.incutio.com/archive/2004/05/26/addLoadEvent
  // do not override any onload function but add to it
  function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = func;
    } else {
      window.onload = function() {
        if (oldonload) {
          oldonload();
        }
        func();
      }
    }
  }

