function createXMLHttpRequest()
{
	if(window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if(window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else
	{
		alert('Uw browser ondersteund geen AJAX.');
		return null;
	}
}

function fn_send_mail(brochure)
{
	xmlHttp = createXMLHttpRequest();
	
	var postvars = 'ajaxrequest=1&company=' + encodeURI(document.getElementById('company').value) + '&contact=' + encodeURI(document.getElementById('contact').value) + '&email=' + encodeURI(document.getElementById('email').value) + '&phone=' + encodeURI(document.getElementById('phone').value) + '&question=' + encodeURI(document.getElementById('question').value);
	
	if(brochure == 1)
	{
		postvars += '&brochure=1';
	}
	
	function handleStateChange() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				if(xmlHttp.responseText == '1'){
					document.getElementById('contactform').innerHTML = '<p>De e-mail is verstuurd.<br /><br />Onze medewerkers zullen u zo spoedig mogelijk terugmailen.</p>';
				}else{
					alert(xmlHttp.responseText);
				}
			}
		}
	}

	xmlHttp.onreadystatechange = handleStateChange
	xmlHttp.open('POST', '../contact_ajax.php', true);
	xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader("Content-length", postvars.length);
	xmlHttp.setRequestHeader("Connection", "close");    
	xmlHttp.send(postvars);
}
