function xmlhttp_supported(){
	try{
		tmp=new XMLHttpRequest();
		//if no error is caught, we need not submit the form and leave it to javascript to handle all. 
		return true;
	} catch(e){
		//something went wrong.. fall back to 'normal' page requests.]
		return false;
	}
}

var xmlhttp;
var delete_id;
function cancel_optie(id){
	if(!xmlhttp_supported()){
		return true;
	}
	
// code for Mozilla, etc.
	try{
		delete_id = id;
		if (window.XMLHttpRequest)
		{
		  xmlhttp=new XMLHttpRequest();
		  xmlhttp.onreadystatechange=deleteRequest;
		  xmlhttp.open("GET",'delete.php?id='+id,true);	  
		  xmlhttp.send();
		}
	// code for IE
		else if (window.ActiveXObject)
		{
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  if (xmlhttp)
		  {
			xmlhttp.onreadystatechange=deleteRequest;
			xmlhttp.open("GET",'delete.php?id='+id,true);
			xmlhttp.send();
		  }
		}
	} catch(e) {
		window.location = 'delete.php?id='+id+'&redirect=1';
	}
	
	return false;
}

function deleteRequest(){
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
	  document.getElementById('row_'+delete_id).style.display = 'none';
    }
  else
    {
      alert('Er is een probleem opgetreden bij het raadplegen van de server.');
    }
  }	
}

function bereken_kosten(){
	if(!xmlhttp_supported()){
		return true;
	}
		
	var hours = document.getElementById('hours').value;
	var days = document.getElementById('days').value;
	var persons = document.getElementById('persons').value;
	
	
	// code for Mozilla, etc.
	
	if (window.XMLHttpRequest)
	{
	  xmlhttp=new XMLHttpRequest();
	  xmlhttp.onreadystatechange=showRequest;
	  xmlhttp.open("GET",'kosten.php?hours='+hours+'&days='+days+'&persons='+persons,true);	  
	  xmlhttp.send();
	}
// code for IE
	else if (window.ActiveXObject)
	{
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  if (xmlhttp)
	  {
		xmlhttp.onreadystatechange=showRequest;
		xmlhttp.open("GET",'kosten.php?hours='+hours+'&days='+days+'&persons='+persons,true);
		xmlhttp.send();
	  }
	}
	return false;
}

function showRequest(){
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
	  document.getElementById('KOSTEN_RESULT').innerHTML = xmlhttp.responseText;
    }
  else
    {
      document.getElementById('KOSTEN_RESULT').innerHTML = '<h1>Oeps!</h1><p>Er ging iets mis. Probeer het later nog een keer.</p>';
    }
  }	
}

function load_group(){
	if(!xmlhttp_supported()){
		document.getElementById('PERSONAL_SELECT_GROEP').innerHTML = '<p>Uw veiligheidsinstellingen staan te hoog om gebruik te maken van deze (niet essentiele en daardoor niet volledig ondersteunde) optie.</p>';
	}
	
	
	var group = document.PERSONAL_SELECT.PERSONAL_SELECT_OPTION.options[document.PERSONAL_SELECT.PERSONAL_SELECT_OPTION.selectedIndex].value;
	
	if (window.XMLHttpRequest)
	{
	  xmlhttp=new XMLHttpRequest();
	  xmlhttp.onreadystatechange = updateReservations;
	  xmlhttp.open("GET",'reservering_group.php?group='+group,true);	  
	  xmlhttp.send();
	}
// code for IE
	else if (window.ActiveXObject)
	{
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  if (xmlhttp)
	  {
		xmlhttp.onreadystatechange = updateReservations;
		xmlhttp.open("GET",'reservering_group.php?group='+group,true);	  
		xmlhttp.send();
	  }
	}
}

function updateReservations(){
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
	  document.getElementById('PERSONAL_SELECT_GROEP').innerHTML = xmlhttp.responseText;
    }
  else
    {
      document.getElementById('PERSONAL_SELECT_GROEP').innerHTML = '<h3>Oeps!</h3><p>Er ging iets mis. Probeer het later nog een keer.</p>';
    }
  }	
}