
// ==== Asynchronous JavaScript and XML :) ===============================

function ajaxFunction(){
  var xmlHttp;
  try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
  } catch(e){
	// Internet Explorer
	try {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e){
	try {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e){
	  alert("Uw browser ondersteund geen AJAX!");
	  return false;
	  }
	}
  }
  return xmlHttp;
}

// ==== AJAX-FUNCTIES VOOR ALUMINIUMFOTO.NL ==========================

$(document).ready(function() {
	
	$('#fancybox').fancybox();

});


function prijsberekenaar(i){
	
	var afm_x = document.getElementById('paneel_'+i+'_afm_x').value;
	var afm_y = document.getElementById('paneel_'+i+'_afm_y').value;
	
	var aantal = document.getElementById('paneel_'+i+'_aantal').value;
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			if(xmlHttp.responseText){
			
				var response = xmlHttp.responseText.split("|");
				
				var fout = response[0];
				var prijs = response[1];
				var verzendkosten = response[2];
				var totaalprijs = response[3];
				
				if(fout){
					
					alert(fout);
					
				} else {
				
					document.getElementById('prijs_paneel_'+i).innerHTML = prijs;
					document.getElementById('verzendkosten').innerHTML = verzendkosten;
					document.getElementById('totaalprijs').innerHTML = totaalprijs;
					
				}

			}

		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=prijsberekenaar&i="+i+"&afm_x="+afm_x+"&afm_y="+afm_y+"&aantal="+aantal, true);
	xmlHttp.send(null);	
	
}

function save_paneel(i, name, value){
	
	if(name == "aantal" && value > 99){
		value = 99;
		$('#paneel_'+i+'_aantal').val('99');
	}
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
				
			if(name == 'aluminium' || name == 'afwerking'){
				
				$('input[rel='+name+'_'+i+']').val('');
				$('#paneel_'+i+'_'+value+'_'+name).val('x');
				
			}

		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=save_paneel&i="+i+"&name="+name+"&value="+value, true);
	xmlHttp.send(null);	
	
}

function remove_paneel(){
	
	if(confirm('Weet u zeker dat u dit paneel wilt verwijderen?')){
	
		var xmlHttp = ajaxFunction();
	
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				
				location.href = location.href;
	
			}
		}
		
		xmlHttp.open("GET", "/ajax.inc.php?action=remove_paneel", true);
		xmlHttp.send(null);	
	}
	
}

function bestellen(id, go_to){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var data = xmlHttp.responseText.split('|');
			
			var melding = data[0];
			var loc = data[1];
			
			if(melding){
				
				alert(melding);

			} else {
				
				location.href = loc;
				
			}

		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=bestellen", true);
	xmlHttp.send(null);
	
}

























function enlarge_afb(url, w, h){
	
	$('div.enlarger').html('<a href="'+url+'" id="fancybox"><img id="inner" style="width:'+w+'px; height:'+h+'px;" src="'+url+'" alt="" /></a>');

	$('#fancybox').fancybox();

}

function zoekactie(e, location, keyword, herkomst){
	var characterCode
	var keyword = keyword.replace(" ", "+");

	if(e && e.which){
		e = e
		characterCode = e.which
	} else{
		e = event
		characterCode = e.keyCode
	}

	if(characterCode == 13){ // ascii 13 = enter key

		var xmlHttp = ajaxFunction();
	
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {

				document.location.href = location+keyword;

			}
		}
		
		xmlHttp.open("GET", "/ajax.inc.php?action=save_zoekactie&keyword="+keyword+"&herkomst="+herkomst, true);
		xmlHttp.send(null);

		return false 
	} else{
		return true 
	}

}

function on_wishlist(product_id, actie){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			if(xmlHttp.responseText){
			
				alert( xmlHttp.responseText );
				
				if(actie == 'remove'){
					location.href = location.href;
				}

			}

		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=on_wishlist&product_id="+product_id+"&actie="+actie, true);
	xmlHttp.send(null);

}

function change_price(hoofdproduct_id, product_id){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			if(xmlHttp.responseText){
			
				$('div.prijs').html( xmlHttp.responseText );
				
				$('div.prijs').slideDown();
				
			} else {

				$('div.prijs').slideUp();
				
				$('div.prijs').html('');

			}

			update_selectors(hoofdproduct_id);

		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=change_price&hoofdproduct_id="+hoofdproduct_id+"&product_id="+product_id, true);
	xmlHttp.send(null);

}

function add_extra_info(hoofdproduct_id, categorie, optie_id){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			update_selectors(hoofdproduct_id);
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=add_extra_info&hoofdproduct_id="+hoofdproduct_id+"&categorie="+categorie+"&optie_id="+optie_id, true);
	xmlHttp.send(null);
	
}

function update_selectors(hoofdproduct_id){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			var json = eval('(' + xmlHttp.responseText + ')');

			for( var key in json ){
				
				if(key.substr(0,5) == "aant_"){
					if( json[key] == "0"){
						$('#'+key.substr(5)+'_selectorBox').slideUp();
						$('#add-'+key.substr(5)).val( '' );
					} else {
						$('#'+key.substr(5)+'_selectorBox').slideDown();
						$('#add-'+key.substr(5)).val( 'check' );
					}
				} else {
					$('#'+key+'_selector').html( json[key] );
				}

			}
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=update_selectors&hoofdproduct_id="+hoofdproduct_id, true);
	xmlHttp.send(null);
	
}

function bestellen_oud(id, go_to){
	
	var aantal  = $('#amount').val();
	var comfort = $('#add-comfort').val();
	var kleur   = $('#add-kleur').val();
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var data = xmlHttp.responseText.split('|');
			
			var melding = data[0];
			
			if(melding){
				
				alert(melding);
				
				if(data[4] && go_to){
					location.href = go_to;
				}

			}
			
			refresh_winkelwagen_aantal();
			

		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=bestellen&id="+id+"&aantal="+aantal+"&comfort="+comfort+"&kleur="+kleur, true);
	xmlHttp.send(null);
	
}
function verwijderen(id, productnaam){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var melding = xmlHttp.responseText.split('|');
			
			document.getElementById('showAlert').innerHTML = "<div style='margin:5px;'><h2 style='font-variant:normal;'>Melding</h2><br />"+melding[0]+"<br /><center><input type='button' value='Ok' onClick='annuleren();'></center></div>";

			document.getElementById('bestel').innerHTML = "<h1 style='font-size:13px;'><a href='javascript:void(0);' onClick=\"bestellen('"+id+"', '"+productnaam.replace(/'/, '\\\'')+"');\" style='text-decoration:none;'>Plaats in winkelwagentje &raquo;</a></h1>";

			overShade();
			showAlert();

			update_winkelwagencontainer();
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=verwijderen&id="+id, true);
	xmlHttp.send(null);
	
	return true;
}
function annuleren(){
	document.getElementById('overShade').style.display = 'none';
	document.getElementById('showAlert').style.display = 'none';
}
	
function bestelling_plaatsen(id, aantal, productnaam){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var melding = xmlHttp.responseText.split('|');
			
			annuleren();
			
			document.getElementById('showAlert').innerHTML = "<div style='margin:5px;'><h2 style='font-variant:normal;'>Melding</h2><br />"+melding[0]+"<br /><center><input type='button' value='Ok' onClick='annuleren();'></center></div>";

			document.getElementById('bestel').innerHTML = "<h1 style='font-size:13px;'><a href='javascript:void(0);' onClick=\"verwijderen('"+id+"', '"+productnaam.replace(/'/, '\\\'')+"');\" style='text-decoration:none;'>Verwijder uit winkelwagentje &raquo;</a></h1>";

			overShade();
			showAlert();

			update_winkelwagencontainer();
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=bestellen&id="+id+"&aantal="+aantal, true);
	xmlHttp.send(null);
	
	return true;
	
}
function refresh_winkelwagen_aantal(){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			if( xmlHttp.responseText ){

				$('.winkelwagen_txt').hide();
				$('#winkelwagen_amount').html( xmlHttp.responseText );
				$('.winkelwagen_txt').fadeIn();
				
			} else {

				$('.winkelwagen_txt').fadeOut();
				$('#winkelwagen_amount').html( 'geen artikelen' );
				
			}
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=winkelwagentje_ophalen", true);
	xmlHttp.send(null);
	
	return true;	
	
}

function update_winkelwagencontainer(){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var data = xmlHttp.responseText.split('|');
			
			var container = document.getElementById('winkelwagentje_container');
			var producten = document.getElementById('winkelwagentje_producten');
			var totaalprijs = document.getElementById('winkelwagentje_totaalprijs');
			var extra_kosten = document.getElementById('winkelwagentje_extra_kosten');

			producten.innerHTML = data[0];
			totaalprijs.innerHTML = data[1];
			extra_kosten.innerHTML = data[2];
			if(data[3] == 'show'){
				container.style.display = 'block';
			} else {
				container.style.display = 'none';
			}
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=winkelwagentje_ophalen", true);
	xmlHttp.send(null);
	
	return true;	
	
}
function update_winkelwagentje(id, aantal){
	
	if(aantal == ""){
		aantal = document.getElementById('aantal_'+id).value;
	}
	
	if(aantal == 0){
		
		if( confirm('Weet u zeker dat u dit product uit de winkelwagen wilt verwijderen?') ){

			var xmlHttp = ajaxFunction();

			xmlHttp.onreadystatechange = function() {
				if (xmlHttp.readyState == 4) {
				
					var data = xmlHttp.responseText.split('|');

					var melding 	= data[0];
					var totaalprijs = data[1];
					var btw			= data[2].split(":");

					if(totaalprijs == "0,00"){
						document.location.reload();
					} else {

						document.getElementById('product_'+id).style.display = 'none';

						document.getElementById('totaalprijs').innerHTML = totaalprijs;
						
						for(i=0; i<=btw.length; i++){
							document.getElementById('btw'+i).innerHTML = btw[i];
						}
						
					}

					refresh_winkelwagen_aantal();

				}
			}

			xmlHttp.open("GET", "/ajax.inc.php?action=verwijderen&id="+id, true);
			xmlHttp.send(null);

			return true;
			
		}

	} else {
	
		var xmlHttp = ajaxFunction();

		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
			
				var data = xmlHttp.responseText.split('|');
			
				var melding 	= data[0];
				var prijs 		= data[1];
				var totaalprijs = data[2];
				var btw			= data[3].split(":");
				
				document.getElementById('prijs_'+id).innerHTML = prijs;
				document.getElementById('totaalprijs').innerHTML = totaalprijs;
				
				var i=0;
				for(i=0; i<btw.length; i++){
					document.getElementById('btw'+i).innerHTML = btw[i];
				}

				refresh_winkelwagen_aantal();
			
			}
		}
	
		xmlHttp.open("GET", "/ajax.inc.php?action=bestellen&product_id="+id+"&aantal="+aantal, true);
		xmlHttp.send(null);
	
		return true;

	}
	
}

function set_validation(naam, validation){
	
	if(document.getElementById(naam).value){
		document.getElementById(naam).title = "Validatie gefaald!";

		check_gegeven(naam, validation);
	}
	
	return true;
}

function check_gegeven(naam, validation, waarde){
	
	if(document.getElementById(naam).title == "Succesvol gevalideerd!" || document.getElementById(naam).title == "Validatie gefaald!" || naam == "aanhef" || naam == "bezorgadres" || naam == "klant_type" ){
	
		if(!waarde || waarde == "undefined"){
			var waarde 	= document.getElementById(naam).value;
		}
	
		if(naam == "wachtwoord"){
			var waarde2 = document.getElementById('gebruikersnaam').value;
		}
		if(naam == "wachtwoord2"){
			var waarde2 = document.getElementById('wachtwoord1').value;
		}
		
		var xmlHttp = ajaxFunction();

		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
	
				var data = xmlHttp.responseText.split('|');

				var validated = data[0];
				var melding = data[1];

				if(validated != "neutral"){

					var input	= document.getElementById(naam);

					if(naam == "postcode" || naam == "plaats"){
						var validationnaam = "postcodeplaats";
					} else if(naam == "b_postcode" || naam == "b_plaats"){
						var validationnaam = "b_postcodeplaats";
					} else {
						var validationnaam = naam;
					}
			
					var icon 	= document.getElementById('validation_'+validationnaam);
			
					if(validated == "failed"){
			
						icon.style.background = "url('/files/validation_failed_icon.png') no-repeat";
						input.style.border = "#FF0000 1px solid";
						icon.innerHTML = melding;
						input.title = 'Validatie gefaald!';
			
					} else if(validated == "passed") {
				
						icon.style.background = "url('/files/validation_passed_icon.png') no-repeat";
						input.style.border = "#DDDDDD 1px solid";
						icon.innerHTML = '';
						input.title = 'Succesvol gevalideerd!';
					}
				}
	
			}
		}

		xmlHttp.open("GET", "/ajax.inc.php?action=update_gegeven&naam="+naam+"&waarde="+waarde+"&validation="+validation+"&waarde2="+waarde2, true);
		xmlHttp.send(null);

		return true;
		
	}
	
}

function stuur_nieuw_wachtwoord(input){
	
	var input = document.getElementById(input).value;
	
	if(!input){
		alert('Gelieve een e-mailadres opgeven!');
	} else {
		
		var xmlHttp = ajaxFunction();

		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {

				var returntje = xmlHttp.responseText;
				
				alert(returntje);

				return false;
			}
		}

		xmlHttp.open("GET", "/ajax.inc.php?action=stuur_nieuw_wachtwoord&input="+input, true);
		xmlHttp.send(null);
		
		
	}
}


function controleer_gegevens(){
	
	var bestaande_klant = document.getElementById('bestaande_klant').checked;
	var nieuwe_klant = document.getElementById('nieuwe_klant').checked;
	
	if(bestaande_klant){
		
		var gebruikersnaam 	= document.getElementById('gebruikersnaam').title;
		var wachtwoord		= document.getElementById('wachtwoord').title;
		
		if(gebruikersnaam == "Succesvol gevalideerd!" && wachtwoord == "Succesvol gevalideerd!"){
			return true;
		} else {
			alert('U heeft nog enkele vereiste gegevens niet of incorrect ingevuld!');
			return false;
		}
		
	} else if(nieuwe_klant){
		
		var voornaam 		= document.getElementById('voornaam').title;
		var achternaam		= document.getElementById('achternaam').title;
		var adres			= document.getElementById('adres').title;
		var postcode		= document.getElementById('postcode').title;
		var plaats			= document.getElementById('plaats').title;
		
		var bezorgadres		= document.getElementById('bezorgadres').checked;

			var b_adres		= document.getElementById('b_adres').title;
			var b_postcode	= document.getElementById('b_postcode').title;
			var b_plaats	= document.getElementById('b_plaats').title;

		var emailadres		= document.getElementById('emailadres').title;
		
		var wachtwoord1		= document.getElementById('wachtwoord1').title;
		var wachtwoord2		= document.getElementById('wachtwoord2').title;
		
		
		if(
			voornaam == "Succesvol gevalideerd!" && 
			achternaam == "Succesvol gevalideerd!" && 
			adres == "Succesvol gevalideerd!" && 
			postcode == "Succesvol gevalideerd!" && 
			plaats == "Succesvol gevalideerd!" && 
			emailadres == "Succesvol gevalideerd!" && 
			wachtwoord1 == "Succesvol gevalideerd!" && 
			wachtwoord2 == "Succesvol gevalideerd!"
		){
			if(bezorgadres){
				if(
					b_adres == "Succesvol gevalideerd!" &&
					b_postcode == "Succesvol gevalideerd!" &&
					b_plaats == "Succesvol gevalideerd!"
				){
					return true;
				} else {
					alert('U heeft nog enkele vereiste gegevens niet of incorrect ingevuld!');
					return false;					
				}
			} else {
				return true;
			}
		} else {
			alert('U heeft nog enkele vereiste gegevens niet of incorrect ingevuld!');
			return false;
		}
		
	} else {
		
		alert('Gelieve aangeven of u een nieuwe of bestaande klant bent');
		return false;
		
	}
	
}
function change_extra_kosten(value, betaalmethodes){
		
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			var value = xmlHttp.responseText.split('|');
			
			document.getElementById('extra_kosten_value').innerHTML = value[0];
			document.getElementById('totaalprijs').innerHTML = value[1];
			if(value[2]){
				document.getElementById('btw0').innerHTML = value[2];
			}
			
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=change_extra_kosten&value="+value+"&betaalmethodes="+betaalmethodes, true);
	xmlHttp.send(null);
	
}

function select_betaalmethode(value){
	
	var next_step = document.getElementById('next_step');
		
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			var value = xmlHttp.responseText;
			
			if(value == 'ideal' || value == 'paypal'){
				next_step.innerHTML = 'AFREKENEN';
			} else {
				next_step.innerHTML = 'BESTELLING VOLTOOIEN';
			}
			
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=select_betaalmethode&value="+value, true);
	xmlHttp.send(null);	
	
}

function add_note(){
	
	var note = document.getElementById('note').value.replace(/\n/g, "<br>");
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=add_note&note="+note, true);
	xmlHttp.send(null);	
	
}

function add_herkomst(herkomst){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=add_herkomst&herkomst="+herkomst, true);
	xmlHttp.send(null);	
	
}

function check_leveringsvoorwaarden(){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=check_leveringsvoorwaarden", true);
	xmlHttp.send(null);	
	
}

function controleer_bestelling(){
	
	var lv = document.getElementById('lv');
	var bm = document.getElementById('bm');
	
	var melding = "";
	if(!lv.checked){
		melding += "- Gelieve de leveringsvoorwaarden accepteren\n";
	}
	if(!bm.value){
		melding += "- Gelieve een betalingsmethode selecteren\n";
	}
	
	if(melding){
		alert("Melding!\n"+melding);
		return false;
	} else {
		return true;
	}
	
}

function afleveradres_wijzigen(value){

	
	if(value == 1){

		var b_naam 	= document.getElementById('b_naam').innerHTML.replace(/'/,' ');
		var b_adres = document.getElementById('b_adres').innerHTML.replace(/'/,' ');
		var b_postcode = document.getElementById('b_postcode').innerHTML.replace(/'/,' ');
		var b_plaats = document.getElementById('b_plaats').innerHTML.replace(/'/,' ');
		var b_link 	= document.getElementById('b_link').innerHTML;
	
		document.getElementById('b_naam').innerHTML = "<input type='text' class='input' style='width:150px; background:#E3E3E3;' id='bz_naam' value='"+b_naam+"'>";
		document.getElementById('b_adres').innerHTML = "<input type='text' class='input' style='width:150px; background:#E3E3E3;' id='bz_adres' value='"+b_adres+"'>";
		document.getElementById('b_postcode').innerHTML = "<input type='text' class='input' style='width:45px; background:#E3E3E3;' id='bz_postcode' value='"+b_postcode+"'>";
		document.getElementById('b_plaats').innerHTML = "<input type='text' class='input' style='width:90px; background:#E3E3E3;' id='bz_plaats' value='"+b_plaats+"'>";
		document.getElementById('b_link').innerHTML = "<a href='javascript:void(0);' onClick=\"afleveradres_wijzigen('2');\" style='text-decoration:none;'>&raquo; Afleveradres opslaan</a>";
		
	} else if(value == 2){
		
		var naam = document.getElementById('bz_naam').value;
		var adres = document.getElementById('bz_adres').value;
		var postcode = document.getElementById('bz_postcode').value;
		var plaats = document.getElementById('bz_plaats').value;

		var xmlHttp = ajaxFunction();

		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				
				document.getElementById('b_naam').innerHTML = naam;
				document.getElementById('b_adres').innerHTML = adres;
				document.getElementById('b_postcode').innerHTML = postcode;
				document.getElementById('b_plaats').innerHTML = plaats
				document.getElementById('b_link').innerHTML = "<a href='javascript:void(0);' onClick=\"afleveradres_wijzigen('1');\" style='text-decoration:none;'>&raquo; Afleveradres wijzigen</a>";


			}
		}

		xmlHttp.open("GET", "/ajax.inc.php?action=wijzig_afleveradres&naam="+naam+"&adres="+adres+"&postcode="+postcode+"&plaats="+plaats, true);
		xmlHttp.send(null);			
		
	}
	
}

function reminder_instellen(actie, naam, emailadres, maand){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var response = xmlHttp.responseText.split("|");
			
			var melding = response[0];

			if(actie != "afmelden"){
				document.getElementById('remindermaand2').innerHTML = response[1];
			}
			
			if(actie == "aanmelden" || actie == "afmelden"){

				if(melding){
					alert("Melding!\n"+melding);
				}
			}
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=reminder_instellen&naam="+naam+"&emailadres="+emailadres+"&maand="+maand, true);
	xmlHttp.send(null);
	
}
function winkelwagen_opslaan(){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			document.getElementById('opslaantxt').innerHTML = "<i><b>Winkelwagen opgeslagen!</b><br />Uw winkelwagentje is succesvol opgeslagen. Als u later nog eens terugkomt, zal de winkelwagen automatisch opgehaald worden.</i>";
			
		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=winkelwagen_opslaan", true);
	xmlHttp.send(null);
	
}


function update_varianten_selector(pos){

	var artnr = $('#artnr_'+pos).val();
	var naam = $('#variant_naam_'+pos).val();
	var prijs = $('#prijs_'+pos).val();
	
	if(prijs){
		prijs = " (&euro; "+prijs+")";
	}

	if(artnr && naam){
		
		$('.box_'+pos).show();
		$('.box_'+pos+' input').attr('checked', true);
		$('.variant_'+pos).html( artnr+" | "+naam+prijs );

	} else {

		$('.box_'+pos).hide();
		$('.box_'+pos+' input').attr('checked', false);
		$('.variant_'+pos).html( "-" );
		
	}

}

function show_suggestions(ID, dropdownId, keyword){

	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var data = xmlHttp.responseText;
			
			if(data){
				document.getElementById(dropdownId).innerHTML = data;
				show_full(dropdownId);
			}

		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=show_suggestions&ID="+ID+"&keyword="+keyword, true);
	xmlHttp.send(null);

}

function hide_suggestions(id){
	setTimeout("hide_full('"+id+"');", 100);
}

function add_bestaand_product(ID, product_id){
	
	var aantal = document.getElementById('aantal_'+ID).value;
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			location.href = location.href;

		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=add_bestaand_product&ID="+ID+"&product_id="+product_id+"&aantal="+aantal, true);
	xmlHttp.send(null);

}

function change_bestelling(ID, name, value){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			var data = xmlHttp.responseText.split("|");
			
			if(name != "extra_kosten"){
				document.getElementById('prijs_'+ID).value = data[0];
			}
			document.getElementById('totaalprijs').innerHTML = data[1];
			document.getElementById('btw').innerHTML = data[2];

		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=change_bestelling&ID="+ID+"&name="+name+"&value="+value, true);
	xmlHttp.send(null);
	
}


function change_afleveradres(ID, name, value){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=change_afleveradres&ID="+ID+"&name="+name+"&value="+value, true);
	xmlHttp.send(null);
	
}

function load_status_mssg(textareaId, status){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			document.getElementById(textareaId).innerHTML = xmlHttp.responseText;

		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=load_status_mssg&status="+status, true);
	xmlHttp.send(null);
	
}

function change_note(bestelcode, value){

	var value = value.replace(/\n/g, "<br>");

	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

		}
	}

	xmlHttp.open("GET", "/ajax.inc.php?action=change_note&bestelcode="+bestelcode+"&value="+value, true);
	xmlHttp.send(null);
	
}

// =======================================================================

