// source --> https://www.essafe.com.tr/wp-content/plugins/currency-exchange-for-woocommerce/js/currency_exchange.js?ver=3.6.2.6 
var brjsf_ce;
(function ($){
    brjsf_ce = function ( block ) {
        if ( typeof(block) != 'undefined' ) {
            brjsf_ce_reload(block);
        }
        $('.brjsf_ce').each( function( i, o ) {
            var width = 200;
            if ( $(o).data('width') ) {
                width = $(o).data('width');
            } 
            var html = '<div class="brjsf_ce_select"><span class="brjsf_ce_text">'+$(o).find('option:selected').data('text')+'</span> <i class="fa fa-caret-down"></i><ul>';
            $(o).find('option').each( function ( i_option, o_option ) {
                html += '<li data-value="'+$(o_option).val()+'">'+$(o_option).data('text')+'</li>';
            });
            html += '</ul></div>';
            $(o).after( html );
            $(o).removeClass('brjsf_ce').addClass('brjsf_ce_ready');
        });
    }
    function brjsf_ce_reload ( input ) {
        if ( $(input).is('.brjsf_ce_ready') ) {
            $(input).removeClass('brjsf_ce_ready').addClass('brjsf_ce').next().remove();
        } else if ( !$(input).is('.brjsf_ce') ) {
            $(input).addClass('brjsf_ce');
        }
    }
    $(document).on( 'click', '.brjsf_ce_select', function (event) {
        event.preventDefault();
        if ( $(this).is('.brjsf_ce_show') ) {
            $(this).removeClass('brjsf_ce_show');
            $(this).find('.fa').removeClass('fa-caret-up').addClass('fa-caret-down');
        } else {
            $('.brjsf_ce_show').removeClass('brjsf_ce_show');
            $(this).addClass('brjsf_ce_show');
            $(this).find('.fa').removeClass('fa-caret-down').addClass('fa-caret-up');
            $(this).find('ul').attr('style', '');
            if( ( jQuery(this).offset().top - jQuery(window).scrollTop() ) > ( jQuery(window).height() / 2 ) ) {
                $(this).find('ul').css('bottom', '100%').css('top', 'initial');
            } else {
                $(this).find('ul').css('bottom', 'initial').css('top', '100%');
            }
        }
    });
    $(document).on( 'click', '.brjsf_ce_select ul li', function(event) {
        var $select = $(this).parents('.brjsf_ce_select');
        $select.find('span.brjsf_ce_text').html($(this).html());
        $select.prev().val($(this).data('value')).trigger('change');
        
    });
    $(document).on( 'mousedown', '.brjsf_ce_select ul li, .brjsf_ce_select', function(event) {
        event.preventDefault();
        event.stopPropagation();
    });
    $(document).on( 'mousedown', function(event) {
        $('.brjsf_ce_show').removeClass('brjsf_ce_show').find('.fa').removeClass('fa-caret-up').addClass('fa-caret-down');
    });
    $(document).ready( function () {
        ce_execute_func( the_ce_js_data.script.js_page_load );
        jQuery(document).trigger('berocket_ce-js_page_load');
        $(document).on( 'change', '.br_ce_currency_select, .br_ce_select_currency', function(event){
            ce_execute_func( the_ce_js_data.script.js_before_set );
            jQuery(document).trigger('berocket_ce-js_before_set');
            var val = $(this).val();
            $.cookie( 'br_ce_language', val, { path: '/', domain: document.domain } );
            $('.br_ce_currency_select').val(val);
            $('.br_ce_'+val).prop('checked', true);
            try {
                sessionStorage.removeItem('wc_fragments');
                sessionStorage.removeItem('wc_cart_hash');
                localStorage.removeItem('wc_cart_hash');
                sessionStorage.removeItem(wc_cart_fragments_params.fragment_name);
            } catch (e) {}
            jQuery(document).trigger('berocket_ce-js_after_set');
            ce_execute_func( the_ce_js_data.script.js_after_set );
        });
        if( the_ce_js_data.visual_only ) {
            fx.base = the_ce_js_data.base;
            fx.rates = the_ce_js_data.rates;
            if( the_ce_js_data.current != 'none' ) {
                fx.settings = {
                    from : fx.base,
                    to : the_ce_js_data.current
                };
                ce_money_replace();
            }
            jQuery(document).on('berocket_ajax_filtering_end', ce_money_replace);
            jQuery(document).on('berocket_lmp_end', ce_money_replace);
            jQuery(document).on('berocket_product_preview-popup_open', ce_money_replace);
            jQuery(document).on('wc_fragments_refreshed', ce_money_replace);
            jQuery(document).on('wc_fragments_loaded', ce_money_replace);
        }
        brjsf_ce();
        jQuery(document).ajaxComplete(function() {
            if( the_ce_js_data.visual_only ) {
                ce_money_replace();
            }
        });
        if( the_ce_js_data.visual_only ) {
            ce_money_replace();
        }
    });
    if( the_ce_js_data.visual_only ) {
        $(document).on('change', '.variations select', ce_money_replace);
        $(document).on('br_popup-show_popup', ce_money_replace);
        $(document).on('berocket_product_preview-popup_open', ce_money_replace);
    }
})(jQuery);
function ce_money_replace() {
    if( the_ce_js_data.current != 'none' ) {
        jQuery('span.amount').each(function(i, o) {
            if( ! jQuery(o).is('.exchanged') ) {
                jQuery(o).find('.woocommerce-Price-currencySymbol').remove();
                var money = accounting.unformat(jQuery(o).text(), the_ce_js_data.accounting.decimal);
                money = fx.convert(money);
                money = accounting.formatMoney(money, the_ce_js_data.accounting);
                jQuery(o).html(money).addClass('exchanged');
            }
        });
    }
}
function ce_execute_func ( func ) {
    if( the_ce_js_data.script != 'undefined'
        && the_ce_js_data.script != null
        && typeof func != 'undefined' 
        && func.length > 0 ) {
        try{
            eval( func );
        } catch(err){
            alert('You have some incorrect JavaScript code (Currency Exchange)');
        }
    }
};
// source --> https://www.essafe.com.tr/wp-content/plugins/currency-exchange-for-woocommerce/js/money.min.js?ver=7.0 
/* money.js 0.2, MIT license, http://openexchangerates.github.io/money.js */
(function(g,j){var b=function(a){return new i(a)};b.version="0.1.3";var c=g.fxSetup||{rates:{},base:""};b.rates=c.rates;b.base=c.base;b.settings={from:c.from||b.base,to:c.to||b.base};var h=b.convert=function(a,e){if("object"===typeof a&&a.length){for(var d=0;d<a.length;d++)a[d]=h(a[d],e);return a}e=e||{};if(!e.from)e.from=b.settings.from;if(!e.to)e.to=b.settings.to;var d=e.to,c=e.from,f=b.rates;f[b.base]=1;if(!f[d]||!f[c])throw"fx error";d=c===b.base?f[d]:d===b.base?1/f[c]:f[d]*(1/f[c]);return a*d},i=function(a){"string"===typeof a?(this._v=parseFloat(a.replace(/[^0-9-.]/g,"")),this._fx=a.replace(/([^A-Za-z])/g,"")):this._v=a},c=b.prototype=i.prototype;c.convert=function(){var a=Array.prototype.slice.call(arguments);a.unshift(this._v);return h.apply(b,a)};c.from=function(a){a=b(h(this._v,{from:a,to:b.base}));a._fx=b.base;return a};c.to=function(a){return h(this._v,{from:this._fx?this._fx:b.settings.from,to:a})};if("undefined"!==typeof exports){if("undefined"!==typeof module&&module.exports)exports=module.exports=b;exports.fx=fx}else"function"===typeof define&&define.amd?define([],function(){return b}):(b.noConflict=function(a){return function(){g.fx=a;b.noConflict=j;return b}}(g.fx),g.fx=b)})(this);
// source --> https://www.essafe.com.tr/wp-content/plugins/currency-exchange-for-woocommerce/js/accounting.min.js?ver=7.0 
/*!
 * accounting.js v0.4.2, copyright 2014 Open Exchange Rates, MIT license, http://openexchangerates.github.io/accounting.js
 */
(function(p,z){function q(a){return!!(""===a||a&&a.charCodeAt&&a.substr)}function m(a){return u?u(a):"[object Array]"===v.call(a)}function r(a){return"[object Object]"===v.call(a)}function s(a,b){var d,a=a||{},b=b||{};for(d in b)b.hasOwnProperty(d)&&null==a[d]&&(a[d]=b[d]);return a}function j(a,b,d){var c=[],e,h;if(!a)return c;if(w&&a.map===w)return a.map(b,d);for(e=0,h=a.length;e<h;e++)c[e]=b.call(d,a[e],e,a);return c}function n(a,b){a=Math.round(Math.abs(a));return isNaN(a)?b:a}function x(a){var b=c.settings.currency.format;"function"===typeof a&&(a=a());return q(a)&&a.match("%v")?{pos:a,neg:a.replace("-","").replace("%v","-%v"),zero:a}:!a||!a.pos||!a.pos.match("%v")?!q(b)?b:c.settings.currency.format={pos:b,neg:b.replace("%v","-%v"),zero:b}:a}var c={version:"0.4.1",settings:{currency:{symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3},number:{precision:0,grouping:3,thousand:",",decimal:"."}}},w=Array.prototype.map,u=Array.isArray,v=Object.prototype.toString,o=c.unformat=c.parse=function(a,b){if(m(a))return j(a,function(a){return o(a,b)});a=a||0;if("number"===typeof a)return a;var b=b||".",c=RegExp("[^0-9-"+b+"]",["g"]),c=parseFloat((""+a).replace(/\((.*)\)/,"-$1").replace(c,"").replace(b,"."));return!isNaN(c)?c:0},y=c.toFixed=function(a,b){var b=n(b,c.settings.number.precision),d=Math.pow(10,b);return(Math.round(c.unformat(a)*d)/d).toFixed(b)},t=c.formatNumber=c.format=function(a,b,d,i){if(m(a))return j(a,function(a){return t(a,b,d,i)});var a=o(a),e=s(r(b)?b:{precision:b,thousand:d,decimal:i},c.settings.number),h=n(e.precision),f=0>a?"-":"",g=parseInt(y(Math.abs(a||0),h),10)+"",l=3<g.length?g.length%3:0;return f+(l?g.substr(0,l)+e.thousand:"")+g.substr(l).replace(/(\d{3})(?=\d)/g,"$1"+e.thousand)+(h?e.decimal+y(Math.abs(a),h).split(".")[1]:"")},A=c.formatMoney=function(a,b,d,i,e,h){if(m(a))return j(a,function(a){return A(a,b,d,i,e,h)});var a=o(a),f=s(r(b)?b:{symbol:b,precision:d,thousand:i,decimal:e,format:h},c.settings.currency),g=x(f.format);return(0<a?g.pos:0>a?g.neg:g.zero).replace("%s",f.symbol).replace("%v",t(Math.abs(a),n(f.precision),f.thousand,f.decimal))};c.formatColumn=function(a,b,d,i,e,h){if(!a)return[];var f=s(r(b)?b:{symbol:b,precision:d,thousand:i,decimal:e,format:h},c.settings.currency),g=x(f.format),l=g.pos.indexOf("%s")<g.pos.indexOf("%v")?!0:!1,k=0,a=j(a,function(a){if(m(a))return c.formatColumn(a,f);a=o(a);a=(0<a?g.pos:0>a?g.neg:g.zero).replace("%s",f.symbol).replace("%v",t(Math.abs(a),n(f.precision),f.thousand,f.decimal));if(a.length>k)k=a.length;return a});return j(a,function(a){return q(a)&&a.length<k?l?a.replace(f.symbol,f.symbol+Array(k-a.length+1).join(" ")):Array(k-a.length+1).join(" ")+a:a})};if("undefined"!==typeof exports){if("undefined"!==typeof module&&module.exports)exports=module.exports=c;exports.accounting=c}else"function"===typeof define&&define.amd?define([],function(){return c}):(c.noConflict=function(a){return function(){p.accounting=a;c.noConflict=z;return c}}(p.accounting),p.accounting=c)})(this);