
function createBox()
{
	oDiv = document.getElementById('shoutboxcontainer');
	
	 while (oDiv.childNodes[0])
	 {
	    oDiv.removeChild(oDiv.childNodes[0]);
	 }
	  
	doAjax('GET', 'shoutbox.php?action=get', null, function(a,b)
	{
		var response = eval(a);	

		var oDiv = document.getElementById('shoutboxcontainer');
		
		oDivBar = document.createElement('div');
		oDivBar.className = 'shoutboxhoofd';
		oBr = document.createElement('br');
		
	
		//var i = response.length;
		var j = response.length;
		
		for(i=0; i<j; i++)
		//for(i>0; i--;)
		{
			oDivBarTijd = document.createElement('div');
			oDivBarTijd.className = 'shoutboxbar';
			oDivBarTijd.innerHTML = response[i]['sho_tijd'];
			
			oDivBarDatum = document.createElement('div');
			oDivBarDatum.className = 'shoutboxbar';
			oDivBarDatum.innerHTML = response[i]['sho_datum'];
			
			oDivBarNaam = document.createElement('div');
			oDivBarNaam.className = 'shoutboxbar';
			oDivBarNaam.innerHTML = '<a class="normallink" href="?page=medewerker&amp;action=show&amp;id='+response[i]['med_id']+'">'+response[i]['med_naam']+'</a>';
			
			oDivBericht = document.createElement('div');
			oDivBericht.className = 'shoutboxbarnaam';
			oDivBericht.innerHTML = response[i]['sho_bericht'];
			
			oDivSpan = document.createElement('div');
			oDivSpan.innerHTML = '&nbsp;';
			
			oDivBar.appendChild(oDivBarTijd);
			oDivBar.appendChild(oDivBarDatum);
			oDivBar.appendChild(oDivBarNaam);
			
			oDivBar.appendChild(oDivSpan);
			
			oDivBar.appendChild(oDivBericht);
			
			oDivBar.appendChild(oDivSpan);
			
			
			oDiv.appendChild(oDivBar);
			
		}
		
			
		}, null);
	
}

function doAjax(action, target, paramaters, callback, args)
{
		
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
	xmlHttp.open(action, target, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(paramaters);
	xmlHttp.onreadystatechange = function (){
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				callback(xmlHttp.responseText, args);
			}
		}
	};
}


function newShout()
{
	var text = document.getElementById('shouttext');
	if(text.value.length == 0 )
	{
		alert('Veld mag niet leeg zijn.');
	}
	else
	{
		
		doAjax('POST', 'shoutbox.php', 'action=insert&text=' + text.value, function(a,b){
			if(a == 1)
			{
				text.value = "";
				createBox();
				//msg bericht geplaatst
				//tabel opbouwen
			}
			else
			{
				//msg niet geplaatst
			}
		}, null);
		
		
	}

}


