// (C) 2000 John M Hanna under the terms of the GPL // copy freely if you include source! // script for shopping cart w/ encryption (soon to be) // put onClick="itemAdd(name, description, quantity, price,weight)" in your html // and showItems() to show the cart // You may need to customize buyItems() for your server // change this if you're not using dollars currency="€ " // if you need descriptions longer than 60 chars change this: dlen=180 wlen=10 // if your quantity or price need be longer than 6 chars, change this: qlen=6 plen=6 rlen=6 // if this cookie name conflicts with another javascript cookie, change this basket="shopping" // how do you calculate shipping costs function shipping(total) { return total/10; // shipping for us is 10% of total } function PickItems (t,w,lang) { if (t < 30) { var msg = ""; if (lang =='it') msg ="Per il Ritira in libreria é necessario un ordine minimo di EUR. 30.\nScegli un'altro libro dal catalogo o un'altra modalit\340 di consegna. Grazie!"; else msg = "Your order must be greater than EUR. 30 for Pick @ your bookshop Service.\n Please, choice another book from the Catalog or another delivery service.\n Thank you!"; alert(msg); } else { var url1 = "/cgi-bin/liberdomus/ordine.cgi?language="+lang+"&bill_e="+t+"&o_type=p&weight="+w; check_login (url1, '',lang);} } function RitiraItems(t,w,lang) { PickItems(t,w,lang); } function AcquistaItems(t,w,lang) { BuyItems(t,w,lang); } function PrenotaItems(t,w,lang) { BookItems(t,w,lang); } function BuyItems (t,w,lang) { var url1 = "/cgi-bin/liberdomus/ordine.cgi?language="+lang+"&bill_e="+t+"&o_type=s&weight="+w; var url2 = "/liberdomus/logord"+lang+".html"; check_login (url1, url2,lang); } function BookItems(t,w,lang) { var url1 = "/cgi-bin/liberdomus/ordine.cgi?language="+lang+"&bill_e="+t+"&o_type=b&weight="+w; var url2 = "/liberdomus/logord.html?language="+lang; check_login (url1, url2,lang); } // change the showItems() function if you don't like how the // shopping cart looks -- it's at the end of the script // You shouldn't need to change anything else here until the body... // have fun! tlen=(wlen+dlen+qlen+plen)+1 function itemCount(co) { // return number of items in basket if (!co) return 0; n=Math.floor(co.length/tlen); return Math.floor(co.length/tlen) } function chop(s,start,end) { return s.substr(0,start)+s.substr(end) } function delItem(basket,n) { SetCookie(basket,chop(GetCookie(basket),n*tlen,(n+1)*tlen)) refresh(); } function fetch(s,n) { return s.substr(n*tlen,tlen) } function itemWeight(n) { // n=item number return fetch(GetCookie(basket),n).substr(0,wlen) } function itemDescription(n) { // n=item number return fetch(GetCookie(basket),n).substr(wlen,dlen) } function itemQuantity(n) { return fetch(GetCookie(basket),n).substr(wlen+dlen,qlen) } function itemPrice(n) { return fetch(GetCookie(basket),n).substr(wlen+dlen+qlen,plen) } function itemRealPrice(n) { return fetch(GetCookie(basket),n).substr(wlen+dlen+qlen+plen,rlen) } function pad(s,n) { var i=n-s.length while(i-- > 0) { s+=" " } return s.substr(0,n) } function itemqSet(basket,n,q) { // just change quantity q=pad(q,qlen) var cookie=GetCookie(basket) SetCookie(basket,cookie.substr(0,n*tlen+dlen+wlen)+q+cookie.substr((n+1)*tlen-plen-1)) refresh(); } function itemSet(n,w,d,q,p) { // description, quantity, price var s=pad(w,wlen)+pad(d,dlen)+pad(q,qlen)+pad(p,plen) var cookie=GetCookie(basket) if (cookie) SetCookie(basket,cookie.substr(0,n*tlen)+s+"_"+cookie.substr((n+1)*tlen)) else SetCookie(basket,s+"_"); } function itemAdd(name,d,q,p,w) { basket=name; itemSet(itemCount(GetCookie(basket)),w,d,q,p); return true; } function emptyCart(basket) { SetCookie(basket,'') refresh(); } function refresh() { self.location.href = self.location.href; } function money(v) { v=Math.round(parseFloat(v)*100) v=String(v) var l=v.length-2 v=v.substring(0,l)+"."+v.substring(l) return currency+" "+v } function showItems(name,lang,origin) { basket=name; if (lang =='it') { if (basket.indexOf('book') != -1) tit1 ="Prenotazioni"; else { if (basket.indexOf('shop') != -1) tit1 ="Acquisti"; else tit1 = "Ritira in Libreria"; } l1 = ""; l2 = "Titolo libro"; l3 = "Importo"; l4 = "Prezzo"; l5 = "Azione"; l6 = "cancella"; but1 ="Scelta altri titoli"; if (basket.indexOf('book') == -1) but2 ="Conferma"; else but2 ="Prenota"; empty = ''; } else { if (basket.indexOf('shop') != -1) tit1 ="Shopping Cart"; else { if (basket.indexOf('book')) tit1 = "P@B (Pick @ your bookshop)"; else tit1 ="Reservations Cart"; } l1 = ""; l2 = "Book title"; l4 = "Price"; l3 = "Value"; l5 = "Action"; l6 = "cancel"; but1 ="Choose other books"; if (basket.indexOf('book') != -1) but2 ="Reserve"; if (basket.indexOf('shop') != -1) but2 ="Buy"; if (basket.indexOf('pick') != -1) but2 ="Pick"; empty = ''; } var n, m=itemCount(GetCookie(basket)) t=0 w=0 if(m==0) { if (lang != 'it') vuo = ' is empty'; else vuo = ' è vuoto'; document.writeln('  '+tit1+vuo+'\ '); } else { document.writeln('\

\   \ '+tit1+'\ \ '+l2+'\ '+l3+'\ Qt.\ '+l4+'\ '+l5+'\ ') for(n=0; n')); var ref=itemWeight(n) - 0; t+=v w+=(ref*q) q = ''; act = '' + ''+ l6 +''; document.writeln('\ \ '+d+'\ '+money(p)+'\ \ \ '+q+'\ \ '+money(v)+'\ \ '+act+'\ \ ') } if (lang == 'it') l4= 'Totale ordine'; else l4= 'Total order'; if (lang == 'it') { action="Acquista"; if (basket == 'booking') action = "Prenota"; if (basket == 'picking') action = "Ritira"; } else { action="Buy"; if (basket == 'booking') action = "Book"; if (basket == 'picking') action = "Pick"; } //uno step indietro url1 = "window.history.go(-1)"; if (origin == 'full') url1 = "window.history.go(-2)"; document.writeln('\ \ '+l4+'\ \ '+money(t)+'\ \ ') document.writeln('\ \ \   '+empty+'  \ ') } document.write(''); } function showItems2(name,lang,ship,zone,credit,discount,acc) { basket=name; var rit = 0; var riga = ' ' + '
'; var colspan = 4; if (lang =='it') { if (basket.indexOf('book') != -1) tit1 ="Prenotazioni"; else { if(basket.indexOf('shop') != -1) tit1 ="Acquisti"; else { tit1 ="Ritira in libreria"; rit = 1; riga = ' ' + '
'; colspan = 3; } } l1 = "vs. riferimento"; l2 = "Titolo libro"; l3 = "Importo"; l4 = "Prezzo"; l5 = "Acconto"; l6 ="Saldo"; } else { if (basket.indexOf('shop') != -1) tit1 ="Shopping Cart"; else { if (basket.indexOf('book')) tit1 = "P@B (Pick@ your bookshop)"; else { tit1 ="Reservations Cart"; rit = 1;} } l1 = "your reference"; l2 = "Book title"; l4 = "Price"; l3 = "Value"; l5 = "Advance Payment"; l6 = "Saldo"; } var n, m=itemCount(GetCookie(basket)) t=0 w=0 if(m==0) { if (lang != 'it') vuo = ' is empty'; else vuo = ' è vuoto'; } else { var newcol = ''; if (rit) newcol = ''+l5+'' + ''+l6+''; else newcol ='Qt.' + ''+l4+''; document.writeln('\
 \ \ \ \ \ \ '+ newcol + '') for(n=0; n')); var ref=itemWeight(n); t+=v w+=ref act = ' '; if (acc == 0) acc = 85; var a = v*parseFloat(acc)/100; var s = v-a; var newcol =''; if (rit) { newcol =''; } document.writeln('\ \ \ \ '+newcol+'\ ') } tot = t+parseFloat(ship); if (discount >0) { dis =tot*3/100; tot = tot - dis; } credit1 = parseFloat(credit); if ( credit1 > 0 ) { if (credit1 > tot) tot = "0.00"; else tot = tot - credit1; } if (lang == 'it') { l1= 'Destinazione'; l2= 'Spese di Spedizione'; l3= 'Costo dei libri'; l4= 'Totale ordine'; l5= 'Credito resa'; l6= 'Ulteriore sconto'; l7 = "Importi dovuti"; } else { l1= 'Shipment zone'; l2= 'Postage Cost'; l3= 'Amount books'; l4= 'Total order'; l5= 'Credit'; l6= 'Further discount'; l7= 'Total Advance payment'; } // stampa dello ship if (ship) if (ship > 0) { document.writeln(riga + '\ \ \ '+riga) } if (discount > 0) { document.writeln('\ \ \ ' + riga) } if (credit > 0) { document.writeln('\ \ \ '+riga) } if (rit) document.writeln('\ \ \ \ \ ') else document.writeln('\ \ \ \ ') } document.writeln('\
\ '+tit1+'
'+l1+''+l2+''+l3+'
'+q+ ''+ money(v)+''+ money(a) + ''+ money(s) + '
'+d+''+money(p)+'\ \
'+l2+'('+zone+'):\ '+money(ship)+'
'+l6+'\ '+money(dis)+'
'+l5+'\ '+money(credit)+'
'+l7+'\ '+money((parseFloat(tot-ship)*parseFloat(acc)/100)+ parseFloat(ship))+'\ \ '+money((parseFloat(tot-ship))*parseFloat(100-acc)/100)+'\
 
'+l4+'\ '+money(tot)+'\
 
\
') } function cartString() { var n, m=itemCount(GetCookie(basket)) var r='' t=0 if(m==0) { return('Empty shopping cart.') } else { for(n=0; n 19) return (false); var sum = 0, mul = 1, i; var digit for (i=st.length-1; i>=0; i--) { digit=st.charCodeAt(i)-48 if(digit <= 9 && digit >=0) { digit *=mul; if(digit > 9) digit=digit % 10 +1 sum += digit mul ^=3 } } return ((sum % 10) == 0) }