function handleResponse() {

  if (req.readyState == 4) {

    // Split the comma delimited response into an array
	
	//alert('here');

    results = req.responseText.split("|");
	elementID = results[0];
	
	//alert(results[0]);
	
	if (elementID == 'alert'){
		alert( results[1]);}
	else{
		if (elementID == 'reload'){
			window.location = results[1];}
		else{
    		document.getElementById(elementID).innerHTML = results[1];
		}
	}

  }

}


function loadCommentaar(commentaar_id, resultbox){
	req.open('get', 'load_commentaar.php?commentaar_id=' + commentaar_id + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function checkRegistration(field, mode, resultbox){
	req.open('get', 'check_registration.php?field=' + field + '&mode=' + mode + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}


function modifyCommentaar(commentaar_id, mode, resultbox){
	if(mode != 'remove' || confirm("Weet u zeker dat u dit commentaar wilt verwijderen ?")){
		req.open('get', 'modify_commentaar.php?commentaar_id=' + commentaar_id + '&mode=' + mode + '&resultbox=' + resultbox);
		req.onreadystatechange = handleResponse;
		req.send(null);
}
}


function modifyFriends(mod_user_id, mod_user_name, mode, icon, resultbox) {
	if(mode != 'delete' || confirm("Weet u zeker dat u '"+ mod_user_name + "' uit uw vriendenlijst wilt verwijderen ?")){
		req.open('get', 'modify_friends.php?mod_user_id=' + mod_user_id + '&mod_username=' + mod_user_name + '&mode=' + mode + '&icon=' + icon + '&resultbox=' + resultbox);
		req.onreadystatechange = handleResponse;
		req.send(null);
	}
}

function modifyIgnoreList(mod_user_id, mode, resultbox) {
	if(mode == 'add'){
	if(confirm('ALLE COMMENTAREN VAN DEZE PERSOON BIJ JOUW FOTO\'S\nEN ALLE COMMENTAREN VAN JOU BIJ DEZE PERSOON ZULLEN VERWIJDERD WORDEN!!\nWeet je zeker dat je dit wilt doen?'))
	{
		req.open('get', 'modify_ignore_list.php?mod_user_id=' + mod_user_id + '&mode=' + mode + '&resultbox=' + resultbox);
		req.onreadystatechange = handleResponse;
		req.send(null);
	}
	else{alert('Niets verwijderd');}
	}
	else{
		req.open('get', 'modify_ignore_list.php?mod_user_id=' + mod_user_id + '&mode=' + mode + '&resultbox=' + resultbox);
		req.onreadystatechange = handleResponse;
		req.send(null);
	}
}

function login(username, password, resultbox, cookie) {
	req.open('get', 'ajax_login.php?username=' + username +'&password=' + password + '&resultbox=' + resultbox + '&cookie=' + cookie);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function modifyWatch(foto_id, mode, resultbox) {
	req.open('get', 'modify_watch.php?foto_id=' + foto_id + '&mode=' + mode + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function modifyFvdw(foto_id, mode, resultbox) {
	req.open('get', 'modify_fvdw.php?foto_id=' + foto_id + '&mode=' + mode + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function modifyMod(type, target_id, mode, resultbox) {
	req.open('get', 'modify_mod.php?type=' + type + '&target_id=' + target_id + '&mode=' + mode + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function modifyEquipment(equipment_id, equipment_name, mode, resultbox) {
	if(mode != 'remove' | confirm("Weet u zeker dat u de '"+ equipment_name + "' uit uw profiel wilt verwijderen ?")){
		req.open('get', 'modify_equipment.php?equipment_id=' + equipment_id + '&mode=' + mode + '&resultbox=' + resultbox);
		req.onreadystatechange = handleResponse;
		req.send(null);
	}
}

function modifySelection(selection_id, resultbox) {
	req.open('get', 'modify_selection.php?selection_id=' + selection_id + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function requestOverschrijving(resultbox) {
	req.open('get', 'sendTransferMail.php?resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function modifyFocus(group_id, mode, resultbox) {
	req.open('get', 'modify_focus.php?group_id=' + group_id + '&mode=' + mode + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function getTransactions(user_id, resultbox) {
	req.open('get', 'get_transactions.php?user_id=' + user_id + '&resultbox=' + resultbox);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function getCost() {
	var group_id = $('input[name=lidmaatschap_type]:checked').val();
	var extra_id = [];
	$('input:checkbox:checked').each(function() {
     extra_id.push(this.value);});

	var extra = $.toJSON(extra_id);
	var period = $('#lidmaatschap_period').val();
	req.open('get', 'get_cost.php?group_id=' + group_id + '&extra=' + extra + '&period=' + period + '&resultbox=total_cost');
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }
  
  return xmlhttp;


}

var req = getHTTPObject(); // We create the HTTP Object