function onLoad() { var biscuit = document.cookie; biscuit = biscuit.substring(biscuit.indexOf("currency"),biscuit.length); if (biscuit.indexOf(";") != -1) biscuit = biscuit.substring(0,biscuit.indexOf(";")); if (biscuit.indexOf("currency") == -1) document.cookie = "currency=GBP; path=/; expires=Thu, 01-Jan-2070 00:00:01 GMT;"; if (biscuit.indexOf("GBP") != -1) document.currencyForm.currency.options[0].selected = true; else if (biscuit.indexOf("USD") != -1) document.currencyForm.currency.options[1].selected = true; else if (biscuit.indexOf("EUR") != -1) document.currencyForm.currency.options[2].selected = true; else if (biscuit.indexOf("JPY") != -1) document.currencyForm.currency.options[3].selected = true; else if (biscuit.indexOf("AUD") != -1) document.currencyForm.currency.options[4].selected = true; else if (biscuit.indexOf("CAD") != -1) document.currencyForm.currency.options[5].selected = true; } function setCurrency() { var currency = document.currencyForm.currency.options[document.currencyForm.currency.options.selectedIndex].value; var currencyCookie = "currency=" + escape(currency) + "; path=/; expires=Thu, 01-Jan-2070 00:00:01 GMT;"; document.cookie = currencyCookie; window.location.reload(true); } function change(id) { var products = getProducts(); id = id+""; if (products[id] == undefined) products[id] = 0; var value = document.getElementById("qty_"+id).value; numProduct = parseInt(products[id]) + parseInt(value); if (isNaN(numProduct)) { alert("Please enter a numeric value to add to the basket"); return; } else if (numProduct < 0) { alert("Please enter a positive value"); return; } products[id] = numProduct; //alert(products[id]); setCookie(products); //window.location.reload(true); } function setQuantity(id) { var products = getProducts(); id = id+""; var value = document.getElementById("qty_"+id).value; numProduct = parseInt(value); if (isNaN(numProduct)) { alert("Please enter a numeric value to add to the basket"); return; } else if (numProduct < 0) { alert("Please enter a positive value"); return; } products[id] = numProduct; setCookie(products); window.location.reload(true); } function add(id) { var products = getProducts(); id = id+""; if (products[id] == undefined) products[id] = 0; products[id] = parseInt(products[id]) +1; setCookie(products); window.location.reload(true); } function removeOne(id) { var products = getProducts(); id = id+""; if (products[id] == undefined) products[id] = 0; if (products[id] > 0) products[id] = parseInt(products[id]) -1; setCookie(products); window.location.reload(true); } function getProducts() { var biscuit = document.cookie; var index = biscuit.indexOf("products="); var cartItems = new Array(); if (index == -1) //if there are no products return empty array return cartItems; biscuit = unescape(biscuit.substring(index+9,biscuit.length)); //grab the end of the product string if (biscuit.indexOf(";") != -1) biscuit = biscuit.substring(0,biscuit.indexOf(";")); var cartPairs = biscuit.split(" "); for ( var count=0; count < cartPairs.length; count++ ) { if (cartPairs[count] == "") { continue; } var itemCodeAndCount = cartPairs[count].split(":"); var key = itemCodeAndCount[0]+""; cartItems[ key ] = itemCodeAndCount[1]; } for (i in cartItems) { //alert(cartItems[i]); } return cartItems; } function setCookie (itemsArray) { var cartPairs = new Array(); //join array into an array of code:quantity var cartCookieValue = ""; for ( var i in itemsArray ) { if (itemsArray[i]) { if (i == "map" || i == "filter" || i == "every" || i == "some" || i == "reduce" || i == "indexOf" || i == "lastIndexOf" || i == "each" || i == "eachSlice" || i == "all" || i == "any" || i == "collect" || i == "detect" || i == "findAll" || i == "grep" || i == "include" || i == "inGroupsOf" || i == "inject" || i == "invoke" || i == "max" || i == "min" || i == "partition" || i == "pluck" || i == "reject" || i == "s||tBy" || i == "toArray" || i == "zip" || i == "size" || i == "inspect" || i == "find" || i == "select" || i == "member" || i == "entries" || i == "_reverse" || i == "_each" || i == "clear" || i == "first" || i == "last" || i == "compact" || i == "flatten" || i == "without" || i == "uniq" || i == "intersect" || i == "clone" || i == "toJSON" || i == "sortBy") { continue; } cartCookieValue = cartCookieValue + i + ":" + itemsArray[i] + " "; } } //alert(cartCookieValue); document.cookie = "products=" + escape(cartCookieValue) + "; path=/;"; //alert(document.cookie); } function setupOptions(view, number, orderBy, order) { if (view != '') setOption(document.optionsForm.view, view); else document.optionsForm.view.options[0].selected = true; if (number != '') setOption(document.optionsForm.number, number); else document.optionsForm.number.options[4].selected = true; if (orderBy != '') setOption(document.optionsForm.orderBy, orderBy); else document.optionsForm.orderBy.options[1].selected = true; if (order != '') setOption(document.optionsForm.order, order); else document.optionsForm.order.options[0].selected = true; } function setPage(num) { //document.products["pageBox"].options[num].selected = true; document.getElementsByName("pageBox")[0].options[num].selected = true; //document.getElementsByName("pageBox")[1].options[num].selected = true; } function setOption(op, value) { for (i = 0; i < op.length ; i++) { if (op.options[i].value == value) { op.options[i].selected = true; } } } function delCookie (name) { document.cookie = name + "=" + "; expires=Thu, 01-Jan-1970 00:00:01 GMT" + "; path=/"; } function clearOrder() { delCookie("products"); document.location.href = "index.php"; } function addbookmark() { if (document.all) { window.external.AddFavorite("http://www.theinternetswitchstore.co.uk/",""); } } function submitForm(paymentProcessor) { var country = document.order.country; if (document.order.first_name.value == "" || document.order.address1.value == "" || document.order.city.value == "" || document.order.state.value == "" || document.order.zip.value == "" || document.order.last_name.value == "" || document.order.tel.value == "" || country[country.selectedIndex].value =="NA" || document.order.email.value.indexOf("@") == -1) { document.getElementById('error').value = 'true'; document.forms['order'].action = "checkout.php"; } document.getElementById("pp").value = paymentProcessor; document.forms['order'].submit(); } function openWin(file) { var newWindow = ''; file = file.toLowerCase(); file = file.trim(); if (file.substr(file.length -1, 1) == " ") { file = file.substr(0,file.length -1); } file = "info/"+file+".html"; newWindow = window.open(file,'mapWin',"resizable=yes,scrollbars=yes,width=600,height=400"); newWindow.focus(); } function updateCountry() { var country = document.order.country; var postage = 0.00; var subTotal = document.order.elements["subTotal"].value; var currency = document.order.currencySymbol.value; if (country[country.selectedIndex].id == "0") postage = document.order.elements["UKPostalCost"].value; else if (country[country.selectedIndex].id == "1") postage = document.order.elements["europePostalCost"].value; else if (country[country.selectedIndex].id == "2") postage = document.order.elements["internationalPostalCost"].value; else return; postage = postage * document.order.currencyRate.value; // postage = postage.toFixed(2); document.getElementById("postage").value = postage.toFixed(2); document.getElementById("handling_cart").value = postage.toFixed(2); subTotal = parseFloat(subTotal) + parseFloat(postage); var vat = subTotal * 0.175; document.getElementById("vat").value = vat.toFixed(2); document.getElementById("tax_cart").value = vat.toFixed(2); var total = subTotal + vat; document.getElementById("total").value = total.toFixed(2) ; } String.prototype.trim = function() { a = this.replace(/^\s+/, ''); return a.replace(/\s+$/, ''); }; function updateBasket() { var products = getProducts(); for (var i = 0; document.products[i].name != "add"; i++) { var id = parseInt(document.products[i].name) + 0; var qty = parseInt(document.products[i].value) + 0; if (products[id]) products[id] = parseInt(products[id]) + qty; else products[id] = qty; if (products[id] < 0) products[id] = 0; } setCookie(products); } function remove(id) { var products = getProducts(); products[id] = 0; setCookie(products); window.location.reload(true); }