function toggleClass(nodeN, className) {
   if (YAHOO.util.Dom.hasClass(nodeN,className)){
     YAHOO.util.Dom.removeClass(nodeN,className);
   }else{
     YAHOO.util.Dom.addClass(nodeN,className);
   }
}

function toggleSibling(navnode) {
   	toggle(navnode.nextSibling.nextSibling);
  	toggleClass(navnode,'selected');
}

//im.onload = function() { setImageSize(this);};

function setImageSize(im, max_w, max_h) {
	alert(im.width);
	if (im.width > im.height) {
		// the image is wider than high. Adjust the width
		if (im.width > max_w)
			YAHOO.util.Dom.setStyle(im,'width', max_w + 'px');
	} else {	
		if (im.height > max_h)
			YAHOO.util.Dom.setStyle(im,'height', max_h + 'px');
	}	
}

String.prototype.trim = function() {	return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {	return this.replace(/^\s+/,"");}
String.prototype.rtrim = function() {	return this.replace(/\s+$/,"");}

function toggle(obj) {
	var el = $(obj);
	el.style.display = (el.style.display != 'none' ? 'none' : 'block' );
}

function getQuery() {
	var loc = document.location.toString();
	var query = null;
	var anchor = getAnchor();
	
	if (loc.lastIndexOf('?')) {
		if (anchor) {
			loc = loc.substr(0,loc.lastIndexOf(anchor) - 1);
		}
		query = loc.substr(loc.lastIndexOf('?') + 1,loc.length);
	}
	
	return query;
}

function getAnchor() {
	var loc = document.location.toString();
	var anchor = null;
	
	if (loc.lastIndexOf('#')) {
		anchor = loc.substr(loc.lastIndexOf('#') + 1,loc.length);
	}
	return anchor;
}

// DOM functions

	function getData(obj) {
		if (obj) {
			if (obj.data) {
				return obj.data.trim();					
			} else {
				if (obj.firstChild){
					var firstnon = firstNonTextChild(obj);
					if (firstnon){
						return getData(firstnon);
					} else {
						if (obj.firstChild.data)
							return obj.firstChild.data.trim();
					}
				}
			}
		}
	}
	
	function firstNonTextChild(node) {
		var max = node.childNodes.length;
 		for (var i =0 ; i < max; i++) {
 			if (node.childNodes[i].nodeName !== '#text')
				return node.childNodes[i];
		}
	}

function GETTAG(obj,tag)
{
	var test=obj.getElementsByTagName(tag);
	if(test[0] && test[0].firstChild && test[0].firstChild.data)
		return test[0].firstChild.data;

	return '';
}

function NV(val,tag,type,par){
	var node = val.getElementsByTagName(tag)[0];
	if (node) {
		ret = node.firstChild;
		var el;
		if (ret) {
			if (par) {
				if (type == 'text') {
					// Safari cannot directly insert textnodes, therefor this explicit creation
					if (ret.nodeValue) {
						el = document.createTextNode(ret.nodeValue);
						par.appendChild(el);
					}
				}

				if (type == 'image') {
					el = document.createElement('img');
					el.setAttribute('src',ret.nodeValue);
					par.appendChild(el);
				}
			}
		}
		return el;
	}
}


function NN(type,cls,val,par) {
	var n = document.createElement(type);
	
	if (cls) {
		n.className = cls;
	}
		
	if (val) {
		n.appendChild(document.createTextNode(val));
	}

	if (par) {
		par.appendChild(n);
	}
	
	return n;
}

// extend Object
Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

Object.extend(String.prototype, {
  stripTags: function() {
    return this.replace(/<\/?[^>]+>/gi, '');
  },

  escapeHTML: function() {
    var div = document.createElement('div');
    var text = document.createTextNode(this);
    div.appendChild(text);
    return div.innerHTML;
  },

  unescapeHTML: function() {
    var div = document.createElement('div');
    div.innerHTML = this.stripTags();
    return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
  }
});

function getXMLObj(URL, endFunc, methd, async) { 
	var req = null;

	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType) 
		{
			req.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) 
	{
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}


	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				endFunc(req.responseText);
			}	
			else	
			{
				alert("XMLHTTP Error: returned status code " + req.status + " for URL " + URL + ". Info: " + req.statusText);
			}	
		} 
	}; 
	req.open(methd, URL, async); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null);
}

// macros
function len(x, y) {
	return Math.sqrt((x*x)+(y*y));
}

function ElmPos(o) {
	this.x = 0;
	this.y = 0;
	if (o.offsetParent) {
		while (o.offsetParent) {
			this.x += o.offsetLeft
			this.y += o.offsetTop
			o = o.offsetParent;
		}
	}
	else if (o.x || o.y) {
		this.x += o.x;
		this.y += o.y;
	}
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function getTarget(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function MousePos(e) {
	// uitbouwen voor mouse relatief tot obj 
	this.x = 0;
	this.y = 0;
	if (e.pageX || e.pageY)
	{
		this.x = e.pageX;
		this.y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		this.x = e.clientX + document.body.scrollLeft;
		this.y = e.clientY + document.body.scrollTop;
	}
}
/*
function hitTest(obj1, obj2) {
	// check if 2 divs intersect
	var x1 = findPosX(obj1);
	var y1 = findPosY(obj1);
	var x2 = findPosX(obj2);
	var y2 = findPosY(obj2);
	var x = Math.max(x1, x2) < Math.min(x1+obj1.offsetWidth, x2+obj2.offsetWidth);
	var y = Math.max(y1, y2) < Math.min(y1+obj1.offsetHeight, y2+obj2.offsetHeight);
	if(x && y) return true;
}

function mousehitTestO(e, o) {
	var mouse = new MousePos(e);
	var oPos = new ElmPos(o);
	return (mouse.x >= oPos.x) && (mouse.x <= oPos.x + o.offsetWidth) && (mouse.y >= oPos.y) && (mouse.y <= oPos.y + o.offsetHeight);	
}
*/

function mousehitTest(e, x, y, w, h) {
	var mouse = new MousePos(e);
	return (mouse.x >= x) && (mouse.x <= w) && (mouse.y >= y) && (mouse.y <= h);	
}

function getPageWidth() {
	if (self.innerWidth) return self.innerWidth;
	if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	if (document.body) return document.body.clientWidth;
}
function getPageHeight() {
	if (self.innerHeight) return self.innerHeight;
	if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight;
}

function getScrollTop(t) {
	if(t.innerHeight) return t.window.pageYOffset;
	else if (t.document.documentElement && t.document.documentElement.scrollTop) return t.document.documentElement.scrollTop;
	else if (t.document.body) return t.document.body.scrollTop;
	else return false;
}

function getScrollLeft(t) {
	if(t.innerHeight) return t.window.pageXOffset;
	else if (t.document.documentElement && t.document.documentElement.scrollLeft) return t.document.documentElement.scrollLeft;
	else if (t.document.body) return t.document.body.scrollLeft;
	else return false;
}

