// JavaScript Document
function AjaxAntwoord(Antwoord,Tracker,Teller){	
	if(Tracker == "AantalLaden"){
		document.getElementById("AantalDiv").innerHTML = Antwoord;
		document.getElementById("AantalSpan").innerHTML = "Aantal";
	}
	if(Tracker == "WinkelmandjeLaden"){
		document.getElementById("Stap1").innerHTML = Antwoord;
	}
	if(Tracker == "EmailVoorraad"){
		document.getElementById("VoorraadEmail").innerHTML = Antwoord;
	}
}




function WinkelmandjeLaden(){
	var Teller = Teller;
	document.getElementById("Stap1").innerHTML = "Een ogenblik geduld a.u.b.";
	AjaxContact('http://www.afcashop.nl/aj_winkelmandje.php','get','WinkelmandjeLaden', Teller);			
}
function KortingBijwerken(){
	var Teller = Teller;
	var Couponcode = document.getElementById("KortingsCode").value;
	document.getElementById("Stap1").innerHTML = "Een ogenblik geduld a.u.b.";
	AjaxContact('http://www.afcashop.nl/aj_winkelmandje.php?Couponcode='+Couponcode,'get','WinkelmandjeLaden', Teller);			
}
function RegelBijwerken(BestellingenDetailsId){
	var Teller = Teller;
	var BestellingenDetailsId = BestellingenDetailsId;
	var Aantal = document.getElementById("Aantal"+BestellingenDetailsId).value;
	document.getElementById("Stap1").innerHTML = "Een ogenblik geduld a.u.b.";
	AjaxContact('http://www.afcashop.nl/aj_winkelmandje.php?BestellingenDetailsId='+BestellingenDetailsId+'&Aantal='+Aantal,'get','WinkelmandjeLaden', Teller);			
}
function RegelVerwijderen(BestellingenDetailsId){
	var Teller = Teller;
	var BestellingenDetailsId = BestellingenDetailsId;	
	document.getElementById("Stap1").innerHTML = "Een ogenblik geduld a.u.b.";
	AjaxContact('http://www.afcashop.nl/aj_winkelmandje.php?BestellingenDetailsId='+BestellingenDetailsId,'get','WinkelmandjeLaden', Teller);			
}
function EmailVoorraad(ProductId){
	var ProductId = ProductId;
	var Email = document.getElementById("EmailWanneerInVoorraad").value;
	document.getElementById("VoorraadEmail").innerHTML = "Een ogenblik geduld a.u.b.";
	AjaxContact('http://www.afcashop.nl/aj_emailvoorraad.php?ProductId='+ProductId+'&Email='+Email,'get','EmailVoorraad', ProductId);			
}

function AantalLaden(){
	var ProductMaatId = document.getElementById("MaatArtikelId").value;
	AjaxContact('http://www.afcashop.nl/aj_aantalladen.php?ProductMaatId='+ProductMaatId,'get','AantalLaden', ProductMaatId);			
}

function ControleerBetaalmethode(){
	submitOK='True';
	if (document.Formulier.BetaalKeuze.value.length==0){
		submitOK='False';
	}

	if (submitOK=='False'){
		alert('Kies een betaalmethode');
		return false;
	}
}

function VeranderBetaalMethode(){
	var Teller = Teller;
	var BetaalMethode = document.getElementById('BetaalKeuze').value;
	if(BetaalMethode==1){ document.Formulier.action = "https://payment.buckaroo.nl/gateway/ideal_payment.asp"; }
	if(BetaalMethode==2){ document.Formulier.action = "https://payment.buckaroo.nl/gateway/machtiging.asp"; }
	if(BetaalMethode==3){ document.Formulier.action = "https://payment.buckaroo.nl/sslplus/request_for_authorization.asp"; }
	if(BetaalMethode==4){ document.Formulier.action = "https://payment.buckaroo.nl/gateway/transfer.asp"; }
	if(BetaalMethode==5){ document.Formulier.action = "https://payment.buckaroo.nl/gateway/paypal_payment.asp"; }
	AjaxContact('http://www.afcashop.nl/aj_betaalmethode_opslaan.php?BetaalmethodeId='+BetaalMethode,'get','Nietsdoen', Teller);			
	//document.getElementById("BPE_Reference").value = BetaalMethode;
	//Betaalmethodes:
	//1 = iDeal
	//2 = Eenmalige machtiging
	//3 = Creditcard
	//4 = Overboeking
	//5 = Paypal
}

// Functie om het gegevensformulier van het winkelmandje te controleren.
function GegevensControle(){
	var TelefoonCheck = /^0[0-9]{9}$/i;
	var PostcodeCheck = /^[1-9]{1}[0-9]{3}[A-Z]{2}$/i;
	var Foutmelding = '';
	submitOK='True';

	if (document.GegevensFormulier.Adres.value.length==0){
		Foutmelding = Foutmelding + '- Adres.\n';
		document.GegevensFormulier.Adres.style.background = '1px solid #D00000';
		submitOK='False';
	}
	else{
		document.GegevensFormulier.Adres.style.background = '1px solid #ffffff';
	}
	if (document.GegevensFormulier.Postcode.value.length==0){
		Foutmelding = Foutmelding + '- Postcode.\n';
		document.GegevensFormulier.Postcode.style.background = '1px solid #D00000';
		submitOK='False';
	}
	else{
		document.GegevensFormulier.Postcode.style.background = '1px solid #ffffff';
	}
	if (document.GegevensFormulier.Plaats.value.length==0){
		Foutmelding = Foutmelding + '- Plaats.\n';
		document.GegevensFormulier.Plaats.style.background = '1px solid #D00000';
		submitOK='False';
	}
	else{
		document.GegevensFormulier.Plaats.style.background = '1px solid #ffffff';
	}
	if (document.GegevensFormulier.Telefoon.value.length==0){
		Foutmelding = Foutmelding + '- Telefoon.\n';
		document.GegevensFormulier.Telefoon.style.background = '1px solid #D00000';
		submitOK='False';
	}
	else{
		document.GegevensFormulier.Telefoon.style.background = '1px solid #ffffff';
	}
	if (document.GegevensFormulier.Email.value.length==0){
		Foutmelding = Foutmelding + '- Email.\n';
		document.GegevensFormulier.Email.style.background = '1px solid #D00000';
		submitOK='False';
	}
	else{
		document.GegevensFormulier.Email.style.background = '1px solid #ffffff';
	}
	if(document.GegevensFormulier.Wachtwoord1){
		if (document.GegevensFormulier.Wachtwoord1.value.length==0){
			Foutmelding = Foutmelding + '- Wachtwoord.\n';
			document.GegevensFormulier.Wachtwoord1.style.background = '1px solid #D00000';
			submitOK='False';
		}
		else{
			document.GegevensFormulier.Wachtwoord1.style.background = '1px solid #ffffff';
		}
		if (document.GegevensFormulier.Wachtwoord2.value.length==0){
			Foutmelding = Foutmelding + '- Herhaal wachtwoord.\n';
			document.GegevensFormulier.Wachtwoord2.style.background = '1px solid #D00000';
			submitOK='False';
		}
		else{
			document.GegevensFormulier.Wachtwoord2.style.background = '1px solid #ffffff';
		}
		if (document.GegevensFormulier.Wachtwoord1.value != document.GegevensFormulier.Wachtwoord2.value){
			Foutmelding = Foutmelding + '- De 2 wachtwoorden zijn niet gelijk aan elkaar.\n';
			document.GegevensFormulier.Wachtwoord1.style.background = '1px solid #D00000';
			document.GegevensFormulier.Wachtwoord2.style.background = '1px solid #D00000';
			submitOK='False';
		}
		else{
			document.GegevensFormulier.Wachtwoord1.style.background = '1px solid #ffffff';
			document.GegevensFormulier.Wachtwoord2.style.background = '1px solid #ffffff';
		}
	}
	if (submitOK=='False'){
		alert('Je dient de volgende velden verplicht in te vullen:\n' + Foutmelding);
		return false;
	}
}
// Einde van deze functie.

// Functie om een element met een bepaalde id weer te geven EN te verbergen door steeds te klikken.
function toggle(element){
	if (document.getElementById(element).style.display == "none"){
		document.getElementById(element).style.display = "";
	} else {
		document.getElementById(element).style.display = "none";
	}
}
// Einde van deze functie

// Functie om het factuuradres te laten tonen en verdwijnen
function toggleFactuur(){	
	if (!document.getElementById('Factuur').checked){
		document.getElementById('extra_velden').style.display = "";
		document.getElementById('FactuurStraat').value = document.getElementById('FactuurStraat2').value;
		document.getElementById('FactuurHuisnummer').value = document.getElementById('FactuurHuisnummer2').value;
		document.getElementById('FactuurToevoeging').value = document.getElementById('FactuurToevoeging2').value;
		document.getElementById('Factuurplaats').value = document.getElementById('Factuurplaats2').value;
		document.getElementById('Factuurpostcode').value = document.getElementById('Factuurpostcode2').value;
	} else {
		document.getElementById('extra_velden').style.display = "none";
		document.getElementById('FactuurStraat').value = "";
		document.getElementById('FactuurHuisnummer').value = "";
		document.getElementById('FactuurToevoeging').value = "";
		document.getElementById('Factuurplaats').value = "";
		document.getElementById('Factuurpostcode').value = "";
		document.getElementById('FactuurLandId').selectedIndex = "";
	}
}

function toggleFactuur2(){	
	if (!document.getElementById('Factuur').checked){
		document.getElementById('extra_veld1').style.display = "";
		document.getElementById('extra_veld2').style.display = "";
		document.getElementById('extra_veld3').style.display = "";
		document.getElementById('extra_veld4').style.display = "";
		document.getElementById('extra_veld5').style.display = "";
		document.getElementById('FactuurStraat').value = document.getElementById('FactuurStraat2').value;
		document.getElementById('FactuurHuisnummer').value = document.getElementById('FactuurHuisnummer2').value;
		document.getElementById('FactuurToevoeging').value = document.getElementById('FactuurToevoeging2').value;
		document.getElementById('Factuurplaats').value = document.getElementById('Factuurplaats2').value;
		document.getElementById('Factuurpostcode').value = document.getElementById('Factuurpostcode2').value;
	} else {
		document.getElementById('extra_veld1').style.display = "none";
		document.getElementById('extra_veld2').style.display = "none";
		document.getElementById('extra_veld3').style.display = "none";
		document.getElementById('extra_veld4').style.display = "none";
		document.getElementById('extra_veld5').style.display = "none";
		document.getElementById('FactuurStraat').value = "";
		document.getElementById('FactuurHuisnummer').value = "";
		document.getElementById('FactuurToevoeging').value = "";
		document.getElementById('Factuurplaats').value = "";
		document.getElementById('Factuurpostcode').value = "";
		document.getElementById('FactuurLandId').selectedIndex = "";
	}
}





// Einde van deze functie

//controle bij account aanpassen
function AccountAanpasControle(){
	var TelefoonCheck = /^0[0-9]{9}$/i;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	var Foutmelding = '';
	submitOK = 'True';
	
	if (filter.test(document.ContactForm.Email.value)){
		document.ContactForm.Email.style.border = '';
	}
	else{
		document.ContactForm.Email.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	if (document.ContactForm.Gebruikersnaam2.value.length == 0){
		Foutmelding = Foutmelding + '- Gebruikersnaam.\n';
		document.ContactForm.Gebruikersnaam2.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Gebruikersnaam2.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.Wachtwoord1.value.length == 0){
		Foutmelding = Foutmelding + '- Het wachtwoord.\n';
		document.ContactForm.Wachtwoord1.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Wachtwoord1.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.Wachtwoord2.value.length == 0){
		Foutmelding = Foutmelding + '- Bevestiging wachtwoord.\n';
		document.ContactForm.Wachtwoord2.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Wachtwoord2.style.border = '1px solid #747577';
	}
	
	
	if (document.ContactForm.Voornaam.value.length == 0){
		Foutmelding = Foutmelding + '- Voornaam.\n';
		document.ContactForm.Voornaam.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Voornaam.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.Achternaam.value.length == 0){
		Foutmelding = Foutmelding + '- Achternaam.\n';
		document.ContactForm.Achternaam.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Achternaam.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.Straat.value.length == 0){
		Foutmelding = Foutmelding + '- Straat.\n';
		document.ContactForm.Straat.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Straat.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.Huisnummer.value.length == 0){
		Foutmelding = Foutmelding + '- Huisnummer.\n';
		document.ContactForm.Huisnummer.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Huisnummer.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.Postcode.value.length == 0){
		Foutmelding = Foutmelding + '- Postcode.\n';
		document.ContactForm.Postcode.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Postcode.style.border = '1px solid #747577';
	}
	
//	if (document.ContactForm.Telefoon.value.length == 0){
//		Foutmelding = Foutmelding + '- Telefoon.\n';
//		document.ContactForm.Telefoon.style.border = '1px solid #ff0000';
//		submitOK = 'False';
//	}
//	else{
//		document.ContactForm.Telefoon.style.border = '1px solid #747577';
//	}
	
	if (document.ContactForm.Telefoon.value.length == 0){
		Foutmelding = Foutmelding + '- Telefoon.\n';
		document.ContactForm.Telefoon.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Telefoon.style.border = '1px solid #747577';
	}
	
	
	
	if (document.ContactForm.Plaats.value.length == 0){
		Foutmelding = Foutmelding + '- Plaats.\n';
		document.ContactForm.Plaats.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Plaats.style.border = '1px solid #747577';
	}
	
	if (document.ContactForm.LandId.value.length == 0){
		Foutmelding = Foutmelding + '- Land.\n';
		document.ContactForm.LandId.style.border = '1px solid #ff0000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.LandId.style.border = '1px solid #747577';
	}
	
	/*if (document.ContactForm.Fax.value.length == 0){
		Foutmelding = Foutmelding + '- Fax.\n';
		document.ContactForm.Fax.style.border = '1px solid #D00000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Fax.style.border = '1px solid #747577';
	}*/
	
	if (document.ContactForm.Wachtwoord2.value != document.ContactForm.Wachtwoord1.value){
		Foutmelding = Foutmelding + '- De wachtwoorden komen niet overeen.\n';
		document.ContactForm.Wachtwoord2.style.border = '1px solid #D00000';
		document.ContactForm.Wachtwoord1.style.border = '1px solid #D00000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Wachtwoord2.style.border = '1px solid #747577';
		document.ContactForm.Wachtwoord1.style.border = '1px solid #747577';
	}
	//Factuuradres is anders
	if (document.ContactForm.FactuurStraat.value.length > 0 || document.ContactForm.Factuurplaats.value.length > 0 || document.ContactForm.Factuurpostcode.value.length > 0){
		
		if (document.ContactForm.FactuurStraat.value.length == 0){
			Foutmelding = Foutmelding + '- Factuur straat.\n';
			document.ContactForm.FactuurStraat.style.border = '1px solid #D00000';
			submitOK = 'False';
		}
		else{
			document.ContactForm.FactuurStraat.style.border = '1px solid #747577';
		}
		
		if (document.ContactForm.FactuurHuisnummer.value.length == 0){
			Foutmelding = Foutmelding + '- Factuur huisnummer.\n';
			document.ContactForm.FactuurHuisnummer.style.border = '1px solid #D00000';
			submitOK = 'False';
		}
		else{
			document.ContactForm.FactuurHuisnummer.style.border = '1px solid #747577';
		}
		
		if (document.ContactForm.Factuurplaats.value.length == 0){
			Foutmelding = Foutmelding + '- Factuurplaats.\n';
			document.ContactForm.Factuurplaats.style.border = '1px solid #D00000';
			submitOK = 'False';
		}
		else{
			document.ContactForm.Factuurplaats.style.border = '1px solid #747577';
		}
		
		if (document.ContactForm.Factuurpostcode.value.length == 0){
			Foutmelding = Foutmelding + '- Factuurpostcode.\n';
			document.ContactForm.Factuurpostcode.style.border = '1px solid #D00000';
			submitOK = 'False';
		}
		else{
			document.ContactForm.Factuurpostcode.style.border = '1px solid #747577';
		}
		
		if (document.ContactForm.FactuurLandId.value.length == 0){
			Foutmelding = Foutmelding + '- Factuurland.\n';
			document.ContactForm.FactuurLandId.style.border = '1px solid #D00000';
			submitOK = 'False';
		}
		else{
			document.ContactForm.FactuurLandId.style.border = '1px solid #747577';
		}
		
	}
// einde factuuradres is anders

	if (submitOK=='False'){
		alert('De volgende velden zijn verplicht:\n' + Foutmelding);
		return false;
	}
}
// Einde van deze functie
function LoginControleStap2(){
	var Foutmelding = '';
	submitOK='True';

	if (document.LoginStap2Formulier.Emailadres.value.length == 0){
		Foutmelding = Foutmelding + '- Gebruikersnaam.\n';
		document.LoginStap2Formulier.Emailadres.style.border = '1px solid #D00000';
		submitOK = 'False';
	}
	else{
		document.LoginStap2Formulier.Emailadres.style.border = '1px solid #747577';
	}
	
	if (document.LoginStap2Formulier.Wachtwoord.value.length == 0){
		Foutmelding = Foutmelding + '- Wachtwoord.\n';
		document.LoginStap2Formulier.Wachtwoord.style.border = '1px solid #D00000';
		submitOK = 'False';
	}
	else{
		document.LoginStap2Formulier.Wachtwoord.style.border = '1px solid #747577';
	}

	if (submitOK=='False'){
		alert('De volgende velden zijn verplicht:\n' + Foutmelding);
		return false;
	}
}

function ControleerContact(){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	var Foutmelding = '';
	submitOK = 'True';

	if (document.ContactForm.Naam.value.length == 0){
		Foutmelding = Foutmelding + '- Je naam.\n';
		document.ContactForm.Naam.style.border = '1px solid #D00000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Naam.style.border = '1px solid #747577';
	}
	
	if (filter.test(document.ContactForm.Email.value)){
		document.ContactForm.Email.style.border = '';
	}
	else{
		document.ContactForm.Email.style.border = '1px solid #D00000';
		Foutmelding = Foutmelding + '- Jouw e-mailadres.\n';
		submitOK = 'False';
	}
	
	if (document.ContactForm.Vraag.value.length == 0){
		Foutmelding = Foutmelding + '- Je vraag / opmerking.\n';
		document.ContactForm.Vraag.style.border = '1px solid #D00000';
		submitOK = 'False';
	}
	else{
		document.ContactForm.Vraag.style.border = '1px solid #747577';
	}
	
	

	if (submitOK=='False'){
		alert('De volgende velden zijn verplicht:\n' + Foutmelding);
		return false;
	}
}

