function f_autoCalc(){
	if(document.getElementById('startDateInput').value != '' && document.getElementById('endDateInput').value != ''){
		f_calcPrice();
	}
}

function f_calcPrice(){
	f_calcPriceKey();
	f_calcPriceNoKey();
}

function f_calcPriceKey(){

	var w_aStartDate = document.getElementById('startDateInput').value.split('-');
	var w_aEndDate = document.getElementById('endDateInput').value.split('-');
		
	var w_oDateStart = new Date(w_aStartDate[2],(w_aStartDate[1]-1),w_aStartDate[0]); 
	var w_oDateEnd = new Date(w_aEndDate[2],(w_aEndDate[1]-1),w_aEndDate[0]);
	var w_oDiff = w_oDateEnd - w_oDateStart;
	var w_iNumDays = w_oDiff / (24*60*60*1000) +1;
	
	if(w_iNumDays < 1){
		alert('De einddatum valt voor de startdatum');
		return;
	}
	
	if(w_iNumDays <= 2){
		f_updatePrice(25, w_iNumDays);
		return;
	}
	if(w_iNumDays <= 4){
		f_updatePrice('37,50', w_iNumDays);
		return;
	}
	if(w_iNumDays <= 7){
		f_updatePrice(45, w_iNumDays);
		return;
	}
	if(w_iNumDays <= 18){
		f_updatePrice(w_iNumDays*6, w_iNumDays);
		return;
	}
	if(w_iNumDays >= 19){
		f_updatePrice(w_iNumDays*5, w_iNumDays);
		return;
	}
}
function f_calcPriceNoKey(){
	
	var w_aStartDate = document.getElementById('startDateInput').value.split('-');
	var w_aEndDate = document.getElementById('endDateInput').value.split('-');
		
	var w_oDateStart = new Date(w_aStartDate[2],(w_aStartDate[1]-1),w_aStartDate[0]); 
	var w_oDateEnd = new Date(w_aEndDate[2],(w_aEndDate[1]-1),w_aEndDate[0]);
	var w_oDiff = w_oDateEnd - w_oDateStart;
	var w_iNumDays = w_oDiff / (24*60*60*1000) +1;
	
	if(w_iNumDays < 1){
		alert('De einddatum valt voor de startdatum');
		return;
	}
	
	if(w_iNumDays <= 2){
		f_updatePriceNoKey(25, w_iNumDays);
		return;
	}
	if(w_iNumDays <= 4){
		f_updatePriceNoKey('37,50', w_iNumDays);
		return;
	}
	if(w_iNumDays <= 7){
		f_updatePriceNoKey(49, w_iNumDays);
		return;
	}
	if(w_iNumDays <= 18){
		f_updatePriceNoKey(w_iNumDays*7, w_iNumDays);
		return;
	}
	if(w_iNumDays >= 19){
		f_updatePriceNoKey(w_iNumDays*6, w_iNumDays);
		return;
	}
}

function f_updatePrice(p_iPrice, p_iNumDays){
	var w_oDiv = document.getElementById('currPrice');
	var w_sStartDate = document.getElementById('startDateInput').value;
	var w_sEndDate = document.getElementById('endDateInput').value;
	var w_sBook = '<a href="reserveren/?vertrekdate='+w_sStartDate+'&aankomstdate='+w_sEndDate+'&aankomstvpdate='+w_sStartDate+'">Reserveer nu >> </a>';
	document.getElementById('reserveernu').innerHTML = w_sBook;
	document.getElementById('days').innerHTML = '<div style="font-size:25px; width:100px;">'+p_iNumDays+' </div>dagen ';
	w_oDiv.innerHTML = '<div style="font-size: 12px; width:120px;">Bij autosleutel <br />inleveren:</div><span style="font-size:30px;"> &euro; '+p_iPrice+'</span> ';
}

function f_updatePriceNoKey(p_iPrice, p_iNumDays){
	var w_oDiv = document.getElementById('currPriceNoKey');
	w_oDiv.innerHTML = '<div style="font-size: 12px; width:120px;">Bij autosleutel <br /><b>niet</b> inleveren:</div><span style="font-size:30px;"> &euro; '+p_iPrice+'</span>';
}

