!function($){"use strict";var defaults={formula:{},currency:"$",currencyPosition:"before",thousandthSeparator:",",decimalSeparator:".",decimalPlaces:2,notNumber:1,updateHidden:""},methods={init:function(r){return this.each(function(){r=$.extend(!1,defaults,r),$(this).data("cost-calculator-options",r),$(this).costCalculator("calculate")})},calculate:function(options){return this.each(function(){if(options=$(this).data("cost-calculator-options"),void 0!==options){var tempFormula=options.formula,array=$.grep(tempFormula.split(/\(|\)|\+|{\+}|\*|{\*}|\/|{\/}|\^|{\^}|{-}/g),function(r){return""!=r});if(0<=options.formula.indexOf("power")){var powerstart=0,powerend=0;for(var i in array)"{powerstart}"!=array[i]&&"{powerend}"!=array[i]&&(powerstart=0,powerend=0,0<=array[i].indexOf("{powerstart}")&&(powerstart=1),0<=array[i].indexOf("{powerend}")&&(powerend=1),tempFormula=tempFormula.replace(array[i],(powerstart?"Math.pow(":"")+(isNaN(parseFloat($("#"+array[i].replace(/{powerstart}|{powerend}/g,"")).val()))?isNaN(parseFloat(array[i].replace(/{powerstart}|{powerend}/g,"")))?0:parseFloat(array[i].replace(/{powerstart}|{powerend}/g,"")):parseFloat($("#"+array[i].replace(/{powerstart}|{powerend}/g,"")).val()))+(powerend?")":"")));tempFormula=tempFormula.replace(/{powerstart}/g,"Math.pow("),tempFormula=tempFormula.replace(/{powerend}/g,")"),tempFormula=tempFormula.replace(/\^/g,",")}else for(var i in array)tempFormula=tempFormula.replace(array[i],isNaN(parseFloat($("#"+array[i]).val()))?isNaN(parseFloat(array[i]))?0:parseFloat(array[i]):parseFloat($("#"+array[i]).val()));tempFormula=tempFormula.replace(/{|}/g,"");var sum=eval(tempFormula);parseInt(options.notNumber,10)&&!isFinite(sum)&&(sum=0);var regex=new RegExp("\\d(?=(\\d{3})+"+(0'+options.currency+"":"")+sum.toFixed(parseInt(options.decimalPlaces,10)).replace(".",options.decimalSeparator).replace(regex,"$&"+options.thousandthSeparator)+("after"==options.currencyPosition?''+options.currency+"":"")),"object"==jQuery.type(options.updateHidden)&&(options.updateHidden.val(("before"==options.currencyPosition?options.currency:"")+sum.toFixed(parseInt(options.decimalPlaces,10)).replace(".",options.decimalSeparator).replace(regex,"$&"+options.thousandthSeparator)+("after"==options.currencyPosition?options.currency:"")),$("#"+options.updateHidden.attr("id")+"-value").val(sum.toFixed(parseInt(options.decimalPlaces,10))))}})}};jQuery.fn.costCalculator=function(r){return methods[r]?methods[r].apply(this,arguments):"object"!=typeof r&&r||""==r.formula?void 0:methods.init.apply(this,arguments)}}(jQuery);