// (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 200 chars change this: dlen=300 wlen=4 // if your id (qlen) or db nickname (plen)need be longer than 10 chars, change this: qlen=25 plen=10 // 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 url1 = "/cgi-bin/liberdomus/ordine.cgi?language="+lang+"&bill_e="+t+"&o_type=p&weight="+w; check_login (url1, '',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 var login = GetCookie('login'); if (login) return itemsCart.length; 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 login = GetCookie('login'); if (login) { self.location.href= '/cgi-bin/umbria/carrello.cgi?delete=' + escape(itemsCart[n][2]); } else { 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 var login = GetCookie('login'); if (login) return itemsCart[n][3]; return fetch(GetCookie(basket),n).substr(0,wlen) } function itemDescription(n) { // n=item number var login = GetCookie('login'); if (login) return itemsCart[n][0]; else return fetch(GetCookie(basket),n).substr(wlen,dlen) } function itemQuantity(n) { var login = GetCookie('login'); if (login) return itemsCart[n][2]; else return fetch(GetCookie(basket),n).substr(wlen+dlen,qlen) } function itemPrice(n) { var login = GetCookie('login'); if (login) return itemsCart[n][1]; else return fetch(GetCookie(basket),n).substr(wlen+dlen+qlen,plen) } 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; var login = GetCookie('login'); if (login) { newwindow('/cgi-bin/umbria/carrello.cgi?noheader=1&add=1&id_z_catalogo='+ p+'&id_libro='+escape(q)+'&z_request='+w+'&descrizione='+escape(d),'Segnalibri'); return false; } else { while (d.length > dlen) d = d.substr (0,dlen-d.lastIndexOf(' ')); itemSet(itemCount(GetCookie(basket)),w,unescape(unescape(d)),unescape(unescape(q)),p); return true; } } function emptyCart(basket) { var login = GetCookie('login'); if (login) { self.location.href = '/cgi-bin/umbria/carrello.cgi?delete=all'; } else { 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,showbotton) { basket=name; var n, m=itemCount(GetCookie(basket)) t=0 w=0 var loginid = GetCookie('login'); if(m==0) { vuo = 'Il tuo SegnaLibri è vuoto'; document.writeln('  '+vuo+'\ '); } else { for(n=0; n' +num+''; } else bookid = ''+num+''; if (showbotton) document.writeln('' + bookid + ''+d+'' + ''); else document.writeln('' + bookid + ''+d+' ' + '') } if (showbotton) { document.writeln('

' + ' ' + ''); if (loginid != '') document.writeln('' + '

'); } } } function repchar (str,ch,newch) { var res = ""; for (var s=str.indexOf(ch); s > 0; s=str.indexOf(ch)) { res = res + str.substring(0, s) + newch; str = str.substring(s+ch.length); } res = res + str; return res; } 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) }