var CloseBut1 = new Image(); var CloseBut2 = new Image(); var plusImg = new Image(); var minusImg = new Image(); var checkoutImg = new Image(); var clearCartImg = new Image(); CloseBut1.src = "/proimages/LEX/closeButton1.gif"; CloseBut2.src = "/proimages/LEX/closeButton.gif"; plusImg.src = "/proimages/LEX/plus.gif"; minusImg.src = "/proimages/LEX/minus.gif"; checkoutImg.src = "/proimages/LEX/checkout.gif"; clearCartImg.src = "/proimages/LEX/clearcart.gif"; function startFlying(flyId){ var flyObj = new fly(); flyObj.flyId = flyId; flyObj.stopId = 'cart'; flyObj.dummyref = 'flydummy'; flyObj.dummyId = 'dummy_' + flyId; // flyObj.dummyId = 'flydummy'; flyObj.flyStopFn[0] = 'putInSession'; flyStopObj = document.getElementById(flyObj.stopId); flyStopObj.className = 'visibleObj'; document.getElementById('cartCont').style.visibility = 'visible'; flyObj.startFly(); } function cartStatus(){ var flyObj = new fly(); var cartTbl = document.getElementById('cart'); var statusObj = cartTbl.tBodies[0].rows[0].cells[0]; if((cartTbl.tBodies[0].rows.length == 5) && (cartTbl.tBodies[0].rows[0].innerHTML.indexOf('order') >=0) ) { cartTbl.tBodies[0].rows[0].cells[1].innerHTML = ''; statusObj.innerHTML = ''; statusObj.style.paddingRight = "10px"; statusObj.style.textAlign = 'right'; statusObj.className = 'crtEmpty'; statusObj.innerHTML = 'Cart is Empty.'; cartTbl.deleteRow(1); cartTbl.deleteRow(1); cartTbl.deleteRow(1); cartTbl.deleteRow(1); }else if(cartTbl.tBodies[0].rows.length > 1) { var statusObj1 = cartTbl.tBodies[0].rows[0].cells[0]; statusObj1.colSpan = 2; statusObj.style.textAlign = 'left'; statusObj1.style.paddingLeft = "10px"; statusObj1.style.paddingTop = "2px"; statusObj1.style.paddingBottom = "2px"; statusObj1.innerHTML = ''; var statusObj = cartTbl.tBodies[0].rows[0].cells[1]; statusObj.innerHTML = 'Continue Shopping Check out'; statusObj.colSpan = 4; statusObj.style.width = '400px'; statusObj.style.textAlign = 'right'; statusObj.style.paddingRight = "0px"; if(cartTbl.tBodies[0].rows.length>1) { if (cartTbl.tBodies[0].rows[1].innerHTML.indexOf('hrId1')<0) { var totalRowObj = cartTbl.tBodies[0].insertRow(1); var totalCellObj = totalRowObj.insertCell(totalRowObj.cells.length); totalCellObj.colSpan = 6; totalCellObj.innerHTML = "
"; } } var totalCur = 0; var maxRows = cartTbl.tBodies[0].rows.length; if(cartTbl.tBodies[0].rows[maxRows-1].innerHTML.indexOf('orders.php') < 0) { var totalRowObj = cartTbl.tBodies[0].insertRow((maxRows)); var totalCellObj = totalRowObj.insertCell(totalRowObj.cells.length); totalCellObj.colSpan = 5; totalCellObj.innerHTML = "Total:"; totalCellObj.className = 'crtTotal'; var totalCellObj = totalRowObj.insertCell(totalRowObj.cells.length); totalCellObj.className = 'crtTotal'; var dummyRows = maxRows; }else{ var totalCellObj = cartTbl.tBodies[0].rows[(maxRows-3)].cells[1]; var dummyRows = (maxRows-3); } for(var i=2; i<(dummyRows); i++) { var curCell = cartTbl.tBodies[0].rows[i]; var prodIdArr = curCell.id.split('_'); prodId = prodIdArr[prodIdArr.length - 1]; var curStr = parseFloat(document.getElementById('price_' + prodId).innerHTML) * parseFloat(document.getElementById('qtyx_image_' + prodId).value); totalCur += parseFloat(curStr); } totalCellObj.innerHTML = flyObj.currency + number_format(totalCur,2); var maxRows = cartTbl.tBodies[0].rows.length; if(cartTbl.tBodies[0].rows[maxRows-1].innerHTML.indexOf('orders.php') < 0) { var totalRowObj = cartTbl.tBodies[0].insertRow(maxRows); var totalCellObj = totalRowObj.insertCell(totalRowObj.cells.length); totalCellObj.colSpan = 6; totalCellObj.innerHTML = "
"; } var maxRows = cartTbl.tBodies[0].rows.length; var totalRowObj = cartTbl.tBodies[0].rows[maxRows - 1]; if(totalRowObj.innerHTML.indexOf('orders.php') < 0 ) { var totalRowObj = cartTbl.tBodies[0].insertRow(maxRows); var totalCellObj = totalRowObj.insertCell(totalRowObj.cells.length); totalCellObj.colSpan = 6; totalCellObj.style.paddingRight = "0px"; totalCellObj.style.paddingTop = "2px"; totalCellObj.style.paddingBottom = "2px"; totalCellObj.style.textAlign = "right"; totalCellObj.innerHTML = 'Continue Shopping Check out'; totalCellObj.className = 'cellpad'; var totalCellObj = totalRowObj.insertCell(totalRowObj.cells.length); }else { var totalCellObj = totalRowObj.cells[1]; totalCellObj.innerHTML = ''; } chkOut1.src = checkoutImg.src; }else{ cartTbl.tBodies[0].rows[0].cells[0].innerHTML = ''; var statusObj = cartTbl.tBodies[0].rows[0].cells[1]; statusObj.innerHTML = ''; statusObj.style.paddingRight = "10px"; statusObj.style.textAlign = 'right'; statusObj.className = 'crtEmpty'; statusObj.innerHTML = 'Cart is Empty.'; } } function addToCart(flyId, qty){ var productinfoArr = flyId.split('_'); var prodId = productinfoArr[productinfoArr.length - 1]; var flyObj = new fly(); flyObj.stopId = 'cart'; flyStopObj = document.getElementById(flyObj.stopId); var newCartObjId = 'cart_' + flyId; var productNameObj = document.getElementById('name_' + prodId); var productPriceObj = document.getElementById('price_' + prodId); var productImgObj = document.getElementById('image_' + prodId); var prodObj = flyStopObj.tBodies[0].insertRow(flyStopObj.rows.length); prodObj.id = newCartObjId; prodObj.className = "cartEntry"; var prodImageObj = prodObj.insertCell(prodObj.cells.length); prodImageObj.id = 'image_' + flyId; prodImageObj.className = 'pname'; var prodNameObj = prodObj.insertCell(prodObj.cells.length); prodNameObj.id = 'name_' + flyId; prodNameObj.className = 'crtName'; var minusObj = prodObj.insertCell(prodObj.cells.length); minusObj.id = 'minus_' + flyId; minusObj.className = 'crtPlus'; minusImgObj = document.createElement('IMG'); minusImgObj.id = 'minusx_' + flyId; minusImgObj.src = minusImg.src; minusObj.appendChild(minusImgObj); var prodQtyObj = prodObj.insertCell(prodObj.cells.length); prodQtyObj.id = 'qty_' + flyId; prodQtyObj.className = 'crtQty'; qtyTextObj = document.createElement('INPUT'); qtyTextObj.id = 'qtyx_' + flyId; qtyTextObj.className = 'crtQtyTxt'; qtyTextObj.maxLength=3; qtyTextObj.readOnly=true; prodQtyObj.appendChild(qtyTextObj); var plusObj = prodObj.insertCell(prodObj.cells.length); plusObj.id = 'plus_' + flyId; plusObj.className = 'crtPlus'; plusImgObj = document.createElement('IMG'); plusImgObj.id = 'plusx_' + flyId; plusImgObj.src = plusImg.src; plusObj.appendChild(plusImgObj); var prodPriceObj = prodObj.insertCell(prodObj.cells.length); prodPriceObj.id = 'price_' + flyId; prodPriceObj.className = 'crtPrice'; prodImageObj.innerHTML = productImgObj.innerHTML; prodNameObj.innerHTML = productNameObj.innerHTML; qtyTextObj.value = qty; prodPriceObj.innerHTML = flyObj.currency + number_format(parseFloat(parseInt(qty, 10) * parseFloat(productPriceObj.innerHTML, 10), 10),2); plusImgObj.qtyId = qtyTextObj.id; plusImgObj.qty = 0; plusImgObj.priceId = prodPriceObj.id; plusImgObj.price = productPriceObj.innerHTML; plusImgObj.flyObj = flyObj; plusImgObj.productId = prodId; plusImgObj.onclick = function(e){ var status = true; this.qty = parseFloat(document.getElementById(this.qtyId).value); if(status) { this.qty++; document.getElementById(this.qtyId).value = this.qty; document.getElementById(this.priceId).innerHTML = this.flyObj.currency + number_format(parseFloat(this.price * this.qty),2); var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'incItem'; ajaxVar.vars["args"] = this.productId; ajaxVar.gotoFunction = "doNothing"; ajaxVar.AjaxPostSQL(); } }; // to put the delete qty code minusImgObj.qtyId = qtyTextObj.id; minusImgObj.qty = 0; minusImgObj.priceId = prodPriceObj.id; minusImgObj.price = productPriceObj.innerHTML; minusImgObj.flyObj = flyObj; minusImgObj.productId = prodId; minusImgObj.onclick = function(e){ this.qty = parseFloat(document.getElementById(this.qtyId).value); var status = true; if(status) { if(this.qty == 1) { this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'delItem'; ajaxVar.vars["args"] = this.productId; ajaxVar.gotoFunction = "doNothing"; ajaxVar.AjaxPostSQL(); }else{ this.qty--; qty = this.qty; document.getElementById(this.qtyId).value = this.qty; document.getElementById(this.priceId).innerHTML = this.flyObj.currency + number_format(parseFloat(this.price * this.qty),2); var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'decItem'; ajaxVar.vars["args"] = this.productId; ajaxVar.gotoFunction = "doNothing"; ajaxVar.AjaxPostSQL(); } } }; } function putInSession(flyObj){ var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'addItem'; var productinfoArr = flyObj.flyId.split('_'); var productId = productinfoArr[productinfoArr.length - 1]; var productImage = document.getElementById('image_' + productId).innerHTML; var productName = document.getElementById('name_' + productId).innerHTML; var productPrice = document.getElementById('price_' + productId).innerHTML; var productQty = 1; ajaxVar.vars["args[0]"] = productId; ajaxVar.vars["args[1]"] = productName; ajaxVar.vars["args[2]"] = productPrice; ajaxVar.vars["args[3]"] = productQty; ajaxVar.fnVars['obj'] = flyObj; ajaxVar.gotoFunction = "putInCart"; ajaxVar.AjaxPostSQL(); } function doNothing(data, fnVars){ cartStatus(); } function putInCart(data, fnVars){ if(data == 1 || data.indexOf('done')>=0){ flyObj = fnVars['obj']; clearTimeout(flyObj.flyTime[flyObj.flyId]); var flyObject = document.getElementById(flyObj.flyId); var flyStopObj = document.getElementById(flyObj.stopId); var flyingObj = document.getElementById(flyObj.dummyId); var productinfoArr = flyObj.flyId.split('_'); var productId = productinfoArr[productinfoArr.length - 1]; var productNameObj = document.getElementById('name_' + productId); var productPriceObj = document.getElementById('price_' + productId); var newCartObjId = 'cart_' + flyObj.flyId; var prodObj = document.getElementById(newCartObjId); if(prodObj) { var prodImageObj = document.getElementById('image_' + flyObj.flyId); var prodNameObj = document.getElementById('name_' + flyObj.flyId); var prodQtyObj = document.getElementById('qty_' + flyObj.flyId); var qtyTextObj = document.getElementById('qtyx_' + flyObj.flyId); var prodPriceObj = document.getElementById('price_' + flyObj.flyId); var plusImgObj = document.getElementById('plusx_' + flyObj.flyId); var minusImgObj = document.getElementById('minusx_' + flyObj.flyId); }else{ var prodObj = flyStopObj.tBodies[0].insertRow((flyStopObj.rows.length == 1) ? flyStopObj.rows.length : flyStopObj.rows.length - 3); prodObj.id = newCartObjId; prodObj.className = "cartEntry"; var prodImageObj = prodObj.insertCell(prodObj.cells.length); prodImageObj.id = 'image_' + flyObj.flyId; prodImageObj.className = 'pname'; var prodNameObj = prodObj.insertCell(prodObj.cells.length); prodNameObj.id = 'name_' + flyObj.flyId; prodNameObj.className = 'crtName'; var minusObj = prodObj.insertCell(prodObj.cells.length); minusObj.id = 'minus_' + flyObj.flyId; minusObj.className = 'crtPlus'; minusImgObj = document.createElement('IMG'); minusImgObj.id = 'minusx_' + flyObj.flyId; minusImgObj.src = minusImg.src; minusObj.appendChild(minusImgObj); var prodQtyObj = prodObj.insertCell(prodObj.cells.length); prodQtyObj.id = 'qty_' + flyObj.flyId; prodQtyObj.className = 'crtQty'; qtyTextObj = document.createElement('INPUT'); qtyTextObj.id = 'qtyx_' + flyObj.flyId; qtyTextObj.className = 'crtQtyTxt'; qtyTextObj.maxLength=3; qtyTextObj.readOnly=true; prodQtyObj.appendChild(qtyTextObj); var plusObj = prodObj.insertCell(prodObj.cells.length); plusObj.id = 'plus_' + flyObj.flyId; plusObj.className = 'crtPlus'; plusImgObj = document.createElement('IMG'); plusImgObj.id = 'plusx_' + flyObj.flyId; plusImgObj.src = plusImg.src; plusObj.appendChild(plusImgObj); var prodPriceObj = prodObj.insertCell(prodObj.cells.length); prodPriceObj.id = 'price_' + flyObj.flyId; prodPriceObj.className = 'crtPrice'; } prodImageObj.innerHTML = flyObject.innerHTML; prodNameObj.innerHTML = productNameObj.innerHTML; var qty = (parseFloat(qtyTextObj.value)) ? parseFloat(parseFloat(qtyTextObj.value) + 1) : 1; prodPriceObj.innerHTML = flyObj.currency + number_format(parseFloat(parseFloat(qty) * parseFloat(productPriceObj.innerHTML)),2); plusImgObj.qtyId = qtyTextObj.id; plusImgObj.qty = 0; plusImgObj.priceId = prodPriceObj.id; plusImgObj.price = productPriceObj.innerHTML; plusImgObj.flyObj = flyObj; plusImgObj.productId = productId; plusImgObj.onclick = function(e){ var status = true; this.qty = parseFloat(document.getElementById(this.qtyId).value); if(status) { this.qty++; document.getElementById(this.qtyId).value = this.qty; document.getElementById(this.priceId).innerHTML = this.flyObj.currency + number_format(parseFloat(this.price * this.qty),2); var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'incItem'; ajaxVar.vars["args"] = this.productId; ajaxVar.gotoFunction = "doNothing"; ajaxVar.AjaxPostSQL(); } }; // to put the delete qty code qtyTextObj.value = qty; minusImgObj.qtyId = qtyTextObj.id; minusImgObj.qty = 0; minusImgObj.priceId = prodPriceObj.id; minusImgObj.price = productPriceObj.innerHTML; minusImgObj.flyObj = flyObj; minusImgObj.productId = productId; minusImgObj.onclick = function(e){ this.qty = parseFloat(document.getElementById(this.qtyId).value); var status = true; if(status) { if(this.qty == 1) { this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'delItem'; ajaxVar.vars["args"] = this.productId; ajaxVar.gotoFunction = "doNothing"; ajaxVar.AjaxPostSQL(); }else{ this.qty--; qty = this.qty; document.getElementById(this.qtyId).value = this.qty; document.getElementById(this.priceId).innerHTML = this.flyObj.currency + number_format(parseFloat(this.price * this.qty),2); var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'decItem'; ajaxVar.vars["args"] = this.productId; ajaxVar.gotoFunction = "doNothing"; ajaxVar.AjaxPostSQL(); } } }; }else{ flyObj = fnVars['obj']; var flyingObj = document.getElementById(flyObj.dummyId); } flyingObj.parentNode.removeChild(flyingObj); cartStatus(); } function hideCart(btnObj){ var cartObj = document.getElementById('cart'); cartObj.className = 'hiddenObj'; btnObj.onclick = function(e) { showCart(this); } btnObj.innerHTML = 'O'; } function showCart(btnObj){ var cartObj = document.getElementById('cart'); cartObj.className = 'visibleObj'; btnObj.onclick = function(e) { hideCart(this); } btnObj.innerHTML = '_'; } function moveCart(event, id){ divDrag = new drag(); var dragDiv = document.getElementById(id); divDrag.id = id; divDrag.dragObj.zIndex = 0; divDrag.dragStopFn[0] = 'fixCartPosition'; divDrag.dragStart(event); } function addOrderCart(Obj, prodId) { var qtyTxtobj = document.getElementById('qty_' + prodId); var priceobj = document.getElementById('price_' + prodId); var qty = Number(qtyTxtobj.value); qty++; qtyTxtobj.value = qty; var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'incItem'; ajaxVar.vars["args"] = prodId; ajaxVar.gotoFunction = "CalcTotal"; ajaxVar.AjaxPostSQL(); } function remOrderCart(Obj, prodId) { var qtyTxtobj = document.getElementById('qty_' + prodId); var priceobj = document.getElementById('price_' + prodId); var qty = Number(qtyTxtobj.value); if (qty==1) { var totalRows = Obj.parentNode.parentNode.parentNode.rows.length; if (totalRows==5) { var cartObj = document.getElementById('shopCart'); cartObj.deleteRow(1); cartObj.deleteRow(1); cartObj.deleteRow(1); var objRow = cartObj.tBodies[0].insertRow(1); objRow.className = 'cartItem'; var objCol = objRow.insertCell(objRow.cells.length); objCol.colSpan = 7; objCol.style.textAlign = 'right'; objCol.innerHTML = "Cart is empty."; }else{ Obj.parentNode.parentNode.parentNode.removeChild(Obj.parentNode.parentNode); } var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'delItem'; ajaxVar.vars["args"] = prodId; ajaxVar.gotoFunction = "CalcTotal"; ajaxVar.AjaxPostSQL(); }else{ qty--; qtyTxtobj.value = qty; var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = 'runFunction'; ajaxVar.vars['class'] = 'cart'; ajaxVar.vars['func'] = 'decItem'; ajaxVar.vars["args"] = prodId; ajaxVar.gotoFunction = "CalcTotal"; ajaxVar.AjaxPostSQL(); } } function CalcTotal(data, fnVars){ var ajaxVar = new ajaxVars(); ajaxVar.phpFile = "/orderCalc.php"; ajaxVar.vars['action'] = 'runFunction'; ajaxVar.gotoFunction = "OrderTotal"; ajaxVar.AjaxPostSQL(); } function OrderTotal(data, fnVars) { var rowArr = data.split("#**#"); var total = 0; for (var i=0; i0) { var qty = Number(document.getElementById('qty_' + colArr[0]).value); document.getElementById('pack_' + colArr[0]).innerHTML = "£" + number_format(parseFloat(colArr[2] * qty),2); document.getElementById('pack_' + colArr[0]).innerHTML = ""; //as commented by vinayak for not to show the shipping price //document.getElementById('price_' + colArr[0]).innerHTML = "£" + number_format(parseFloat(colArr[2] * qty) + parseFloat(colArr[1] * qty),2); document.getElementById('price_' + colArr[0]).innerHTML = "£" + number_format(parseFloat(0 * qty) + parseFloat(colArr[1] * qty),2); //as commented by vinayak for not to calculate the shipping price //total += parseFloat(colArr[2] * qty) + parseFloat(colArr[1] * qty); total += parseFloat(0 * qty) + parseFloat(colArr[1] * qty); } } if (total>0) { document.getElementById('grandTotal').innerHTML = '£' + number_format(total,2); }else{ msg='

Shopping cart is empty currently.

'; document.getElementById('showCart').innerHTML = msg; document.getElementById('odForm').innerHTML = ''; document.getElementById('mand').innerHTML = ''; } }