// JavaScript Document
// calculate price based on quantity
function changeQty(change){
    var currentQty = parseInt($F('quant')) // Where quant is the id of your quantity input field. Gets value of currentQty field
    
    switch (change) {
        case 'add':
            currentQty += 1
            $('quant').value = currentQty
            calculate()
            break
        case 'subtract':
            if (currentQty > 1) { // only subtract if qty is greater than zero
                currentQty -= 1
                $('quant').value = currentQty
                calculate()
            }
            break
        case 'field':
            if (currentQty > 0) {
                window.setTimeout('calculate()', 500)
            }
            break
    }
}
	/////////
      function number_format( number, decimals, dec_point, thousands_sep ) {
      // http://kevin.vanzonneveld.net
      // + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
      // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
      // + bugfix by: Michael White (http://crestidg.com)
      // + bugfix by: Benjamin Lupton
      // + bugfix by: Allan Jensen (http://www.winternet.no)
      // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
      // * example 1: number_format(1234.5678, 2, '.', '');
      // * returns 1: 1234.57
      var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
      var d = dec_point == undefined ? "," : dec_point;
      var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
      var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
      return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
      }
	//////////
function calculate(){
	var currentQty = parseInt($F('quant')) // Where quant is the id of your quantity input field. Gets value of currentQty field    
	var jsnormalprice = $F('jsnormalprice') // Where jsnormalprice is the id of your hidden base price field. Gets value of base_price field	
	var jsspecialprice = $F('jsspecialprice') // Where  is the id of your hidden base price field. Gets value of base_price field	

	if (currentQty > 0) { // Don't want price to display if zero if customer zeros out quantity
        var new_jsnormalprice = jsnormalprice * currentQty // Calculate the price.		
        var new_jsnormalprice = new_jsnormalprice.toFixed(2) // Only allow 2 decimals. I'll let you add rounding features up or down.
		
        var new_jsspecialprice = jsspecialprice * currentQty // Calculate the price.		
        var new_jsspecialprice = new_jsspecialprice.toFixed(2) // Only allow 2 decimals. I'll let you add rounding features up or down.
    
	} else { // set price back to original price
        new_jsnormalprice = jsnormalprice
        new_jsspecialprice = jsspecialprice
    }	

	        new_jsnormalprice = number_format(new_jsnormalprice, 2, ",", ".") + '&euro;'
			new_jsspecialprice = number_format(new_jsspecialprice, 2, ",", ".") + '&euro;'
    $('jsnormalpriceshow').update(new_jsnormalprice) // Where jsnormalpriceshow is the id of your span for the echoed product price
    $('jsspecialpriceshow').update(new_jsspecialprice) // Where jsspecialpriceshow is the id of your span for the echoed product price

}


