
window.addEvent('domready',function(){new Browse();new Galery($$('.extraits')[0]);new Book($$('.panel.about')[0]);var contact=$$('.panel.contact form')[0];var validateContact=new Validator(contact).addEvent('onValidate',function(){stage.to(1);contact.getElements('input, textarea').set('value','');});var stage=new Step($('contactForm')).addEvent('onInitialize',function(){delete this.form;if(form=this.step[this.index].getElement('form')){form.addEvent('submit',function(event){new Event(event).stop();});this.form=form;}}).to(0);function nextStage(stage,validate){if(stage.form&&(r=stage.form.getProperty('request')))
validate.get(stage.form).check(r);}
contact.getElements('span.input').addEvent('keydown',function(event){event=new Event(event);if(event.key!='enter')return;nextStage(stage,validateContact);});contact.getElement('a').setHref().addEvent('click',nextStage.pass([stage,validateContact]));contact.getParent().getParent().getElements('a')[1].setHref().addEvent('click',function(){stage.to(0);});var buy=$$('.panel.buy form')[0];var quantityInput=buy.getElement('input[name=quantity]');var printPrice=$('price');var totalCurrency=$('totalCurrency');var currencyInput=$('currencyInput');var amountInput=$('amountInput');quantityInput.addEvent('keyup',calculate);var currency=new Radio(buy.getElements('span[name=currency]')).addEvent('onChange',calculate);currency.setValue('CHF');function calculate(event){var price=$('price'+currency.getValue()).get('text').toInt(),quantity=(quantityInput.get('value')=='')?0:quantityInput.get('value').toInt(),shipping=0;switch(true){case quantity==1:shipping=7;break;case(quantity<7&&quantity>1):shipping=quantity*6;break;case(quantity>=7):shipping=36;break;}
price=(price*quantity)+shipping;totalCurrency.set('text',currency.getValue());currencyInput.set('value',currency.getValue());printPrice.set('text',price);amountInput.set('value',price);}
var validateBuy=new Validator(buy).addEvent('onValidate',function(response){(function(){var href='https://securepay.planet.ch/php/bd-champagne/?amount={price}&currency={currency}&uniqid={uniqid}';window.location.href=href.substitute({price:printPrice.get('text').toInt()*100,currency:totalCurrency.get('text'),uniqid:response.uniqid});}).delay(2000);stageBuy.to(1);});var stageBuy=new Step($('buy')).addEvent('onInitialize',function(){delete this.form;if(form=this.step[this.index].getElement('form')){form.addEvent('submit',function(event){new Event(event).stop();});this.form=form;}}).to(0);buy.getElements('span.input').addEvent('keydown',function(event){event=new Event(event);if(event.key!='enter')return;nextStage(stageBuy,validateBuy);});buy.getElement('a').setHref().addEvent('click',nextStage.pass([stageBuy,validateBuy]));});