var connection = Array();
var live_site = '';

function AJAXConnection () {
	
	var xmlHttp;

	try {
		
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		
		return xmlHttp;
	}
	catch (e) {
		
		try {
			
			// Oude Internet Explorer
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			
			return xmlHttp;
		}
		catch (e) {

			try {
				
				// Nieuwe Internet Explorer
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			}
			catch (e) {
				
				// Er is geen AJAX mogelijk voor deze browser
				return false;
			}
		}
	}
}


function requestPage(method, dataMode, scriptName, divObj, values) {
	
	if (typeof method == "undefined")
		var method = 'POST';
	
	if (typeof dataMode == "undefined")
		var dataMode = 'text';
	
	if (typeof scriptName == "undefined")
		var scriptName = '';
	
	if (typeof divObj == "undefined")
		var divObj = false;
	
	if (typeof values == "undefined")
		var values = null;
	
	if (method != 'POST' && method != 'GET')
		alert('Method mag alleen "POST" of "GET" zijn.');
	
	if (dataMode != 'text' && dataMode != 'xml')
		alert('dataMode mag alleen "text" of "xml" zijn.');
	
	var strLen = String(scriptName).length;
	
	if (!scriptName || String(scriptName).substring(strLen, strLen - 4) != '.php')
		alert('scriptName moet ingevuld en een PHP bestand zijn.');
	
	if (!divObj)
		alert('Je hebt geen divObj opgegeven');
	
	var getValues = '';
	var postValues = '';
	
	if (method == 'GET' && values != null)
		getValues = '?' + values;
	else if (method == 'POST' && values != null)
		postValues = '' + values;
	
	
	if (!live_site)
		var live_site = '';
	
	// Random offset voor de connection maken
	var random = Math.random();
	random = random * 10000;
	random = Math.ceil(random);
	
	// XMLHTTP object inladen
	connection[random] = AJAXConnection();
	
	// Functie aanroepen zodra de status veranderd
	connection[random].onreadystatechange = function() {
		
		// Is de status positief, ga dan hier verder
		if (connection[random].readyState == 4) {
			
			// Output van script verkrijgen
			var output = connection[random].responseText;
			
			// Output in div zetten
			document.getElementById(divObj).innerHTML = output;
			
			// Stop de onreadystatechange call
			return false;
		}
	}
	
	// Open script
	connection[random].open(method, live_site + scriptName + getValues, true);
	
	connection[random].setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	
	connection[random].send(postValues);
}

