!function(e){function r(e,r){e.hasClass("fn_currency2")||(e.addClass("fn_currency2"),new t(e,r))}var a={liraTxt:null,kurusTxt:null,value:null,liraTxtPlaceholder:"1.234,5",kurusTxtPlaceholder:"00",liraValue:"",kurusValue:""};e.fn.fn_currency2=function(t,l){if("string"==typeof t)switch($el=e(this),t){case"setVal":r($el,a);var o=v(l);(s=n($el)).value=o.value,s.liraValue=o.liraValue,s.kurusValue=o.kurusValue,i($el,s.value),u($el,s);break;case"getVal":return c($el,l);case"clearVal":(s=n($el)).value=null,s.liraValue="",s.kurusValue="",u($el,s),i($el,null);break;case"setDisable":if("boolean"==typeof l){var s=n($el);e(s.liraTxt).prop("disabled",l),e(s.kurusTxt).prop("disabled",l)}break;default:return $el}return this.each(function(){r(e(this),t)})};var t=function(r,t){var c=e.extend({},a,t);if(null==c.liraTxt){var v=r.find('input[type="text"].fn_currency2_beforeDot:eq(0)');if(0==v.length)return;c.liraTxt="#"+v.attr("id")}if(null==c.kurusTxt){var y=r.find('input[type="text"].fn_currency2_afterDot:eq(0)');if(0==y.length)return;c.kurusTxt="#"+y.attr("id")}e(c.liraTxt).attr("autocomplete","off"),e(c.liraTxt).addClass("fn_currency2_beforeDot"),e(c.liraTxt).css({"text-align":"right"}),e(c.kurusTxt).attr("autocomplete","off"),e(c.kurusTxt).attr("maxlength","2"),e(c.kurusTxt).addClass("fn_currency2_afterDot"),0==r.find(".fn_currency2_currencyAddon").length&&r.find("span.input-group-addon:eq(0)").addClass("fn_currency2_currencyAddon"),0==r.find(".fn_currency2_commaAddon").length&&r.find("span.input-group-addon:eq(1)").addClass("fn_currency2_commaAddon"),r.find(".fn_currency2_currencyAddon").css({}),r.find(".fn_currency2_commaAddon").css({padding:"4px"});var g="";if(null!=c.value){var V=(g=c.value.toString()===c.value.toLocaleString()?c.value.toString():c.value.toLocaleString()).split(".");c.liraValue=void 0!==V[0]?V[0]:"",c.kurusValue=void 0!==V[1]?V[1]:"00",i(r,c.value)}else i(r,null);u(r,c),e(c.liraTxt).on("keydown",function(a){var t=n(r);if(d(a.key))t.liraValue=t.liraValue+a.key;else if("Enter"==a.key)a.preventDefault();else if("Backspace"==a.key){i=k(this);t.liraValue=o(l(e(this).val(),i)),console.log(t.liraValue)}else if("Delete"==a.key){var i=k(this);t.liraValue=o(l(e(this).val(),i+1))}u(r,t)}),e(c.liraTxt).on("keyup",function(a){var t=n(r);e(this).val(s(t.liraValue))}),e(c.kurusTxt).on("keydown",function(e){var a=n(r);d(e.key)&&2!=a.kurusValue.length?a.kurusValue=a.kurusValue+e.key:"Enter"==e.key?e.preventDefault():"Backspace"==e.key&&(a.kurusValue=a.kurusValue.slice(0,-1)),u(r,a)}),e(c.kurusTxt).on("keyup",function(a){var t=n(r);e(this).val(f(t.kurusValue))})},l=function(e,r){return e=e.slice(0,r-1)+e.slice(r)},u=function(e,r){var a=e.attr("id");"undefined"!=typeof Storage&&localStorage.setItem(a,JSON.stringify(r))},n=function(e){var r=e.attr("id");if("undefined"!=typeof Storage)return JSON.parse(localStorage.getItem(r))},i=function(r,a){var t,l=r.find(".fn_currency2_beforeDot")[0],u=r.find(".fn_currency2_afterDot")[0];if(void 0!==a&&null!=a){var n=(t=a.toString()===a.toLocaleString()?a.toString():a.toLocaleString()).split(".");void 0!==l&&e(l).val(s(n[0])),n[1]&&void 0!==u&&e(u).val(f(n[1]))}else e(l).val(""),e(u).val("00")},c=function(e,r){e.find(".fn_currency2_beforeDot")[0],e.find(".fn_currency2_afterDot")[0];var a,t,l,u=n(e);switch(void 0===r?"C":r,r){case"C":case"c":l=",",a=s(u.liraValue);break;case"D":case"d":default:l=".",a=u.liraValue}return""==a?null:(t=u.kurusValue,t.length>0?1==t.length&&(t+="0"):t="00",a+l+t)},o=function(e){return-1!=e.indexOf(".")?(e=e.replace(".",""),o(e)):e},s=function(e){var r=e;if(r.toString()===r.toLocaleString()){var a=r.toString().split(".");a[0]=a[0].replace(/\B(?=(\d{3})+(?!\d))/g,"."),r=a[1]?a.join("."):a[0]}else r=r.toLocaleString();return r},f=function(e){return e.slice(0,2)},d=function(e){return!isNaN(e)&&function(e){return(0|e)===e}(parseFloat(e))},v=function(e){var r={liraValue:"",kurusValue:"",value:""};if(null==e)return r.liraValue="",r.kurusValue="00",r.value=null,r;-1==e.indexOf(",")&&(e+=",00");var a=e.split(",");return r.liraValue=o(a[0]),a[1]?a[1].length>=2?r.kurusValue=a[1].slice(0,2):r.kurusValue=a[1].slice(0,1)+"0":r.kurusValue="00",r.value=r.liraValue+"."+r.kurusValue,r},k=function(e){var r=0;if(document.selection){e.focus();var a=document.selection.createRange();a.moveStart("character",-e.value.length),r=a.text.length}else(e.selectionStart||"0"==e.selectionStart)&&(r=e.selectionStart);return r}}(jQuery);