// (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) { var expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); var found = 0; for (var i = 0; i < document.picking.elements.length; i++) { if((document.picking.elements[i].name.indexOf ('itemsel') != (-1)) && document.picking.elements[i].checked) { found++; break; } } if (found == 0){ if (lang == 'it') alert("Almeno un libro deve essere selezionato"); else alert("No books selected"); return false; } found = 0; for (var i = 0; i < document.picking.elements.length; i++) { if((document.picking.elements[i].name.indexOf ('itemsel') != (-1)) && !document.picking.elements[i].checked) { n = document.picking.elements[i].value - found; basket='picking'; var p=itemPrice(n), q=itemQuantity(n), v=parseFloat(p)*parseFloat(q) var d=itemDescription(n); var ref=itemWeight(n) - 0; t-=v w-=(ref*q) SetCookie(basket,chop(GetCookie(basket),n*tlen,(n+1)*tlen),expdate) itemAdd2(basket+'_pref',d,q,p,ref+ ""); found++; } } 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 expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); var found = 0; for (var i = 0; i < document.shopping.elements.length; i++) { if((document.shopping.elements[i].name.indexOf ('itemsel') != (-1)) && document.shopping.elements[i].checked) { found++; break; } } if (found == 0){ if (lang == 'it') alert("Almeno un libro deve essere selezionato"); else alert("No books selected"); return false; } found = 0; for (var i = 0; i < document.shopping.elements.length; i++) { if((document.shopping.elements[i].name.indexOf ('itemsel') != (-1)) && !document.shopping.elements[i].checked) { n = document.shopping.elements[i].value - found; basket='shopping'; var p=itemPrice(n), q=itemQuantity(n), v=parseFloat(p)*parseFloat(q) var d=itemDescription(n); var ref=itemWeight(n) - 0; t-=v w-=(ref*q) SetCookie(basket,chop(GetCookie(basket),n*tlen,(n+1)*tlen),expdate) itemAdd2(basket+'_pref',d,q,p,ref+ ""); found++; } } 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 expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); var found = 0; for (var i = 0; i < document.booking.elements.length; i++) { if((document.booking.elements[i].name.indexOf ('itemsel') != (-1)) && document.booking.elements[i].checked) { found++; break; } } if (found == 0){ if (lang == 'it') alert("Almeno un libro deve essere selezionato"); else alert("No books selected"); return false; } found = 0; for (var i = 0; i < document.booking.elements.length; i++) { if((document.booking.elements[i].name.indexOf ('itemsel') != (-1)) && !document.booking.elements[i].checked) { n = document.booking.elements[i].value - found; basket='booking'; var p=itemPrice(n), q=itemQuantity(n), v=parseFloat(p)*parseFloat(q) var d=itemDescription(n); var ref=itemWeight(n) - 0; t-=v w-=(ref*q) SetCookie(basket,chop(GetCookie(basket),n*tlen,(n+1)*tlen),expdate) itemAdd2(basket+'_pref',d,q,p,ref+ ""); found++; } } 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) { var expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); SetCookie(basket,chop(GetCookie(basket),n*tlen,(n+1)*tlen),expdate) 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 sf = String(s); var i=n-sf.length; while(i-- > 0) { sf+=" " } var sf = sf.substr(0,n); return sf; } function itemqSet(basket,n,q) { // just change quantity // q = String(q).replace('\s',''); if(q == 0) q = 1; q=pad(q,qlen) var cookie=GetCookie(basket) var expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); SetCookie(basket,cookie.substr(0,n*tlen+dlen+wlen)+q+cookie.substr((n+1)*tlen-plen-1),expdate) 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) var expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); if (cookie) SetCookie(basket,cookie.substr(0,n*tlen)+s+"_"+cookie.substr((n+1)*tlen),expdate) else SetCookie(basket,s+"_",expdate); } function itemAdd2(name,d,q,p,w) { basket=name; itemSet(itemCount(GetCookie(basket)),w,d,q,p); return true; } function itemAdd(name,d,q,p,w) { if (check_login_car() == false) return false; basket=name; itemSet(itemCount(GetCookie(basket)),w,d,q,p); return true; } function emptyCart(basket) { var expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); SetCookie(basket,'',expdate) refresh(); } function printCart(basket,lang) { var specs='width=800,height=500,resizable=yes,scrollbars=yes,status=0'; var url = '/cgi-bin/liberdomus/print_cart.cgi?o_type=' + basket+ '&language=' + lang; var infow=window.open(url,'cart',specs); if (!infow) return; infow.focus('cart'); // infow.location.href = '/cgi-bin/print_cart.cgi?o_type=' + basket+ '&language=' + lang; } 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"; } l2 = "Titolo libro"; l3 = "Importo"; l4 = "Prezzo"; l5 = "Azione"; l6 = "cancella"; but1 ="Scelta altri titoli"; if (basket.indexOf('book') == -1) { but2 ="Conferma"; l1 = "Compra"; } else { but2 ="Prenota"; l1 = "Seleziona"; } empty = ''; print1 = ''; } else { if (basket.indexOf('shop') != -1) tit1 ="Shopping Cart"; else { if (basket.indexOf('book')) tit1 = "P@B (Pick @ your bookshop)"; else tit1 ="Selections Form"; } l2 = "Book title"; l4 = "Price"; l3 = "Value"; l5 = "Action"; l6 = "cancel"; but1 ="Choose other books"; if (basket.indexOf('book') != -1){ but2 ="Confirm Selections"; l1 = "Select"; } if (basket.indexOf('shop') != -1) { but2 ="Buy"; l1 = "Buy"; } if (basket.indexOf('pick') != -1){ but2 ="Pick"; l1 = "Pick"; } empty = ''; print1 = ''; } var n, m=itemCount(GetCookie(basket)) var newbasket= GetCookie(basket+'_pref'); if (itemCount(newbasket) !=0) { var expdate = new Date(); expdate.setTime (expdate.getTime() + (24*60*60*1000*365)); if (m == 0) SetCookie(basket, newbasket); else SetCookie(basket, newbasket + GetCookie(basket),expdate); SetCookie(basket+'_pref','',expdate) } t=0 w=0 m=itemCount(GetCookie(basket)); if(m==0) { if (lang != 'it') vuo = ' is empty'; else vuo = ' è vuoto'; document.writeln('  '+tit1+vuo+'\ '); } else { document.writeln('\

\   \ '+tit1+'\ \ '+l1+'\ '+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+'    '+print1+'\ ') document.write(''); } } function showItems2(name,lang,ship,zone,credit,discount,acc) { basket=name; var rit = 0; var colspan = 4; if(basket.indexOf('book') != -1) colspan = 5; var riga = ' ' + '
'; if (lang =='it') { l1 = "vs. riferimento"; l2 = "Titolo libro"; l3 = "Importo"; l4 = "Prezzo"; l5 = "Acconto"; l6 ="Saldo"; l7 =""; if (basket.indexOf('book') != -1) { tit1 ="Prenotazioni"; l1 = "fondo"; l7 = "localizz."; rit = 2; } else { if(basket.indexOf('shop') != -1) tit1 ="Acquisti"; else { tit1 ="Ritira in libreria"; rit = 1; riga = ' ' + '
'; colspan = 3; } } } else { l7 =""; l1 = "your reference"; l2 = "Book title"; l4 = "Price"; l3 = "Value"; l5 = "Advance Payment"; l6 = "Saldo"; if (basket.indexOf('shop') != -1) tit1 ="Shopping Cart"; else { if (basket.indexOf('book') != -1) { tit1 ="Selections Form"; l1 = "fund code"; l7 = "library loc."; rit = 2; } else { tit1 = "P@B (Pick@ your bookshop)"; rit = 1;} } } 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 == 1) newcol = ''+l5+'' + ''+l6+''; else newcol ='Qt.' + ''+l4+''; if (rit == 2) { document.writeln('\
 \ \ \ \ \ \ \ '+ newcol + '') } else { document.writeln('\
\ '+tit1+'
'+l1+''+l7+''+l2+''+l3+'
 \ \ \ \ \ \ '+ 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 == 1) { newcol =''; } if (rit == 2) { document.writeln('\ \ \ \ \ '+newcol+'\ ') } else { 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 == 1) document.writeln('\ \ \ \ \ ') else document.writeln('\ \ \ \ ') } document.writeln('\
\ '+tit1+'
'+l1+''+l2+''+l3+'
'+q+ ''+ money(v)+''+ money(a) + ''+ money(s) + '
'+d+''+money(p)+'\ \
'+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) }