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;"; return; 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 = "GBP"; 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, oper) { var products = getProducts(); if (oper == "+") if (products[id]) products[id]++; else products[id] = 1; else if (oper == "-") if (products[id]) products[id]--; else products[id] = 0; setCookie(products); document.getElementById("qty_"+id).value = products[id]; } 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++ ) { var itemCodeAndCount = cartPairs[count].split(":"); cartItems[ itemCodeAndCount[0] ] = itemCodeAndCount[1]; } return cartItems; } function setCookie (itemsArray) { var cartPairs = new Array(); var i=0; //join array into an array of code:quantity for ( var count=0; count < itemsArray.length; count++ ) if (itemsArray[count]) cartPairs[i++] = ( count + ":" + itemsArray[count] ); var cartCookieValue = cartPairs.join(" "); document.cookie = "products=" + escape(cartCookieValue) + "; path=/;"; } 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.emu-oil-well.com/",""); } } function submitForm() { 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.forms['order'].action = "checkout.php"; } } 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; subTotal = subTotal.substring(1); 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 * 1.175; postage = postage.toFixed(2); document.order.elements["postage"].value = currency + postage; document.order.elements["handling_cart"].value = postage; subTotal = parseFloat(subTotal) + parseFloat(postage); document.order.elements["total"].value = currency + subTotal.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 submitVoucher() { var voucher = document.getElementById("voucherInput").value; if (voucher == "") { alert("Invalid voucher"); return; } document.cookie = voucher + "=true; path=/; expires=Thu, 01-Jan-2070 00:00:01 GMT;"; window.location.reload(true); }