var basketBalloonTimeout; function getBasket(){ var intQuantity = 0; var intSubTotal = 0; var intPrice = 0; if(document.getElementById("formBasket_strBasket").value.length>0){ $.getJSON("http://www.uppercup.com/api/getBasket.aspx", {campaign: "UPPERCUP", formBasket_strBasket: document.getElementById("formBasket_strBasket").value}, function(json) { var j=eval(json); var strReturn = ""; for (var i = 0 ; i < j.length ; i++) { intQuantity += parseFloat(j[i]["QTY"]); if(j[i]["bolVATExempt"] == "False"){ if(j[i]["intSpecialPrice"] > 0){intPrice = j[i]["intSpecialPrice"];}else{intPrice = j[i]["intPrice"];} }else{ if(j[i]["intExVATSpecialPrice"] > 0){intPrice = j[i]["intExVATSpecialPrice"];}else{intPrice = j[i]["intExVATPrice"];} } intSubTotal = intSubTotal + (parseFloat(j[i]["intSubTotal"])); } document.getElementById("divBasketQuantity").innerHTML = intQuantity; document.getElementById("divBasketTotal").innerHTML = intSubTotal.toFixed(2); } ); }else{ document.getElementById("divBasketQuantity").innerHTML = "0"; document.getElementById("divBasketTotal").innerHTML = "0.00"; } } function addtobasket(Id, quantity){ addtobasketproducts(Id, quantity); } function closeBasket(){ document.getElementById('fade').style.display='none'; } function addproducttobasket(Id, quantity, variants){ var strBasket = ""; if(variants.length > 0){ document.getElementById("fade").style.display='none'; showBasketBalloon(); //deleteCookie("Basket"); strBasket = getCookie("Basket"); if(strBasket==null||strBasket.length<1){ strBasket = "{\"Id\":\"" + Id + "\",\"QTY\":\"" + quantity + "\",\"Variant\":\"" + variants + "\"}"; }else{ var bolFound = false; //We now see if this product already exists in the basket in order to increase the quantity var j=eval("[" + strBasket + "]"); strBasket = ""; for (var i = 0 ; i < j.length ; i++) { if(j[i]["Id"]==Id && j[i]["Variant"]==variants){ strBasket = strBasket + "{\"Id\":\"" + j[i]["Id"] + "\",\"QTY\":\"" + (parseInt(j[i]["QTY"])+parseInt(quantity)) + "\",\"Variant\":\"" + j[i]["Variant"] + "\"},"; bolFound = true; }else{ strBasket = strBasket + "{\"Id\":\"" + j[i]["Id"] + "\",\"QTY\":\"" + j[i]["QTY"] + "\",\"Variant\":\"" + j[i]["Variant"] + "\"},"; } } if(bolFound==false){ strBasket = strBasket + "{\"Id\":\"" + Id + "\",\"QTY\":\"" + quantity + "\",\"Variant\":\"" + variants + "\"},"; } strBasket = Left(strBasket, strBasket.length-1) } setCookie("Basket", strBasket, "", "/", "", ""); if(strBasket.length > 0){document.getElementById("formBasket_strBasket").value = "[" + strBasket + "]";}else{document.getElementById("formBasket_strBasket").value = "";} getBasket(); return false; }else{ alert("Sorry, but this size is currrently out of stock."); return false; } } // ************************************************************ // Name : showBasketBalloon() // Purpose : Show the basket balloon // Change Requests: // Name Date Summary // ************************************************************ function showBasketBalloon(){ // stretch overlay to fill page and fade in var arrayPageSize = getWindowSize(); document.getElementById("fade").style.width = arrayPageSize[0] + "px"; document.getElementById("fade").style.height = arrayPageSize[1] + "px"; document.getElementById('fade').style.display = 'block'; // Position the basket balloon var arrayBasketPosition = findElementPosition(document.getElementById("shoppingbag")); document.getElementById("basketBalloon").style.top = arrayBasketPosition[1]+50 + "px"; document.getElementById("basketBalloon").style.left = arrayBasketPosition[0]-310 + "px"; document.getElementById("basketBalloon").style.display = "block"; //Take user to top of page in order to see basket balloon scroll(0,0); basketBalloonTimeout = setTimeout(closeBasketBalloon,6000); } // ************************************************************ // Name : gotoCheckout() // Purpose : Redirect user to checkout // Change Requests: // Name Date Summary // ************************************************************ function gotoCheckout(){ closeBasketBalloon(); window.location = "checkout.aspx"; } // ************************************************************ // Name : closeBasketBalloon() // Purpose : Hide the basket balloon // Change Requests: // Name Date Summary // ************************************************************ function closeBasketBalloon(){ document.getElementById("basketBalloon").style.display = "none"; document.getElementById("fade").style.display = "none"; clearTimeout(basketBalloonTimeout); } // ************************************************************ // Name : findElementPosition() // Purpose : Find the position of the basket image // Change Requests: // Name Date Summary // ************************************************************ function findElementPosition(obj) { var curleft = curtop = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); return [curleft,curtop]; } } function Left(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0,n); } function Right(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } // ************************************************************ // Name : checkNumeric() // Purpose : Make sure only numbers can be added into text box // Change Requests: // Name Date Summary // ************************************************************ function checkNumeric(booAllowFullstop) { // Allow chars between 0 - 9. Allow fullstop if booAllowFullstop = true if ((window.event.keyCode < 48 || window.event.keyCode > 57) && (window.event.keyCode != 45) && (window.event.keyCode != 46 || !booAllowFullstop)) { window.event.keyCode = 0; // Don't allow any other character } } // ************************************************************ // Name : getWindowSize() // Purpose : Find size of users browser window // Change Requests: // Name Date Summary // ************************************************************ function getWindowSize() { var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = window.innerWidth + window.scrollMaxX; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer if(document.documentElement.clientWidth){ windowWidth = document.documentElement.clientWidth; } else { windowWidth = self.innerWidth; } windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = xScroll; } else { pageWidth = windowWidth; } return [pageWidth,pageHeight]; }