Calendar.setup=function(params){function param_default(pname,def){if(typeof params[pname]=="undefined"){params[pname]=def;}};param_default("inputField",null);param_default("displayArea",null);param_default("button",null);param_default("eventName","click");param_default("ifFormat","%Y/%m/%d");param_default("daFormat","%Y/%m/%d");param_default("singleClick",true);param_default("disableFunc",null);param_default("dateStatusFunc",params["disableFunc"]);param_default("dateText",null);param_default("firstDay",null);param_default("align","Br");param_default("range",[1900,2999]);param_default("weekNumbers",true);param_default("flat",null);param_default("flatCallback",null);param_default("onSelect",null);param_default("onClose",null);param_default("onUpdate",null);param_default("date",null);param_default("showsTime",false);param_default("timeFormat","24");param_default("electric",true);param_default("step",2);param_default("position",null);param_default("cache",false);param_default("showOthers",false);param_default("multiple",null);var tmp=["inputField","displayArea","button"];for(var i in tmp){if(typeof params[tmp[i]]=="string"){params[tmp[i]]=document.getElementById(params[tmp[i]]);}}if(!(params.flat||params.multiple||params.inputField||params.displayArea||params.button)){alert("Calendar.setup:\n  Nothing to setup (no fields found).  Please check your code");return false;}function onSelect(cal){var p=cal.params;var update=(cal.dateClicked||p.electric);if(update&&p.inputField){p.inputField.value=cal.date.print(p.ifFormat);if(typeof p.inputField.onchange=="function")p.inputField.onchange();}if(update&&p.displayArea)p.displayArea.innerHTML=cal.date.print(p.daFormat);if(update&&typeof p.onUpdate=="function")p.onUpdate(cal);if(update&&p.flat){if(typeof p.flatCallback=="function")p.flatCallback(cal);}if(update&&p.singleClick&&cal.dateClicked)cal.callCloseHandler();};if(params.flat!=null){if(typeof params.flat=="string")params.flat=document.getElementById(params.flat);if(!params.flat){alert("Calendar.setup:\n  Flat specified but can't find parent.");return false;}var cal=new Calendar(params.firstDay,params.date,params.onSelect||onSelect);cal.showsOtherMonths=params.showOthers;cal.showsTime=params.showsTime;cal.time24=(params.timeFormat=="24");cal.params=params;cal.weekNumbers=params.weekNumbers;cal.setRange(params.range[0],params.range[1]);cal.setDateStatusHandler(params.dateStatusFunc);cal.getDateText=params.dateText;if(params.ifFormat){cal.setDateFormat(params.ifFormat);}if(params.inputField&&typeof params.inputField.value=="string"){cal.parseDate(params.inputField.value);}cal.create(params.flat);cal.show();return false;}var triggerEl=params.button||params.displayArea||params.inputField;triggerEl["on"+params.eventName]=function(){var dateEl=params.inputField||params.displayArea;var dateFmt=params.inputField?params.ifFormat:params.daFormat;var mustCreate=false;var cal=window.calendar;if(dateEl)params.date=Date.parseDate(dateEl.value||dateEl.innerHTML,dateFmt);if(!(cal&&params.cache)){window.calendar=cal=new Calendar(params.firstDay,params.date,params.onSelect||onSelect,params.onClose||function(cal){cal.hide();});cal.showsTime=params.showsTime;cal.time24=(params.timeFormat=="24");cal.weekNumbers=params.weekNumbers;mustCreate=true;}else{if(params.date)cal.setDate(params.date);cal.hide();}if(params.multiple){cal.multiple={};for(var i=params.multiple.length;--i>=0;){var d=params.multiple[i];var ds=d.print("%Y%m%d");cal.multiple[ds]=d;}}cal.showsOtherMonths=params.showOthers;cal.yearStep=params.step;cal.setRange(params.range[0],params.range[1]);cal.params=params;cal.setDateStatusHandler(params.dateStatusFunc);cal.getDateText=params.dateText;cal.setDateFormat(dateFmt);if(mustCreate)cal.create();cal.refresh();if(!params.position)cal.showAtElement(params.button||params.displayArea||params.inputField,params.align);else cal.showAt(params.position[0],params.position[1]);return false;};return cal;};;function CurrencyFormatted(amount)
{var i=parseFloat(amount);if(isNaN(i)){i=0.00;}
var minus='';if(i<0){minus='-';}
i=Math.abs(i);i=parseInt((i+.005)*100);i=i/100;s=new String(i);if(s.indexOf('.')<0){s+='.00';}
if(s.indexOf('.')==(s.length-2)){s+='0';}
s=minus+s;return s;}
function fireEvent(element,event){myflag=0;if(document.createEventObject){var evt=document.createEventObject();return element.fireEvent('on'+event,evt)}else{var evt=document.createEvent('HTMLEvents');evt.initEvent(event,true,true);return!element.dispatchEvent(evt);}}
document.observe('dom:loaded',function(){$$('.super-attribute-select').each(function(element){var next;var akt=element.selectedIndex;if(akt<element.length-1){next=akt+1;element.selectedIndex=next;}
fireEvent(element,'change');});$$('.options-list').each(function(element){element.select('li input[type=radio]')[0].checked=true;});$$('select.product-custom-option').each(function(element){element.options[1].selected=true;});$$('.info_box_show').each(function(element){element.observe('click',function(e){Event.stop(e);$(element).up(0).next(0).show();});});$$('.info_box_hide').each(function(element){element.observe('click',function(e){Event.stop(e);$(element).up(1).hide();});});});Product.Config.prototype.getProductByAttributes=function(productIds,attributes){for(var i=0;i<productIds.length;i++){var foundMatchingProduct=true;for(var a=0;a<attributes.length;a++){if(attributes[a].indexOf(productIds[i])==-1){foundMatchingProduct=false;break;}}
if(foundMatchingProduct){return productIds[i];}}
return false;}
Product.Config.prototype.getMatchingSimpleProduct=function(){var childProducts=this.config.childProducts;var childProductIds=[];for(var x in childProducts){childProductIds.push(x);}
var attributeProducts=[];for(var s=this.settings.length-1;s>=0;s--){var selected=this.settings[s].options[this.settings[s].selectedIndex];if(!selected.config){return false;}
attributeProducts.push(selected.config.products);}
return this.getProductByAttributes(childProductIds,attributeProducts);}
Product.Config.prototype.getLowestPossiblePrice=function(){var childProducts=this.config.childProducts;var minPrice=Infinity;var minPriceString="";for(var x in childProducts){var thisPrice=Number(childProducts[x]);if(thisPrice<minPrice){minPrice=thisPrice;minPriceString=childProducts[x];}}
return minPriceString;}
Product.Config.prototype.updateFormProductId=function(productId){if(!productId){return false;}
var currentAction=$('product_addtocart_form').action;newcurrentAction=currentAction.sub(/product\/\d+\//,'product/'+productId+'/');$('product_addtocart_form').action=newcurrentAction;$('product_addtocart_form').product.value=productId;}
Product.Config.prototype.addParentProductIdToCartForm=function(parentProductId){if(typeof $('product_addtocart_form').cpid!='undefined'){return;}
var el=document.createElement("input");el.type="hidden";el.name="cpid";el.value=parentProductId.toString();$('product_addtocart_form').appendChild(el);}
Product.Config.prototype.showTierPricesBlock=function(productId){config=this.config;$$('ul.product-pricing').each(function(label){label.remove();});if(productId&&config.childProductTierPriceHtml[productId]){$$('div.product-options-bottom').each(function(label){label.innerHTML=this.config.childProductTierPriceHtml[productId]+label.innerHTML;});}}
Product.Config.prototype.reloadPrice=function(){var childProductId=this.getMatchingSimpleProduct();if(childProductId){optionsPrice.productPrice=this.config.childProducts[childProductId];optionsPrice.reload();optionsPrice.reloadPriceLabels(true);this.updateFormProductId(childProductId);this.addParentProductIdToCartForm(this.config.productId);this.showTierPricesBlock(childProductId);this.showCustomOptionsBlock(childProductId,this.config.productId);flag=1;}else{optionsPrice.productPrice=0;optionsPrice.reload();optionsPrice.reloadPriceLabels(false);this.showTierPricesBlock(false);this.showCustomOptionsBlock(false,false);flag=0;}}
Product.Config.prototype.showCustomOptionsBlock=function(productId,parentId){var coUrl=this.config.ajaxBaseUrl+"co/?id="+productId+'&pid='+parentId;var prodForm=$('product_addtocart_form');if($('SCPcustomOptionsDiv')==null){return;}
Effect.Fade('SCPcustomOptionsDiv',{duration:0.5,from:1,to:0.5});if(productId){$$('span.scp-please-wait').each(function(el){el.show()});tmp=prodForm.submit;prodForm.submit=function(){return false};prodForm.getElements().each(function(el){el.disable()});new Ajax.Updater('SCPcustomOptionsDiv',coUrl,{method:'get',evalScripts:true,onComplete:function(){$$('span.scp-please-wait').each(function(el){el.hide()});Effect.Fade('SCPcustomOptionsDiv',{duration:0.5,from:0.5,to:1});prodForm.submit=tmp;prodForm.getElements().each(function(el){el.enable()});$$('.options-list').each(function(element){element.select('li input[type=radio]')[0].checked=true;});$$('select.product-custom-option').each(function(element){element.options[1].selected=true;});}});}else{$('SCPcustomOptionsDiv').innerHTML='';window.opConfig=new Product.Options([]);}};Product.OptionsPrice.prototype.reloadPriceLabels=function(productPriceIsKnown){var priceSpanId='configurable-price-from-'+this.productId;var duplicatePriceSpanId=priceSpanId+this.duplicateIdSuffix;}
