/* author: Data Access Europe B.V. */ /* Creation date: 4-4-2006 */ /* This file handles all javascript functions for DataFlex CM webshop*/ var cDecimalSeparator = "."; var xmlreqs = new Array(); var bUpdateShippingPayment = false; function CXMLReq(freed) { this.freed = freed; this.xmlhttp = false; if (window.XMLHttpRequest) { this.xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } } function xmlhttpPostWS(sURL, bASynchronous) { var pos = -1; for (var i=0; i 10){ iMultiply = '1.' + iTax; } else { iMultiply = '1.0' + iTax; } iPrice_tax = iPrice * iMultiply; iPrice_tax = iPrice_tax.toFixed(2); if (isNaN(iPrice_tax)) { //return "Error in calculating tax price"; }else{ iPrice_tax = makeNumber(iPrice_tax); //iPrice_tax = iPrice_tax + ""; return makeDecimal(iPrice_tax); } } // End CalculateTax function CalculateTotal(){ var nSubTotalPrice = makeNumber(document.getElementById("sub_total").innerHTML); try { var oShippingSelect = document.getElementById("shipping_select") var nShippingPrice = makeNumber(oShippingSelect.options[oShippingSelect.selectedIndex].getAttribute('price')); }catch(err){ var nShippingPrice = 0; } try { var oPaymentSelect = document.getElementById("payment_select") var nPaymentPrice = makeNumber(oPaymentSelect.options[oPaymentSelect.selectedIndex].getAttribute('price')); }catch(err){ var nPaymentPrice = 0; } if (isNaN(nSubTotalPrice) || isNaN(nShippingPrice) || isNaN(nPaymentPrice) ) { try{document.getElementById("total_field").innerHTML = makeDecimal("0")}catch(err){}; }else{ var nOverallTotal = nSubTotalPrice + nShippingPrice + nPaymentPrice; try{document.getElementById("total_field").innerHTML = makeDecimal(nOverallTotal)}catch(err){}; } } function TotalProdPrice(iLoopId, iProdId, sFormName, iCartDtlId){ var iUnitPrice, iAmount, iTotalProdPrice, iLoop, iSubTotal, iAttributeCost; var oCoupon, oCartDtlRow, iLoopCoupon, sCouponType, iCouponValue, sPreference, iCount, iCouponPrice, iRowCount, iProductAmount; var anProductPrice = new Array(); iLoop = parseInt(document.getElementById("loop").value); if (document.getElementById("amount" + iLoopId).value != ""); iAmount = parseInt(document.getElementById("amount" + iLoopId).value); if (isNaN(iAmount) || (iAmount <=0 )) iAmount = 0; //Update quantity. if (document.getElementById("amount" + iLoopId).value != "" && (isNaN(document.getElementById("amount" + iLoopId).value) != true)){ sSaveQuantity = xmlhttpPostWS('./SaveProductQuantity.asp?CartDetailId=' + iCartDtlId + '&Amount=' + iAmount + '&QtyChanged=True', false) } iAttributeCost = makeNumber(document.getElementById("attributeprice" + iLoopId).innerHTML); var iProdUnitPrice = xmlhttpPostWS('./WebshopProductUnitPrice.asp?productid=' + iProdId + '&amount=' + iAmount, false) document.getElementById("unitprice" + iLoopId).innerHTML = iProdUnitPrice iUnitPrice = makeNumber(document.getElementById("unitprice" + iLoopId).innerHTML); if (isNaN(iAmount) || (iAmount <= 0)){ iTotalProdPrice = 0.00; if (iLoop <= 1) { check_nextstep(false); } }else{ iTotalProdPrice = (iUnitPrice + iAttributeCost) * iAmount; check_nextstep(true); } document.getElementById("totalprodprice" + iLoopId).innerHTML = makeDecimal(iTotalProdPrice); iSubTotal = 0.0; for (i=1; i<=iLoop; i++){ iSubTotal = (iSubTotal + makeNumber(document.getElementById("totalprodprice" + i).innerHTML)) } if(iSubTotal == 0.00) check_nextstep(false); document.getElementById("sub_total").innerHTML = makeDecimal(iSubTotal); CalculateTotal(); var sSubTotal = document.getElementById("sub_total").innerHTML; var sOrderTotal = document.getElementById("total_field").innerHTML; sRemoveCouponIds = xmlhttpPostWS('./RemoveCoupon.asp?ordertotal=' + sOrderTotal + '&subtotal=' + sSubTotal + '&productid=' + iProdId + '&amount=' + iAmount + '&CartDtlId=' + iCartDtlId, false) removeCouponRows(sRemoveCouponIds); //update coupon of type free product iLoopCoupon = parseInt(document.getElementById("loopcoupons").value); for(i=1; i<=iLoopCoupon; i++) { oCoupon = document.getElementById("CouponValue" + i) sCouponType = oCoupon.getAttribute('coupontype'); iCouponValue = makeNumber(oCoupon.getAttribute('value')); if (sCouponType == "Free Product" && iCouponValue == iProdId) { sPreference = oCoupon.getAttribute('preference'); iCount = 0; for (iRowCount=1; iRowCount<=iLoop; iRowCount++) { oCartDtlRow = document.getElementById("CartDtlRow" + iRowCount); iProductAmount = parseInt(document.getElementById("amount" + iRowCount).value); if (oCartDtlRow.getAttribute('productid') == iProdId && iProductAmount > 0) { anProductPrice[iCount] = makeNumber(document.getElementById("unitprice" + iRowCount).innerHTML) + makeNumber(document.getElementById("attributeprice" + iRowCount).innerHTML); iCount = iCount + 1; } } if (anProductPrice.length > 0) { anProductPrice.sort(function(a,b){return a - b}); if (sPreference == "0") iCouponPrice = anProductPrice[0]; else if(sPreference =="1") iCouponPrice = anProductPrice[anProductPrice.length - 1]; if(document.getElementById("CouponPrice" + i)) document.getElementById("CouponPrice" + i).innerHTML = makeDecimal("-" + iCouponPrice); } else { if(document.getElementById("CouponPrice" + i)) document.getElementById("CouponPrice" + i).innerHTML = makeDecimal("0"); } } } CalculateDiscount(); } function enablefields(status){ if (document.getElementById("ship_div")) { var ship_table = document.getElementById("ship_div"); //Enable field if (status == true){ ship_table.style.display = ""; }else{ ship_table.style.display = "none"; } } } function check_nextstep(status){ var next = document.getElementById("next") if (status == true){ next.disabled = false; next.src = 'Images/Webshop_Next.gif'; }else{ next.disabled = true; next.src = 'Images/Webshop_Next_Disabled.gif'; } } /* function make_decimal(price){ var iPrice, iPos; iPrice = price.toFixed(2); iPrice = iPrice+"";//convert to string iPrice = iPrice.replace(".",","); iPos = (iPrice.indexOf(",") + 1); if((iPrice.length - iPos) == 1) iPrice = iPrice + "0"; else if(iPos == 0) iPrice = iPrice + ",00"; return iPrice; }*/ //returns a number function makeNumber(sPrice){ var nNumber; sPrice = sPrice+""; if(cDecimalSeparator == ",") { if (sPrice.indexOf(",") > 0) { nNumber = parseFloat(sPrice.replace(",",".")); } else return (parseFloat(sPrice) + 0.0); } else nNumber = (parseFloat(sPrice) + 0.0); return nNumber; } // this functions makesure that the price has always 2 decimals. most have a . (dot) function makeDecimal(price){ var iPrice, iPos; var sPrice; iPrice = parseFloat(price); iPrice = iPrice.toFixed(2); sPrice = iPrice+"";//convert to string if (cDecimalSeparator == ",") sPrice = sPrice.replace(".", cDecimalSeparator); iPos = (sPrice.indexOf(cDecimalSeparator) + 1); if((sPrice.length - iPos) == 1) sPrice = sPrice + "0"; else if(iPos == 0) sPrice = sPrice + cDecimalSeparator + "00"; return sPrice; } function CalculateTotalDiscount() { var iLoop, iTotalDiscount, iDiscount; iLoop = parseInt(document.getElementById("loopcoupons").value); iTotalDiscount = 0.0; for (i=1; i<=iLoop; i++){ if (document.getElementById("CouponPrice" + i)) iDiscount = makeNumber(document.getElementById("CouponPrice" + i).innerHTML); else iDiscount = 0.0; iTotalDiscount = (iTotalDiscount + iDiscount); } document.getElementById("discount_total").innerHTML = makeDecimal(iTotalDiscount); document.getElementById("TotalWithoutDiscount").innerHTML = document.getElementById("total_field").innerHTML; var nOverallTotal = iTotalDiscount + makeNumber(document.getElementById("total_field").innerHTML); document.getElementById("OverallTotal").innerHTML = makeDecimal(nOverallTotal); } function CalculateDiscount() { var oCoupon, sCouponType, iCouponValue, iCouponPrice, nVat; try { var oShippingSelect = document.getElementById("shipping_select") var nShippingPrice = "-" + makeNumber(oShippingSelect.options[oShippingSelect.selectedIndex].getAttribute('price')); } catch(err) { var nShippingPrice = 0; } nTotal = makeNumber(document.getElementById("total_field").innerHTML); iLoop = parseInt(document.getElementById("loopcoupons").value); for(i=1; i<=iLoop; i++) { oCoupon = document.getElementById("CouponValue" + i) sCouponType = oCoupon.getAttribute('coupontype'); iCouponValue = makeNumber(oCoupon.getAttribute('value')); switch(sCouponType) { case "Percentage": iCouponPrice = ((nTotal * iCouponValue)/100); nVat = parseFloat('19') iCouponPrice = "-" + (((nVat + 100)/100) * iCouponPrice) if(document.getElementById("CouponPrice" + i)) document.getElementById("CouponPrice" + i).innerHTML = makeDecimal(iCouponPrice); break; case "Free Shipping": if(document.getElementById("CouponPrice" + i)) document.getElementById("CouponPrice" + i).innerHTML = makeDecimal(nShippingPrice); break; } } CalculateTotalDiscount(); } function removeCouponRows(sRemoveCouponIds) { var oTable, oRow, oCurrentRow; var iCount, iCouponId; var asCouponRow = new Array(); asCouponRow = sRemoveCouponIds.split(","); for (iCount=0; iCount