// JavaScript Document

// variabelen 
var proceed = true;
var message = '';
var xmlHttp4Gastenboek;

function createXMLHttpRequest4Gastenboek() {
    if (window.ActiveXObject) {
        xmlHttp4Gastenboek = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp4Gastenboek = new XMLHttpRequest();
    }
}

function confirmGastenboek() {
	document.getElementById("loadingMessage").innerHTML = "Uw gegevens worden verstuurd.";
	//alert ("1_in");
	createXMLHttpRequest4Gastenboek();
    xmlHttp4Gastenboek.onreadystatechange = handleStateChange4Gastenboek;
		
	var naam 		= document.getElementById("naam");	
	var reactie		= document.getElementById("reactie");
	
	naam 			= 	escape(naam.value);
	reactie			=	escape(reactie.value);
	
	
	if ( !naam 		|| ( naam 		== "" ) ) { naam="Anoniem"; }
	if ( !reactie 	|| ( reactie 	== "" ) ) { proceed = false; message = message + 'Reactie ontbreekt\n'; }
	
	var _totalString  = "&submit=Reageren&naam="+naam+"&reactie="+reactie;
	
	//alert (_totalString);
	//alert (proceed);
	
	if ( proceed == true ) {
		//alert ("in functie waar: " + proceed);
		var url = "http://www.musicavocale.nl/content/pageGasten.php?" + _totalString ; 
		xmlHttp4Gastenboek.open("POST", url, true);
		xmlHttp4Gastenboek.send(null);
	}  
	
	if (proceed == false) {				
		//alert ("in functie false: " + proceed);
		proceed = true ;
		//alert ("1_vals");
		document.getElementById("loadingMessage").innerHTML = message;
		message = '';
		return;
	}
}

function handleStateChange4Gastenboek() {
	//alert ("10_in");
	if(xmlHttp4Gastenboek.readyState == 4) {
        if(xmlHttp4Gastenboek.status == 200) {
			//alert ("11_in");
		    document.getElementById("resultsCenter").innerHTML =  xmlHttp4Gastenboek.responseText;
			document.getElementById("loadingMessage").innerHTML = "";
			return;
        }
    }
}