/* CONFIG */ var porto = 20; var cart_style = '#cart, #cart td, #cart input { font-size:8pt; }\n'+ '.cartqty { width:40px; }\n'+ '.carttot td { border-top:1px solid #ddd; }\n'+ '.carttot td { font-weight:bold; }\n'; var buy_style = ''; /* '.buy { border:1px solid #ddd; }\n'+ '.buy, .buy td { font-size:8pt; }\n'+ '.aofull { width:200px; }\n'+ '.aohalf { width:100px; }\n'+ '.buyprice { font-weight:bold; }\n'+ '.buyconfirm { font-weight:bold; color:green; }\n'+ '.radiodiv { border:1px solid #ccc; height:22px; padding-top:2px; cursor:default; margin-top:4px; }\n'+ '.radiodiv:hover { background:#def; }\n'+ 'button[name="buy"], #cobtn { background:#f80; color:white; font-weight:bold; border:1px solid #888; }\n'+ 'button[name="buy"]:hover, #cobtn:hover { background:#fa0; }\n'; */ var cart = null; var cartsimple = null; var dynlang = 0; /* INIT */ $(function() { cart = $('#cart'); cartsimple = $('#cartsimple'); $('body').append('\n'); if(cart) cartget(); buysetarticle(); }); // had conflict when added to seeland // $.support.cors = true; /* SESSION HELPER */ var cartid = "14479r9dq5cp3hh7qpm7n8rvr2"; if(!cartid) { if (document.cookie.length>0){ c_start=document.cookie.indexOf("PHPSESSID="); if (c_start!=-1){ c_start=c_start + 10; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; cartid = unescape(document.cookie.substring(c_start,c_end)); } } } /* CART */ function carthtml(html) { cart.html(html).show(); } function cartshow(d) { data = d['rows']; if(data.length==0) { if(cart) cart.hide(); if(cartsimple) cartsimple.hide(); return; } if(cart) { var h='
'; var t=0; for(var n in data) { h+=''; t+=parseFloat(data[n]['price'])*parseFloat(data[n]['qty']); } h+=''; t+=porto; h+=''; h+='
'; h+=''; h+=''; h+=$('
').text(data[n]['text']).html(); h+='
'; h+=$('
').text(data[n]['price']?(parseFloat(data[n]['qty'])*parseFloat(data[n]['price'])).toFixed(2):'').html(); h+='
1Porto'+porto.toFixed(2)+'
TOTAL (CHF inkl. MwSt.)'+t.toFixed(2)+'
'; h+=''; h+=''; h+='
'; cart.html(h).show(); } if(cartsimple) cartsimple.find('#cartsimpletext').html(d['htmlsimple']).end().show(); } function cartget() { cart.html('loading...'); // $.get('http://www.dynavox.ch/dynshop/cart.php', {}, cartshow); $.ajax('https://www.dynavox.ch/dynshop/cart.php', {type:'GET',data:{'cartid':cartid},success:cartshow,xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); // $.ajax('http://www.dynavox.ch/dynshop/cart.php', {type:'GET',data:{'cartid':cartid,'html':'simple'},success:cartshow,xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); } function cartsaveqty(t) { var row = parseInt($(t).attr('name')); var qty = parseInt($(t).val()); cart.html('loading...'); // $.post('http://www.dynavox.ch/dynshop/cart.php', {'id':row, 'qty':qty}, cartshow); $.ajax('https://www.dynavox.ch/dynshop/cart.php', {type:'POST',data:{'cartid':cartid,'id':row,'qty':qty},success:cartshow,xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); // $.ajax('http://www.dynavox.ch/dynshop/cart.php', {type:'POST',data:{'cartid':cartid,'id':row,'qty':qty,'html':'simple'},success:cartshow,xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); } function cartqtykeypress(t,e) { $(t).css('background-color','#ff8'); $(t).blur(function() { cartsaveqty(t); }); if(!e) return; if(e.charCode == 13) { cartsaveqty(t); return false; } return (e.charCode === 0) || (/\d/.test(String.fromCharCode(e.charCode))); } function cartdelete() { cart.html('loading...'); // $.post('http://www.dynavox.ch/dynshop/cart.php', {'delete':1}, cartshow); $.ajax('https://www.dynavox.ch/dynshop/cart.php', {type:'POST',data:{'cartid':cartid,'delete':1},success:cartshow,xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); // $.ajax('http://www.dynavox.ch/dynshop/cart.php', {type:'POST',data:{'cartid':cartid,'delete':1,'html':'simple'},success:cartshow,xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); } function cartcheckout() { cart.html('processing...'); // $.get('http://www.dynavox.ch/dynshop/checkout.php',{'ajax':'carthtml'}, carthtml); // window.location.href = 'http://www.dynavox.ch/dynshop/checkout.php?cartid='+cartid; window.top.location.href = 'http://www.dynavox.ch/dynshop/checkout.php?cartid='+cartid; return false; } function cartadd(qty, aname, text, price) { cart.html('loading...'); // $.post('http://www.dynavox.ch/dynshop/cart.php', {'aid':aname,'qty':qty,'text':text,'price':price}, cartshow); $.ajax(window.location.protocol+"//"+window.location.host+window.location.pathname, {type:'POST',data:{'cart':'add','aid':aname,'qty':qty,'text':text,'price':price},success:function() {window.location.reload();},xhrFields:{withCredentials:true},beforeSend:function(xhr){xhr.withCredentials=true;}}); } /* BUY */ function lang(l) { if(l) { var ll = l.split("|"); if(ll.length>1) l=ll[dynlang] || ""; } return l; } function strclean(s) { s = (s+'').replace('{black}',lang('schwarz|noir|black')) .replace('{silver}',lang('silber|argent|silver')) .replace('{white}',lang('weiss|blanc|white')) .replace('{black-hg}',lang('schwarz hochglanz|noir laqu�|black high-gloss')) .replace('{white-hg}',lang('weiss hochglanz|blanc laqu�|white high-gloss')) .replace('{cherry}',lang('Kirsche|cerisier|cherry')) .replace('{nut}',lang('Nuss|noyer|nut')) .replace('{walnut}',lang('Nussbaum|noyer|walnut')) .replace('{red}',lang('rot|rouge|red')) .replace('{sienna}',lang('Sienna|Sienna|Sienna')); return s.replace(/{\w+}/g, '').replace(/\\n/g, ''); } function strhtml(s) { if(!s) return ''; return s.replace(/{\d}/g, '') .replace(/&/g, '&') .replace(/>/g, '>') .replace(/"); } function getarticle(aid) { return articles[aid]; } if (typeof Object.create !== "function") { // IE helper Object.create = (function () { function F() {} return function (o) { F.prototype = o; return new F(); }; })(); } function buygetname(form) { // var aname = form['aid'].value; var aname = $(form).find('input[name="aid"]:checked').val(); if(!aname) return ''; for(var i=0; i<10; i++) if(form['o'+i+'_item'] || form['o'+i+'_qty']) { aname+= ':'; if(form['o'+i+'_qty']) aname+= form['o'+i+'_qty'].value; if(form['o'+i+'_item']) aname+= form['o'+i+'_item'].value; } return aname.replace(/:+$/,''); } function valueunit(s) { var v = ""; if(!s) return [1, ""]; for(var i=0; i= 48) && (a <= 57)) || (a == 46)) v+= s.charAt(i); else { i--; break; } } if(v == "") v = "1"; return [parseFloat(v), s.substr(++i)]; } function replaceorappend(n, r, s) { var res = s.replace(n, r); if(res==s) res+=r; return res; } function object_first_elem(obj) { var f; for(var key in obj) { f = obj[key]; if(typeof(f)!=='function') break; } return f; } function buycalc(aname) { var params = aname.split(':'); var aid = params.shift(); var a = getarticle(aid); if(!a) return {}; a = Object.create(a); a['name'] = lang(a['name']); a['descr'] = lang(a['descr']); if(!a['net']) a['net'] = 0; if(!a['prod']) a['prod'] = new Array(); if(params.length) { var maxpd = 0; var options = a['opts']; // if(options) options = JSON.parse(options); if(options) options = $.parseJSON(options); if(options) { for(var i=0; i0)) { var pd = parseFloat(item['proddays']); if(pd > maxpd) maxpd = pd; } if(item['prod']) for(var pi in item['prod']) { a['prod'].push({'qty':parseFloat(f)*parseFloat(item['prod'][pi]['qty']), 'aid':item['prod'][pi]['aid']}); } } } a['name'] = replaceorappend('{'+(i*1+1)+'}', name, a['name']); a['descr'] = replaceorappend('{'+(i*1+1)+'}', descr, a['descr']); } } a['proddays'] = (parseFloat(a['proddays'])?parseFloat(a['proddays']):0) + maxpd; } return a; } function buy_onsubmit(e) { var qty = parseFloat($(e).find('input[name="qty"]').val()); if(!qty || (qty<1)) qty = 1; var aname = buygetname(e); var a = buycalc(aname); cartadd(qty, aname, a.name, parseFloat(a.price)); $(e).find('.buyconfirm').text("Ware wurde dem Warenkorb hinzugef�gt."); return false; } function buyrecalc(e) { // e is a form var aname = buygetname(e); var a = buycalc(aname); $(e).find('.buydescr').html(strhtml(a.descr)); $(e).find('.buyprice').text('CHF '+parseFloat(a.price).toFixed(2)); $(e).find('.buypricestereo').text((parseFloat(a.price)*2).toFixed(2)); console.log('price: '+parseFloat(a.price).toFixed(2)); var delay = 10000; if((stocks[aname]) && (stocks[aname]['delay'] != null)) delay = stocks[aname]['delay']; else { var params = aname.split(':'); var aid = params.shift(); if(stocks[aid]) { if((stocks[aid]['delay'] != null)) delay = stocks[aid]['delay']; } // else delay = 0; // deactivated for articles without stock info // if base article has no stock info (virtual article) then delay is 0 if(a['proddays']) delay = (delay>10000?0:delay) + a['proddays']; } var avail = lang('unbekannt|inconnu|unknown'); if(delay==0) avail = lang('lieferbar|livrable|available'); else if((delay>0) && (delay<10000)) avail = lang('in ca.|dans env.|in ca.')+' '+delay+' '+(delay>1?lang('Tagen|jours|days'):lang('Arbeitstag|jour ouvrable|workday')); $(e).find('.buyavail').text(avail); } function buyrecalcnumber(e) { if(parseFloat(e.value) > parseFloat(e.max)) e.value = e.max; if(parseFloat(e.value) < parseFloat(e.min)) e.value = e.min; if(e.step) e.value = Math.round((parseFloat(e.value)-parseFloat(e.min?e.min:0)) / parseFloat(e.step)) * parseFloat(e.step) + parseFloat(e.min?e.min:0); /* does not work as "e" is a element and not the options array! if(e.values) { var best = parseFloat(e.values[0]); for(var i=0; i Math.abs(parseFloat(e.value)-parseFloat(e.values[i]))) best = parseFloat(e.values[i]); e.value = best; } */ buyrecalc(e.form); } function buyform(aname) { var h = '
'; var params = aname.split(':'); var aid = params.shift(); var a = getarticle(aid); if(typeof a == 'undefined') a = {}; var a = Object.create(a); h+= ''; var options = a['opts']; if(options) options = $.parseJSON(options); if(options) for(var i=0; i'; } if(a['state'].indexOf('price')>=0) { h+= '\n'; } h+= '\n'; h+= '
'; for(var n in articles) { var ta = getarticle(n); if(ta['type']==1) { var sel = (n == aid)?" checked":""; h+= '
'+strclean(lang(ta['name']))+'
'; // prop(\'checked\',true); } } h+= '
'; var c = "aofull"; if(o['qty'] && o['items'] && (o['items'].length>0)) c = "aohalf"; if(o['qty']) { if(o['values']) { h+= ''; } else { if(!o['step']) o['step'] = o['qty']; h+= ''; } } p = valueunit(p); var f = p[0]; p = p[1]; if(o['items'] && (o['items'].length>0)) { h+= ''; } else { var item = getarticle(o['items'][0]); if(item) if(item['price']) h+= ' ('+strclean(item['price']+'/'+(item['name']?item['name']:lang('Stk.|pce.|pc.')))+')'; } h+= '
'+lang('Preis|prix|Price')+':CHF .-'; if(a['unit']) h+= ' /'+a['unit']+''; else h+= ' /'+lang('Stk.|pce.|pc.')+''; if(a['unit']=='mono') h+= '   /'+lang('Stereo|stéréo|stereo')+''; h+= '
'+lang('Beschreibung|description|Description')+':-
'; h+= '
\n'; return h; } function buysetarticle(aname) { $('.buy').each(function() { if(!aname) aname = $(this).attr('title'); $(this).removeAttr('title'); $(this).html(buyform(aname)); buyrecalc($(this).children('form').get(0)); }); }