﻿$(function () {
    var isGiftCardsServer = Utils.isGiftCardsServer();

    document.netminersPushDirect = function (title) {
        if (isGiftCardsServer) {
            return;
        }

        document.netminers.title = title;
        $netminers.bc = [];

        if ($.cookie('debugNetminers') == 'true') {
            var ui = $("#netminersDataLog");
            if (!ui.length) {
                ui = $("<div id='netminersDataLog' style='color: blue; text-align: center; font-size: 18px; padding: 5px 0px 5px 0px; line-height: 25px;'></div>");

                if ($("div.topbar").length)
                    ui.insertBefore("div.topbar");
                else
                    ui.insertBefore("div#header");
            }

            ui.append(title + '<br/>');
        }

        var netminersTitle = title;

        document.netminers.title = title;

        if (!$netminers.standardOperationsPerformed) {
            $netminers.standardOperationsPerformed = true;

            // Account configuration            
            $netminers.push(
                ['disableFormTracking',
                    [
            /* Totally disable tracking of gift cards site */
                        [(/giftcards\.pandora\.net/), 	// Page selector regex: .* (any url)
                        [
                            [(/.*/), 		// Form selector regex: .* (any form id or name)
                                [
                                    (/.*/i)	// input/select/textarea regex: .*creditcard.*
                                ]
                            ]
                        ]
                        ]
                    ]
                ],
                ['enqueueUrlTasks'],
                ['initInteractive'],
                ['initFormTracking'],
                ['setAccountId', 'pandora'],
                ['enableFirstPartyCookie'],
                ['setVersion', '3', '01'],
                ['setSeparator', '>'],
                ['trackPage', function (tracker) {
                    tracker.take(netminersTitle);
                } ]);
        }
        else {
            $netminers.push(['postPageView', netminersTitle]);
        }
    }

    // push to Net Miners
    document.netminersPush = function (beforeHandler) {
        var tracker = new NetminersTracker();
        var siteLanguage = Utils.SiteLanguage(false);
        var title = tracker.BuildBreadcrumbs(window.location, $.cookie("userEmail"), siteLanguage ? siteLanguage.toUpperCase() : '');
        if (beforeHandler) {
            if (title)
                title = beforeHandler(title);
            else
                return;
        }

        if (title) {
            document.netminersPushDirect(title);
        }
    }

    // occurs when page is loaded, process all update panels and so on.
    var pageLoadCallback = function (breadCrumbs) {
        var breadCrumbsParts = breadCrumbs.split(' > ');
        breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
        var appendix = null;
        var url = location.pathname;
        var href = location.href;
        var urlAppendix = url.match(/^\/(?:\w{2}-\w{2}\/)?(.*)/im);

        if (urlAppendix && urlAppendix.length >= 2) {
            if (urlAppendix[1].toLowerCase() == 'my-pandora/my-profile') {
                // my profile - change country
                $("#content_1_ddlCountry").bind('change.netminers', function (event) {
                    document.netminersPush(function (breadCrumbs) {
                        return breadCrumbs + ' > Change Country';
                    });
                });

                // my profile - change language
                $("#content_1_ddlLanguage").bind('change.netminers', function (event) {
                    document.netminersPush(function (breadCrumbs) {
                        return breadCrumbs + ' > Change Language';
                    });
                });

                return breadCrumbsParts.join(' > ') + 'Pandora Club' + ' > ' + 'Profile';
            }
            if (unescape(urlAppendix[1].toLowerCase()) == 'my-pandora/my designs area/my-wishlist') {
                if ($.inArray("My Wishlist", breadCrumbsParts) != -1) {
                    // remove from wishlist when in 'My design Area mode'
                    $("li.product span.action-links a span.r").live('click.netminers', function (event) {
                        var productId = $(event.currentTarget).parent().parent().children(":hidden").val();
                        ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
                            if (!response) {
                                return;
                            }
                            else {
                                RemoveCallback(breadCrumbs, response, productId);
                            }
                        });
                        return null;
                    });
                }
                return breadCrumbs;
            }
            // my designs - remove
            if (unescape(urlAppendix[1].toLowerCase()) == 'my-pandora/my-designs') {
                $("li.jcarousel-item span.action-links a.removeDesign").live('click.netminers', function (event) {
                    var t = $(event.currentTarget).parents("li").children("strong.heading").text().trim();
                    document.netminersPush(function (breadCrumbs) {
                        var breadCrumbsParts = breadCrumbs.split(' > ');
                        breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                        return breadCrumbsParts.join(' > ') + ' > Remove > ' + t;
                    });
                });
                return breadCrumbs;
            }
            // my jewelley - remove
            if (unescape(urlAppendix[1].toLowerCase()) == 'my-pandora/my designs area/my-jewellery') {
                if ($.inArray("My Jewelry", breadCrumbsParts) != -1) {
                    // remove from jewellery when in 'My design Area mode'
                    $("li.product span.action-links a span.r").live('click.netminers', function (event) {
                        var productId = $(event.currentTarget).parent().parent().children(":hidden").val();
                        ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
                            if (!response) {
                                return;
                            }
                            else {
                                RemoveCallback(breadCrumbs, response, productId);
                            }
                        });
                        return null;
                    });
                }
                return breadCrumbs;
            }
            // remove from designs when in 'My design Area mode'
            if (unescape(urlAppendix[1].toLowerCase()) == 'my-pandora/my designs area/my-designs') {
                $("li.product span.action-links a.remove").live('click.netminers', function (event) {
                    var t = $(event.currentTarget).parents("li").children("strong").eq(0).text().trim();
                    document.netminersPush(function (breadCrumbs) {
                        var breadCrumbsParts = breadCrumbs.split(' > ');
                        breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                        return breadCrumbsParts.join(' > ') + ' > Remove > ' + t;
                    });
                });
                return breadCrumbs;
            }
        }
        // my wishlist - remove
        if ($.inArray("My Wishlist", breadCrumbsParts) != -1) {
            $("li.product span.action-links a span.r").live('click.netminers', function (event) {
                var productId = $(event.currentTarget).parent().parent().children(":hidden").val();
                ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
                    if (!response) {
                        return;
                    }
                    else {
                        RemoveCallback(breadCrumbs, response, productId);
                    }
                });
                return null;
            });
        }

        if ($.inArray("My Jewelry", breadCrumbsParts) != -1) {
            // my jewelley - remove
            $("li.product span.action-links a span.r").live('click.netminers', function (event) {

                var productId = $(event.currentTarget).parent().parent().children(":hidden").val();
                ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
                    if (!response) {
                        return;
                    }
                    else {
                        RemoveCallback(breadCrumbs, response, productId);
                    }
                });
                return null;
            });
        }

        return breadCrumbs;
    }

    // end of callback

    // remove from designs click
    $("#mycarousel li.jcarousel-item :eq(2) :last").bind('click.netminers', function (event) {
        var t = $(event.currentTarget).parents("li").children("strong.heading").text();
        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
            return breadCrumbsParts.join(' > ') + ' > Remove > ' + t;
        });
    });

    //share flow from myWishlist - Email
    $("div.share li.shareEmail a").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + 'Email';
            $netminers.push(['postPageView', document.netminers.title]);
        });
    });

    //share flow from myWishlist - Facebook
    $("div.share li.facebook a").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + 'Facebook';
            $netminers.push(['postPageView', document.netminers.title]);
        });
    });

    //share flow from myWishlist - Twitter
    $("div.share li.twitter a").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);

            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + 'Twitter';
            $netminers.push(['postPageView', document.netminers.title]);
        });
    });

    // paging on the my lewellery, my wishlist and my designs
    $("div.pPagingList ul").live('click.netminers', function (event) {
        var pageId = $(event.target).text();
        var appendix = pageId ? pageId : '1';

        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);

            return breadCrumbsParts.join(' > ') + ' > ' + 'Page ' + appendix;
        });
    });

    // add to my jewellery by clicking on the overlay
    $("div.overlay ul li:nth-child(1) a:not(.added)").bind('click.netminers', function (event) {
        var prefix = window.location.pathname.split('/').length == 5 ? 'Jewelry > Result' : 'Jewelry > Show Product';
        event.preventDefault();
        var idNode = $(event.currentTarget).parents("li.product");
        var productId = idNode.eq(0).attr('id').toUpperCase().substr(1);
        if ($.cookie("userEmail")) {
            ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
                if (!response) {
                    return;
                }
                else {
                    document.netminersPush(function (breadCrumbs) {
                        var tracker = new NetminersTracker();
                        var breadCrumbsParts = breadCrumbs.split(' > ');
                        breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                        breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
                        breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
                        breadCrumbsParts[tracker.Indexes.Material] = response.Material;
                        breadCrumbsParts[tracker.Indexes.Category] = response.Category;
                        breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price;
                        breadCrumbsParts[tracker.Indexes.ProductID] = productId;
                        if ($.inArray("Jewelry", breadCrumbsParts) == -1) {
                            //return breadCrumbsParts.join(' > ') + ' > ' + prefix + ' > ' + response.Name + ' > Add to My Jewelry';
                            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + prefix + ' > ' + response.Name + ' > Add to My Jewelry';
                            $netminers.push(['postPageView', document.netminers.title]);
                        }
                        else {
                            //return breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Jewelry';
                            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Jewelry';
                            $netminers.push(['postPageView', document.netminers.title]);
                        }
                    });
                }
            });
        }
        return false;
    });

    // add to my wishlist by clicking on the overlay
    $("div.overlay ul li:nth-child(2) a:not(.added)").bind('click.netminers', function (event) {
        var prefix = window.location.pathname.split('/').length == 5 ? 'Jewelry > Result' : 'Jewelry > Show Product';
        event.preventDefault();
        var idNode = $(event.currentTarget).parents("li.product");
        var productId = idNode.eq(0).attr('id').toUpperCase().substr(1);
        if ($.cookie("userEmail")) {
            ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
                if (!response) {
                    return;
                }
                else {
                    document.netminersPush(function (breadCrumbs) {
                        var tracker = new NetminersTracker();
                        var breadCrumbsParts = breadCrumbs.split(' > ');
                        breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                        breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
                        breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
                        breadCrumbsParts[tracker.Indexes.Material] = response.Material;
                        breadCrumbsParts[tracker.Indexes.Category] = response.Category;
                        breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price;
                        breadCrumbsParts[tracker.Indexes.ProductID] = productId;
                        if ($.inArray("Jewelry", breadCrumbsParts) == -1) {
                            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + prefix + ' > ' + response.Name + ' > Add to My Wishlist';
                            $netminers.push(['postPageView', document.netminers.title]);
                        }

                        else {
                            document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Wishlist';
                            $netminers.push(['postPageView', document.netminers.title]);
                        }
                    });
                }
            });
        }
        return false;
    });

    // add to wishlist by clicking on the button
    $("a.addToMyWishlist").bind('click.netminers', function (event) {
        var productsRegex = /.*?\/.*?\/(jewellery|ranges|materials|stone|price)(?:\/(\w+)\/((?:\w|-)+)(?:\/?(\w+(?:-\w+)?)?))?/im;
        var url = location.pathname;

        var urlParts = url.match(productsRegex);

        if (urlParts == null)
            return; // todo: fix later

        var productId = urlParts[4].toUpperCase()
        ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
            if (!response) {
                return;
            }
            else {
                document.netminersPush(function (breadCrumbs) {
                    var tracker = new NetminersTracker();
                    var breadCrumbsParts = breadCrumbs.split(' > ');
                    breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                    breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
                    breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
                    breadCrumbsParts[tracker.Indexes.Material] = response.Material;
                    breadCrumbsParts[tracker.Indexes.Category] = response.Category;
                    breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price; //parsePriceRange($('div.price strong').text());
                    document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Wishlist';
                    $netminers.push(['postPageView', document.netminers.title]);
                    //return breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Wishlist';
                });
            }
        })
    });

    // add to jewellery by clicking on the button
    $("a.addToMyJewellery").bind('click.netminers', function (event) {
        var productsRegex = /.*?\/.*?\/(jewellery|ranges|materials|stone|price)(?:\/(\w+)\/((?:\w|-)+)(?:\/?(\w+(?:-\w+)?)?))?/im;
        var url = location.pathname;
        var urlParts = url.match(productsRegex);

        if (urlParts == null)
            return; // todo: fix later

        var productId = urlParts[4].toUpperCase()
        ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
            if (!response) {
                return;
            }
            else {
                document.netminersPush(function (breadCrumbs) {
                    var tracker = new NetminersTracker();
                    var breadCrumbsParts = breadCrumbs.split(' > ');
                    breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                    breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
                    breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
                    breadCrumbsParts[tracker.Indexes.Material] = response.Material;
                    breadCrumbsParts[tracker.Indexes.Category] = response.Category;
                    breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price;
                    document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Jewelry';
                    $netminers.push(['postPageView', document.netminers.title]);
                    //return breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Jewelry';
                });
            }
        })
    });

    // add to basket event.
    $("a.add").bind('click.netminers', function (event) {
        var productsRegex = /.*?\/.*?\/(jewellery|ranges|materials|stone|price)(?:\/(\w+)\/((?:\w|-)+)(?:\/?([-\w]+)?))?/im
        var url = location.pathname;
        var urlParts = url.match(productsRegex);
        var productId = urlParts[4].toUpperCase()
        ProductInfoClass.GetProductByItemNumber(productId, Utils.SiteLanguage(false), function (response) {
            if (!response) {
                return;
            }
            else {
                document.netminersPush(function (breadCrumbs) {
                    var tracker = new NetminersTracker();
                    var breadCrumbsParts = breadCrumbs.split(' > ');
                    breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
                    breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
                    breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
                    breadCrumbsParts[tracker.Indexes.Material] = response.Material;
                    breadCrumbsParts[tracker.Indexes.Category] = response.Category;
                    breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price;
                    document.netminers.title = breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to Basket';
                    $netminers.push(['postPageView', document.netminers.title]);
                    //return breadCrumbsParts.join(' > ') + ' > ' + response.Name + ' > Add to My Jewelry';
                });
            }
        });
    });
    
    // process banners clicks
    $('div.spot a.image-wrapper, div.spot div.spot-text h3 a, div.spot div.image a.pandoraPlayer').live('click', function () {
        var target = this;

        if ($(this).closest(".spot").attr("data-enablenetminers").toLowerCase() == "false") {
            return;
        }

        var spotType = $(this).closest(".spot").attr("data-spottype");
        var spotPath = $(this).closest(".spot").attr("data-spotpath");

        var getCategory = function () {
            var capitaliseFirstLetter = function (string) {
                return string.charAt(0).toUpperCase() + string.slice(1);
            };

            var capitaliseFirstLetters = function (string) {
                var words = string.split(' ');
                return $.Enumerable.From(words).Select(function (t) { return capitaliseFirstLetter(t); }).ToArray().join(' ');
            };

            var title = $.Enumerable
                .From(location.pathname.split('/'))
                .Select('$.replace("-", " ")')
                .Where('$!=""').Select(function (t) { return capitaliseFirstLetters(t); }).ToArray();
            return title.length < 2 ? ['Front Page'] : title.slice(1);
        };

        document.netminersPush(function (breadCrumbs) {
            var result = NetminersTracker.GetStandardBreadcrumbs(breadCrumbs);
            var breadcrumb = result + ' > ' + spotType + ' > ' + spotPath;

            //var category = getCategory().join(' > ');
            //var bannerName = $('img', target).attr('alt');
            //var breadcrumb = result + ' > ' + spotType + ' > ' + category + ' > ' + bannerName;
            return breadcrumb;
        });
    });

    // become a member
    $("div.members-box fieldset div.form-box a").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
            return breadCrumbsParts.join(' > ') + ' > Sign Up > Join > Pandora Club';
        });
    });

    // my wishlist - send
    $("div.wrapper div.flash-holder ul.flash-links a:eq(1)").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            var breadCrumbsParts = breadCrumbs.split(' > ');
            breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
            return breadCrumbsParts.join(' > ') + ' > Send';
        });
    });

    // my profile - change gender
    $("#content_1_rbGender").bind('change.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            return breadCrumbs + ' > Gender > ' + $("#content_1_rbGender :selected").val();
        });
    });

    // my profile - change country
    $("#content_1_ddlCountry").bind('change.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            return breadCrumbs + ' > Change Country';
        });
    });

    // my profile - change language
    $("#content_1_ddlLanguage").bind('change.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            return breadCrumbs + ' > Change Language';
        });
    });

    // my profile - change password
    $("#content_1_btnSaveProfile").bind('click.netminers', function (event) {
        if ($("#content_1_txtNewPassword").length && $("#content_1_txtNewPassword").val() != '')
            document.netminersPush(function (breadCrumbs) {
                return breadCrumbs + ' > Change Password';
            });
    });

    //my profile - delete profile
    $("#content_1_btnDelete").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            return breadCrumbs + ' > Delete Profile';
        });
    });

    //my profile - cancel
    $("div#content_1_pEditFooter a.cancel").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            return breadCrumbs + ' > Cancel';
        });
    });

    //my profile - save
    $("#content_1_btnSaveProfile").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            return breadCrumbs + ' > Save';
        });
    });

    $("#frontpage-text").bind('click.netminers', function (event) {
        document.netminersPush(function (breadCrumbs) {
            var tag = $("#frontpage-text").attr("data-netminerstag"); ;
            return breadCrumbs + ' > ' + tag;
        });
    });

    //product search - send selected filters to NetMiners as well
    var productsRegex = /.*?\/.*?\/(jewellery|ranges|materials|stone|price)(?:\/(\w+)\/((?:\w|-)+)(?:\/?(.*)))?/im
    var appendix = null;
    var url = location.pathname;
    var href = location.href;
    if (url.match(productsRegex)) {
        var urlParts = url.match(productsRegex);

        if (urlParts && urlParts.length >= 3 && urlParts[1]) {
            var material = getUrlParams("MetalId");
            var category = getUrlParams("CategoryId");
            var priceRange = getUrlParams("PriceRangeId");
            var stone = getUrlParams("StoneId");
            var all = '00000000-0000-0000-0000-000000000000';
            switch (urlParts[1].toLowerCase()) {
                case 'jewellery':
                    var prefix = '';

                    if (urlParts[2]) {
                        if ((material && material != all) || (category && category != all) || (priceRange && priceRange != all) || (stone && stone != all)) {
                            var self = new NetminersTracker();
                            var collectionName = urlParts[3];
                            collectionName = collectionName.substring(0, 1).toUpperCase() + collectionName.substring(1).toLowerCase();

                            ProductInfoClass.GetSelectionInfo({ Category: category, Material: material, Stone: stone, PriceRange: priceRange, Locale: Utils.SiteLanguage(false) }, function (response) {
                                self.bc[self.Indexes.Site] = location.host.toLowerCase();

                                var urlParts = Utils.SiteLanguage().split('-');
                                if (urlParts && urlParts.length == 2) {
                                    var countryCode = urlParts[1].toUpperCase();
                                    var languageCode = urlParts[0].toLowerCase();
                                    self.bc[self.Indexes.Country] = countryCode;
                                    self.bc[self.Indexes.Language] = languageCode;
                                    var regionInfo = self.Regions[countryCode];
                                    if (regionInfo) {
                                        self.bc[self.Indexes.Region] = regionInfo.Region;
                                        self.bc[self.Indexes.Market] = regionInfo.Market;
                                        self.bc[self.Indexes.Currency] = regionInfo.Currency;
                                    }
                                }
                                if ($.cookie("userEmail"))
                                    self.bc[self.Indexes.ClientID] = $.cookie("userEmail").toLowerCase();
                                self.bc[self.Indexes.Material] = response.Material;
                                self.bc[self.Indexes.Category] = response.Category;
                                self.bc[self.Indexes.Collection] = collectionName;
                                self.bc[self.Indexes.Stone] = response.Stone;
                                self.bc[self.Indexes.PriceRange] = response.PriceRange;
                                var pageNumber = getUrlParams("Page");
                                if (pageNumber)
                                    appendix = 'Jewelry > Result > Page ' + pageNumber;
                                else
                                    appendix = 'Jewelry > Result > Page 001';
                                document.netminers.title = self.bc.join(' > ') + ' > ' + appendix;
                                //$netminers.push(['postPageView', document.netminers.title]);
                            });

                            return null;
                        }
                    }
                    break;
            }
        }

        // if this is a product info page - call web servce to get product info in english language.
        if (urlParts.length >= 5 && urlParts[4]) {
            ProductInfoClass.GetProductByItemNumber(urlParts[4].toUpperCase(), Utils.SiteLanguage(false), function (response) {
                if (!response) {
                    return;
                }
                else {
                    document.netminersPush(function (breadCrumbs) {
                        var crumbParts = new Array();
                        var breadCrumbsParts = breadCrumbs.split(' > ');
                        var tracker = new NetminersTracker();
                        breadCrumbsParts[tracker.Indexes.ProductID] = urlParts[4].toUpperCase();
                        breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price; //parsePriceRange($('div.price strong').text());
                        breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
                        breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
                        breadCrumbsParts[tracker.Indexes.Material] = response.Material;
                        breadCrumbsParts[tracker.Indexes.Category] = response.Category;
                        var appendix = ' > Jewelry > Show Product > ' + response.Name;

                        return breadCrumbsParts.join(' > ') + appendix
                    }); // close document.netminersPush               
                }
            });
        }
        else
            document.netminersPush(pageLoadCallback);
    }
    else
        document.netminersPush(pageLoadCallback);


});

// Tracks selection in the fash
function flashTracking(path)
{
    document.netminersPush(function (breadCrumbs)
    {
        var crumbParts = new Array();
        var breadCrumbsParts = breadCrumbs.split(' > ');
        var tracker = new NetminersTracker();
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Site]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Region]);
//        crumbParts.push(breadCrumbsParts[tracker.Indexes.Country]);
//        crumbParts.push(breadCrumbsParts[tracker.Indexes.Language]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Market]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Currency]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.ClientID]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.ProductID]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Collection]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Category]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Material]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.Stone]);
        crumbParts.push(breadCrumbsParts[tracker.Indexes.PriceRange]);
        var result = crumbParts.join(' > ') + ' > ' + 'FrontPage' + ' > ' + path;
        return result;
    });
};

function RemoveCallback(breadCrumbs, response, productId)
{
	var tracker = new NetminersTracker();
	var breadCrumbsParts = breadCrumbs.split(' > ');
	breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
	breadCrumbsParts[tracker.Indexes.Stone] = response.Stone;
	breadCrumbsParts[tracker.Indexes.Collection] = response.Collection;
	breadCrumbsParts[tracker.Indexes.Material] = response.Material;
	breadCrumbsParts[tracker.Indexes.Category] = response.Category;
	breadCrumbsParts[tracker.Indexes.PriceRange] = response.Price;
	breadCrumbsParts[tracker.Indexes.ProductID] = productId;							
	breadCrumbsParts = breadCrumbsParts.slice(0, breadCrumbsParts.length - 1);
	document.netminers.title = breadCrumbsParts.join(' > ') + ' > Remove > ' + response.Name;							      
	$netminers.push(['postPageView', document.netminers.title]);
}

// by OCH 23 aug. 2010
// tracks BYOP flash. 
function BYOB_Tracking(arrayOfActionParts, itemNumber)
{
    // ignore following breadcrumbs as they are not included into specification
    switch (arrayOfActionParts)
    {
        case 'Add Rings|Ringbuilder Result':
        case 'Add Rings|Close':
        case 'Remove':
        case 'Copy':
        case 'Information':
        case 'Edit Title':
            return;

        case 'Nearest Store':
            document.netminersPush(function (breadCrumbs)
            {
                return breadCrumbs + ' > Find store';
            });

            return;
    }

itemNumber = itemNumber || "[ProductID]";
    
    var actions = arrayOfActionParts.split('|').join(' > ');

    document.netminersPush(function (breadCrumbs)
    {
        var result = NetminersTracker.GetStandardBreadcrumbs(breadCrumbs, itemNumber);

        switch (arrayOfActionParts)
        {
            case 'New':
                result += ' > Explore > Inspiration > Create Combine > Bracelet Designer > New';
                break;

            case 'Clear':
                result += ' > Explore > Inspiration > Create Combine > Bracelet Designer > Clear';
                break;

            case 'Change Bracelet':
                result += ' > Explore > Inspiration > Create Combine > Bracelet Designer > Change';
                break;

            case 'Add Bracelet':
                result += ' > Explore > Inspiration > Create Combine > Bracelet Designer > Add bracelet';
                break;

            case 'Add Charms':
            case 'Add Charms > Add charm':
            case 'Add Charms|Add charm':
                result += ' > Explore > Inspiration > Create Combine > Bracelet Designer > Add charms';
                break;

            case 'Add|Recommended charms':
            case 'Add > Recommended charms':
                result += ' > Explore > Inspiration > Create Combine > Bracelet Designer > Add recommended charms';
                break;

            case 'New Design':
                result += ' > Explore > Inspiration > Create Combine > Ring Designer > New';
                break;

            case 'Reset Design':
                result += ' > Explore > Inspiration > Create Combine > Ring Designer > Clear';
                break;

            case 'Add Rings':
            case 'Add Rings|Add ring':
                result += ' > Explore > Inspiration > Create Combine > Ring Designer > Add rings';
                break;

            case 'Add Recommended Ring':
                result += ' > Explore > Inspiration > Create Combine > Ring Designer > Add recommended rings';
                break;

            case 'Print List':
                if ($('.promotionStoresListUrl').length > 0)
                {
                    //result = breadCrumbs + ' > See-print list';
                    return null;
                }

                result += ' > Explore > Inspiration > Create Combine > Ring Designer > Print';
                break;

            default:
                result += ' > ' + actions;
                break;
        }

        return result;
    });
};

//returns URL parameters 
function getUrlParams(name)
{
    var newName = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + newName + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
};

if (typeof (document.netminers) != 'object') document.netminers = {};
var $netminers = $netminers || [];



//---------------------------------------------------------------------------------------------------------------------------------------
// v4.0.7 (unminified)
//---------------------------------------------------------------------------------------------------------------------------------------
var $$nm_queue_name = $$nm_queue_name || '$netminers';
var $$nm_instance_name = $$nm_instance_name || 'tracker';
(function(x, y) {
    var z = '407';
    if (typeof(document.netminers) != 'object') {
        document.netminers = { };
    }
    Array.from = function(a) {
        var b = [];
        for (var i = 0; i < a.length; i++) {
            b.push(a[i]);
        }
        return b;
    };
    Function.prototype.$bind = function() {
        var a = this;
        var b = Array.from(arguments);
        var c = b.shift();
        return function() {
            return a.apply(c, b.concat(Array.from(arguments)));
        };
    };
    Function.prototype.$bindAsEventListener = function() {
        var b = this;
        var c = Array.from(arguments);
        var d = c.shift();
        return function(a) {
            return b.apply(d, [a || window.event].concat(c));
        };
    };
    String.prototype.trimcc = function() {
        return this.replace( /[\u0000-\u001f]|\u007f|\u007f|\u007f|\u0085|\u2028|\u2028|\2029|\ufff9|\ufffa|\ufffb|\u200e|\u200f/g , '');
    };
    String.prototype.trim = function() {
        return this.replace( /^[\s\xA0]+|[\s\xA0]+$/g , '');
    };
    String.prototype.escapeHTML = function() {
        return this.replace( /&/g , '&amp;').replace( /</g , '&lt;').replace( />/g , '&gt;');
    };
    String.prototype.queryParams = function() {
        var o = { };
        var d = this.trim().match( /[^?#]*(#.*)?$/ );
        if (d.length > 0) {
            var f = d[0];
            var g = f.split('&');
            g.$forEach(function(a, b) {
                var c;
                try {
                    c = decodeURIComponent(a).split('=');
                } catch(e) {
                    c = unescape(a).split('=');
                }
                o[decodeURIComponent(c[0])] = c.length > 1 ? c[1] : null;
            });
        }
        return o;
    };
    Object.$extend = function(a, b) {
        for (var c in b) {
            a[c] = b[c];
        }
        return a;
    };
    Object.$clone = function(a) {
        return Object.$extend({ }, a);
    };
    Object.isUndefinedOrNull = function(a) {
        return typeof a === "undefined" || a === null;
    };
    var A = {
        stop: function(a) {
            a.cancelBubble = true;
            a.returnValue = false;
        }
    };
    if (!Array.prototype.$forEach) {
        Array.prototype.$forEach = function(a) {
            var b = this.length;
            var c = arguments[1];
            for (var i = 0; i < b; i++) {
                if (i in this) {
                    a.call(c, this[i], i, this);
                }
            }
        };
    }
    document.netminers.setCookie = function(a, b, c) {
        document.cookie = a + '=' + escape(b) + ((c) ? '; expires=' + c.toGMTString() : '') + '; path=/';
    };
    document.netminers.removeCookie = function(a, b) {
        document.cookie = a + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
    };
    document.netminers.getCookie = function(a) {
        var b = document.cookie;
        var c = a + "=";
        var d = b.indexOf("; " + c);
        if (d == -1) {
            d = b.indexOf(c);
            if (d !== 0) {
                return null;
            }
        } else {
            d += 2;
        }
        var e = document.cookie.indexOf(";", d);
        if (e == -1) {
            e = b.length;
        }
        return unescape(b.substring(d + c.length, e));
    };
    var B = { };
    B.getValues = function(a, b) {
        var c = (b || document).getElementsByTagName('meta');
        var d = [];
        for (var i = 0; i < c.length; i++) {
            var e = c[i].getAttribute('name');
            if (e && e.toLowerCase() == a.toLowerCase()) {
                d.push(c[i].getAttribute('content'));
            }
        }
        return d;
    };

    function NMTracker(u) {
        var u = u;
        this.async = true;
        this.syncTimeout = !!(window.attachEvent && !window.opera) ? 10000 : 250;
        this.timerHandle = null;
        this.bcRemove = new RegExp('');
        this.trackingTopDomain = null;
        this.trackingSubDomain = null;
        this.trackingPath = null;
        this.rdl = false;
        this.allowDynamicScripts = true;
        this.dbg = false;
        this.syncFirst = true;
        this.enableRemoteDebugging = true;
        var v = window;
        try {
            var w = window.top.location.href;
            v = window.top;
        } catch(e) {
        }
        // Iframe fix
        if (top.frames.length!=0) {
            v = document;
        }
        this.interactive = /\$\$nm|nminteractive/ .test(v.location.href.toLowerCase());
        this.persistInteractive = /\$\$nm=p|nminteractive=p/ .test(v.location.href.toLowerCase());
        this.allowVerbose = false;
        this.uid = 0;
        this.useFirstParty = false;
        this.syncTasks = { trackPage: true, postCommerceResetItem: true, postCommerceEmptyBasket: true, delay: true };
        this.fieldSubmitDelay = 0;
        this.getElementsByClass = function(c, n, t) {
            var r = [];
            if (!n || n === null) {
                n = document;
            }
            if (typeof(n) == 'string') {
                n = document.getElementById(n);
            }
            if (!c || c === null) {
                c = '*';
            }
            if (!t || t === null) {
                t = '*';
            }
            var e = n.getElementsByTagName(t);
            var l = e.length;
            var a = new RegExp("(^|\\s)" + c + "(\\s|$)");
            for (i = 0, j = 0; i < l; i++) {
                if (a.test(e[i].className)) {
                    r[j] = e[i];
                    j++;
                }
            }
            return r;
        };
        this.it = function(e) {
            if (!e) {
                return '';
            }
            var a = '';
            for (var i = 0; i < e.childNodes.length; i++) {
                switch (e.childNodes.item(i).nodeType) {
                case 1:
                    a += this.it(e.childNodes.item(i));
                    break;
                case 3:
                    a += e.childNodes.item(i).nodeValue;
                    break;
                default:
                    break;
                }
            }
            return a;
        };
        this.cb = function(s) {
            return s.replace(new RegExp('[\s]+' + this.srcBcSep + '[\s]+'), ' ' + this.srcBcSep + ' ');
        };
        this.te = function(a) {
            for (var i = 0; i < a.length; i++) {
                a[i] = a[i].trim();
            }
            return a;
        };
        this.attachEvent = function(a, b, c, d) {
            if (a.addEventListener) {
                a.addEventListener(b, c, false);
            } else {
                if (a.attachEvent) {
                    a.attachEvent('on' + b, c);
                }
            }
        };
        this.detachEvent = function(a, b, c, d) {
            if (a.removeEventListener) {
                a.removeEventListener(b, c, d);
            } else {
                if (a.detachEvent) {
                    a.detachEvent('on' + b, c);
                }
            }
        };
        this.stopPropagation = function(a) {
            if (a.stopPropagation) {
                a.preventDefault();
                a.stopPropagation();
            }
            a.cancelBubble = true;
            a.returnValue = false;
        };
        this.disableFormTracking = function(a) {
            this.formDisableRules = a;
        };
        this.setFieldSubmitDelay = function(a) {
            this.fieldSubmitDelay = a;
        };
        this.ignoreFormField = function(a, b, c) {
            for (var i = 0; i < this.formDisableRules.length; i++) {
                var d = this.formDisableRules[i];
                var e = d[0];
                if (e.test(a)) {
                    if (d.length > 1) {
                        var g = d[1];
                        for (var j = 0; j < g.length; j++) {
                            var h = g[j];
                            var k = h[0];
                            if (b && (k.test(b.id) || k.test(b.name))) {
                                if (h.length > 1) {
                                    var l = h[1];
                                    for (var f = 0; f < l.length; f++) {
                                        var m = l[f];
                                        if (c && (m.test(c.id) || m.test(c.name))) {
                                            return true;
                                        }
                                    }
                                } else {
                                    return true;
                                }
                            }
                        }
                    } else {
                        return true;
                    }
                }
            }
            return false;
        };
        this.initFormTracking = function() {
            var a = [], i;
            this.formDisableRules = this.formDisableRules || [];
            a = a.concat(Array.from(document.getElementsByTagName('input')));
            a = a.concat(Array.from(document.getElementsByTagName('select')));
            a = a.concat(Array.from(document.getElementsByTagName('textarea')));
            for (i = 0; i < a.length; i++) {
                var b = a[i];
                var c = b.tagName.toLowerCase();
                var d = b.type ? b.type.toLowerCase() : '';
                if ((c == 'input' && ( /text|file|password|checkbox|radio/ ).test(d)) || ( /select|textarea/ ).test(c)) {
                    if (!this.ignoreFormField(document.location.href, b.form, b)) {
                        this.observeFieldChanges(b, c, d);
                    } else {
                        this.out('*&nbsp;Disable field = ' + b.id + '/' + b.name + ' (' + (b.type || b.tagName) + ')', '#dd8888', true);
                    }
                }
            }
            var e = Array.from(document.getElementsByTagName("form"));
            for (i = 0; i < e.length; i++) {
                var f = e[i];
                this.attachEvent(f, 'submit', this.onFormChange.$bind(this, f, true));
                this.attachEvent(f, 'reset', this.onFormChange.$bind(this, f, false));
            }
        };
        this.onFormChange = function(a, b, c) {
            var d = [];
            d.push(a.name ? (a.name.length > 0) ? a.name : 'n/a' : 'n/a');
            d.push(a.id ? (a.id.length > 0) ? a.id : 'n/a' : 'n/a');
            d.push(a.action);
            d = d.join(' ' + this.destBcSep + ' ');
            if (b) {
                this.tasks.push(['postEvent', 'Form', 'Submit', d]);
                if (this.fieldSubmitDelay > 0) {
                    setTimeout(this.delayedSubmit.$bind(this, a), this.fieldSubmitDelay);
                    A.stop(c);
                }
            } else {
                this.tasks.push(['postEvent', 'Form', 'Reset', d]);
            }
        };
        this.delayedSubmit = function(a) {
            a.submit();
        };
        this.observeFieldChanges = function(a, b, c) {
            if (b == 'input' && (c == 'radio' || c == 'file' || c == 'checkbox')) {
                this.attachEvent(a, 'change', this.onFieldChanged.$bindAsEventListener(this, a, b, c, true));
            } else {
                this.attachEvent(a, 'blur', this.onFieldChanged.$bindAsEventListener(this, a, b, c, false));
                this.attachEvent(a, 'focus', this.onFieldFocusChanged.$bindAsEventListener(this, a, b, c));
            }
        };
        this.TrackFieldChange = function(a) {
            var b = a.tagName.toLowerCase();
            var c = a.type ? a.type.toLowerCase() : '';
            this.onFieldChanged(a, b, c, true);
            return true;
        };
        this.onFieldChanged = function(a, b, c, d, e) {
            if (this.lastFocusedField || e) {
                var f = '';
                if (c == 'input' && d == 'checkbox') {
                    f = b.value ? b.value : (b.checked ? 'checked' : 'unchecked');
                } else if (c == 'input' && (d == 'radio' || d == 'file')) {
                    f = b.value;
                } else if (c == 'textarea' || (c == 'input' && ( /text|password/ ).test(d))) {
                    if (d == 'password') {
                        f = '***';
                    } else {
                        f = b.value;
                    }
                } else if (c == 'select') {
                    f = null;
                    if (b.selectedIndex > -1) {
                        f = b.options[b.selectedIndex].text;
                    }
                }
                if (e || f != this.lastFocusedField.value) {
                    c = [];
                    c.push(b.form ? b.form.name ? (b.form.name.length > 0) ? b.form.name : 'n/a' : 'n/a' : 'n/a');
                    c.push(b.form ? b.form.id ? (b.form.id.length > 0) ? b.form.id : 'n/a' : 'n/a' : 'n/a');
                    c.push(d || c);
                    c.push(b.name ? (b.name.length > 0 ? b.name : 'n/a') : 'n/a');
                    c.push(b.id ? (b.id.length > 0 ? b.id : 'n/a') : 'n/a');
                    var g = [];
                    g.push(b.form ? b.form.name ? (b.form.name.length > 0) ? b.form.name : 'n/a' : 'n/a' : 'n/a');
                    g.push(b.form ? b.form.id ? (b.form.id.length > 0) ? b.form.id : 'n/a' : 'n/a' : 'n/a');
                    this.tasks.push(['postFieldChange', c.join(' ' + this.destBcSep + ' '), f]);
                }
            }
            this.lastFocusedField = null;
        };
        this.onFieldFocusChanged = function(a, b, c, d) {
            this.lastFocusedField = this.lastFocusedField || { };
            this.lastFocusedField.object = b;
            this.lastFocusedField.value = '';
            var e = false;
            if (c == 'input' && d == 'checkbox') {
                this.lastFocusedField.value = b.value ? b.value : (b.checked ? 'checked' : 'unchecked');
                e = true;
            } else if ((c == 'input' && (d == 'radio' || d == 'text' || d == 'file' || d == 'password')) || d == 'textarea') {
                this.lastFocusedField.value = b.value;
                e = true;
            } else if (c == 'select') {
                if (b.selectedIndex > -1) this.lastFocusedField.value = b.options[b.selectedIndex].text;
                e = true;
            }
        };
        this.addFieldEventDelay = function(a, b, c, d) {
            for (var i = 0; i < a.length; i++) {
                var e = document.getElementById(a[i]);
                if (Object.isUndefinedOrNull(e)) {
                    continue;
                }
                for (var j = 0; j < b.length; j++) {
                    c = c || e['on' + b[j]];
                    e['on' + b[j]] = null;
                    this.attachEvent(e, b[j], this.manageSubmitDelay.$bindAsEventListener(this, e, b[j], c, d || this.fieldSubmitDelay));
                }
            }
        };
        this.manageSubmitDelay = function(a, b, c, d, e) {
            var f = d(a, this, false);
            if (f === true) {
                b.blur();
                setTimeout(this.newSubmitHandler.$bind(this, Object.$clone(a), b, d), e);
                this.stopPropagation(a);
                return false;
            }
            a.returnValue = true;
            return true;
        };
        this.newSubmitHandler = function(a, b, c) {
            var d = [];
            d.push(a, this, true);
            c.apply(b, d);
        };
        this.execute = function(a) {
            if (typeof(a) == 'function') {
                a(this)
            } else {
                this.out('execute() missing method', '#ff0000', false);
            }
        };
        this.setSyncTimeout = function(a) {
            this.syncTimeout = a;
        };
        this.setAccountId = function(a) {
            this.accountId = a;
        };
        this.setTrackingPath = function(a) {
            this.trackingPath = a;
        };
        this.setTrackingSubDomain = function(a) {
            this.trackingSubDomain = a;
        };
        this.setTrackingTopDomain = function(a) {
            this.trackingTopDomain = a;
        };
        this.enableInteractive = function(a, b) {
            this.allowVerbose = b || false;
            this.interactive = true;
            if (a) {
                this.persistInteractive = a;
            }
        };
        this.enableDebug = function() {
            this.dbg = true;
        };
        this.disableDebug = function() {
            this.dbg = false;
        };
        this.setSeparator = function(s) {
            this.srcBcSep = s;
        };
        this.disableDynamicScripts = function() {
            this.allowDynamicScripts = false;
        };
        this.enableDynamicScripts = function() {
            this.allowDynamicScripts = true;
        };
        this.enableCommerceTracking = function(f) {
            f(this, NMCommerce, NMCommerceTemplate);
        };
        this.postDownload = function(a, b) {
            this.postEvent('Download', 'MouseLeft', a, b);
        };
        this.postFieldChange = function(a, b) {
            this.postEvent('Field', 'Change', a, b, isNaN(parseFloat(b)) ? null : parseFloat(b));
        };
        this.postExitLink = function(a, b) {
            this.postEvent('Exit', 'SameWindow', a, b);
        };
        this.postExitLinkNewWindow = function(a, b) {
            this.postEvent('Exit', 'NewWindow', a, b);
        };
        this.postOther = function(a) {
            this.postEvent('Other', '', a);
        };
        this.postSurveyAnswer = function() {
            var a = Array.from(arguments);
            s = a.shift();
            while (a.length > 1) {
                q = a.shift();
                c = a.shift();
                this.postEvent('Survey', 'ParameterAnswer', 's_name=' + encodeURIComponent(s) + '&q_text=' + encodeURIComponent(q) + '&c_text=' + encodeURIComponent(c), '', '');
            }
        };
        this.postCommerceAddItem = function(s, n, p, q) {
            this.postEvent('Commerce', 'AddItem', n, s, p, q);
        };
        this.postCommerceResetItem = function(s, n) { this.postEvent('Commerce', 'ResetItem', n, s) };
        this.postCommerceEmptyBasket = function() { this.postEvent('Commerce', 'Reset') };
        this.allowTrimDuplicatesFromBreadcrumb = function() { this.rdl = true };
        this.clipParam = function(a, b, c) {
            var d = a.length + b.length + c.length;
            var e = 900, urlMaxLength = 700, refMaxLength = 250;
            if (d > (e + urlMaxLength + refMaxLength)) {
                if (c.length > refMaxLength) {
                    c = c.substr(0, refMaxLength - 1) + '*'
                }
                d = a.length + b.length;
                if (d > e + urlMaxLength) {
                    b = b.substr(0, urlMaxLength - 1) + '*'
                }
                if (a.length > e) {
                    a = a.substr(0, e - 1) + '*'
                }
            }
            return { pv: a, url: b, ref: c }
        };
        this.communicate = function(a, b, c, d) {
            if (!a) {
                a = this.accountId
            }
            if (!b) {
                b = 'netminers.dk'
            }
            if (!c) {
                c = '/tracker/put.aspx'
            } else {
                if (c.charAt(0) != '/') {
                    c = '/' + this.trackingPath
                }
            }
            var e;
            if (this.allowDynamicScripts) {
                e = document.createElement('script');
                e.language = 'javascript'
            } else {
                e = new Image();
                e.style.display = 'none'
            }
            e.src = document.location.protocol + '//' + a + '.' + b + c + '?' + d;
            var f = document.getElementsByTagName('body');
            if (f.length === 0) {
                f = document.getElementsByTagName('head')
            }
            f[0].appendChild(e);
            this.out('Communicate: (Using &lt;' + e.tagName + '/&gt; element) ' + e.src, '#880000');
            return e
        };
        this.postEvent = function(a, b, c, d, f, g) {
            try {
                this.bc = [];
                if (typeof(c) == 'function') {
                    c(this);
                    c = this.bc.join(' ' + this.destBcSep + ' ')
                }
                var h = document.location.href, com;
                c = c ? c.trimcc() : c;
                d = d ? d.trimcc() : d;
                if (typeof(g) != 'undefined') {
                    h += (h.indexOf('?') != -1 ? '&' : '?');
                    h += '_np_e=' + encodeURIComponent('en2=' + encodeURIComponent(g))
                }
                switch (a) {
                case 'PageView':
                    c = this.applyVerRev(c);
                    break;
                default:
                    break
                }
                var i = this.clipParam(c || '', h, '');
                c = i.pv;
                h = i.url;
                d = d && d !== null ? d.substr(0, 250) : d;
                if (this.interactive) {
                    this.out('*&nbsp;action type=' + a, '#dd8888', false);
                    this.out('*&nbsp;ation subtype=' + b, '#dd8888', false);
                    this.out('*&nbsp;name=' + (c ? c : ''), '#dd8888', false);
                    this.out('*&nbsp;text=' + (d ? d : ''), '#dd8888', false);
                    this.out('*&nbsp;number=' + (f ? f : ''), '#dd8888', false);
                    this.out('*&nbsp;url=' + h, '#dd8888', true)
                }
                var j = this.communicate(this.trackingSubDomain, this.trackingTopDomain, this.trackingPath, 'action=' + a + '&sub=' + (b || '') + '&n=' + Math.random() + '&nav=' + encodeURIComponent(h) + '&cid=' + this.accountId + '&ti1=' + encodeURIComponent(c || '') + (d ? '&tva=' + encodeURIComponent(d || '') : '') + (f ? '&num=' + encodeURIComponent('' + (f || '')) : ''));
                if (!this.async || this.syncFirst) {
                    if (this.syncFirst) {
                        this.syncFirst = false;
                        this.async = false;
                        this.triggerScheduler(this.syncTimeout)
                    }
                    var r = this.onStateChange.$bind(this);
                    this.attachEvent(j, 'readystatechange', r);
                    this.endObserveReadyState = function() { this.detachEvent(j, 'readystatechange', r) };
                    return { endObserveReadyState: this.endObserveReadyState.$bind(this) }
                }
            } catch(e) {
                this.reportDebugInfo(e);
                if (this.dbg) {
                    throw e;
                }
            }
        };
        this.onStateChange = function(a) {
            var b = a || window.event;
            if ( /loaded|complete/ .test(b.srcElement.readyState)) {
                this.taskCompleted()
            }
        };
        this.delay = function(a) { setTimeout(this.taskCompleted.$bind(this), a) };
        this.readValue = function(a) { this.out('*&nbsp;' + a + '=' + this[a], '#dd8888', true) };
        this.disableRemoteDebugging = function() { this.enableRemoteDebugging = false };
        this.reportDebugInfo = function(e) {
            if (!this.enableRemoteDebugging) {
                return
            }
            try {
                var t = [];
                try {
                    t.push(this.accountId || 'no acc')
                } catch(e1) {
                    t.push('no acc')
                }
                try {
                    t.push(this.ver)
                } catch(e1) {
                    t.push('no ver')
                }
                try {
                    t.push(Math.round(this.rev / 100, 0))
                } catch(e1) {
                    t.push('no gen')
                }
                try {
                    t.push(this.rev % 100)
                } catch(e1) {
                    t.push('no rev')
                }
                try {
                    t.push(e.name)
                } catch(e1) {
                }
                try {
                    t.push(e.number)
                } catch(e1) {
                }
                try {
                    t.push(e.message)
                } catch(e1) {
                }
                this.communicate('debug', 'netminers.dk', '/tracker/put.aspx', 'action=Other&cid=debug' + '&n=' + Math.random() + '&nav=' + encodeURIComponent(document.location.href) + '&ti1=' + encodeURIComponent(t.join(' > ')) + '&tva=&num=');
                this.out('Error: ' + t.join(','), '#ff0000', true)
            } catch(e2) {
                if (this.dbg) {
                    throw e2;
                }
            }
        };
        this.out = function(a, b, c) {
            if (!this.interactive) {
                return
            }
            c = c || false;
            if (!c || c && this.allowVerbose) {
                if (!this.domDebugOut) {
                    this.domDebugOut = document.createElement('div');
                    this.domDebugOut.style.backgroundColor = '#ffffff';
                    this.domDebugOut.style.fontFamily = 'Arial';
                    this.domDebugOut.style.fontSize = '9px';
                    this.domDebugOut.style.textAlign = 'left';
                    this.domDebugOut.style.lineHeight = '9px';
                    this.domDebugOut.style.padding = '10px 10px 10px 10px';
                    document.getElementsByTagName('body')[0].appendChild(this.domDebugOut);
                    this.out('<hr/>');
                    this.out('<b>Netminers log:</b>', '#002c45')
                }
                var d = document.createElement('div');
                d.style.color = b || '#000000';
                d.innerHTML = a;
                this.domDebugOut.appendChild(d)
            }
        };
        this.push = function() { this.tasks.push.apply(this.tasks, arguments) };
        this.scheduler = function(a) {
            if (a) {
                this.out('Task delayed: Time-out elapsed (' + this.syncTimeout + ' sec)', '#ff0000')
            }
            if (this.tasks.length === 0) {
                this.triggerScheduler(200);
                return
            }
            if (typeof this.taskInfo == 'object') {
                this.taskInfo.endObserveReadyState();
                this.taskInfo = null
            }
            var b, args;
            while (this.tasks.length > 0) {
                this.async = true;
                var c = this.tasks.splice(0, 1)[0];
                if (typeof c[0] == 'boolean') {
                    this.async = !c.shift()
                }
                b = c.shift();
                if (this.syncTasks[b]) {
                    this.async = !this.syncTasks[b]
                }
                args = Array.from(c);
                try {
                    if (!this.async) {
                        this.triggerScheduler(this.syncTimeout, true)
                    }
                    this.out('Task name: ' + b + '(' + args.join(',') + ')', this.async ? '#0000ff' : '#0088ff');
                    this.taskInfo = this[b].apply(this, args)
                } catch(e) {
                    this.reportDebugInfo(e);
                    if (this.dbg) {
                        throw e;
                    }
                }
                if (!this.async) {
                    return
                }
            }
            this.triggerScheduler(50)
        };
        this.triggerScheduler = function(a, b) { this.timerHandle = setTimeout(this.scheduler.$bind(this, b), a) };
        this.taskCompleted = function() {
            if (this.timerHandle !== null) {
                clearTimeout(this.timerHandle)
            }
            this.scheduler()
        };
        this.enqueueUrlTasks = function() {
            var o = document.location.href.queryParams();
            if (o.$$nmq) {
                var a = o.$$nmq.split(';');
                for (var t = 0; t < a.length; t++) {
                    var b = a[t].split(',');
                    var c = [];
                    for (var i = 0; i < b.length; i++) {
                        var d = decodeURIComponent(b[i]);
                        if (d.indexOf('function(') === 0) {
                            var e;
                            eval('method=' + d);
                            c.push(e)
                        } else {
                            c.push(d)
                        }
                    }
                    if (c.length > 0) {
                        this.tasks.push(c)
                    }
                }
            }
        };
        this.initInteractive = function() {
            if (this.persistInteractive) {
                var l = document.links;
                for (var i = 0; i < document.links.length; i++) {
                    if (document.links[i].href.indexOf('?') != -1) {
                        document.links[i].href += '&$$nm=p'
                    } else {
                        document.links[i].href += '?$$nm=p'
                    }
                }
            }
        };
        this.visitNumber = function(a) {
            this.vc = a;
            if (this.useFirstParty) {
                var b = new Date();
                b.setTime(b.getTime() + 100 * 365 * 24 * 60 * 60 * 1000);
                document.netminers.setCookie('$nmvc', a, b)
            }
        };
        this.lastVisit = function(a) {
            this.lv = a;
            if (this.useFirstParty) {
                var b = new Date();
                b.setTime(b.getTime() + 100 * 365 * 24 * 60 * 60 * 1000);
                document.netminers.setCookie('$nmlv', a, b)
            }
        };
        this.setUID = function(a) {
            if (this.useFirstParty) {
                var b = new Date();
                b.setTime(b.getTime() + 100 * 365 * 24 * 60 * 60 * 1000);
                document.netminers.setCookie('$nmuid', a, b)
            }
        };
        this.getFirstPartyCookie = function() {
            this.uid = parseInt(document.netminers.getCookie('$nmuid'), 10);
            this.vc = parseInt(document.netminers.getCookie('$nmvc'), 10);
            this.lv = parseInt(document.netminers.getCookie('$nmlv'), 10);
            this.out('*&nbsp;uid (C)=' + this.uid, '#dd8888', true);
            this.out('*&nbsp;visitCount (C)=' + this.vc, '#dd8888', true);
            this.out('*&nbsp;lastVisit (C)=' + this.lv, '#dd8888', true)
        };
        this.detectCookiePolicy = function() {
            var a = new Date();
            a.setTime(a.getTime() + 365 * 24 * 60 * 60 * 1000);
            document.netminers.setCookie('$nm$', 'true', a);
            this.useFirstParty = (document.netminers.getCookie('$nm$') == 'true');
            document.netminers.removeCookie('$nm$')
        };
        this.enableFirstPartyCookie = function() {
            this.detectCookiePolicy();
            if (this.useFirstParty) {
                this.getFirstPartyCookie()
            }
        };
        this.tasks = [];
        this.tasks = this.tasks.concat(u)
    }

    function NMCommerce() {
        this.emptyBasket = function() {
            if (NMCommerce.ignore) {
                return
            }
            this.push([true, 'postCommerceEmptyBasket'])
        }
    }

    NMCommerce.ignore = false;
    NMCommerce.report = function(a) {
        var b = '<table style="position: absolute; top: 10px; right: 10px; width:250px; border: 1px solid red; background-color:white; color: black; font-famlity: tahoma; font-size: 11px;"><tr><td colspan=4 align=left style="font-family: Times New Roman; font-size:14px; color: black">Netminers E-commerce:</td></tr><tr><td align=left>SKU</td><td align=left>Name</td><td align=right>Units</td><td align=right>Unit Price</td></tr>';
        for (var i = 0; i < a.length; i++) {
            b += '<tr><td align=left>' + a[i].getSKU().escapeHTML() + '</td><td align=left>' + a[i].getName().escapeHTML() + '</td><td align=right>' + a[i].getUnits() + '</td><td align=right>' + a[i].getPrice() + '</td></tr>'
        }
        b += '</table>';
        var o = document.createElement('div');
        o.innerHTML = b;
        document.getElementsByTagName('body')[0].appendChild(o)
    };
    NMCommerce.prototype = new NMTracker();

    function NMCommerceTemplate() {
        this.toString = function() { return 'SKU: ' + this.getSKU() + '\nUnits: ' + this.getUnits() + '\nPrice: ' + this.getPrice() };
        this.getItemInfo = function() {
            this.SKU = this.getSKU();
            this.Units = this.getUnits();
            this.Price = this.getPrice();
            this.Name = this.getName()
        };
        this.observeInput = function() {
            this.observeUpdateItem();
            this.observeRemoveItem();
            this.observeAddItem()
        };
        this.onAddItem = function() {
            if (NMCommerce.ignore) {
                return
            }
            var i;
            this.getItemInfo();
            if (arguments.length >= 2 && typeof(arguments[0]) == 'boolean' && arguments[0]) {
                if ((arguments[1] || window.event).keyCode == 13) {
                    this.push(['postCommerceAddItem', this.SKU, this.Name, this.Price, this.Units])
                }
            } else {
                this.push(['postCommerceAddItem', this.SKU, this.Name, this.Price, this.Units])
            }
        };
        this.onChangeItem = function() {
            if (NMCommerce.ignore) {
                return
            }
            this.getItemInfo();
            if (arguments.length == 2 && typeof(arguments[0]) == 'boolean' && arguments[0]) {
                if ((arguments[1] || window.event).keyCode == 13) {
                    this.onRemoveItem();
                    this.onAddItem();
                    NMCommerce.ignore = true
                }
            } else {
                this.onRemoveItem();
                this.onAddItem()
            }
        };
        this.onRemoveItem = function() {
            if (NMCommerce.ignore) {
                return
            }
            this.getItemInfo();
            this.push([true, 'postCommerceResetItem', this.SKU, this.Name])
        }
    }

    NMCommerceTemplate.prototype = new NMCommerce();

    function NMPageTracker() {
        this.bc = [];
        var u = (typeof(document.netminers) == 'object' && document.netminers.title) ? document.netminers.title : '';
        this.srcBcSep = '>';
        this.destBcSep = '>';
        this.bind = false;
        this.take = function(s, p) {
            if (!s || s === null) {
                return
            }
            var i;
            if (typeof(s.innerHTML) != 'undefined') {
                s = this.it(s).trim()
            } else {
                if (typeof(s) == 'object' && s.length) {
                    for (i = 0; i < s.length; i++) {
                        this.take(s[i], p)
                    }
                    return
                }
            }
            var l = s.split(p || this.srcBcSep);
            for (i = 0; i < l.length; i++) {
                this.bc[this.bc.length] = l[i]
            }
        };
        this.takeById = function(i, p) { this.take(document.getElementById(i), p) };
        this.takeFirst = function(q, r, t) {
            var e = this.getElementsByClass(q, r, t);
            if (e !== null && e.length > 0) {
                if (arguments.length > 3) {
                    var a = [];
                    var o = 0;
                    var j = 0;
                    for (var i = 3; i < arguments.length; i++) {
                        if (j == 1) {
                            a[j] = e[0];
                            j++
                        }
                        a[j] = arguments[i];
                        j++
                    }
                    this.takeFirst.apply(this, a)
                } else {
                    this.take(e[0])
                }
            }
        };
        this.takeAll = function(q, r, t) {
            var e = this.getElementsByClass(q, r, t);
            if (e !== null && e.length > 0) {
                for (var i = 0; i < e.length; i++) {
                    this.take(e[i])
                }
            }
        };
        this.takeFirstTag = function(t) { this.takeFirst(null, null, t) };
        this.takeAllFirst = function(q, r, t, a, b) {
            var e = this.getElementsByClass(q, r, t);
            for (var i = 0; i < e.length; i++) {
                this.takeFirst(a, e[i], b)
            }
        };
        this.remove = function() {
            for (var a = 0; a < arguments.length; a++) {
                var b = arguments[a];
                if (typeof(b) == 'number') {
                    this.bc.splice(b, 1)
                } else {
                    if (typeof(b) == 'string') {
                        var r = new RegExp(b);
                        for (var i = 0; i < this.bc.length; i++) {
                            if (r.test(this.bc[i])) {
                                remove(i)
                            }
                        }
                    }
                }
            }
        };
        this.removeLast = function() { return this.bc.splice(this.bc.length - 1, 1) };
        this.update = function(i, a) { this.bc[i] = a };
        this.smooth = function(a) {
            for (var i = 0; i < this.bc.length; i++) {
                this.bc[i] = this.smoothWords(this.bc[i], a || false)
            }
        };
        this.smoothWords = function(a, b) {
            var c = a.split(' ');
            a = '';
            for (var i = 0; i < c.length; i++) {
                if (i > 0) {
                    a += ' '
                }
                if (b && i > 0) {
                    a += c[i]
                } else {
                    a += c[i].charAt(0).toUpperCase() + c[i].substr(1).toLowerCase()
                }
            }
            return a
        };
        this.read = function(i) { return this.bc[i] };
        this.readLast = function() { return this.bc[this.bc.length - 1] };
        this.swap = function(i, j) {
            if (this.bc.length <= i && this.bc.length <= j) {
                return
            }
            var a = this.bc[i];
            this.bc[i] = this.bc[j];
            this.bc[j] = a
        };
        this.insert = function(i, a) { this.bc.splice(i, 0, a) };
        this.reverse = function() { this.bc.reverse() };
        this.takeMeta = function(a, b, c) {
            var d = Array.from(arguments);
            a = null;
            if (typeof(d[0]) != 'string') {
                a = d.shift()
            }
            b = d.shift();
            c = d.shift();
            var e = B.getValues(b, a);
            if (e.length > 0) {
                this.take(e[0])
            } else {
                this.take(c)
            }
        };
        this.removeDuplicateLevels = function() {
            var a = [];
            var b = null;
            for (var i = 0; i < this.bc.length; i++) {
                if (this.bc[i].trim().length > 0) {
                    if ((b !== null && b.toLowerCase()) != this.bc[i].trim().toLowerCase()) {
                        b = this.bc[i].trim();
                        a[a.length] = b
                    }
                }
            }
            this.bc = a
        };
        this.setVersion = function(a, b) {
            this.ver = a;
            this.rev = b
        };
        this.applyVerRev = function(a) { return '!' + this.ver + '.' + z + this.rev + '!' + a };
        this.postPageView = function(a) { this.postEvent('PageView', '', a) };
        this.postFlashEvent = function(a) { this.postEvent('PageView', 'Flash', a) };
        this.enableServerBinding = function() { this.bind = true };
        this.disablePageTracking = function() { document.netminers.trackPage = false };
        this.trackPage = function(a, b) {
            try {
                this.srcBcSep = b || this.srcBcSep;
                var d = document.location.href;
                if ((typeof(document.netminers.trackPage) == 'boolean' && document.netminers.trackPage === false) || d.toLowerCase().indexOf('nmtrackpage=false') != -1) {
                    return null
                }
                if (a) {
                    a(this)
                }
                if (document.netminers.additionalSuperContext) {
                    this.bc = this.te(this.cb(document.netminers.additionalSuperContext).split(this.srcBcSep)).concat(this.bc)
                }
                if (document.netminers.additionalSubContext) {
                    this.bc = this.bc.concat(this.te(this.cb(document.netminers.additionalSubContext).split(this.srcBcSep)))
                }
                if (u !== '') {
                    this.bc = this.cb(u.replace(this.bcRemove, '')).trim().split(this.srcBcSep)
                }
                if (this.rdl) {
                    this.removeDuplicateLevels()
                }
                u = this.bc.join(' ' + this.destBcSep + ' ');
                var f = d;
                try {
                    var g = top.document.location.href;
                    f = g.indexOf('nm_extag') != -1 ? g : f
                } catch(e) {
                }
                if (u === '') {
                    u = document.title
                }
                var h = '';
                var c = document.cookie;
                if (c.indexOf('nm_exref') != -1) {
                    var j = c.split(';');
                    for (i = 0; i < c.length; i++) {
                        var k = j[i];
                        var l = k.indexOf('nm_exref');
                        if (l != -1) {
                            h = k.substr(l + 9)
                        }
                    }
                    document.cookie = 'nm_exref='
                }
                if (h === '') {
                    h = document.referrer;
                    try {
                        h = top.document.referrer
                    } catch(e) {
                    }
                }
                var m = f.indexOf('nm_extag=');
                var n = '';
                if (m != -1) {
                    m += 9;
                    var o = f.indexOf('&', m);
                    n = o == -1 ? f.substr(m) : f.substr(m, o - m);
                    n = encodeURIComponent(n)
                }
                u.trimcc();
                u = this.applyVerRev(u);
                var p = [u, n, h, d];
                u = encodeURIComponent(u);
                d = encodeURIComponent(d.trimcc());
                h = encodeURIComponent(h.trimcc());
                n = encodeURIComponent(n.trimcc());
                var q = this.clipParam(u, d, h);
                u = q.pv;
                d = q.url;
                h = q.ref;
                this.out('*&nbsp;breadcrumb=' + p.shift(), '#dd8888', false);
                this.out('*&nbsp;extags=' + p.shift(), '#dd8888', true);
                this.out('*&nbsp;referrer=' + p.shift(), '#dd8888', true);
                this.out('*&nbsp;url=' + p.shift(), '#dd8888', false);
                this.out('*&nbsp;uid=' + this.uid, '#dd8888', true);
                var r = this.communicate(this.trackingSubDomain, this.trackingTopDomain, this.trackingPath, 'action=log' + '&n=' + Math.random() + '&nav=' + d + '&cid=' + this.accountId + (h.length > 0 ? ('&ref=' + h) : '') + '&ti1=' + u + (n.length > 0 ? '&ext=' + n : '') + (this.bind ? '&bind=true' : '') + (this.firstParty ? '&fp=true' : '') + (this.uid ? '&uid=' + this.uid : '') + (this.vc ? '&vc=' + this.vc : '') + (this.lv ? '&lv=' + this.lv : ''));
                this.attachEvent(r, 'readystatechange', this.onStateChange.$bind(this));
                this.syncFirst = true
            } catch(e) {
                this.reportDebugInfo(e);
                if (this.dbg) {
                    throw e;
                }
            }
            this.title = decodeURIComponent(u);
            u = '';
            return this.title
        };
        this.start = function() { this.triggerScheduler(1) }
    }

    ;
    NMPageTracker.prototype = new NMTracker(x || $netminers);
    var C = new NMPageTracker();
    document.netminers[y] = C;
    if (window.attachEvent) {
        window.attachEvent('onload', C.start.$bind(C, x))
    } else if (window.addEventListener) {
        window.addEventListener('load', C.start.$bind(C, x), true)
    } else {
        var D = window.onload;
        if (typeof D != 'function') {
            window.onload = C.start.$bind(C, x)
        } else {
            var E = C.start.$bind(C, x);
            window.onload = function() {
                E();
                D()
            }
        }
    }
})(window[$$nm_queue_name], $$nm_instance_name);
window[$$nm_queue_name] = document.netminers[$$nm_instance_name];

