(function($) {
    $.extend($.fn, {bindUp: function(event, cbFunc) {
            return this.each(function() {
                var highIndex = 1000000;
                var eventData = event.split('.');
                var eventName = eventData[0];
                $(this).bind(event, cbFunc);
                var events = $(this).data('events'), ourIndex = !1, usedIndicies = {};
                $.each(events[eventName], function(index, func) {
                    if (func === cbFunc) {
                        ourIndex = index
                    }
                    usedIndicies[index] = 1
                });
                if (ourIndex !== !1) {
                    while (usedIndicies[highIndex] == 1) {
                        highIndex++
                    }
                    events[eventName][highIndex] = events[eventName][ourIndex];
                    delete events[eventName][ourIndex]
                    $(this).data('events', events)
                }
            })
        }})
})(jQuery);
function quote(regex) {
    return regex.replace(/([()[{*+.$^\\|?])/g, '\\$1')
}
$(function() {
    $.ajaxSetup({beforeSend: function() {
            $(".pop_loader").removeClass('hide')
        }, complete: function() {
            $(".pop_loader").addClass('hide')
        }});
    var cache = {};
    $(document).on("click", ".filters", function() {
        $(".filter-contents").show()
    });
    $(document).on("click", ".sortby", function() {
        var thisObj = $(this);
        $(".selected_sort").html($(this).text());
        $("#sort-by").trigger("click")
    });
    if (enableAlgolia != "Yes")
    {
        $("#searchKeyword").catcomplete({select: function(event, ui) {
                $("#searchKeyword").val(ui.item.value);
                $("#searchCategory").val(ui.item.productCategoryID);
                $("#serachButton").trigger('click')
            }, minLength: 3, appendTo: "#searchResult", source: function(request, response) {
                request.catID = $("#searchCategory").val();
                var key = $.trim(request.term + request.catID).replace(/[^a-zA-Z0-9]+/g, "-").toLowerCase();
                if (key in cache) {
                    response(cache[key]);
                    return
                }
                $.ajax({type: "GET", url: GLOBAL_BASE_PATH + '/search/ajaxAutoSuggest/', dataType: 'json', data: request, beforeSend: function() {
                    }, success: function(data) {
                        var sugg = new Array();
                        var searchkeyword = quote((request.term).toLowerCase());
                        for (x in data) {
                            if (((data[x].productTitle).toLowerCase()).search(searchkeyword) >= 0) {
                                if (typeof data[x].productCategoryID == 'undefined') {
                                    sugg.push({'label': data[x].productOptionName, 'category': '', 'brandKey': data[x].brandKey, 'productCategoryID': ''})
                                } else {
                                    sugg.push({'label': data[x].productOptionName, 'category': data[x].productCategoryName, 'productCategoryID': data[x].productCategoryID})
                                }
                            }
                            else if (((data[x].productOptionName).toLowerCase()).search(searchkeyword) >= 0) {
                                sugg.push({'label': data[x].productOptionName, 'category': data[x].productCategoryName, 'productCategoryID': data[x].productCategoryID, })
                            }
                            else if (typeof data[x].productCategoryName != 'undefined' && ((data[x].productCategoryName).toLowerCase()).search(searchkeyword) >= 0) {
                                sugg.push({'label': data[x].productOptionName, 'category': data[x].productCategoryName, 'productCategoryID': data[x].productCategoryID, })
                            }
                        }
                        cache[key] = $.unique(sugg);
                        response(sugg)
                    }})
            }})
    }
});
$.widget("custom.catcomplete", $.ui.autocomplete, {_renderMenu: function(ul, items) {
        var that = this, currentCategory = "";
        $.each(items, function(index, item) {
            if (item.category != currentCategory) {
                if (item.category != '') {
                    ul.append("<li class='ui-autocomplete-category'><strong>" + item.category + "</strong></li>");
                    currentCategory = item.category
                }
            }
            that._renderItemData(ul, item)
        })
    }, _renderItem: function(ul, item) {
        var re = (this.term).toLowerCase();
        item.label = (item.label).replace(re, "<span class='text-selected'>" + this.term + "</span>");
        var link = 'javascript:void(0)';
        var label = item.label;
        if (typeof item.brandKey != 'undefined' && item.brandKey != '') {
            link = global_http_url + "brand/" + item.brandKey;
            label = item.label + "<strong>" + lblInbrands + "</strong>"
        }
        return $("<li></li>").data("item.autocomplete", item).append("<a href='" + link + "'>" + label + "</a>").appendTo(ul)
    }})

$(document).on('blur', '#subscEmailID', function() {
    var form_subscEmailID = $("#subscEmailID").val();
    var reg = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if (reg.test(form_subscEmailID)) {
        $("#div_err_formCityEmailSubscription_subscEmailID").addClass('hide');
        $("#hid_err_formCityEmailSubscription_subscEmailID").val(0)
    } else {
        $("#div_err_formCityEmailSubscription_subscEmailID").removeClass('hide');
        $("#hid_err_formCityEmailSubscription_subscEmailID").val(1)
    }
});
$(document).on('blur', '#subscPopEmailID', function() {
    var form_subscEmailID = $("#subscPopEmailID").val();
    var reg = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if (reg.test(form_subscEmailID)) {
        $("#div_err_formCityEmailPopSubscription_subscPopEmailID").addClass('hide');
        $("#hid_err_formCityEmailPopSubscription_subscPopEmailID").val(0)
    } else {
        $("#div_err_formCityEmailPopSubscription_subscPopEmailID").removeClass('hide');
        $("#hid_err_formCityEmailPopSubscription_subscPopEmailID").val(1)
    }
});

$(document).on("click",".submitPopEmailValid", function (e) {
    e.preventDefault()
    $("#submitPopEmail").val($(this).attr('value'));
    var form_subscEmailID = $("#subscPopEmailID").val();
    var reg = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if (reg.test(form_subscEmailID)) {
        $("#div_err_formCityEmailPopSubscription_subscPopEmailID").addClass('hide');
        $("#hid_err_formCityEmailPopSubscription_subscPopEmailID").val(0);
        $('#formCityEmailPopSubscription').submit()
    } else {
        $("#div_err_formCityEmailPopSubscription_subscPopEmailID").removeClass('hide');
        $("#hid_err_formCityEmailPopSubscription_subscPopEmailID").val(1);
        return!1
    }
});
$("#div_err_formCityEmailSubscription_subscEmailID").addClass('hide');
$(document).on("click",".submitCityEmailValid", function (e) {
    e.preventDefault()
    var form_subscEmailID = $("#subscEmailID").val();
    var reg = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if (reg.test(form_subscEmailID)) {
        $("#div_err_formCityEmailSubscription_subscEmailID").addClass('hide');
        $("#hid_err_formCityEmailSubscription_subscEmailID").val(0);
        $('#formCityEmailSubscription').submit()
    } else {
        $("#div_err_formCityEmailSubscription_subscEmailID").removeClass('hide');
        $("#hid_err_formCityEmailSubscription_subscEmailID").val(1);
        return!1
    }
});

function updateCartNotification()
{
    if (statPageName != 'cart')
    {
        var notificationTop = '';
        var notificationBottom = '';
        var userID = '';
        if (showCartNotification != 'No') {
            userID = $("#userLogined").val();
            cart.userLogined = userID;
            var html = $("#CartNotificationTemplate").render([cart]);
            $('.cart-dropdown-box').html('');
            $('.cart-dropdown-box').append(html)
        }
        $(".cart-notification-dropdown").hide()
    }
}
function updateCartPopUp()
{
    var notificationTop = '';
    var notificationBottom = '';
    var userID = '';
    if (showCartNotification != 'No')
    {
        userID = $("#userLogined").val();
        cart.userLogined = userID;
        $('.cart-popup-box').html('')
    }
    $("#CategoryFade").trigger('click');
    $(".cart-notification-dropdown-popup").show();
    setTimeout(function()
    {
        $(".cart-notification-dropdown-popup").hide()
    }, 5000)
}

function __verifyMobileProcess() {
    if ($("#verify-block").find(".message_validation :visible").length > 0) return !1;
    var e = $("#formVerifyMobile").serializeArray();
    return e.push({
        name: "submitVerify",
        value: 1
    }), $.ajax({
        type: "POST",
        url: popup_iframe_url + "/login/ajaxVerifyMobile/",
        data: e,
        beforeSend: function() {
            $("#submit-verify").hide(), $("#submitVerifyDisable").show()
        },
        success: function(e) {
            var t = $("#userPhoneVerify").val().substring(6);
            $(".moibleHint").html("XXXXXX" + t), $("#verify-code-div").attr("style", "display:block"), $("#sendCodeBlock").addClass("hide"), $("#resendCodeBlock").removeClass("hide"), $("#submitCodeDisable").hide();
            try {
                var r = $.parseJSON(e)
            } catch (t) {
                return $(".loginSignupPanel").html(""), $(".loginSignupPanel").html(e), activePopupSection("signup"), $(".signup-div").hide(), $("#verify-block").attr("style", "display:block"), $("#submit-verify").show(), $("#submitVerifyDisable").hide(), !1
            }
            "Yes" == r.error ? (jNotify(r.errorMessage, "common_login_message", "message_error"), $("#submit-verify").show(), $("#submitVerifyDisable").hide()) : "No" == r.error && jNotify(msgCodeSentSucces, "common_verify_message", "message_success")
        }
    }), !1
}
function __verifyCodeProcess() {
    if ($("#verify-code-div").find(".message_validation :visible").length > 0) return !1;
    var e = $("#formVerifyCode").serializeArray();
    return e.push({
        name: "submitCode",
        value: 1
    }), $.ajax({
        type: "POST",
        url: popup_iframe_url + "/login/ajaxVerifyMobile/",
        data: e,
        beforeSend: function() {
            $("#submitCode").hide(), $("#submitCodeDisable").show()
        },
        success: function(e) {
            var t = $.parseJSON(e);
            if ("Yes" == t.error) jNotify(t.errorMessage, "common_verify_message", "message_error"), $("#submitCode").show(), $("#submitCodeDisable").hide();
            else if ("No" == t.error)
                if ("undefined" != typeof redirectURL) window.top.location.href = GLOBAL_BASE_PATH + "/" + redirectURL + "/";
                else {
                    var r = t.redirectUrl;
                    "" != r && void 0 !== r ? window.top.location.href = GLOBAL_BASE_PATH + "/" + r + "/" : (jNotify(msgVerifiedMobile, "common_verify_message", "message_success"), window.top.location.href = document.referrer)
                }
        }
    }), !1
}

var bool;
var currentProductCurreny = _defaultCurrency;
$(document).ready(function() {
    var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
    var eventer = window[eventMethod];
    var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
    eventer(messageEvent, function(e) {
        try {
            var data = JSON.parse(e.data)
        } catch (e) {
            var data = (e.data)
        }
        if (typeof data != "undefined") {
            if (data.functionality == "CloseLoginPopup" || data.functionality == "closePopup") {
                hideModalPopup()
            }
            if (data.functionality == "Close Popup") {
                $('.quickpopup, .popupsectionlogin').addClass('popupShowLogin');
                $("body").removeClass('popup-enabled')
            }
            if (data.functionality == "cartRedirectCheckout") {
                $("body").removeClass('popup-enabled');
                parent.$.fancybox.close();
                parent.location.href = popup_iframe_url + '/cart/checkout/'
            }
        }
    }, !1);
  
    $('.form input:text,.form textarea,.form input:password').each(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if (this.value == default_value) {
                this.value = ''
            }
        });
        $(this).blur(function() {
            if (this.value == '') {
                this.value = default_value
            }
        })
    });
   
    
    /*if (!(cart.items.length === 0 || cart.currencyID == 0)) {
        resetCurrency(cart.currencyID)
    }*/
    //updateCartNotification();
    $(document).on('click', '#show_dropdown', function() {
        $(".cart-notification-dropdown").toggle()
    });
    $(document).on('click', '.close_cart', function() {
        $(".cart-notification-dropdown").toggle()
    });
    $(document).on('click', '.ajax_cart_block_remove_link', function() {
        //removeItemFromCart($(this).attr('rel'))
    });
    $(document).on('click', '#clear_cart', function() {
        clearCart($(this).attr('rel'))
    });
    $(document).on('click', '#show_dropdown-popup', function() {
        $(".cart-notification-dropdown-popup").toggle()
    })
});
$(document).mouseup(function(e)
{
    var container = $(".cart-dropdown-box");
    if (container.has(e.target).length === 0)
    {
        $(".cart-notification-dropdown").hide()
    }
});

function fbShare(url)
{
    var urlshare = encodeURIComponent(url)
    var d = document;
    var D = 548, A = 325, C = screen.height, B = screen.width, H = Math.round((B / 2) - (D / 2)), G = Math.round((C / 2) - (A / 2));
    window.open('http://www.facebook.com/sharer.php?' + Math.random() + '&u=' + urlshare, 'sharer', 'left=' + H + ',top=' + G + ',width=' + D + ',height=' + A + ',toolbar=0,status=0,resizable=1')
}
function googlePlusShare(url)
{
    var d = document;
    var D = 600, A = 500, C = screen.height, B = screen.width, H = Math.round((B / 2) - (D / 2)), G = Math.round((C / 2) - (A / 2));
    var f = 'https://plus.google.com/share?' + Math.random() + '&url=' + encodeURIComponent(url);
    window.open(f, 'sharer', 'left=' + H + ',top=' + G + ',width=' + D + ',height=' + A + ',toolbar=0,status=0,resizable=1')
}
function pinterestShare(url, image, text)
{
    var d = document;
    var D = 700, A = 500, C = screen.height, B = screen.width, H = Math.round((B / 2) - (D / 2)), G = Math.round((C / 2) - (A / 2));
    var f = 'http://pinterest.com/pin/create/button/?' + Math.random() + '&url=' + encodeURIComponent(url) + '&media=' + encodeURIComponent(image) + '&description=' + encodeURIComponent(text);
    window.open(f, 'sharer', 'left=' + H + ',top=' + G + ',width=' + D + ',height=' + A + ',toolbar=0,status=0,resizable=1')
}
function twitterShare(url, text)
{
    var d = document;
    var D = 700, A = 300, C = screen.height, B = screen.width, H = Math.round((B / 2) - (D / 2)), G = Math.round((C / 2) - (A / 2));
    var f = 'http://twitter.com/intent/tweet?' + Math.random() + '&text=' + encodeURIComponent(text) + '&url=' + encodeURIComponent(url);
    window.open(f, 'sharer', 'left=' + H + ',top=' + G + ',width=' + D + ',height=' + A + ',toolbar=0,status=0,resizable=1')
}
function unserialize(data)
{
    var that = this, utf8Overhead = function(chr)
    {
        var code = chr.charCodeAt(0);
        if (code < 0x0080) {
            return 0
        }
        if (code < 0x0800) {
            return 1
        }
        return 2
    }, error = function(type, msg, filename, line)
    {
        throw new that.window[type](msg, filename, line)
    }, read_until = function(data, offset, stopchr)
    {
        var i = 2, buf = [], chr = data.slice(offset, offset + 1);
        while (chr != stopchr)
        {
            if ((i + offset) > data.length)
            {
                error('Error', 'Invalid')
            }
            buf.push(chr);
            chr = data.slice(offset + (i - 1), offset + i);
            i += 1
        }
        return[buf.length, buf.join('')]
    }, read_chrs = function(data, offset, length)
    {
        var i, chr, buf;
        buf = [];
        for (i = 0; i < length; i++)
        {
            chr = data.slice(offset + (i - 1), offset + i);
            buf.push(chr);
            length -= utf8Overhead(chr)
        }
        return[buf.length, buf.join('')]
    }, _unserialize = function(data, offset)
    {
        var dtype, dataoffset, keyandchrs, keys, readdata, readData, ccount, stringlength, i, key, kprops, kchrs, vprops, vchrs, value, chrs = 0, typeconvert = function(x)
        {
            return x
        };
        if (!offset)
        {
            offset = 0
        }
        dtype = (data.slice(offset, offset + 1)).toLowerCase();
        dataoffset = offset + 2;
        switch (dtype) {
            case 'i':
                typeconvert = function(x) {
                    return parseInt(x, 10)
                };
                readData = read_until(data, dataoffset, ';');
                chrs = readData[0];
                readdata = readData[1];
                dataoffset += chrs + 1;
                break;
            case 'b':
                typeconvert = function(x) {
                    return parseInt(x, 10) !== 0
                };
                readData = read_until(data, dataoffset, ';');
                chrs = readData[0];
                readdata = readData[1];
                dataoffset += chrs + 1;
                break;
            case 'd':
                typeconvert = function(x) {
                    return parseFloat(x)
                };
                readData = read_until(data, dataoffset, ';');
                chrs = readData[0];
                readdata = readData[1];
                dataoffset += chrs + 1;
                break;
            case 'n':
                readdata = null;
                break;
            case 's':
                ccount = read_until(data, dataoffset, ':');
                chrs = ccount[0];
                stringlength = ccount[1];
                dataoffset += chrs + 2;
                readData = read_chrs(data, dataoffset + 1, parseInt(stringlength, 10));
                chrs = readData[0];
                readdata = readData[1];
                dataoffset += chrs + 2;
                if (chrs != parseInt(stringlength, 10) && chrs != readdata.length) {
                    error('SyntaxError', 'String length mismatch')
                }
                break;
            case 'a':
                readdata = {};
                keyandchrs = read_until(data, dataoffset, ':');
                chrs = keyandchrs[0];
                keys = keyandchrs[1];
                dataoffset += chrs + 2;
                for (i = 0; i < parseInt(keys, 10); i++) {
                    kprops = _unserialize(data, dataoffset);
                    kchrs = kprops[1];
                    key = kprops[2];
                    dataoffset += kchrs;
                    vprops = _unserialize(data, dataoffset);
                    vchrs = vprops[1];
                    value = vprops[2];
                    dataoffset += vchrs;
                    readdata[key] = value
                }
                dataoffset += 1;
                break;
            default:
                error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
                break
        }
        return[dtype, dataoffset - offset, typeconvert(readdata)]
    };
    return _unserialize((data + ''), 0)[2]
}
function addslashes(str) {
    return(str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0')
}
function removeItemFromCart(relData)
{
    var parts = relData.split("-");
    var cartID = parts[0];
    var cartItemID = parts[1];
    $.ajax({type: "POST", url: GLOBAL_BASE_PATH + "/cart/ajaxDeleteItem/", data: {cartID: cartID, cartItemID: cartItemID}, success: function(data)
        {
            assignJsonDataToCartJS(data);
            //updateCartNotification();
            jNotifyShow(lblCartItemRemovedSuccessfully, "common_message", "message_info")
        }})
}
function assignJsonDataToCartJS(JsonData)
{
    try
    {
        var x = $.parseJSON(JsonData)
    } catch (e)
    {
        window.location = location.href;
        return!1
    }
    $(x).each(function(index, value)
    {
        cart.cartID = value.cartID;
        cart.orderSubtotal = value.orderSubtotal;
        cart.orderPromoDiscountAmount = value.orderPromoDiscountAmount;
        cart.orderUserCreditAmount = value.orderUserCreditAmount;
        cart.orderOtherServiceCharge = value.orderOtherServiceCharge;
        cart.shippingAmount = value.shippingAmount;
        cart.orderTaxAmount = value.orderTaxAmount;
        cart.orderQty = value.orderQty;
        cart.orderTotalAmount = value.orderTotalAmount;
        cart.currencyID = value.currencyID;
        var cartItemArray = new Array();
        $(value.items).each(function(index1, value1) {
            var cartItem = new Array();
            cartItem.productOptionID = value1.productOptionID;
            cartItem.productID = value1.productID;
            cartItem.cartItemID = value1.cartItemID;
            cartItem.orderItemPrice = value1.orderItemPrice;
            cartItem.orderItemQuantity = value1.orderItemQuantity;
            cartItem.orderGiveAsGift = value1.orderGiveAsGift;
            var ItemDetails = unserialize(value1.itemDetails);
            cartItem.productOptionName = addslashes(ItemDetails.productOptionName);
            cartItem.productURL = ItemDetails.productURL;
            cartItem.imagePath = ItemDetails.imagePath;
            cartItem.combinationHash = value1.combinationHash;
            cartItem.optionsHash = value1.optionsHash;
            cartItem.orderItemTotal = (Number(ItemDetails.orderItemTotal)).toFixed(2);
            cartItemArray.push(cartItem);
            cartItem.freeProduct = value1.freeProduct
            cartItem.businessID  = value1.businessID
        });
        cart.items = cartItemArray
    })
}

function clearCart(relData, updateHtml)
{
    var cartID = relData;
    $.ajax({type: "POST", url: GLOBAL_BASE_PATH + "/cart/ajaxDeleteItem/", data: {cartID: cartID}, success: function(data)
        {
            assignJsonDataToCartJS(data);
            if (updateHtml == 'Yes')
            {
                //updateCartNotification();
                jNotifyShow(lblCartItemsRemovedSuccessfully, "common_message", "message_info")
            }
        }})
}
function formatCurrency(amount, type)
{
    return $.getFormattedCurrency(amount, type, currentProductCurreny, currentCurrencyID)
}
function resetCurrency(currencyID)
{
    currentProductCurreny = currencyID;
    currencySymbolPosition = currencyForJS[currencyID].position;
    currencySymbol = currencyForJS[currencyID].symbol;
    currencyDecimalPlaces = currencyForJS[currencyID].currencyDecimalPlaces
}
function stripslashes(str)
{
    return $.stripslashes(str)
}
function htmlspecialchars_decode(string, quote_style)
{
    return $.htmlspecialchars_decode(string, quote_style)
}
function cleanHtmlElements(element)
{
    var tempSameItem = 'No';
    /*for (var i = 0; i < cart.items.length; i++)
    {
        if (cart.items[i].productID == productID)
        {
            tempSameItem = 'Yes'
        }
    }*/
    return tempSameItem
}
function round(value, precision, mode) {
    var m, f, isHalf, sgn;
    precision |= 0;
    m = Math.pow(10, precision);
    value *= m;
    sgn = (value > 0) | -(value < 0);
    isHalf = value % 1 === 0.5 * sgn;
    f = Math.floor(value);
    if (isHalf) {
        switch (mode) {
            case 'PHP_ROUND_HALF_DOWN':
                value = f + (sgn < 0);
                break;
            case 'PHP_ROUND_HALF_EVEN':
                value = f + (f % 2 * sgn);
                break;
            case 'PHP_ROUND_HALF_ODD':
                value = f + !(f % 2);
                break;
            default:
                value = f + (sgn > 0)
            }
    }
    return(isHalf ? value : Math.round(value)) / m
}
function callPostAjax(url, postData, dataCaching, cacheKey)
{
    var response;
    if (url != '')
    {
        $.ajax({type: "POST", url: url, data: postData, success: function(data) {
                if (dataCaching == !0 && cacheKey != '')
                {
                    ajaxResponse[cacheKey] = data
                }
                response = data
            }});
        return response
    }
}
function explode(delimiter, string, limit) {
    if (arguments.length < 2 || typeof delimiter === 'undefined' || typeof string === 'undefined')
        return null;
    if (delimiter === '' || delimiter === !1 || delimiter === null)
        return!1;
    if (typeof delimiter === 'function' || typeof delimiter === 'object' || typeof string === 'function' || typeof string === 'object')
    {
        return{0: ''}
    }
    if (delimiter === !0)
        delimiter = '1';
    delimiter += '';
    string += '';
    var s = string.split(delimiter);
    if (typeof limit === 'undefined')
        return s;
    if (limit === 0)
        limit = 1;
    if (limit > 0) {
        if (limit >= s.length)
            return s;
        return s.slice(0, limit - 1).concat([s.slice(limit - 1).join(delimiter)])
    }
    if (-limit >= s.length)
        return[];
    s.splice(s.length + limit);
    return s
}
function implode(glue, pieces) {
    var i = '', retVal = '', tGlue = '';
    if (arguments.length === 1) {
        pieces = glue;
        glue = ''
    }
    if (typeof(pieces) === 'object') {
        if (Object.prototype.toString.call(pieces) === '[object Array]') {
            return pieces.join(glue)
        }
        for (i in pieces) {
            retVal += tGlue + pieces[i];
            tGlue = glue
        }
        return retVal
    }
    return pieces
}
(function(e, t, n) {
    "use strict";
    function _(e, t) {
        if (t && t.onError) {
            if (t.onError(e) === !1) {
                return
            }
        }
        this.name = "JsRender Error";
        this.message = e || "JsRender error"
    }
    function D(e, t) {
        var n;
        e = e || {};
        for (n in t) {
            e[n] = t[n]
        }
        return e
    }
    function P(e, t, n) {
        if (!it.rTag || arguments.length) {
            a = e ? e.charAt(0) : a;
            f = e ? e.charAt(1) : f;
            l = t ? t.charAt(0) : l;
            c = t ? t.charAt(1) : c;
            h = n || h;
            e = "\\" + a + "(\\" + h + ")?\\" + f;
            t = "\\" + l + "\\" + c;
            o = "(?:(?:(\\w+(?=[\\/\\s\\" + l + "]))|(?:(\\w+)?(:)|(>)|!--((?:[^-]|-(?!-))*)--|(\\*)))" + "\\s*((?:[^\\" + l + "]|\\" + l + "(?!\\" + c + "))*?)";
            it.rTag = o + ")";
            o = new RegExp(e + o + "(\\/)?|(?:\\/(\\w+)))" + t, "g");
            u = new RegExp("<.*>|([^\\\\]|^)[{}]|" + e + ".*" + t)
        }
        return[a, f, l, c, h]
    }
    function H(e, t) {
        if (!t) {
            t = e;
            e = n
        }
        var r, i, s, o, u = this, a = !t || t === "root";
        if (e) {
            o = u.type === t ? u : n;
            if (!o) {
                r = u.views;
                if (u._.useKey) {
                    for (i in r) {
                        if (o = r[i].get(e, t)) {
                            break
                        }
                    }
                } else
                    for (i = 0, s = r.length; !o && i < s; i++) {
                        o = r[i].get(e, t)
                    }
            }
        } else if (a) {
            while (u.parent.parent) {
                o = u = u.parent
            }
        } else
            while (u && !o) {
                o = u.type === t ? u : n;
                u = u.parent
            }
        return o
    }
    function B() {
        var e = this.get("item");
        return e ? e.index : n
    }
    function j(e) {
        var t, r = this, i = (r.ctx || {})[e];
        i = i === n ? r.getRsc("helpers", e) : i;
        if (i) {
            if (typeof i === "function") {
                t = function() {
                    return i.apply(r, arguments)
                };
                D(t, i)
            }
        }
        return t || i
    }
    function F(e, t, r) {
        var i, s, o, u = +r === r && r, a = t.linkCtx;
        if (u) {
            r = (u = t.tmpl.bnds[u - 1])(t.data, t, M)
        }
        o = r.args[0];
        if (e || u) {
            s = a && a.tag || {_: {inline: !a}, tagName: e + ":", flow: !0, _is: "tag"};
            s._.bnd = u;
            if (a) {
                a.tag = s;
                s.linkCtx = a;
                r.ctx = Z(r.ctx, a.view.ctx)
            }
            s.tagCtx = r;
            r.view = t;
            s.ctx = r.ctx || {};
            delete r.ctx;
            t._.tag = s;
            e = e !== "true" && e;
            if (e && ((i = t.getRsc("converters", e)) || J("Unknown converter: {{" + e + ":"))) {
                s.depends = i.depends;
                o = i.apply(s, r.args)
            }
            o = u && t._.onRender ? t._.onRender(o, t, u) : o;
            t._.tag = n
        }
        return o
    }
    function I(e, t) {
        var r, i = this, s = M[e];
        r = s && s[t];
        while (r === n && i) {
            s = i.tmpl[e];
            r = s && s[t];
            i = i.parent
        }
        return r
    }
    function q(e, t, r, i) {
        var s, o, u, a, f, l, c, h, p, d, v, m, g, y, b, w = "", E = +i === i && i, S = t.linkCtx || 0, x = t.ctx, T = r || t.tmpl, N = t._;
        if (e._is === "tag") {
            o = e;
            e = o.tagName
        }
        if (E) {
            i = (g = T.bnds[E - 1])(t.data, t, M)
        }
        h = i.length;
        o = o || S.tag;
        for (c = 0; c < h; c++) {
            d = i[c];
            m = d.tmpl;
            m = d.content = m && T.tmpls[m - 1];
            r = d.props.tmpl;
            if (!c && (!r || !o)) {
                y = t.getRsc("tags", e) || J("Unknown tag: {{" + e + "}}")
            }
            r = r || (o ? o._def : y).template || m;
            r = "" + r === r ? t.getRsc("templates", r) || et(r) : r;
            D(d, {tmpl: r, render: $, index: c, view: t, ctx: Z(d.ctx, x)});
            if (!o) {
                if (y._ctr) {
                    o = new y._ctr;
                    b = !!o.init;
                    o.attr = o.attr || y.attr || n
                } else {
                    o = {render: y.render}
                }
                o._ = {inline: !S};
                if (S) {
                    S.attr = o.attr = S.attr || o.attr;
                    S.tag = o;
                    o.linkCtx = S
                }
                if (o._.bnd = g || S) {
                    o._.arrVws = {}
                }
                o.tagName = e;
                o.parent = l = x && x.tag, o._is = "tag";
                o._def = y
            }
            N.tag = o;
            d.tag = o;
            o.tagCtxs = i;
            if (!o.flow) {
                v = d.ctx = d.ctx || {};
                u = o.parents = v.parentTags = x && Z(v.parentTags, x.parentTags) || {};
                if (l) {
                    u[l.tagName] = l
                }
                v.tag = o
            }
            o.rendering = {}
        }
        for (c = 0; c < h; c++) {
            d = o.tagCtx = i[c];
            o.ctx = d.ctx;
            if (!c && b) {
                o.init(d, S, o.ctx);
                b = n
            }
            if (s = o.render) {
                p = s.apply(o, d.args)
            }
            w += p !== n ? p : d.tmpl ? d.render() : ""
        }
        delete o.rendering;
        o.tagCtx = o.tagCtxs[0];
        o.ctx = o.tagCtx.ctx;
        if (o._.inline && (a = o.attr) && a !== "html") {
            w = a === "text" ? tt.html(w) : ""
        }
        return w = E && t._.onRender ? t._.onRender(w, t, E) : w
    }
    function R(e, t, r, i, s, o, u, a) {
        var f, l, c, h = t === "array", p = {key: 0, useKey: h ? 0 : 1, id: "" + N++, onRender: a, bnds: {}}, d = {data: i, tmpl: s, content: u, views: h ? [] : {}, parent: r, ctx: e, type: t, get: H, getIndex: B, getRsc: I, hlp: j, _: p, _is: "view"};
        if (r) {
            f = r.views;
            l = r._;
            if (l.useKey) {
                f[p.key = "_" + l.useKey++] = d;
                c = l.tag;
                p.bnd = h && (!c || !!c._.bnd && c)
            } else {
                f.splice(p.key = d.index = o !== n ? o : f.length, 0, d)
            }
            d.ctx = e || r.ctx
        }
        return d
    }
    function U(e) {
        var t, n, r, i, s;
        for (t in O) {
            i = O[t];
            if ((s = i.compile) && (n = e[t + "s"])) {
                for (r in n) {
                    n[r] = s(r, n[r], e, t, i)
                }
            }
        }
    }
    function z(e, t, n) {
        var r, i;
        if (typeof t === "function") {
            t = {depends: t.depends, render: t}
        } else {
            if (i = t.template) {
                t.template = "" + i === i ? et[i] || et(i) : i
            }
            if (t.init !== !1) {
                r = t._ctr = function(e) {
                };
                (r.prototype = t).constructor = r
            }
        }
        if (n) {
            t._parentTmpl = n
        }
        return t
    }
    function W(r, i, s, o, a, f) {
        function l(n) {
            if ("" + n === n || n.nodeType > 0) {
                try {
                    h = n.nodeType > 0 ? n : !u.test(n) && t && t(e.document).find(n)[0]
                } catch (i) {
                }
                if (h) {
                    n = h.getAttribute(k);
                    r = r || n;
                    n = et[n];
                    if (!n) {
                        r = r || "_" + T++;
                        h.setAttribute(k, r);
                        n = et[r] = W(r, h.innerHTML, s, o, a, f)
                    }
                }
                return n
            }
        }
        var c, h;
        i = i || "";
        c = l(i);
        f = f || (i.markup ? i : {});
        f.tmplName = r;
        if (s) {
            f._parentTmpl = s
        }
        if (!c && i.markup && (c = l(i.markup))) {
            if (c.fn && (c.debug !== i.debug || c.allowCode !== i.allowCode)) {
                c = c.markup
            }
        }
        if (c !== n) {
            if (r && !s) {
                A[r] = function() {
                    return i.render.apply(i, arguments)
                }
            }
            if (c.fn || i.fn) {
                if (c.fn) {
                    if (r && r !== c.tmplName) {
                        i = Z(f, c)
                    } else {
                        i = c
                    }
                }
            } else {
                i = X(c, f);
                Q(c, i)
            }
            U(f);
            return i
        }
    }
    function X(e, t) {
        var n, r = st.wrapMap || {}, s = D({markup: e, tmpls: [], links: {}, tags: {}, bnds: [], _is: "template", render: $}, t);
        if (!t.htmlTag) {
            n = w.exec(e);
            s.htmlTag = n ? n[1].toLowerCase() : ""
        }
        n = r[s.htmlTag];
        if (n && n !== r.div) {
            s.markup = i.trim(s.markup);
            s._elCnt = !0
        }
        return s
    }
    function V(e, t) {
        function r(s, o, u) {
            var a, f, l, c;
            if (s && "" + s !== s && !s.nodeType && !s.markup) {
                for (l in s) {
                    r(l, s[l], o)
                }
                return M
            }
            if (o === n) {
                o = s;
                s = n
            }
            if (s && "" + s !== s) {
                u = o;
                o = s;
                s = n
            }
            c = u ? u[i] = u[i] || {} : r;
            f = t.compile;
            if (a = it.onBeforeStoreItem) {
                f = a(c, s, o, f) || f
            }
            if (!s) {
                o = f(n, o)
            } else if (o === null) {
                delete c[s]
            } else {
                c[s] = f ? o = f(s, o, u, e, t) : o
            }
            if (o) {
                o._is = e
            }
            if (a = it.onStoreItem) {
                a(c, s, o, f)
            }
            return o
        }
        var i = e + "s";
        M[i] = r;
        O[e] = t
    }
    function $(e, t, r, s, o, u) {
        var a, f, l, c, h, p, d, v, m, g, y, b, w, E = this, S = !E.attr || E.attr === "html", x = "";
        if (s === !0) {
            d = !0;
            s = 0
        }
        if (E.tag) {
            v = E;
            E = E.tag;
            g = E._;
            b = E.tagName;
            w = v.tmpl;
            t = Z(t, E.ctx);
            m = v.content;
            if (v.props.link === !1) {
                t = t || {};
                t.link = !1
            }
            r = r || v.view;
            e = e === n ? r : e
        } else {
            w = E.jquery && (E[0] || J('Unknown template: "' + E.selector + '"')) || E
        }
        if (w) {
            if (!r && e && e._is === "view") {
                r = e
            }
            if (r) {
                m = m || r.content;
                u = u || r._.onRender;
                if (e === r) {
                    e = r.data;
                    o = !0
                }
                t = Z(t, r.ctx)
            }
            if (!r || r.data === n) {
                (t = t || {}).root = e
            }
            if (!w.fn) {
                w = et[w] || et(w)
            }
            if (w) {
                u = (t && t.link) !== !1 && S && u;
                y = u;
                if (u === !0) {
                    y = n;
                    u = r._.onRender
                }
                if (i.isArray(e) && !o) {
                    c = d ? r : s !== n && r || R(t, "array", r, e, w, s, m, u);
                    for (a = 0, f = e.length; a < f; a++) {
                        l = e[a];
                        h = R(t, "item", c, l, w, (s || 0) + a, m, u);
                        p = w.fn(l, h, M);
                        x += c._.onRender ? c._.onRender(p, h) : p
                    }
                } else {
                    c = d ? r : R(t, b || "data", r, e, w, s, m, u);
                    if (g && !E.flow) {
                        c.tag = E
                    }
                    x += w.fn(e, c, M)
                }
                return y ? y(x, c) : x
            }
        }
        return""
    }
    function J(e) {
        throw new M.sub.Error(e)
    }
    function K(e) {
        J("Syntax error\n" + e)
    }
    function Q(e, t, n, r) {
        function i(t) {
            t -= c;
            if (t) {
                p.push(e.substr(c, t).replace(v, "\\n"))
            }
        }
        function s(t) {
            t && K('Unmatched or missing tag: "{{/' + t + '}}" in template:\n' + e)
        }
        function u(o, u, l, g, w, E, S, x, T, N, C, k) {
            if (E) {
                w = ":";
                g = "html"
            }
            N = N || n;
            var L, A, O = u && [], M = "", _ = "", D = "", P = !N && !w && !S;
            l = l || w;
            i(k);
            c = k + o.length;
            if (x) {
                if (f) {
                    p.push(["*", "\n" + T.replace(m, "$1") + "\n"])
                }
            } else if (l) {
                if (l === "else") {
                    if (b.test(T)) {
                        K('for "{{else if expr}}" use "{{else expr}}"')
                    }
                    O = d[6];
                    d[7] = e.substring(d[7], k);
                    d = h.pop();
                    p = d[3];
                    P = !0
                }
                if (T) {
                    T = T.replace(v, " ");
                    M = Y(T, O, t).replace(y, function(e, t, n) {
                        if (t) {
                            D += n + ","
                        } else {
                            _ += n + ","
                        }
                        return""
                    })
                }
                _ = _.slice(0, -1);
                M = M.slice(0, -1);
                L = _ && _.indexOf("noerror:true") + 1 && _ || "";
                a = [l, g || !!r || "", M, P && [], 'params:"' + T + '",props:{' + _ + "}" + (D ? ",ctx:{" + D.slice(0, -1) + "}" : ""), L, O || 0];
                p.push(a);
                if (P) {
                    h.push(d);
                    d = a;
                    d[7] = c
                }
            } else if (C) {
                A = d[0];
                s(C !== A && A !== "else" && C);
                d[7] = e.substring(d[7], k);
                d = h.pop()
            }
            s(!d && C);
            p = d[3]
        }
        var a, f = t && t.allowCode, l = [], c = 0, h = [], p = l, d = [, , , l];
        e = e.replace(g, "\\$1");
        s(h[0] && h[0][3].pop()[0]);
        e.replace(o, u);
        i(e.length);
        if (c = l[l.length - 1]) {
            s("" + c !== c && +c[7] === c[7] && c[0])
        }
        return G(l, n ? e : t, n)
    }
    function G(e, n, r) {
        var i, s, o, u, a, f, l, c, h, p, d, m, g, y, b, w, E, S, x, T, N, C, k, L, A, O, M, _, D, P = 0, H = "", B = "", j = {}, F = e.length;
        if ("" + n === n) {
            E = r ? 'data-link="' + n.replace(v, " ").slice(1, -1) + '"' : n;
            n = 0
        } else {
            E = n.tmplName || "unnamed";
            if (T = n.allowCode) {
                j.allowCode = !0
            }
            if (n.debug) {
                j.debug = !0
            }
            m = n.bnds;
            w = n.tmpls
        }
        for (i = 0; i < F; i++) {
            s = e[i];
            if ("" + s === s) {
                H += '\nret+="' + s + '";'
            } else {
                o = s[0];
                if (o === "*") {
                    H += "" + s[1]
                } else {
                    u = s[1];
                    a = s[2];
                    N = s[3];
                    f = s[4];
                    B = s[5];
                    C = s[7];
                    if (!(O = o === "else")) {
                        P = 0;
                        if (m && (g = s[6])) {
                            P = m.push(g)
                        }
                    }
                    if (M = o === ":") {
                        if (u) {
                            o = u === "html" ? ">" : u + o
                        }
                        if (B) {
                            _ = "prm" + i;
                            B = "try{var " + _ + "=[" + a + "][0];}catch(e){" + _ + '="";}\n';
                            a = _
                        }
                    } else {
                        if (N) {
                            S = X(C, j);
                            S.tmplName = E + "/" + o;
                            G(N, S);
                            w.push(S)
                        }
                        if (!O) {
                            x = o;
                            A = H;
                            H = "";
                            y = i
                        }
                        L = e[i + 1];
                        L = L && L[0] === "else"
                    }
                    f += ",args:[" + a + "]}";
                    if (M && g || u && o !== ">") {
                        D = new Function("data,view,j,u", " // " + E + " " + P + " " + o + "\n" + B + "return {" + f + ";");
                        D.paths = g;
                        D._ctxs = o;
                        if (r) {
                            return D
                        }
                        d = 1
                    }
                    H += M ? "\n" + (g ? "" : B) + (r ? "return " : "ret+=") + (d ? (d = 0, p = !0, 'c("' + u + '",view,' + (g ? (m[P - 1] = D, P) : "{" + f) + ");") : o === ">" ? (c = !0, "h(" + a + ");") : (h = !0, "(v=" + a + ")!=" + (r ? "=" : "") + 'u?v:"";')) : (l = !0, "{tmpl:" + (N ? w.length : "0") + "," + f + ",");
                    if (x && !L) {
                        H = "[" + H.slice(0, -1) + "]";
                        if (r || g) {
                            H = new Function("data,view,j,u", " // " + E + " " + P + " " + x + "\nreturn " + H + ";");
                            if (g) {
                                (m[P - 1] = H).paths = g
                            }
                            H._ctxs = o;
                            if (r) {
                                return H
                            }
                        }
                        H = A + '\nret+=t("' + x + '",view,this,' + (P || H) + ");";
                        g = 0;
                        x = 0
                    }
                }
            }
        }
        H = "// " + E + "\nvar j=j||" + (t ? "jQuery." : "js") + "views" + (h ? ",v" : "") + (l ? ",t=j._tag" : "") + (p ? ",c=j._cnvt" : "") + (c ? ",h=j.converters.html" : "") + (r ? ";\n" : ',ret="";\n') + (st.tryCatch ? "try{\n" : "") + (j.debug ? "debugger;" : "") + H + (r ? "\n" : "\nreturn ret;\n") + (st.tryCatch ? "\n}catch(e){return j._err(e);}" : "");
        try {
            H = new Function("data,view,j,u", H)
        } catch (I) {
            K("Compiled template code:\n\n" + H, I)
        }
        if (n) {
            n.fn = H
        }
        return H
    }
    function Y(e, t, n) {
        function r(r, d, y, b, w, E, S, x, T, N, C, k, L, A, O, M, _, D, P) {
            function B(e, n, r, i, o, u, a) {
                if (n) {
                    t && !s && t.push(b);
                    if (n !== ".") {
                        var f = (r ? 'view.hlp("' + r + '")' : i ? "view" : "data") + (a ? (o ? "." + o : r ? "" : i ? "" : "." + n) + (u || "") : (a = r ? "" : i ? o || "" : n, ""));
                        f = f + (a ? "." + a : "");
                        return f.slice(0, 9) === "view.data" ? f.slice(5) : f
                    }
                }
                return e
            }
            var H;
            w = w || "";
            y = y || d || C;
            b = b || x;
            T = T || M || "";
            if (E) {
                K(e)
            } else {
                if (t && O) {
                    H = h[v];
                    if (P.length - 2 > D - H) {
                        H = P.slice(H, D + 1);
                        O = f + ":" + H + l;
                        O = o[O] = o[O] || Q(a + O + c, n, !0);
                        if (!O.paths) {
                            Y(H, O.paths = [], n)
                        }
                        t.push({_jsvOb: O})
                    }
                }
                return g ? (g = !k, g ? r : '"') : m ? (m = !L, m ? r : '"') : (y ? (v++, h[v] = D++, y) : "") + (_ ? v ? "" : i ? (i = s = !1, "\b") : "," : S ? (v && K(e), i = b, s = b.charAt(0) === "~", "\b" + b + ":") : b ? b.split("^").join(".").replace(p, B) + (T ? (u[++v] = !0, b.charAt(0) !== "." && (h[v] = D), T) : w) : w ? w : A ? (u[v--] = !1, A) + (T ? (u[++v] = !0, T) : "") : N ? (u[v] || K(e), ",") : d ? "" : (g = k, m = L, '"'))
            }
        }
        var i, s, o = n.links, u = {}, h = {0: -1}, v = 0, m = !1, g = !1;
        return(e + " ").replace(d, r)
    }
    function Z(e, t) {
        return e && e !== t ? t ? D(D({}, t), e) : e : t && D({}, t)
    }
    function ot(e) {
        return C[e] || (C[e] = "&#" + e.charCodeAt(0) + ";")
    }
    if (t && t.views || e.jsviews) {
        return
    }
    var r = "v1.0pre", i, s, o, u, a = "[", f = "[", l = "]", c = "]", h = "^", p = /^(?:null|true|false|\d[\d.]*|([\w$]+|\.|~([\w$]+)|#(view|([\w$]+))?)([\w$.^]*?)(?:[.[^]([\w$]+)\]?)?)$/g, d = /(\()(?=\s*\()|(?:([([])\s*)?(?:([#~]?[\w$.^]+)?\s*((\+\+|--)|\+|-|&&|\|\||===|!==|==|!=|<=|>=|[<>%*!:?\/]|(=))\s*|([#~]?[\w$.^]+)([([])?)|(,\s*)|(\(?)\\?(?:(')|("))|(?:\s*(([)\]])(?=\s*\.|\s*\^)|[)\]])([([]?))|(\s+)/g, v = /\s*\n/g, m = /\\(['"])/g, g = /\\?(['"\\])/g, y = /\x08(~)?([^\x08]+)\x08/g, b = /^if\s/, w = /<(\w+)[>\s]/, E = /<(\w+)[^>\/]*>[^>]*$/, S = /[\x00`><"'&]/g, x = S, T = 0, N = 0, C = {"&": "&", "<": "<", ">": ">", "\0": "&#0;", "'": "&#39;", '"': "&#34;", "`": "&#96;"}, k = "data-jsv-tmpl", L = [].slice, A = {}, O = {template: {compile: W}, tag: {compile: z}, helper: {}, converter: {}}, M = {jsviews: r, render: A, settings: {delimiters: P, debugMode: !0, tryCatch: !0}, sub: {View: R, Error: _, tmplFn: Q, parse: Y, extend: D, error: J, syntaxError: K}, _cnvt: F, _tag: q, _err: function(e) {
            return st.debugMode ? "Error: " + (e.message || e) + ". " : ""
        }};
    (_.prototype = new Error).constructor = _;
    B.depends = function() {
        return[this.get("item"), "index"]
    };
    for (s in O) {
        V(s, O[s])
    }
    var et = M.templates, tt = M.converters, nt = M.helpers, rt = M.tags, it = M.sub, st = M.settings;
    if (t) {
        i = t;
        i.fn.render = $
    } else {
        i = e.jsviews = {};
        i.isArray = Array && Array.isArray || function(e) {
            return Object.prototype.toString.call(e) === "[object Array]"
        }
    }
    i.render = A;
    i.views = M;
    i.templates = et = M.templates;
    rt({"else": function() {
        }, "if": {render: function(e) {
                var t = this, n = t.rendering.done || !e && (arguments.length || !t.tagCtx.index) ? "" : (t.rendering.done = !0, t.selected = t.tagCtx.index, t.tagCtx.render());
                return n
            }, onUpdate: function(e, t, n) {
                var r, i, s;
                for (r = 0; (i = this.tagCtxs[r]) && i.args.length; r++) {
                    i = i.args[0];
                    s = !i !== !n[r].args[0];
                    if (!!i || s) {
                        return s
                    }
                }
                return!1
            }, flow: !0}, "for": {render: function(e) {
                var t, r, s = this, o = s.tagCtx, u = !arguments.length, a = "", f = u || 0;
                if (!s.rendering.done) {
                    if (u) {
                        a = n
                    } else if (e !== n) {
                        a += o.render(e);
                        f += i.isArray(e) ? e.length : 1
                    }
                    if (s.rendering.done = f) {
                        s.selected = o.index
                    }
                }
                return a
            }, onUpdate: function(e, t, n) {
            }, onArrayChange: function(e, t) {
                var n, r = this, i = t.change;
                if (this.tagCtxs[1] && (i === "insert" && e.target.length === t.items.length || i === "remove" && !e.target.length || i === "refresh" && !t.oldItems.length !== !e.target.length)) {
                    this.refresh()
                } else {
                    for (n in r._.arrVws) {
                        n = r._.arrVws[n];
                        if (n.data === e.target) {
                            n._.onArrayChange.apply(n, arguments)
                        }
                    }
                }
                e.done = !0
            }, flow: !0}, include: {flow: !0}, "*": {render: function(e) {
                return e
            }, flow: !0}});
    tt({html: function(e) {
            return e != n ? String(e).replace(x, ot) : ""
        }, attr: function(e) {
            return e != n ? String(e).replace(S, ot) : e === null ? null : ""
        }, url: function(e) {
            return e != n ? encodeURI(String(e)) : e === null ? null : ""
        }});
    P()
})(this, this.jQuery);
(function($) {
    var vars = {};
    $.views.tags({setvar: function(key, value) {
            if (value) {
                vars[key] = value
            } else {
                vars[key] = this.tagCtx.render()
            }
            return""
        }});
    $.views.helpers({formatDate: function(val, format) {
            return $.formatDate(val, format)
        }, getvar: function(key) {
            return vars[key]
        }, truncate: function(string, limit, html) {
            if ($.trim(string) == '')
                return string;
            if (html)
                var content = $($.truncate(string, limit)).html();
            else
                var content = $.truncate(string, limit);
            return $('<div/>').html(content).text()
        }, getFormattedCurrency: function(originalPrice, decimalType, from, to) {
            return $.getFormattedCurrency(originalPrice, decimalType, from, to)
        }, htmlspecialchars_decode: function(string, quote_style) {
            return $.htmlspecialchars_decode(string, quote_style)
        }, stripslashes: function(str) {
            return $.stripslashes(str)
        }, in_array: function(needle, arr) {
            return $.in_array(needle, arr)
        }, round: function(value) {
            var val = parseFloat(value);
            return Math.round(val)
        }, integer: function(value) {
            return parseInt(value)
        }, print: function(string) {
            console.log(string)
        }})
})(jQuery);

$(window).bind("load", function()
{
    /*if (__ANALYTICS_MODULE || __AFFILIATE_MODULE)
    {
        $.extend({ua: {version: (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) ? (navigator.userAgent.match(/.+(?:chrome)[\/: ]([\d.]+)/i) || [])[1] : ((navigator.userAgent.toLowerCase().indexOf("msie") >= 0) ? (navigator.userAgent.match(/.*?msie[\/:\ ]([\d.]+)/i) || [])[1] : (navigator.userAgent.match(/.+(?:it|pera|irefox|ersion)[\/: ]([\d.]+)/i) || [])[1]), browser: (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) ? 'Chrome' : ($.browser.safari ? 'Safari' : ($.browser.opera ? 'Opera' : ($.browser.msie ? 'Internet Explorer' : 'Firefox'))), os: (navigator.platform.toLowerCase().indexOf('mac') != -1 ? 'MacOS' : (navigator.platform.toLowerCase().indexOf('win') != -1 ? 'Windows' : 'Linux')), language: (navigator.language ? navigator.language : (navigator.browserLanguage ? navigator.browserLanguage : (navigator.userLanguage ? navigator.userLanguage : (navigator.systemLanguage ? navigator.systemLanguage : ''))))}});
        $.ajax({type: "POST", url: GLOBAL_BASE_PATH + '/track/ajaxStat/', data: {'url': location.href, 'title': document.title, 'browser_version': BrowserDetect.version, 'browser': BrowserDetect.browser, 'os': BrowserDetect.OS, 'client_language': $.ua.language, 'referrer': document.referrer, 'targetPath': targetPath, 'targetPathType': targetPathType, 'statPageName': statPageName}, beforeSend: function() {
            }, complete: function() {
            }, success: function(data) {
            }})
    }*/
});


$(document).ready(function() {
    var winWidth = Number($(window).width());
    $('.languageList .lang-optionlist').click(function() {
        var LanguageIDString = $(this).attr("id");
        var LanguageArray = LanguageIDString.split("common_language_");
        var LanguageIDArray = LanguageArray[1].split("_");
        var LanguageID = LanguageIDArray[0];
        var LCIDString = LanguageIDArray[1];
        if ($('.languagebox_head').attr("id") == undefined || $('.languagebox_head').attr("id") == '') {
            var oldLCIDString = AjaxCurrLanguage
        } else {
            var oldLCIDString = $('.languagebox_head').attr("id")
        }
        setLanguage(LanguageID, LCIDString, oldLCIDString)
    })
    $('.currencyList .lang-optionlist').click(function() {
        var IDString = $(this).attr("id");
        var CurrencyArray = IDString.split("common_currency_");
        var CurrencyIDArray = CurrencyArray[1].split("_");
        var currencyID = CurrencyIDArray[0];
        var currencyCode = CurrencyIDArray[1];        
        setCurrency(currencyID,currencyCode)
    })
});
function setLanguage(languageID, newLCIDString, oldLCIDString)
{
    $.ajax({url: GLOBAL_BASE_PATH + "/index/Ajaxresetlanguage/", type: "POST", cache: !1, global: !1, data: {languageID: languageID, newLCIDString: newLCIDString, oldLCIDString: oldLCIDString}, success: function(data) {
            if ($.trim(data) != '')
            {
                window.location.href = data
            }
            else if (oldLCIDString != '' && newLCIDString != '')
            {
				if (location.href.indexOf('en') > -1 || location.href.indexOf('ar') > -1)
					{
					 
					 var newhref = (location.href).replace('/' + oldLCIDString + '/', '/' + newLCIDString + '/');
                
					}
				else{
					var newhref = (location.href)+ newLCIDString + '/';
					}
                window.location.href = newhref
            }
            else {
                window.location.reload()
            }
        }})
}
function setCurrency(currencyID,currencyCode)
{
    $.ajax({url: GLOBAL_BASE_PATH + "/index/Ajaxresetcurrency/", type: "POST", cache: !1, global: !1, data: {currencyID: currencyID, currencyCode: currencyCode}, success: function(data) {
        if ($.trim(data) != '')
        {
            window.location.href = data
        }           
        else {
            window.location.reload()
        }
    }})
}