$(document).ready(function() {	
	if(po!=9){
		var TotalAmount = 0.00;
		$('#TotalAmount').html('&euro; ' + TotalAmount.toFixed(2));	

		var ra = $('#ra').val();
		var ra_rk = $('#ra_rk').val();
		
		if(ra!=0 || ra_rk!=0){
			TotalAmount = CountTotal(ra, ra_rk, po);	
		}
		
		$('#ra').change(function() {
			var TotalAmount = 0.00;
			var ra = $('#ra').val();
			var ra_rk = $('#ra_rk').val();
			TotalAmount = CountTotal(ra, ra_rk, po);
		});
		$('#ra_rk').change(function() {
			var TotalAmount = 0.00;
			var ra = $('#ra').val();
			var ra_rk = $('#ra_rk').val();
			TotalAmount = CountTotal(ra, ra_rk, po);
		});
		
		$('#rk_controle').change(function() {
			var TotalAmount = 0.00;
			var ra = $('#ra').val();
			var ra_rk = $('#ra_rk').val();
			var code = $('#rk_pas').val();
			var control = $('#rk_controle').val();
			TotalAmount = CountTotal(ra, ra_rk, po);
		});
		
		
		function CountTotal(ra, ra_rk, po){
			var TotalRa = 0;
			var TotalRaRk = 0;
			if(ra>0){
				TotalRa = (15.50 * parseInt(ra));
			}	
			if(ra_rk>0){
				if(po==0){
					TotalRaRk = (20.50 * parseInt(ra_rk));
				}
				else {
					TotalRaRk = (18 * parseInt(ra_rk));
				}	
			}	
			
			var Total = (parseFloat(TotalRa) + parseFloat(TotalRaRk));
			
			var code = $('#rk_pas').val();
			var control = $('#rk_controle').val();
			var TotalDiscount = 0;
			if(code.length==7 && control.length==3){
				$.ajax({
					type: "POST",
					url: "/check.php",
					data: { 
						code: code,
						control: control
					},
					success: function(msg){
						if(msg==1){
							TotalAmount = (Total * 0.9);
							TotalDiscount = (Total * 0.1);
							$('#TotalAmount').html('&euro; ' + TotalAmount.toFixed(2));	
							$('#TotalDiscount').html('&euro; -' + TotalDiscount.toFixed(2));	
						}
						else {
							TotalDiscount = 0;
							$('#TotalDiscount').html('&euro; -' + TotalDiscount.toFixed(2));	
							alert('Let op! ' + msg);
						}
					}
				});
			}	
			else {
				TotalDiscount = 0;
				$('#TotalDiscount').html('&euro; -' + TotalDiscount.toFixed(2));	
			}
			TotalAmount = Total;
			$('#TotalAmount').html('&euro; ' + TotalAmount.toFixed(2));						
		}
	}
});



function CheckInput(){
	if((document.preorder.ra.value=='0') && (document.preorder.ra_rk.value=='0')){
		alert('Je hebt geen aantal opgegeven. Probeer opnieuw.');
		return false;
	}
	if(document.preorder.naam.value==''){
		alert('Je hebt geen naam ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.preorder.email.value==''){
		alert('Je hebt geen e-mailadres ingevuld. Probeer opnieuw.');
		return false;
	}
	if(!document.preorder.av.checked){
		alert('Je bent nog niet akkoord met onze voorwaarden. Probeer opnieuw.');
		return false;
	}
	
	return true;
}

function CheckInputOrder(){
	if((document.order.ra.value=='0') && (document.order.ra_rk.value=='0')){
		alert('Je hebt geen aantal opgegeven. Probeer opnieuw.');
		return false;
	}
	if(document.order.naam.value==''){
		alert('Je hebt geen naam ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.order.adres.value==''){
		alert('Je hebt geen adres ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.order.postcode.value==''){
		alert('Je hebt geen postcode ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.order.plaats.value==''){
		alert('Je hebt geen plaats ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.order.email.value==''){
		alert('Je hebt geen e-mailadres ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.order.payment.value==''){
		alert('Je hebt geen betaaloptie geselecteerd. Probeer opnieuw.');
		return false;
	}
	if(!document.order.av.checked){
		alert('Je bent nog niet akkoord met onze voorwaarden. Probeer opnieuw.');
		return false;
	}
	
	return true;
}

function CheckInputContact(){
	if(document.contact.msg.value==''){
		alert('Je hebt geen bericht ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.contact.naam.value==''){
		alert('Je hebt geen naam ingevuld. Probeer opnieuw.');
		return false;
	}
	if(document.contact.email.value==''){
		alert('Je hebt geen e-mailadres ingevuld. Probeer opnieuw.');
		return false;
	}
	
	return true;
}

var po = 9;
