// CART REVISIONS /* Cart version 1.04 10/05/02 - popupConvert() altered to let user choose currency if they click the "curreny convertor" link, not the "check todays rate" links - Using images instead of wingdings font (there's no point keeping it - Kids, wingdings are bad, mmkay?) - VAT Floating point error sorted (again) was using- vatcost = (priceFormat(vatcost)*quant); now using- vatcost = (priceFormat(vatcost)*quant); vatcost = priceFormat(vatcost); 21/12/01 - popupConvert() altered to accomodate different currencies now pass popupConvert([cur]), cur can be any valid 3 letter currency code eg; 'USD' or 'EUR' - Currency conversion rates are now able to cope with non-decimal values, I simply priceFormatted it!! 29/11/01 - Floating point error on calculating VAT resolved (VAT now calculated before quantity applied) UPDATE To Above: This didn't work, see 10/05/02 note above - Can no longer select a delivery location until cart is loaded - Rounding error on summing is corrected 27/11/01 - Define font colors for the cart to contrast with the stripes */ var exchRate = 1.52; //USD to pound var euroRate = 1.62; //euro to pound var prodvat = 0; var bgcolorStripe1 = "#AAAAAA"; // these dictate the color of the cart var fontColor1 = "#000000"; // these dictate the color of the cart var bgcolorStripe2 = "#CCCCCC"; // these dictate the color of the cart var fontColor2 = "#000000"; // these dictate the color of the cart var numItems = 0; var thisText = ""; var bgcolor = bgcolorStripe1; var fontColor = fontColor1; var requireColour = 1; var requireSize = 1; var safeFlag = false; tempArray = new Array(20); function setTempArray() { for(w=0;w<20;w++) { tempArray[w] = 0; } return; } setTempArray(); function hRule() { if(requireColour && requireSize) { document.write('
'); } else if(requireColour || requireSize) { document.write('
'); } else { document.write('
'); } } function makeSpaces() { if(requireColour) { document.write(' '); } if(requireSize) { document.write(' '); } } function popupConvert(cur) { if(cur=="USD") { cur = "&To=USD"; } else if(cur=="EUR") { cur = "&To=EUR"; } else { cur = ""; } priceToConvert = document.orderform.grandtotal.value; if(priceToConvert == 0) { priceToConvert = 1; } CurrencyWindow = window.open ('http://www.xe.net/ecc/input.cgi?Template=sw&Amount=' + priceToConvert + '&From=GBP'+cur, 'CurrencyWindow', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height=170,width=600'); CurrencyWindow.focus(); } function listCheck(theForm,what,theString) { setTempArray(); if(theString) // no need to set theString in every cart { tempArray = theString.split('|'); } theIndex = what.selectedIndex; addprice = tempArray[theIndex]; theName = what.name + "price"; theForm[theName].value = priceFormat(addprice); theTotal = ((theForm.basicprice.value*100) + (theForm.descprice.value*100) + (theForm.sizeprice.value*100) + (theForm.colourprice.value*100))/100; theForm.price.value = priceFormat(theTotal); } function checkout(what) { mycookies=new Array(20); var i=0; subtotal=0; var startpoint=0; whole_len=document.cookie.length; //alert(document.cookie); while(whole_len!=startpoint&&i<20) { if((temlen=document.cookie.indexOf(";",startpoint))!=-1) { mycookies[i]=document.cookie.substring(startpoint,temlen); i++; startpoint=temlen+1 } else if(startpoint!=whole_len) { mycookies[i]=document.cookie.substring(startpoint,whole_len); i++; startpoint=whole_len; } } for(j=0;j"); document.write(""); document.write(""); document.write(""); } } function getCookie(acookie,what) { //alert("what: "+what); //alert("acookie: "+acookie); clen = acookie.length; nlen = acookie.indexOf("=",0); if(acookie.substring(0,1) == " ") { cname = acookie.substring(6,nlen); } else { cname = acookie.substring(4,nlen); } bname = acookie.substring(nlen+1,clen); //alert("bname: "+ bname); sname_len = cname.indexOf("+",0); store = cname.substring(0,sname_len); dlen = cname.indexOf("+",sname_len+1); descrip = cname.substring(cname.indexOf("|D|",0),dlen); if(descrip.substring(0,1) == " ") { descrip = descrip.substring(1,descrip.length); } product = cname.substring(dlen+1,nlen); vatrate = cname.substring(sname_len+1,cname.indexOf(" ",sname_len+1)); /// vatrate = 20; vatrate = parseFloat(vatrate); ///alert("VAT ::"+vatrate); if(vatrate) vatrate = 20; // alert(vatrate); qlen = bname.indexOf("+",0); rlen = bname.indexOf("+",qlen+1); ilen = bname.indexOf("+",rlen+1); colen = bname.indexOf("+",ilen+1); //color slen = bname.indexOf("+",colen+1); //size olen = bname.indexOf("+",slen+1); //option elen = bname.indexOf("-",olen+1); //end quant = bname.substring(0,qlen); if(quant==0) { document.cookie = cname+"=bb; expires=Saturday, 16-Sep-90 23:59:59 GMT; path=/"+""; } refer = bname.substring(qlen+1,rlen); price = bname.substring(rlen+1,ilen); prodId = bname.substring(ilen+1,colen); colorId = bname.substring(colen+1,slen); sizeId = bname.substring(slen+1,olen); optionId = bname.substring(olen+1,elen); price = priceFormat(price); itemcost = quant*price; itemcost = priceFormat(itemcost); vatcost = price*vatrate/100; vatcost = (priceFormat(vatcost)*quant); vatcost = priceFormat(vatcost); if(quant!=0 && what=="hidden") // prevent double count of VAT { subtotal+=price*quant; prodvat = parseFloat(vatcost) + parseFloat(prodvat); //alert("prodvat1: "+prodvat); } printcontent(what); return subtotal; } function printcontent(what) { if(quant!=0) { vatrate = parseFloat(vatrate); itemcost = quant*price; itemcost = priceFormat(itemcost); vatcost = price*vatrate/100; vatcost = (priceFormat(vatcost)*quant); vatcost = priceFormat(vatcost); // SPLIT the descrip field into bits! descPart = descrip.indexOf("|D|",0); colorPart = descrip.indexOf("|C|",0); sizePart = descrip.indexOf("|S|",0); showDesc = descrip.substring(descPart+3,colorPart); showColour = descrip.substring(colorPart+3,sizePart); myshowColour = showColour; if(showColour=='undefined') showColour='undefined'; if(showColour=='na') myshowColour=''; showSize = descrip.substring(sizePart+3,descrip.length); myshowSize = showSize; if(showSize=='undefined') showSize='undefined'; if(showSize=='na') myshowSize=''; if(what=="display") { if(bgcolor == bgcolorStripe1) { bgcolor = bgcolorStripe2; fontColor = fontColor2; } else // alternate row colors { bgcolor = bgcolorStripe1; fontColor = fontColor1; } numItems = j + 1; var upOne = parseInt(quant) + 1; var downOne = parseInt(quant) - 1; thisText = ("\n
") + ("\n\t") //+ ("\n\t\tprodId:"+ prodId +".SizeId:"+ sizeId +".ColorId:"+ colorId +".OptionId:"+optionId +" + ("" + product + ""); if(requireColour) { thisText = thisText + "\n\t\t " + myshowColour + ""; } if(requireSize) { thisText = thisText + "\n\t\t " + myshowSize + ""; } thisText = thisText + ("\n\t\t" + quant + "\n\t\t£" + price + "\n\t\t£" + itemcost + "\n\t\t£" + vatcost + "") + ("\n\t\t"); /* + ("increase quantity") + ("   decrease quantity") + ("   delete   ") */ thisText = thisText + ("\n\t") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n\t\n
"); document.write(thisText); } else if(what=="hidden") { thisText = ("\n\t") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n"); /* thisText = ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n") + ("\n"); */ document.write(thisText); } //alert(thisText); } } function priceFormat(tmpprice) { dot=tmpprice.toString().indexOf("."); if(dot!=-1) tmpprice=tmpprice.toString().substr(0,dot+4); tmpprice=Math.round(tmpprice*100)/100; dot=tmpprice.toString().indexOf("."); if(dot==-1) tmpprice=tmpprice.toString()+".00"; else if((tmpprice.toString().length-dot)==2) tmpprice=tmpprice.toString()+"0"; return tmpprice; } function addto(entry,i) { var description; // make sure all fields are filled out /* if(!check(i)){ return; } */ entry.quantity.value = stripNonNumbers(entry.quantity.value); if(entry.quantity.value) { if(entry.desc) { //alert("entry.desc.value:"+entry.desc.value); if(entry.desc.type!="hidden") // check to see if select used { thisDesc = entry.desc.options[entry.desc.selectedIndex].value; } else { thisDesc = entry.desc.value; } } else { thisDesc = " "; } if(entry.color) { if(entry.color.options) // check to see if select used { thisColour = entry.color.options[entry.color.selectedIndex].text; colorId = entry.color.value; } else { thisColour = entry.color.value; //colorId = entry.color.value; //entry.color.options[entry.color.selectedIndex].value; //alert ("="+entry.chap +":"+ entry.color ); if(entry.color.options){ //alert("1"); colorId = entry.color.options[entry.color.selectedIndex].value; } else colorId=''; if(entry.colorId){ //alert("2"); colorId = entry.colorId.value; }else colorId=''; } } else { thisColour = " "; colorId = " "; } //alert("entry.size: "+entry.size); if(entry.size) { //alert ("entry.size:"+entry.size); //alert ("entry.size.value:"+entry.size.value); if(entry.size.options) // check to see if select used { thisSize = entry.size.options[entry.size.selectedIndex].text; sizeId = entry.size.value; } else { //alert("Ein!"+ entry.size.value ); thisSize = entry.size.value; //sizeId = entry.sizeId.value; //if(entry.sizeId) if(entry.size.options){ sizeId = entry.size.options[entry.size.selectedIndex].value; }else sizeId=''; if(entry.sizeId){ sizeId = entry.sizeId.value; }else sizeId=''; /* if(entry.chap && !entry.size ) sizeId = entry.sizeId.value; else sizeId = entry.size.options[entry.size.selectedIndex].value; */ } } else { thisSize = " "; sizeId = " "; } //alert("entry.option: "+entry.option); if(entry.option) { if(!entry.option.options) // check to see if select used { thisOption = entry.option.options[entry.size.selectedIndex].text; optionId = entry.option.value; } else { thisOption = entry.option.value; //optionId = entry.optionId.value; if(entry.option.options){ optionId = entry.option.options[entry.option.selectedIndex].value; }else optionId=''; if(entry.optionId){ optionId = entry.optionId.value; }else sizeId=''; /* if(entry.option.options) optionId = entry.option.options[entry.option.selectedIndex].value; else optionId = entry.optionId.value; */ } } else { thisOption = " "; optionId = " "; } description = entry.VATrate.value + " |D|" + thisDesc + "|C|" + thisColour + "|S|" + thisSize; //alert("cart.js.php.php: description: "+ description ); store_name = entry.store.value; product_name = (entry.FTShop.value) ? entry.FTShop.value : entry.FTShop.options[entry.FTShop.selectedIndex].text; if(product_name=="") { alert("Please select a color"); return; } qty = entry.quantity.value; price = entry.price.value; //alert ("entry.prodId.value:"); prodId = entry.prodId.value; if(!entry.size.options) { sizeId = entry.size.value; } else { // we're using a select sizeId = entry.size.options[entry.size.selectedIndex].value; } if(!entry.color.options) { colorId = entry.color.value; } else { // we're using a select colorId = entry.color.options[entry.color.selectedIndex].value; } /* if(!entry.color.options) { colorId = entry.color.value; } else { // we're using a select colorId = entry.color.options[entry.color.selectedIndex].value; } */ visDesc = thisDesc; if(visDesc != "" && visDesc != " ") { visProd = entry.FTShop.value + " (" + visDesc + ")"; } else { visProd = entry.FTShop.value; } document.cookie ="FTS" + store_name + "+" + description + "+" + product_name + "=" + qty + "++" + price + "+" + prodId + "+" + colorId + "+" + sizeId + "+" + optionId + "-"; if(qty==1) { alert(qty + ' x ' + visProd + '\nhas been placed in your shopping cart.\nThank you!'); } else if(qty>1) { alert(qty + ' x ' + visProd + '\nhave been placed in your shopping cart.\nThank you!'); } else if(qty<1) { alert('All ' + visProd + '\nare now removed from your shopping cart\nThank you!'); } } else { entry.quantity.value = 0; } //alert(document.cookie); } function check(i) { ok=true; //if true, don't go anywhere! // Color if (eval("document.forms['store"+i+"'].color")!=null) { if(eval("document.forms['store"+i+"'].color.value==''")) { alert("Please, select a Color !"); ok=false; } } // Size if (eval("document.forms['store"+i+"'].size")!=null) { if (eval("document.forms[\'store"+i+"\'].size.value==''")) { alert("Please, select a SIZE !"); ok=false; } } // Option if (eval("document.forms['store"+i+"'].option")!=null) { if (eval("document.forms[\'store"+i+"\'].option.value==''")) { alert("Please, select an OPTION !"); ok=false; } } return ok; } function stripNonNumbers (InString) { // DO NOT CHANGE ANY OF CODE BELOW!! OutString=""; for (Count=0;Count