function getAjaxRequest()
{
	var ajaxRequest;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Error
				alert("Uw browser ondersteund geen AJAX! Gelieve uw browser te updaten naar een meer recente versie.");
				return false;
			}
		}
	}
	
	return ajaxRequest;
}

function stripslashes(str){
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}

function getRadioCheckedValue(name) {
	var x = document.getElementsByTagName("input");
	
	for(i=0; i < x.length; i++){
		if(x[i].name == name){
			if (x[i].type == "radio" && x[i].checked){
				return x[i].value;
			}
		}
	}   
}

function sendmail()
{
	var ajaxRequest = getAjaxRequest();
	
	var type 				= document.getElementById("type").value.toUpperCase();
	var email 				= document.getElementById("txtEmail").value;
	var name 				= document.getElementById("txtNaam").value;
	var tel					= document.getElementById("txtTelefoon").value;
	
	var message 			= "";
	var bedrijf 			= "";
	var doel				= "";
	var taalNL				= "";
	var taalFR				= "";
	var taalEN				= "";
	var taalDE				= "";
	var talen				= "";
	var hosting				= "";
	var cms					= "";
	var logo				= "";
	
	if(type === "CONTACT")
	{
		var message 			= document.getElementById("txtBericht").value;
	}
	
	if(type === "OFFERTE")
	{
		var bedrijf 	= document.getElementById("txtBedrijf").value;
		var doel	 	= document.getElementById("txtDoelgroep").value;
		var taalNL 		= document.getElementById("chbTaalNL").value;
		var taalFR 		= document.getElementById("chbTaalFR").value;
		var taalEN 		= document.getElementById("chbTaalEN").value;
		var taalDE 		= document.getElementById("chbTaalDE").value;
		var hosting		= getRadioCheckedValue('rdHosting');
		var cms			= getRadioCheckedValue('rdCMS');
		var logo		= getRadioCheckedValue('rdLogoHuisstijl');
		
		var talen 		= taalNL + " - " + taalFR + " - " + taalEN + " - " + taalDE;
	}
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4){
			var myString = new String(ajaxRequest.responseText); 
			var validation = document.getElementById("validation");
			myString = stripslashes(myString);
			validation.innerHTML = myString;
			window.scrollTo(0,0);
		}
	}
	
	ajaxRequest.open("GET", "http://www.eralution.be/new/php/sendmail.php?type="+type+"&email="+email+"&name="+name+"&message="+message+"&bedrijf="+bedrijf+"&doel="+doel+"&phone="+tel+"&talen="+talen+"&hosting="+hosting+"&cms="+cms+"&logo="+logo, true);
	ajaxRequest.send(null);
}

function getRssFeed()
{
	var ajaxRequest = getAjaxRequest();
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4){
			var myString = new String(ajaxRequest.responseText); 
			var rss = document.getElementById("rssnews");
			myString = stripslashes(myString);
			rss.innerHTML = myString;
		}
	}
	
	ajaxRequest.open("GET", "php/rss.php", true);
	ajaxRequest.send(null);
}
