function create_http_object()
{
	var ActiveXTypes = [
		"Microsoft.XMLHTTP",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP"
	];

	for( var i = 0; i < ActiveXTypes.length; i++ )
	{
		try
		{
			return new ActiveXObject( ActiveXTypes[i] );
		}
		catch( e )
		{ }
	}

	try
	{
		return new XMLHttpRequest();
	}
	catch( e )
	{ }

	return false;
}

function make_request(url, callback_function, extra, total, http_method, post_values, return_xml)
{
	http = create_http_object();

	if(!http)
	{
		alert('Could not create XMLHTTP Object');
		return false;
	}

	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
		{
			if(http.status == 200)
			{
				if(callback_function)
				{
					if(return_xml)
					{
						eval(callback_function + '(http.responseXML)');
					}
					else
					{
						eval(callback_function + '(http.responseText, extra, total)');
					}
				}
			}
			else
			{
				alert('Error! (' + http.status + ')');
			}
		}
	}

	if(!post_values)
	{
		post_values = null;
	}
	if(!http_method)
	{
		http_method = "GET";
	}

	http.open(http_method, url, true);

	if(http_method == "POST")
	{
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}

	http.send(post_values);
}

function rate(id, rating, total)
{
	make_request('gedicht_rate.php?id=' + id + '&rating=' + rating, 'rate_handle_response', rating, total, 'GET', null, false);
	// alert(id + 'gedicht,' + rating);
}

function favorite(id)
{
	make_request('quiz_favoriet.php?id=' +id, 'fav_handle_response', id, id, 'GET', null, false);
}

function rate_handle_response(response, rating, total)
{		
	if(response == 'Bedankt voor je stem!')
	{

		element = document.getElementById("current_rating");
		val = rating * 16 + "px";
		element.style.width = val;

		nieuw = total + 1;

		if(nieuw == 1)
		{
			document.getElementById("total").innerHTML = "&nbsp; Rating (1 stem)";
		}
		else
		{
			document.getElementById("total").innerHTML = "&nbsp; Rating (' + nieuw + ' stemmen)";
		}

        	document.getElementById('response').innerHTML = '<b>' + response + ' | </b>'; 

	} 
	else 
	{	
        	document.getElementById('response').innerHTML = '<b>' + response + ' | </b>';	
	}
}

function fav_handle_response(response, id, total)
{

	element = document.getElementById("quiz_favoriet_" + id);

	if(response == 'Favoriet is toegevoegd.')
	{
		element.className = 'verwijder-icon';
		element.innerHTML = 'Verwijderen';
	}

	if(response == 'Favoriet is verwijderd.')
	{
		element.className = 'toevoegen-icon';
		element.innerHTML = 'Toevoegen';
	}

        alert(response); 
}

function navigate(id, page)
{
	alert(id);
}