// JavaScript Document
function calcTotal(iQuant, iProductId ) {
	if(iQuant == '' ) { return null; }
	iQuant = parseInt(iQuant);
	var key = document.getElementById('shop_basket_products_key_' + iProductId).value;
	var iOldQaunt = parseInt(document.getElementById('shop_basket_previous_' + iProductId).value);
	if(!isNaN(iQuant) ) {	
		document.getElementById('shop_basket_previous_' + iProductId).value = iQuant;
		
		// voer functie uit (vervang komma's door punten)
		replacePunt(iProductId);
	}
	if(iQuant == 0) {
		var url = 'shopDo.php?what=remove&products_key='+key;
		nullframe.document.location = url;		
	}	
	if(!isNaN(iQuant) ) {
		// oude totaal
		//var test = String(Math.round(document.getElementById('shop_basket_products_price_' + iProductId).value*100*iOldQaunt));
		//var oudeTotaal = test.substr(0, test.length-2) +',';
		//document.writeln(oudeTotaal);
		var oldTotal =  (Math.round(document.getElementById('shop_basket_products_price_' + iProductId).value*100*iOldQaunt));
		
		// nieuwe totaal
		var newTotal = String(Math.round(document.getElementById('shop_basket_products_price_' + iProductId).value*100*iQuant));
		
		// set product totaal
		document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML = '&euro;&nbsp;&nbsp;' + newTotal.substr(0, newTotal.length-2) +'.' + newTotal.substr(newTotal.length-2, 2);
				
		// huidige totaal = grandTotaal + nieuwe totaal - oude totaal
		var currentTotal = String((parseFloat(document.getElementById('grandtotal').innerHTML)*100)+ parseFloat(newTotal) - parseFloat(oldTotal));
		//alert(String(parseFloat(Math.round(document.getElementById('grandtotal').innerHTML)*100)));
		
		// extra toeslag
		if(parseFloat(currentTotal) < 1750){
			if(document.getElementById('geheven_toeslag').value == 500){
				document.getElementById('extra_toeslag').style.display = 'block';
				
				currentTotal = String(parseFloat(currentTotal));
			} else {
				currentTotal = String(parseFloat(currentTotal) + 500);
				document.getElementById('geheven_toeslag').value = 500;
				document.getElementById('extra_toeslag').style.display = 'block';
				
			}
		} else {
			if(document.getElementById('geheven_toeslag').value == 500){
				if((parseFloat(currentTotal) - 500) > 1750){
					document.getElementById('extra_toeslag').style.display = 'none';
					currentTotal = String(parseFloat(currentTotal) - 500);
					document.getElementById('geheven_toeslag').value = '';
					
				} else {
					//document.getElementById('geheven_toeslag').value = 500;
					document.getElementById('extra_toeslag').style.display = 'block';
					
				}
			}
		} 
		
		// set grandTotaal
		document.getElementById('grandtotal').innerHTML = currentTotal.substr(0, currentTotal.length-2) +'.' + currentTotal.substr(currentTotal.length-2, 2);
		
		// voer functie uit (vervang punten door komma's)
		replaceKomma(iProductId);
		
		// set sessie in verborgen frame
		var url = 'shopDo.php?what=modify&products_key='+key+'&quantity='+iQuant;
		nullframe.document.location = url;
	}
}

// replacePunt
function replacePunt(iProductId){
	document.getElementById('grandtotal').innerHTML = document.getElementById('grandtotal').innerHTML.replace(",",".");
	document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML = document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML.replace(",",".");
	if(document.getElementById('extra_toeslag')){
		document.getElementById('extra_toeslag').innerHTML = document.getElementById('extra_toeslag').innerHTML.replace(",",".");
	}
	document.getElementById('xtra_toeslag').innerHTML = document.getElementById('xtra_toeslag').innerHTML.replace(",",".");

} // function replacePunt()

// replaceKomma
function replaceKomma(iProductId){
	if(document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML.substr(13,1) == "."){
		document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML = '&euro;&nbsp;&nbsp;0' + document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML.substr(13,document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML.length);
	}
	document.getElementById('grandtotal').innerHTML = document.getElementById('grandtotal').innerHTML.replace(".",",");
	document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML = document.getElementById('shop_basket_Order_price_total'+iProductId).innerHTML.replace(".",",");
	if(document.getElementById('extra_toeslag')){
		document.getElementById('extra_toeslag').innerHTML = document.getElementById('extra_toeslag').innerHTML.replace(".",",");
	}
	document.getElementById('xtra_toeslag').innerHTML = document.getElementById('xtra_toeslag').innerHTML.replace(".",",");

} // function replaceKomma()

// myReset()
function myReset( tf, iProductId ) {
	if(	isNaN(parseInt(tf.value)) ) {
		tf.value = document.getElementById('shop_basket_previous_' + iProductId).value;
	}
} // function myReset()
