	function checkEmail(email) {
		var filter = /^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/;
		if ( !filter.test(email) ) {
			return false;
		} else {
			return true;
		}
	}

	var xmlHttp;

	function createXMLHttpRequest() {
		if ( window.ActiveXObject ) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else if ( window.XMLHttpRequest ) {
			xmlHttp = new XMLHttpRequest();
		}
	}

	function fn_select_gemeente(gemeenteID, status) {
		createXMLHttpRequest();

		params = "gemeenteID=" + gemeenteID + "&status=" + status;

		xmlHttp.open("POST","/ajax/ajax-check-gemeente.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				var brokenstring = xmlHttp.responseText.split("@@@");
				document.getElementById("area").innerHTML = brokenstring[0];
				document.getElementById("frm_badsteden").value = brokenstring[1];
			}
		}
		xmlHttp.send(params);
	}

	function fn_show_pic(path, picName) {
		createXMLHttpRequest();

		params = "path=" + path + "&pic=" + picName;

		xmlHttp.open("POST","/ajax/ajax-detail-change-picture.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				document.getElementById("detail-img").innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(params);
	}

	function fn_subscribe_newsletter(error) {
		createXMLHttpRequest();

		var get_email = document.getElementById("newsletter_email").value;
		
		if ( get_email == 'Uw e-mailadres' ) { get_email = ''; }

		if ( checkEmail(get_email) ) {
			params = "address=" + get_email;
	
			xmlHttp.open("POST","/ajax/ajax-subscribe-newsletter.php", true);
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
			xmlHttp.onreadystatechange = function() {
				if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
					document.getElementById("newsletterDIV").innerHTML = xmlHttp.responseText;
				}
			}
			xmlHttp.send(params);
		} else {
			alert(error);
		}
	}

	function tell_a_friend_detail(error, error2) {
		createXMLHttpRequest();

		var get_naam = document.getElementById("source_naam").value;
		var get_target = document.getElementById("target_email").value;
		var get_appID = document.getElementById("taf_appID").value;
		var get_appname = document.getElementById("taf_app_name").value;

		if ( get_naam == 'Uw naam' ) { get_naam = ''; }
		if ( get_target == 'E-mail van uw vriend' ) { get_target = ''; }
		if ( get_naam == 'Votre nom' ) { get_naam = ''; }
		if ( get_target == 'E-mail de votre ami' ) { get_target = ''; }

		if ( get_appname == '' ) {
			if ( get_naam != '' && get_target != '' ) {
				if ( !checkEmail(get_target) ) {
					alert(error2);
				} else {
					params = "naam=" + get_naam + "&target=" + get_target + "&appID=" + get_appID;
	
					xmlHttp.open("POST","/ajax/ajax-tell-a-friend.php", true);
					xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
					xmlHttp.onreadystatechange = function() {
						if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
							document.getElementById("tellafriendDIV").innerHTML = xmlHttp.responseText;
						}
					}
					xmlHttp.send(params);
				}
			} else {
				alert(error);
			}
		}
	}

	//DELETE STUFF
	function fn_delete(what, ID) {
		createXMLHttpRequest();

		params = "what=" + what + "&ID=" + ID;

		xmlHttp.open("POST","ajax/ajax-delete.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				document.getElementById('fotoDIV').innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(params);
	}

	//CHANGE PLACE STUFF
	function fn_change_place(what, jquery_string) {
		createXMLHttpRequest();
		
		//REPLACE & BY @ - OTHERWISE IT WON'T GO THROUGH
		var jquery = jquery_string.replace(/&/g,'@');
		params = "what=" + what + "&jquery=" + jquery;

		xmlHttp.open("POST","ajax/ajax-change-place.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				//document.getElementById("subcontent").innerHTML = xmlHttp.responseText;

				//MAKE SURE SORTING WORKS AGAIN AFTER AJAX CALL
				bind();
			}
		}
		xmlHttp.send(params);
	}

	function fn_move_month_new(move, app) {
		createXMLHttpRequest();
	
		params = "move=" + move + "&app=" + app;
	
		xmlHttp.open("POST","ajax/ajax-move-calendar.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				document.getElementById('calendar_space').innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(params);
	}
	
	function fn_delete_verhuurperiode(appID, start, stop) {
		createXMLHttpRequest();
	
		params = "app=" + appID + "&start=" + start + "&stop=" + stop;
	
		xmlHttp.open("POST","ajax/ajax-delete-verhuurperiode.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				window.location = '/aanpassen/' + appID + '/kalender/';
			}
		}
		xmlHttp.send(params);	
	}

	function fn_add_favo(appID) {
		createXMLHttpRequest();
	
		params = "app=" + appID;

		xmlHttp.open("POST","ajax/ajax-add-favo.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		xmlHttp.onreadystatechange = function() {
			if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
				document.getElementById('favoDIV').innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(params);	
	}
