function buyUrl(p_stockRg, p_pdlsOrg) { var buyqty = document.getElementById("buy_qty_"+p_stockRg+"_"+p_pdlsOrg).value; var selectUnitEle = document.getElementById("select_unit_"+p_stockRg+"_"+p_pdlsOrg); var isBtl = ""; if (selectUnitEle == null) { isBtl = "N"; } else { var index = selectUnitEle.selectedIndex; var select_value = selectUnitEle.options[index].value; if (select_value == "btl") { isBtl = "Y"; } else { isBtl = "N"; } } //alert(isBtl); if (buyqty <= 0 || buyqty == null) { document.getElementById("qtyErMsg_"+p_stockRg+"_"+p_pdlsOrg).innerHTML = (getLanguage() == 0) ? "購買數量不能為空,且必須大于 0" : "購買數量不能為空,;且必須大于 0"; } else { var url = "/winecave/cleanShoppingCart.jsp?" +"action=add" +"&stIrg="+p_stockRg +"&pdlsOrg="+p_pdlsOrg +"&qty="+buyqty +"&isBtl="+isBtl ; cleanGetUrl(url, null, afterBuyUrl, {"buyqtyId":p_stockRg+"_"+p_pdlsOrg, "buyqty":buyqty, "isBtl":isBtl}); } } function afterBuyUrl(p_status, p_consumer, p_request, p_params) { if (p_status < 200 || p_status > 299) { alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668"); return; } var xmlDoc = p_request.responseXML; var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; if (status == "OK") { shoppingOKTips("buyurl_"+p_params["buyqtyId"], (getLanguage() == 0) ? "Item added to shopping cart" : "已經加入購物車" ); var totalqty = xmlDoc.getElementsByTagName("totalQuantity")[0].childNodes[0].nodeValue; document.getElementById("totalqty1").innerHTML = totalqty; var stockBtlQuantity = xmlDoc.getElementsByTagName("stockBtlQuantity")[0].childNodes[0].nodeValue; var stockCsQuantity = xmlDoc.getElementsByTagName("stockCsQuantity")[0].childNodes[0].nodeValue; var buyqtyEl = document.getElementById("buy_qty_"+p_params["buyqtyId"]); var buyqty = p_params["buyqty"]; var attCsQty = parseInt(buyqtyEl.getAttribute("csqty")); var attPdlsQty = parseInt(buyqtyEl.getAttribute("pdlsqty")); var attSaleStatus = buyqtyEl.getAttribute("salestatus"); if (attSaleStatus == "Y") { buyqtyEl.setAttribute("pdlsqty", attPdlsQty - buyqty); } else { buyqtyEl.setAttribute("csqty", attCsQty - buyqty); } if (stockCsQuantity <= 0) { var selectUnitEle = document.getElementById("select_unit_"+p_params["buyqtyId"]); if (selectUnitEle != null) { var options = selectUnitEle.options; if (options != null) { for (var i=options.length-1; i>=0; i--) { var option = options[i]; if (option.value == "cs") { selectUnitEle.remove(i); } } } } else { document.getElementById("buy_qty_"+p_params["buyqtyId"]).disabled = true; document.getElementById("buy_qty_"+p_params["buyqtyId"]).value = ""; document.getElementById("buyurl_"+p_params["buyqtyId"]).setAttribute("disabled", "disabled"); document.getElementById("buyurl_"+p_params["buyqtyId"]).className = (getLanguage() == 0) ? "eng-grey" : "chi-grey"; } } if (stockBtlQuantity <= 0 && stockCsQuantity <= 0) { document.getElementById("buy_qty_"+p_params["buyqtyId"]).disabled = true; document.getElementById("buy_qty_"+p_params["buyqtyId"]).value = ""; document.getElementById("buyurl_"+p_params["buyqtyId"]).setAttribute("disabled", "disabled"); document.getElementById("buyurl_"+p_params["buyqtyId"]).className = (getLanguage() == 0) ? "eng-grey" : "chi-grey"; //var elemSelectUnit = document.getElementById("select_unit_"+p_params["buyqtyId"]); if (document.getElementById("select_unit_"+p_params["buyqtyId"]) != null) { document.getElementById("select_unit_"+p_params["buyqtyId"]).setAttribute("disabled", "disabled"); //elemSelectUnit.setAttribute("disabled", "disabled"); } } document.getElementById("qtyErMsg_"+p_params["buyqtyId"]).innerHTML = ''; } else { var isBtl = p_params["isBtl"]; var errorMessage = xmlDoc.getElementsByTagName("errorMessage")[0].childNodes[0].nodeValue; var errorMessageText = (getLanguage() == 0) ? "Dont more than " : "\u6700\u591a\u53ea\u80fd\u8cfc\u8cb7 "; var elemQtyErMsg = document.getElementById("qtyErMsg_"+p_params["buyqtyId"]); if (isBtl == 'Y') { var btlUnit = (getLanguage() == 0) ? " Btl" : " \u652f"; elemQtyErMsg.innerHTML = errorMessageText + errorMessage + btlUnit; } else { var csUnit = (getLanguage() == 0) ? " Cs" : " \u7bb1"; elemQtyErMsg.innerHTML = errorMessageText + errorMessage + csUnit; } } } function onProductClick(p_pidx) { var selectedall = document.getElementsByName("selected"); var i = 0; for (; i 299) { alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668"); return; } var xmlDoc = p_request.responseXML; var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; if (status == "OK") { var peoductssize = xmlDoc.getElementsByTagName("getProductsSize")[0].childNodes[0].nodeValue; var totalqty = xmlDoc.getElementsByTagName("totalQuantity")[0].childNodes[0].nodeValue; //document.getElementById("totalqty1").innerHTML = totalqty; document.getElementById("totalqty2").innerHTML = totalqty; var totalAmount = xmlDoc.getElementsByTagName("totalAmount")[0].childNodes[0].nodeValue; document.getElementById("totalAmount1").innerHTML = "(HKD)"+totalAmount; document.getElementById("totalAmount2").innerHTML = "(HKD)"+totalAmount; var stringSelectedProductId = xmlDoc.getElementsByTagName("stringSelectedProductId")[0].childNodes[0].nodeValue; var selectedProductId = stringSelectedProductId.split(","); for (var i = 0; i < selectedProductId.length; i++) { var itemProductEl = document.getElementById("item_"+selectedProductId[i]); itemProductEl.parentElement.removeChild(itemProductEl); } if (peoductssize <= 0) { document.getElementById("ccartc").style.display = "None"; document.getElementById("cartempty").style.display = ""; } } else { alert((getLanguage() == 0) ? "Remove Failed" : "刪除失敗"); } } function checkAll(item) { var selectedall = document.getElementsByName("selected"); for (var i=0; i 299) { alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668"); return; } var xmlDoc = p_request.responseXML; var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; if (status == "OK") { var totalqty = xmlDoc.getElementsByTagName("totalQuantity")[0].childNodes[0].nodeValue; //document.getElementById("totalqty1").innerHTML = totalqty; document.getElementById("totalqty2").innerHTML = totalqty; var totalAmount = xmlDoc.getElementsByTagName("totalAmount")[0].childNodes[0].nodeValue; document.getElementById("totalAmount1").innerHTML = "(HKD)"+totalAmount; document.getElementById("totalAmount2").innerHTML = "(HKD)"+totalAmount; } else { alert((getLanguage() == 0) ? "Check All Failed" : "全選失敗"); } } function qtyUpdate(p_kind, p_productid){ var buynum = 0; var updateQty = 0; var buyQtyEl = document.getElementById("buy_num_"+p_productid); var buyqty = buyQtyEl.value; var oldQty = parseInt(buyQtyEl.getAttribute("oldqty")); var attCsQty = parseInt(buyQtyEl.getAttribute("csqty")); var attBtlQty = parseInt(buyQtyEl.getAttribute("btlqty")); var attSize1 = parseInt(buyQtyEl.getAttribute("size1")); var attIsBtl = buyQtyEl.getAttribute("isbtl"); //alert ("qtyUpdate:" + p_productid + ":"+ updateQty + "," + buyqty + "," + oldQty + "," + attCsQty + "," + attBtlQty + "," + attSize1 + "," + attIsBtl); if (attIsBtl == "Y") { updateQty = attCsQty * attSize1 + attBtlQty; } else { updateQty = attCsQty; } buynum = oldQty; if(p_kind == "up") { if (buyqty >= updateQty) { updateQtyTips("buy_num_"+p_productid, ((getLanguage() == 0) ? "Quantity cannot be greater than " : "填寫數量不能大于 ") + updateQty); buynum = updateQty; } else { buyqty++; buynum = buyqty; } } else if(p_kind == "down"){ if(buyqty > 1) { buyqty--; buynum = buyqty; } else { removeDownProductDialog(p_productid); buynum = 1; } } else if(p_kind == "num"){ if (buyqty == null) { updateQtyTips("buy_num_"+p_productid, ((getLanguage() == 0) ? "Please enter purchase quantity!" : "輸入數量不能為空!")); // buynum = 1; } else if (buyqty.replace(/[^0-9]/g,'') != buyqty ) { // updateQtyTips("buy_num_"+p_productid, "只能填寫數字!"); updateQtyTips("buy_num_"+p_productid, ((getLanguage() == 0) ? "Please enter purchase quantity!" : "輸入數量不能為空!")); // buynum = 1; } else if (buyqty == 0) { updateQtyTips("buy_num_"+p_productid, ((getLanguage() == 0) ? "Please enter purchase quantity!" : "輸入數量不能為空!")); // buynum = 1; } else { buynum = buyqty; } } document.getElementById("buy_num_"+p_productid).value = buynum; //buyQtyEl.setAttribute("oldqty", buynum); if (oldQty != buynum) { var url = "/winecave/cleanShoppingCart.jsp?" +"action=qtyupdate" +"&pidx="+p_productid +"&buyqty="+buynum ; cleanGetUrl(url, null, afterQtyUpdate, {"productId": p_productid, "oldQty" : oldQty}); } } function afterQtyUpdate(p_status, p_consumer, p_request, p_params) { var p_productid = p_params["productId"] var buyQtyEl = document.getElementById("buy_num_"+p_productid); if (p_status < 200 || p_status > 299) { buyQtyEl.value = p_params["oldQty"]; alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668"); return; } var xmlDoc = p_request.responseXML; var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; if (status == "OK") { var totalqty = xmlDoc.getElementsByTagName("totalQuantity")[0].childNodes[0].nodeValue; //document.getElementById("totalqty1").innerHTML = totalqty; document.getElementById("totalqty2").innerHTML = totalqty; var totalAmount = xmlDoc.getElementsByTagName("totalAmount")[0].childNodes[0].nodeValue; document.getElementById("totalAmount1").innerHTML = "(HKD)"+totalAmount; document.getElementById("totalAmount2").innerHTML = "(HKD)"+totalAmount; var buynum = buyQtyEl.value; buyQtyEl.setAttribute("oldqty", buynum); if (buynum >= 1) { updateQtyTips("buy_num_"+p_productid, ((getLanguage() == 0) ? "Quantity changed!
Item price is: "+totalAmount : "商品數量修改成功!
商品金額為:"+totalAmount)); } } else { var errorMessage = xmlDoc.getElementsByTagName("errorMessage")[0].childNodes[0].nodeValue; buyQtyEl.value = p_params["oldQty"]; updateQtyTips("buy_num_"+p_productid, errorMessage); } } function updateQtyTips(p_id, p_text) { layer.tips(p_text, $( "#"+p_id ), { guide: 0, style: ['background-color:#fFd5d5; color:#f00', '#fFd5d5'], maxWidth:200, closeBtn:[0,true], time:1 }); } function shoppingOKTips(p_id, p_text) { layer.tips(p_text, $( "#"+p_id ), { guide: 0, style: ['background-color:#e43f45; color:#fff;font-weight:bold', '#e43f45'], maxWidth:200, closeBtn:[0,true], time:1 }); } function comfirmbtn() { var deliveryMethod = ""; var deliveryMethodId = ""; var deliveryAddress = ""; var addressType = ""; var paymentMethod = ""; var discount = ""; var deliveryCharge = ""; var els = document.getElementsByName("radiodm"); for (var i=0; i 299) { alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668"); return; } var xmlDoc = p_request.responseXML; var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; if (status == "OK") { var invoiceRg = xmlDoc.getElementsByTagName("invoiceRg")[0].childNodes[0].nodeValue; var invoiceUrl = xmlDoc.getElementsByTagName("invoiceUrl")[0].childNodes[0].nodeValue; var paymentMethod = xmlDoc.getElementsByTagName("paymentMethod")[0].childNodes[0].nodeValue; document.getElementById("invoice_rg").value = invoiceRg; document.getElementById("invoice_id").value = invoiceUrl; document.getElementById("payment_method").value = paymentMethod; document.frmComfirm.submit(); } else { var errorMessage = xmlDoc.getElementsByTagName("errorMessage")[0].childNodes[0].nodeValue; alert((getLanguage() == 0) ? "This Order Cann't Be Processed Reason!\n\n"+errorMessage : "This Order Cann't Be Processed Reason!\n\n"+errorMessage); } } function deliveryMethod() { //var radioSpEl = document.getElementById("radioSp"); var radioLdEl = document.getElementById("radioLd"); var personAddressIdEl = document.getElementById("personAdressId"); if (radioLdEl.checked) { personAddressIdEl.style.display = ""; // document.getElementById("freightId").innerHTML = "120"; } else { personAddressIdEl.style.display = "none"; // document.getElementById("freightId").innerHTML = "0"; } checkoutRecalAmount(); } function deliveryAddress(p_addressId) { var radioAddress1El = document.getElementById("radioAddress1"); var radioAddress2El = document.getElementById("radioAddress2"); var radioAddressOtherEl = document.getElementById("radioAddressOther"); var liAddress1Bg = document.getElementById("liAddress1"); var liAddress2Bg = document.getElementById("liAddress2"); var liAddressOtherBg = document.getElementById("liAddressOther"); var inputAddressOtherEl = document.getElementById("otherAddressId"); var addressTypeOtherEl = document.getElementById("otherAddressType"); if (radioAddress1El.checked == p_addressId.checked) { liAddress1Bg.className = "libg"; liAddress2Bg.className = ""; liAddressOtherBg.className = ""; inputAddressOtherEl.style.display = "none"; addressTypeOtherEl.style.display = "none"; } else if (radioAddress2El.checked == p_addressId.checked) { liAddress1Bg.className = ""; liAddress2Bg.className = "libg"; liAddressOtherBg.className = ""; inputAddressOtherEl.style.display = "none"; addressTypeOtherEl.style.display = "none"; } else if (radioAddressOtherEl.checked == p_addressId.checked) { liAddress1Bg.className = ""; liAddress2Bg.className = ""; liAddressOtherBg.className = "libg"; inputAddressOtherEl.style.display = ""; addressTypeOtherEl.style.display = ""; } checkoutRecalAmount(); } var g_SaveBuyNum = 0; //var btlQty = 0; function setAmount(p_stirg, p_pdlsorg){ var buyNumInputId = document.getElementById("buy_qty_"+p_stirg+"_"+p_pdlsorg); if(buyNumInputId.value.length==1){ if (buyNumInputId.value == 0) buyNumInputId.value = 1; else buyNumInputId.value = buyNumInputId.value.replace(/[^1-9]/g,''); }else{ if (buyNumInputId.value != buyNumInputId.value.replace(/\D/g,'')) buyNumInputId.value = buyNumInputId.value.replace(/\D/g,''); } var attCsQty = parseInt(buyNumInputId.getAttribute("csqty")); var attStockQty = parseInt(buyNumInputId.getAttribute("stockqty")); //var attSize1 = parseInt(buyNumInputId.getAttribute("size1")); var attSaleStatus = buyNumInputId.getAttribute("salestatus"); if (attSaleStatus=="Y") { var selectUnitEle = document.getElementById("select_unit_"+p_stirg+"_"+p_pdlsorg); var index = selectUnitEle.selectedIndex; var select_value = selectUnitEle.options[index].value; if (select_value=="btl") { //var btlQty = attCsQty * attSize1 + attPdlsQty; if (buyNumInputId.value > attStockQty){ buyNumInputId.value = attStockQty; document.getElementById("qtyErMsg_"+p_stirg+"_"+p_pdlsorg).innerHTML = (getLanguage() == 0) ? "最多可以購買 "+attStockQty+" BTL(s)" : "最多可以購買"+attStockQty+" BTL(s)"; } else { g_SaveBuyNum = buyNumInputId.value; } } else { if (buyNumInputId.value > attCsQty){ buyNumInputId.value = attCsQty; document.getElementById("qtyErMsg_"+p_stirg+"_"+p_pdlsorg).innerHTML = (getLanguage() == 0) ? "最多可以購買 "+attCsQty+" Cs" : "最多可以購買"+attCsQty+" Cs"; } else { g_SaveBuyNum = buyNumInputId.value; } } } else { if (buyNumInputId.value > attCsQty){ buyNumInputId.value = attCsQty; document.getElementById("qtyErMsg_"+p_stirg+"_"+p_pdlsorg).innerHTML = (getLanguage() == 0) ? "最多可以購買 "+attCsQty+" Cs" : "最多可以購買"+attCsQty+" Cs"; } else { g_SaveBuyNum = buyNumInputId.value; } } } function printDivImg(p_printImg) { var imageId = document.getElementById(p_printImg); printImage(imageId); } function printImage(p_imageId) { /* var printWindow = window.open('', 'Print Window','height=500,width=965'); printWindow.document.write('Print Window'); printWindow.document.write(''); printWindow.document.close(); printWindow.print(); */ var strHtml = '\n'; strHtml += '\n'; strHtml += ' Print Window\n'; strHtml += ' \n'; strHtml += '\n'; strHtml += '\n'; strHtml += '\n'; strHtml += '\n'; strHtml += '\n'; var printWindow = window.open('', '','width=965,height=500'); printWindow.document.open(); printWindow.document.write(strHtml); printWindow.document.close(); } function checkoutRecalAmount() { // alert("checkoutRecalAmount"); var radioLdEl = document.getElementById("radioLd"); //Local Delivery Radio var radioAddress1E1 = document.getElementById("radioAddress1"); var radioAddress2E1 = document.getElementById("radioAddress2"); var radioAddressOtherE1 = document.getElementById("radioAddressOther"); var address1TypeE1 = document.getElementById("address1Type"); var address2TypeE1 = document.getElementById("address2Type"); var addressTypeOtherEl = document.getElementById("otherAddressType"); var paymentMethod = $("input[name='radiopm']:checked").val(); if (radioLdEl.checked) { var addrType = ""; if (radioAddress1E1.checked) addrType = address1TypeE1.value; else if (radioAddress2E1.checked) addrType = address2TypeE1.value; else if (radioAddressOtherE1.checked) addrType = addressTypeOtherEl.value; var url = "/winecave/cleanShoppingCart.jsp?" +"action=gettotal" +"&delimethod="+urlencode("Local Delivery") +"&delidistrict="+urlencode(addrType) +"&paymentmethod="+urlencode(paymentMethod) ; } else { var url = "/winecave/cleanShoppingCart.jsp?" +"action=gettotal" +"&delimethod="+urlencode("Self Pickup") +"&delidistrict=None" +"&paymentmethod="+urlencode(paymentMethod) ; } cleanGetUrl(url, null, afterRecalAmount); } function afterRecalAmount(p_status, p_consumer, p_request) { if (p_status < 200 || p_status > 299) { alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668"); return; } var xmlDoc = p_request.responseXML; var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; if (status == "OK") { //var totalqty = xmlDoc.getElementsByTagName("totalQuantity")[0].childNodes[0].nodeValue; //document.getElementById("totalqty2").innerHTML = totalqty; //var totalAmount = xmlDoc.getElementsByTagName("totalAmount")[0].childNodes[0].nodeValue; //document.getElementById("totalAmount1").innerHTML = "(HKD)"+totalAmount; //document.getElementById("totalAmount2").innerHTML = "(HKD)"+totalAmount; // alert("selected ok "+xmlDoc); var totalAmount = xmlDoc.getElementsByTagName("totalAmount")[0].childNodes[0].nodeValue; // alert("selected total "+totalAmount); var discountAmount = xmlDoc.getElementsByTagName("discountAmount")[0].childNodes[0].nodeValue; // alert("selected discount "+discountAmount); var freightAmount = xmlDoc.getElementsByTagName("freightAmount")[0].childNodes[0].nodeValue; // alert("selected freight "+freightAmount); var paidAmount = xmlDoc.getElementsByTagName("paidAmount")[0].childNodes[0].nodeValue; // alert("selected paid "+paidAmount); document.getElementById("totalamtId").innerHTML = "(HKD)"+totalAmount; document.getElementById("discountId").innerHTML = discountAmount; document.getElementById("freightId").innerHTML = freightAmount; document.getElementById("paidId").innerHTML = paidAmount; document.getElementById("paidId1").innerHTML = "(HKD)"+paidAmount; } else { alert("selected fail"); } }