var basketBalloonTimeout; var intMaxSamples = 4; // ************************************************************ // Name : getBasket() // Purpose : Display basket summary // Change Requests: // Name Date Summary // ************************************************************ function getBasket(){ var intQuantity = 0; var intSubTotal = 0; var intPrice = 0; //MADE TO MEASURE - We now go through the made to measure basket if(document.getElementById("formBasket_strMadeToMeasureBasket").value.length>0){ var j = eval(document.getElementById("formBasket_strMadeToMeasureBasket").value); for (var i = 0 ; i < j.length ; i++) { intQuantity += parseFloat(j[i]["qty"]); intSubTotal = intSubTotal + (parseFloat(j[i]["total"])*intQuantity); } } if(document.getElementById("formBasket_strBasket").value.length>0){ $jq.ajax({ async: false, url: "http://www.mostynscurtains.co.uk/api/getBasket.aspx", data: {campaign: "MOSTYNS", formBasket_strBasket: document.getElementById("formBasket_strBasket").value}, dataType: "json", success: function(j) { var strReturn = ""; for (var i = 0 ; i < j.length ; i++) { intQuantity = 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"])); } } }); } if(intQuantity > 0){ document.getElementById("divBasketQuantity").innerHTML = intQuantity; document.getElementById("divBasketTotal").innerHTML = intSubTotal.toFixed(2); }else{ document.getElementById("divBasketQuantity").innerHTML = "0"; document.getElementById("divBasketTotal").innerHTML = "0.00"; } } // ************************************************************ // Name : removeFromBasket() // Purpose : Remove item from the basket // Change Requests: // Name Date Summary // ************************************************************ function removeFromBasket(Id, Variant) { var strBasket = ""; strBasket = getCookie("Basket"); if(strBasket==null||strBasket.length<1){ //Cannot be null really as we must have something in it in order to drag over to this remove product from basket handler! }else{ var j=dojo.json.evalJSON("[" + strBasket + "]"); strBasket = ""; for (var i = 0 ; i < j.length ; i++) { if(j[i]["Id"]==Id && j[i]["Variant"]==Variant){ // Remove completely }else{ strBasket = strBasket + "{\"Id\":\"" + j[i]["Id"] + "\",\"QTY\":\"" + j[i]["QTY"] + "\",\"Variant\":\"" + j[i]["Variant"] + "\"},"; } } strBasket = Left(strBasket, strBasket.length-1) } setCookie("Basket", strBasket, "", "/", "", ""); if(strBasket.length > 0){$("formBasket_strBasket").value = "[" + strBasket + "]";}else{$("formBasket_strBasket").value = "";} getBasket(); } // ************************************************************ // Name : calcNetCurtainCost() // Purpose : Calculate the cost of a net curtain // Change Requests: // Name Date Summary // Olly 02/10/2011 Created // ************************************************************ function calcNetCurtainCost(bolAddToBasket, producttitle){ var drop = document.getElementById("net_drop").options[document.getElementById("net_drop").selectedIndex].value; var width = document.getElementById("net_windowwidth").value; var gather = document.getElementById("net_gather").options[document.getElementById("net_gather").selectedIndex].value; var sides = document.getElementById("net_sides").options[document.getElementById("net_sides").selectedIndex].value; var top = document.getElementById("net_top").options[document.getElementById("net_top").selectedIndex].value; var quantity = document.getElementById("net_quantity").value; var tempWidth = ""; var userwidth = 0; var totalcost = 0; var metres = 0; var totalmetres = 0; var variantid = ""; var variantcode = ""; var variantcost = 0; var dropwidth = ""; var sidescost = 0; var topcost = 0; var chosengather = ""; var gatherlength = 0; var chosenheading = ""; var chosensides = ""; var windowref = ""; var arraysplit; var total = 0; var finaltotal = 0; if(drop.length > 0 && width.length > 0 && gather.length > 0 && sides.length > 0 && top.length > 0 && isNaN(width)==false){ // Gather arraySplit = gather.split("_"); gatherlength = arraySplit[1]; chosengather = arraySplit[2]; width = parseInt(width); userwidth = width; metres = parseInt(width) * gatherlength; metres = roundNumber(metres); if(String(metres).length>2){ tempWidth = Right(metres,1); if(tempWidth != "0"){ metres = parseInt(metres) + parseInt(10-parseInt(tempWidth)); } } totalmetres = metres/100; if(totalmetres==0.99){totalmetres = 1;} // Variant and cost per m arraySplit = drop.split("_"); variantid = arraySplit[1]; variantcode = arraySplit[2]; dropwidth = arraySplit[3]; variantcost = arraySplit[4]; // Sides and any additional cost arraySplit = sides.split("_"); sides = arraySplit[0]; sidescost = arraySplit[1]; if(sides == "OVERLOCKED"){chosensides = "Overlocked";} if(sides == "HEMMED"){chosensides = "Hemmed";} // Top and any additional cost arraySplit = top.split("_"); top = arraySplit[0]; topcost = arraySplit[1]; topcost = topcost * totalmetres; if(top == "SLOT"){chosenheading = "Slot Top and Bottom";} if(top == "TAPE"){chosenheading = "Tape";} // Calc total cost total = total + parseFloat(totalmetres*parseFloat(variantcost)) + parseFloat(sidescost) + parseFloat(topcost); // Quantity if(isNaN(quantity)==true || quantity.length < 1){ quantity = 1; } finaltotal = roundNumber(total, 2); //This is the cost per net total = total * parseFloat(quantity); total = roundNumber(total, 2); total = total.toFixed(2); // Window name windowref = document.getElementById("windowref").value; document.getElementById("netcurtain_total").innerHTML = total; if(bolAddToBasket == true){ var strBasket = ""; var id = createGUID(); showBasketBalloon(); strBasket = getCookie("MadeToMeasureBasket"); if(strBasket==null||strBasket.length<1){ strBasket = "{\"id\":\"" + id + "\",\"title\":\"" + producttitle + "\",\"type\":\"NETCURTAINALTERATION\",\"reference\":\"" + variantcode + "\",\"width\":\"" + userwidth + "\",\"gather\":\"" + chosengather + "\",\"drop\":\"" + dropwidth + "\",\"meterage\":\"" + totalmetres + "\",\"alter-top\":\"" + chosenheading + "\",\"alter-sides\":\"" + chosensides + "\",\"window-ref\":\"" + windowref + "\",\"total\":\"" + finaltotal + "\",\"qty\":\"" + quantity + "\"}"; }else{ strBasket = strBasket + ",{\"id\":\"" + id + "\",\"title\":\"" + producttitle + "\",\"type\":\"NETCURTAINALTERATION\",\"reference\":\"" + variantcode + "\",\"width\":\"" + userwidth + "\",\"gather\":\"" + chosengather + "\",\"drop\":\"" + dropwidth + "\",\"meterage\":\"" + totalmetres + "\",\"alter-top\":\"" + chosenheading + "\",\"alter-sides\":\"" + chosensides + "\",\"window-ref\":\"" + windowref + "\",\"total\":\"" + finaltotal + "\",\"qty\":\"" + quantity + "\"}"; } setCookie("MadeToMeasureBasket", strBasket, "", "/", "", ""); if(strBasket.length > 0){document.getElementById("formBasket_strMadeToMeasureBasket").value = "[" + strBasket + "]";}else{document.getElementById("formBasket_strMadeToMeasureBasket").value = "";} getBasket(); } }else{ if(bolAddToBasket == true){ alert("You have not entered all the measurements required."); } document.getElementById("netcurtain_total").innerHTML = "0.00"; } } // ************************************************************ // Name : addreadymadevoile() // Purpose : Add ready made voile to the basket // Change Requests: // Name Date Summary // Olly 30/09/2011 Created // ************************************************************ function addreadymadevoile(chosenvariant){ addproducttobasket(document.getElementById("variantProduct").value, 1, chosenvariant); } // ************************************************************ // Name : addreadymadevoilealteration() // Purpose : Add ready made voile with alteration to the basket // Change Requests: // Name Date Summary // Olly 30/09/2011 Created // ************************************************************ function addreadymadevoilealteration(chosenvariant, total, producttitle, variantcode, width, drop, voileheading, shorteningcost, shortening){ var strBasket = ""; var id = createGUID(); var unit = ""; var headingcost = 0; var chosenheading = ""; //Determine unit if(document.getElementById("unit_" + chosenvariant + "_cms").checked==true){unit = "cm";}else{unit = "in";} //We firstly determine whether any eyelet alteration or shorten drop has been entered otherwise add as regular variant if(voileheading.length < 1 && shortening.length < 1){ addproducttobasket(document.getElementById("variantProduct").value, 1, chosenvariant); }else{ showBasketBalloon(); strBasket = getCookie("MadeToMeasureBasket"); //Determine cost if(voileheading.length > 0){ var arrayHeading = voileheading.split("_"); //CHOSEN HEADING if(arrayHeading[0] == "SLOTTOP"){chosenheading = "Slot Top";} if(arrayHeading[0] == "SLOT"){chosenheading = "Slot Top and Bottom";} if(arrayHeading[0] == "TAPE"){chosenheading = "Tape";} if(arrayHeading[0] == "EYELET"){chosenheading = "Eyelet - " + arrayHeading[2];} // HEADING COST headingcost = arrayHeading[1]; total = total + parseFloat(headingcost); } if(shortening.length > 0){total = total + shorteningcost;}else{unit = "";} total = roundNumber(total, 2); if(strBasket==null||strBasket.length<1){ strBasket = "{\"id\":\"" + id + "\",\"title\":\"" + producttitle + "\",\"type\":\"READYMADEVOILEALTERATION\",\"reference\":\"" + variantcode + "\",\"width\":\"" + width + "\",\"drop\":\"" + drop + "\",\"alter-heading\":\"" + chosenheading + "\",\"shorten-drop\":\"" + shortening + unit + "\",\"total\":\"" + total + "\",\"qty\":\"1\"}"; }else{ strBasket = strBasket + ",{\"id\":\"" + id + "\",\"title\":\"" + producttitle + "\",\"type\":\"READYMADEVOILEALTERATION\",\"reference\":\"" + variantcode + "\",\"width\":\"" + width + "\",\"drop\":\"" + drop + "\",\"alter-heading\":\"" + chosenheading + "\",\"shorten-drop\":\"" + shortening + unit + "\",\"total\":\"" + total + "\",\"qty\":\"1\"}"; } setCookie("MadeToMeasureBasket", strBasket, "", "/", "", ""); if(strBasket.length > 0){document.getElementById("formBasket_strMadeToMeasureBasket").value = "[" + strBasket + "]";}else{document.getElementById("formBasket_strMadeToMeasureBasket").value = "";} getBasket(); } } // ************************************************************ // Name : addreadymadecurtain() // Purpose : Add ready made curtain to the basket // Change Requests: // Name Date Summary // ************************************************************ function addreadymadecurtain(chosenvariant){ addproducttobasket(document.getElementById("variantProduct").value, 1, chosenvariant); } // ************************************************************ // Name : addreadymadecurtainalteration() // Purpose : Add ready made curtain with alteration to the basket // Change Requests: // Name Date Summary // ************************************************************ function addreadymadecurtainalteration(chosenvariant, total, producttitle, variantcode, width, drop, eyeletcost, eyelet, shorteningcost, shortening){ var strBasket = ""; var id = createGUID(); var unit = ""; //Determine unit if(document.getElementById("unit_" + chosenvariant + "_cms").checked==true){unit = "cm";}else{unit = "in";} //We firstly determine whether any eyelet alteration or shorten drop has been entered otherwise add as regular variant if(eyelet.length < 1 && shortening.length < 1){ addproducttobasket(document.getElementById("variantProduct").value, 1, chosenvariant); }else{ showBasketBalloon(); strBasket = getCookie("MadeToMeasureBasket"); //Determine cost if(eyelet.length > 0){total = total + eyeletcost;} if(shortening.length > 0){total = total + shorteningcost;} total = roundNumber(total, 2); if(strBasket==null||strBasket.length<1){ strBasket = "{\"id\":\"" + id + "\",\"title\":\"" + producttitle + "\",\"type\":\"READYMADECURTAINALTERATION\",\"reference\":\"" + variantcode + "\",\"width\":\"" + width + "\",\"drop\":\"" + drop + "\",\"alter-eyelet\":\"" + eyelet + "\",\"shorten-drop\":\"" + shortening + unit + "\",\"total\":\"" + total + "\",\"qty\":\"1\"}"; }else{ strBasket = strBasket + ",{\"id\":\"" + id + "\",\"title\":\"" + producttitle + "\",\"type\":\"READYMADECURTAINALTERATION\",\"reference\":\"" + variantcode + "\",\"width\":\"" + width + "\",\"drop\":\"" + drop + "\",\"alter-eyelet\":\"" + eyelet + "\",\"shorten-drop\":\"" + shortening + unit + "\",\"total\":\"" + total + "\",\"qty\":\"1\"}"; } setCookie("MadeToMeasureBasket", strBasket, "", "/", "", ""); if(strBasket.length > 0){document.getElementById("formBasket_strMadeToMeasureBasket").value = "[" + strBasket + "]";}else{document.getElementById("formBasket_strMadeToMeasureBasket").value = "";} getBasket(); } } // ************************************************************ // Name : roundNumber() // Purpose : Round up a number // Change Requests: // Name Date Summary // ************************************************************ function roundNumber(number, decimals) { var newnumber = new Number(number+'').toFixed(parseInt(decimals)); return parseFloat(newnumber); } // ************************************************************ // Name : createGUID() // Purpose : Create unique id // Change Requests: // Name Date Summary // ************************************************************ function createGUID() { var chars = '0123456789abcdef'.split(''); var uuid = [], rnd = Math.random, r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; // version 4 for (var i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | rnd()*16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; } } return uuid.join(''); } // ************************************************************ // Name : getProductVariations() // Purpose : List out product variations // Change Requests: // Name Date Summary // ************************************************************ function getProductVariations(strProductGUID){ var strReturn = ""; var intVariant = 1; var strRow = "odd" $jq.ajax({ async: false, url: "http://www.mostynscurtains.co.uk/api/doGetProductVariations.aspx", data: {campaign: "MOSTYNS", strGet: strProductGUID}, dataType: "json", success: function(j) { if(j.length == 0){ }else{ for (var i = 0 ; i < j.length ; i++) { if(j[i]["Status"]=="1"){ strReturn = strReturn + "" strReturn = strReturn + "
')\">
" //Variants for(var ii = 0; ii < j[i]["Variants"].length; ii++){ strReturn = strReturn + "" + j[i]["Variants"][ii]["Value"] + "" } //Stock check if(parseFloat(j[i]["Stock"]) < 1){ strReturn = strReturn + "
Out of stock
" }else{ //Variant Price if(j[i]["vatexempt"]=="true"){ if(j[i]["specialpriceexvat"]=="0.00"){ strReturn = strReturn + "£" + j[i]["priceexvat"] + ""; }else{ strReturn = strReturn + "£" + j[i]["specialpriceexvat"] + ""; } }else{ if(j[i]["specialpriceincvat"]=="0.00"){ strReturn = strReturn + "£" + j[i]["priceincvat"] + ""; }else{ strReturn = strReturn + "£" + j[i]["specialpriceincvat"] + ""; } } strReturn = strReturn + "
" intVariant++; } strReturn = strReturn + "\n" if(strRow=="odd"){strRow = "even";}else{strRow = "odd";} //We check to see if actually all variants are out of stock and if so then of course we cannot add this to the basket if(parseFloat(j[i]["variantstocklevel"]) < 1){ document.getElementById("add-button").style.display = "none"; } } } } } }); return strReturn; } function addtobasket(Id, quantity){ addtobasketproducts(Id, quantity); } function closeBasket(){ document.getElementById('light').style.display='none'; basketOverlay.close(); //Close overlay } function addtobasketproducts(strProductGUID, intQuantity){ var strVariations = ""; var strReturn = ""; var variantProducts = ""; var strProductVariations = ""; var bolVariations = false; document.getElementById("add-button").style.display = ""; $jq.getJSON("http://www.mostynscurtains.co.uk/api/dogetaddtobasketproducts.aspx", {campaign: "MOSTYNS", strGet: strProductGUID}, function(j) { //data = "[]"; //JUST FOR MOSTYNS TO ENSURE A FABRIC HAS A MIN QTY OF 5 WHEN DRAGGED INTO BASKET!! if(j[0]["variants"] == ""){ if(j[0]["producttype"] == 'FABRIC' && intQuantity < 5){ intQuantity = 5; alert("Please note that 5 metres of fabric has been added into the basket which is our minimum order quantity.\n\nIf you would like a longer length of fabric then please go directly to the fabrics product page."); } addproducttobasket(strProductGUID, intQuantity, ""); }else{ // Variation pop-up header and image strReturn = strReturn + "')\">" if("BUNDLE" == j[0]["producttype"]){ strReturn = strReturn + "
" + j[0]["producttitle"] + " - " if(j[0]["specialofferpriceexvat"] == "0.00"){strReturn = strReturn + "£" + j[0]["priceincvat"];}else{strReturn = strReturn + "£" + j[0]["specialofferpriceincvat"];} if(j[0]["saving"] != "0.00"){strReturn = strReturn + " Saving £" + j[0]["saving"];} strReturn = strReturn + "
" }else{ strReturn = strReturn + "
" + j[0]["producttitle"] + "
" } document.getElementById("headerBar").innerHTML = strReturn; strReturn = ""; for (var i = 0 ; i < j[0]["variants"].length ; i++) { strReturn = strReturn + "
" + j[0]["variants"][i]["title"] + "
" if(j[0]["variants"][i]["headings"].length > 0){ strReturn = strReturn + "" strReturn = strReturn + "" strReturn = strReturn + " " //Image column var strHeadingSplit = j[0]["variants"][i]["headings"].split(""); for(var s = 0; s < strHeadingSplit.length; s++){ strReturn = strReturn + "" } strReturn = strReturn + "" strReturn = strReturn + "" strProductVariations = getProductVariations(j[0]["variants"][i]["productid"]); //It may be the case that although a product type should have variants, it may not have any and the default stock level is used instead if(strProductVariations == ""){ if(parseFloat(j[0]["variants"][i]["stocklevel"]) < 1){ strReturn = strReturn + "" strReturn = strReturn + " " strReturn = strReturn + " " for(var s = 1; s < strHeadingSplit.length; s++){ strReturn = strReturn + "" } strReturn = strReturn + " " strReturn = strReturn + "" document.getElementById("add-button").style.display = "none"; }else{ //We firstly determine whether this is a single product (not a bundle) because we can auto-add it to the basket if(j[0]["variants"].length==1){ addproducttobasket(strProductGUID, intQuantity, ""); return; }else{ strReturn = strReturn + "" strReturn = strReturn + " " strReturn = strReturn + " " for(var s = 1; s < strHeadingSplit.length; s++){ strReturn = strReturn + " " } if(j[0]["variants"][i]["vatexempt"]=="true"){ strReturn = strReturn + " " }else{ strReturn = strReturn + " " } strReturn = strReturn + " " strReturn = strReturn + "" } } } strReturn = strReturn + strProductVariations + "
" + strHeadingSplit[s] + "  
')\">
Standard
Out of stock
')\">
Standard£" + j[0]["variants"][i]["priceexvat"] + "£" + j[0]["variants"][i]["priceincvat"] + "
"; variantProducts = variantProducts + j[0]["variants"][i]["productid"] + "," }else{ strReturn = strReturn + "
" } } if(variantProducts.length>0){variantProducts = Left(variantProducts, variantProducts.length-1);} document.getElementById("variantQuantity").value = intQuantity; document.getElementById("variantProduct").value = strProductGUID; document.getElementById("variantProductsWithVariants").value = variantProducts; document.getElementById("scrollPanel").innerHTML = strReturn; document.getElementById("qtyInput").value = "1"; basketOverlay.load(); //Make the background of everything else dark document.getElementById('light').style.display = 'block'; $jq("#light").center(); } } ); } function minusQuantity(){ var intQuantity = parseInt(document.getElementById('qtyInput').value); if(intQuantity>1){ document.getElementById("qtyInput").value = intQuantity-1; } } function plusQuantity(){ var intQuantity = parseInt(document.getElementById('qtyInput').value); if(intQuantity<999){ document.getElementById("qtyInput").value = intQuantity+1; } } function GetRadioButtonValue(id) { var radio = document.getElementsByName(id); for (var ii = 0; ii < radio.length; ii++) { if (radio[ii].checked) return radio[ii].value; } } function addtobasketproductwithvariants(strRadioButton){ var arraySplit = document.getElementById("variantProductsWithVariants").value.split(","); var chosenVariants = ""; for(var s = 0; s < arraySplit.length; s++){ chosenVariants = chosenVariants + GetRadioButtonValue(strRadioButton + arraySplit[s]) + ","; } if(chosenVariants.length>0){chosenVariants = Left(chosenVariants, chosenVariants.length-1);} //We now also set the quantity to the quantity box in the pop-up if(document.getElementById("qtyInput").value=="0"){ closeBasket(); }else{ document.getElementById("variantQuantity").value = document.getElementById("qtyInput").value; addproducttobasket(document.getElementById("variantProduct").value, document.getElementById("variantQuantity").value, chosenVariants); } } // ************************************************************ // Name : addproducttobasket() // Purpose : Add product into basket // Change Requests: // Name Date Summary // ************************************************************ function addproducttobasket(Id, quantity, variants){ var strBasket = ""; closeBasket(); showBasketBalloon(); //deleteCookie("Basket"); strBasket = getCookie("Basket"); var bolSample = isSample(Id, variants); // Check to see whether this is a free sample if (bolSample == "true"){quantity = 1;} // Only can add quantity of 1 to a free sample per product if(strBasket==null||strBasket.length<1){ strBasket = "{\"Id\":\"" + Id + "\",\"QTY\":\"" + quantity + "\",\"Variant\":\"" + variants + "\"}"; }else{ var intSamplesInBasket = parseFloat(countSamplesInBasket()); intSamplesInBasket = intSamplesInBasket + parseFloat(quantity); if(bolSample=="true" && intSamplesInBasket > intMaxSamples){ closeBasketBalloon(); alert("We're sorry, but you can only have up to " + intMaxSamples + " free samples."); return; } 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){ if(bolSample=="true"){ closeBasketBalloon(); alert("We're sorry, but you can only have one free sample per product."); return; }else{ 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(); } // ************************************************************ // Name : isSample() // Purpose : Is this product variant a sample // Change Requests: // Name Date Summary // ************************************************************ function isSample(Id, variant){ var bolReturn = "false"; $jq.ajax({ async: false, url: "http://www.mostynscurtains.co.uk/api/isSample.aspx", data: {campaign: "MOSTYNS", productid: Id, variant: variant}, dataType: "json", success: function(json) { var j = eval(json); if(j[0]["issample"]=="True"){bolReturn = "true";}else{bolReturn = "false";} } }); return bolReturn; } // ************************************************************ // Name : countSamplesInBasket() // Purpose : Count number of samples already in basket // Change Requests: // Name Date Summary // ************************************************************ function countSamplesInBasket(){ var intSamples = 0; if(document.getElementById("formBasket_strBasket").value.length>0){ $jq.ajax({ async: false, url: "http://www.mostynscurtains.co.uk/api/countSamplesInBasket.aspx", data: {campaign: "MOSTYNS", formBasket_strBasket: document.getElementById("formBasket_strBasket").value}, dataType: "json", success: function(json) { var j = eval(json); intSamples = j[0]["samples"]; } }); }else{ intSamples = 0; } return intSamples; } // ************************************************************ // 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("basketDropZone")); 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,3000); } // ************************************************************ // 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 errorHandler( type, error ) { var msg = "Sorry but a problem has occured. Perhaps refresh your browser ...\n" + error.message; alert( msg ); } 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]; } // ************************************************************ // Name : IsNumeric() // Purpose : Check to see if a value is numeric // Change Requests: // Name Date Summary // ************************************************************ function IsNumeric(input){ var RE = /^-{0,1}\d*\.{0,1}\d+$/; return (RE.test(input)); }