var IE = document.all?true:false

function GetHttpRequest() { // Functie die http_request vult met een XmlHttp object, geeft false terug als er een fout optreedt.
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	return http_request
}

function updateRating(id,rating) {
	var http_request = GetHttpRequest();
	if(!http_request) return false; // Kan geen ajax component aanmaken.

	var url = ""
	url = "xml/updateRating.xml.asp?id=" + id + "&rating=" + rating
	
	//window.open(url)
	http_request.onreadystatechange = function() {updateRatingResult(http_request);};
	http_request.open('GET', url, true);
	http_request.send(null);
}

function updateRatingResult(http_request){
	if (http_request.readyState == 4)	{
		if (http_request.status == 200) {
			//als node te lang is wordt deze afgebroken door Mozilla
			if(!IE) http_request.responseXML.normalize() 

			//haal xml op
			var xmldoc = http_request.responseXML;
			//vraag container node op
			var container_node = xmldoc.getElementsByTagName('container').item(0);
			//vraag content node op
			var content_node = xmldoc.getElementsByTagName('content').item(0);

			//als content node bestaat
			if(content_node.firstChild){
				if(!IE){ //als geen IE
					document.getElementById(container_node.firstChild.data).innerHTML = xmldoc.getElementsByTagName("content")[0].textContent
				}else{ //als wel IE
					document.getElementById(container_node.firstChild.data).innerHTML = content_node.firstChild.data
				}
			}
		}	
	}
}
