
//deze functie moet aangeroepen worden
//pre:		url van aan te roepen pagina, object wat verzonden moet worden (form)
//post: 	class aanroep met XMLHTTPRequest
function makeRequest(url,object) {
	xhr = new XHR(url,object);
}

//Constructor
function XHR(url,object) {
	var http_request = null;
	this._load(url,object);
}

XHR.prototype._load = function(url,object) {
	var _this = this;
	
	if (window.XMLHttpRequest) {
		this.http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
		
	this.http_request.onreadystatechange = function(){_this.getRequest()};
	this.http_request.open("POST", url,true);
	this.http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	if (document.getElementById('textarea_url')) document.getElementById('textarea_url').value += url + "\n\n" + ((object!=false)?get(document.getElementById(object)):'');
	this.http_request.send('xml=<root>' + ((object!=false)?get(document.getElementById(object)):'') +  '</root>');
}

XHR.prototype.getRequest = function() {
	if (this.http_request!=null) {
		if (this.http_request.readyState==4) {
			if (document.getElementById('textarea_code')) document.getElementById('textarea_code').value = this.http_request.responseText;
			try {
				var output = this.http_request.responseXML.documentElement;
				process(output);
			} catch(e) {
				alert('niet goed');
			}
		}
	}
}


function process(output) {
	var node, childNode;
	
	if (output!=null && output.hasChildNodes() && output.childNodes!=null) {
		for(var i = 0;i < output.childNodes.length; i++) {
			this.node = output.childNodes[i];
			if (this.node.nodeType!=3 && this.node.hasChildNodes()) {
				eval(this.node.nodeName + "();");
			}
		}
	}
}

function showhide(object,display) {
	var html_target;
	var childNode;
	if (!object && !display) {
		for(var i = 0; i < this.node.childNodes.length; i++) {
			if (this.node.childNodes[i].nodeType!=3) {
				childNode = this.node.childNodes[i];
				html_target = document.getElementById(this.node.childNodes[i].nodeName);
				html_target.style.display = (childNode.firstChild.nodeValue=="hide" || childNode.firstChild.nodeValue=="0" || childNode.firstChild.nodeValue=="false") ? "none" : "block";
			}
		}
	} else {
		html_target = document.getElementById(object);
		html_target.style.display = (display=="hide" || display=="0" || display=="false") ? "none" : "block";
	}
}

function add() {
	var target = getNode("target");
	var html_target;
	var elements;
	if (target && target.hasChildNodes()) {
		html_target = document.getElementById(target.firstChild.nodeValue);
		
		if (html_target!=null && html_target!="undefined") {
			for(var i = 0; i < this.node.childNodes.length; i++) {
				if (this.node.childNodes[i].nodeType!=3 && this.node.childNodes[i].nodeName!="target") {
					addElements(this.node.childNodes[i],html_target);
				}
			}
		}		
	} //else foutmelding geven
}


function fill() {
	var target = getNode("target");
	var html_target;
	var childNode;
	
	if (target!=false && target.firstChild) {
		eval("html_target = document." + target.firstChild.nodeValue);
		if (html_target!=null && html_target!="undefined") {
			
			for(var i = 0; i < this.node.childNodes.length; i++) {
				childNode = node.childNodes[i];
				if (childNode.nodeName=="action") html_target.action = childNode.firstChild.nodeValue;
				else {
					eval("if (form." + childNode.nodeName + "!=null) form." + childNode.nodeName + ".value = (childNode.hasChildNodes()) ? childNode.firstChild.nodeValue : ''");
				}
			}
		}
	}
}

function remove_all() {
	if (this.node.firstChild && document.getElementById(this.node.firstChild.nodeValue)!=null) {
		var element = document.getElementById(this.node.firstChild.nodeValue);
		var aantal = element.childNodes.length-1;
		while(aantal>=0) element.removeChild(element.childNodes[aantal--]);
	} //else
		//alert("kan " + node.firstChild.nodeValue + " niet vinden.");								
}

function remove() {
	if (this.node.firstChild && document.getElementById(this.node.firstChild.nodeValue)!=null) {
		document.getElementById(this.node.firstChild.nodeValue).parentNode.removeChild(document.getElementById(this.node.firstChild.nodeValue));
	} //else
		//alert("kan " + node.firstChild.nodeValue + " niet vinden.");								
}

/*function showhide(obj,hide) {
	if (el = document.getElementById(obj)) {
		el.style.display = (hide=="hide" || hide=="0" || hide=="false") ? "none" : "block";
	}
}*/


function javascript() {
	eval(this.node.firstChild.nodeValue);
}

function getNode(name) {
	if (this!=null && this.node!=null) {
		for(var i = 0; i< this.node.childNodes.length; i++) {
			if (name==this.node.childNodes[i].nodeName) return this.node.childNodes[i];
		}
	}
	return false;
}






//extra functies
function addElements(node,target) {
	switch(node.nodeName.toLowerCase()) {
		case "html":
		case "head":
		case "body":
		case "title":
		case "script":
		case "object":
		case "em":
		case "strong":
		case "q":
		case "cite":
		case "dfn":
		case "abbr":
		case "acronym":
		case "code":
		case "var":
		case "kbd":
		case "samp":
		case "sub":
		case "sup":
		case "del":
		case "ins":
		case "isindex":
		case "a":
		case "br":
		case "map":
		case "area":
		case "param":
		case "embed":
		case "noembed":
		case "applet":
		case "span":
		case "p":
		case "blockquote":
		case "h1":
		case "h2":
		case "h3":
		case "h4":
		case "h5":
		case "h6":
		case "dl":
		case "dt":
		case "dd":
		case "ol":
		case "ul":
		case "li":
		case "dir":
		case "menu":
		case "table":
		case "tr":
		case "th":
		case "td":
		case "colgroup":
		case "caption":
		case "thead":
		case "tbody":
		case "tfoot":
		case "button":
		case "form":
		case "input":
		case "select":
		case "option":
		case "div":
		case "pre":
		case "address":
		case "iframe":
		case "frameset":
		case "frame":
		case "noframes":
		case "big":
		case "small":
		case "tt":
		case "img":
			var element = document.createElement(node.nodeName);
			if (node.hasChildNodes()) {
				for(var e = 0; e < node.childNodes.length; e++) {
					addElements(node.childNodes[e], element);
				}
			}
			target.appendChild(element);
		break;
		
		case "checkbox":
			BrowserDetect.init();
			if (BrowserDetect.browser=="Explorer") {
				var element=document.createElement("<input type='checkbox'>");
			} else {
				var element = document.createElement("input");
			}
			target.appendChild(element);
			if (node.hasChildNodes()) {
				for(var e = 0; e < node.childNodes.length; e++) {
					addElements(node.childNodes[e], element);
				}
			}
		break;
				
		case "onblur":
		case "onchange":
		case "onclick":
		case "ondblclick": 
		case "onfocus":
		case "onkeydown":
		case "onkeypress": 
		case "onkeyup":
		case "onmousedown":
		case "onmousemove":
		case "onmouseout":
		case "onmouseover": 
		case "onmouseup":
		case "onresize":
		case "onscroll":
			BrowserDetect.init();
			if (BrowserDetect.browser=="Explorer") {
				eval('target.' + node.nodeName + ' = function() { ' + node.firstChild.nodeValue + ' } ');
			} else {
				setAttribute(target,node.nodeName,(node.hasChildNodes())?node.firstChild.nodeValue:'',BrowserDetect.browser);
			}
		break;
		
		case "txt":
			//ce = obj.first;
			var element = document.createTextNode('');
			element.data = (node.firstChild) ? node.firstChild.nodeValue : '';
			target.appendChild(element);
		break;
		default:
			BrowserDetect.init();
			if (node.firstChild) setAttribute(target,node.nodeName,(node.hasChildNodes())?node.firstChild.nodeValue:'',BrowserDetect.browser);
		break;
		
	}
}

function setAttribute(node,name,value,browser) {
	//IE / FF verschillen... zucht
	switch(name.toLowerCase()) {
		case "classname":
		case "class":
			name = (browser=="Explorer") ? "className" : "class";
		break;
		case "id":
			name = (browser=="Explorer") ? "id" : "id";
		break;
	}
	
	value = (value=="false" || value=="true") ? ((value=="false")?false:true) : value;
	
	if (name.toLowerCase()=="style" && browser=="Explorer") {
		node.style.cssText = value;
	} else {
		node.setAttribute(name,value,0);
	}
}


function get(obj) {
	var getstr = "";
	var i = 0;
	
	if (obj!=false && obj!=null) {
		if (obj.tagName.toUpperCase()!="INPUT" && obj.tagName.toUpperCase()!="TEXTAREA" && obj.tagName.toUpperCase()!="SELECT") {
			if (obj.tagName.toUpperCase()!="FORM") {
				for (i; i<obj.childNodes.length; i++) {
					var oo = obj.childNodes[i];
					if (oo.hasChildNodes() && oo.tagName.toUpperCase()!="TEXTAREA" && oo.tagName.toUpperCase()!="SELECT") {
						getstr += get(oo);
					}
					getstr += get_element(oo);
				}
			} else {
				for (i; i<obj.elements.length; i++) {
					var oo = obj.elements[i];
					getstr += get_element(oo);
				}
			}
		} else {
			getstr += get_element(obj);
		}
		return getstr;
	}
}

function get_element (obj) {
	var getstr = '';
	
	if (obj!=null) {
		switch(obj.tagName) {
			case "TEXTAREA":
			case "INPUT":
				switch(obj.type.toLowerCase()) {
					case "button":
					break;
					case "checkbox":
					   getstr +=  (obj.checked) ? "<"+obj.name + ">" + obj.value + "</" + obj.name + ">" : "";
					break;
					case "radio":
					   if (obj.checked) getstr += "<" + obj.name + ">" + obj.value + "</" + obj.name + ">";
					break;
					case "text":
					case "password":
					default:
					   getstr += "<"+obj.name + ">" + ((obj.value!="undefined")?obj.value:'') + "</" + obj.name + ">";
					break;
					
				}
			break;
			
			case "SELECT":
				if (obj.multiple) {
					for(i = 0;i<obj.options.length;i++) {
						getstr += "<" + obj.name + ">" + obj.options[i].value + "</" + obj.name + ">";	
					}
				} else {
					getstr += "<" + obj.name + ">" + obj.options[obj.selectedIndex].value + "</" + obj.name + ">";	
				}
			break;
		 }
	}
	return getstr;
}

function interrogate(what) {
    var output = '';
	var val;
	var txt;
    for (var i in what) {
		eval('val = what.' + i)
        output += i+ ' - ' + val + '\n';
	}
    txt += "\n\n\n\n\n\n\n\n\n\n-------------" + what + "------------------------------------\n\n\n\n\n\n\n\n" + output;
	alert(txt);
}



var hexChars = "0123456789ABCDEF";
function Dec2Hex (Dec) {
	var a = Dec % 16;
	var b = (Dec - a)/16;
	hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
	return hex;
}

function changbg (begin, end, steps) {   
	steps = steps -1 ;
	redA     = begin.charAt(0) + begin.charAt(1);
	red_valA = parseInt(redA,'16');
	redB     = end.charAt(0) + end.charAt(1);
	red_valB = parseInt(redB,'16');
	red_int  = ((red_valB - red_valA) / steps) * -1;
	grnA     = begin.charAt(2) + begin.charAt(3);
	grn_valA = parseInt(grnA,'16');
	grnB     = end.charAt(2) + end.charAt(3);
	grn_valB = parseInt(grnB,'16');
	grn_int  = ((grn_valB - grn_valA) / steps) * -1;
	bluA     = begin.charAt(4) + begin.charAt(5);
	blu_valA = parseInt(bluA,'16');
	bluB     = end.charAt(4) + end.charAt(5);
	blu_valB = parseInt(bluB,'16');
	blu_int  = ((blu_valB - blu_valA) / steps) * -1;
	red = red_valA;
	grn = grn_valA;
	blu = blu_valA;
	document.bgColor = begin;
	red -= red_int;
	red_round = Math.round(red);
	red_hex = Dec2Hex(red);
	grn -= grn_int;
	grn_round = Math.round(grn);
	grn_hex = Dec2Hex(grn);
	blu -= blu_int;
	blu_round = Math.round(blu);
	blu_hex = Dec2Hex(blu);
	setTimeout("changbg('" + red_hex + grn_hex + blu_hex + "','"+end+"'," + steps + ")",1);
}

























//BrowserDetect.init();
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};




 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

var oc;
function mouse(o,e,c) {
	if (e=="over") {
		oc = o.className;
		o.className = c;
	} else if (e=="out") {
		o.className = oc;
		oc = null;
	}
}

function openWindow(theURL,width,height,scrollbar,windowname) {
  if (!scrollbar) scrollbar = 'no';
  if (!width) width = 500;
  if (!height) height = 600;
  if (!windowname) windowname = 'window'; 
  window.open(theURL,windowname,'status=0,toolbar=0,location=0,menubar=0,resizable=0,scrollbars='+scrollbar+',width='+width+',height='+height);
}


