﻿$(function(){    
    if($('.myAccountLinks').last().attr('href') == 'default.aspx?Page=Logon&Action=LogOff'){
        var product;
        var insertInto;
        $('.ItemSearchResults_Table tr, .ShoppingCart_Table tr').each(function(){
            product = $(this).children('.ItemSearchResults_ItemCodeTextAlign').children('.ItemSearchResults_ItemCode').html();
            if(product == null){
                product = $(this).children('.ShoppingCart_ItemCodeDescriptionTextAlign').children('.ShoppingCart_ItemCode').html();
            }
            insertInto = $(this).children('.ItemSearchResults_AvailabilityTextAlign, .ShoppingCart_AvailabilityTextAlign');
            
            if(product != null){
                insertInto.html('').html("<span id=\"qty-"+product+"\" class=\"insertLocation\"></span>");
                
                $.get('/ajax/itemqty.aspx', {'product':product}, function(data){
                    var dataArray = data.split("|");
                    $(cleanDot(dataArray[2])).parent().html(dataArray[0]);
                    // cr
                    if(dataArray[3] == '1'){
                        $('.ItemSearchResults_ItemCode:contains('+ cleanDot(dataArray[1]) +')').parent().addClass('newProductOverlayAnchor');
                        $('.newProductOverlayAnchor a:has(img)').css('position','relative').append('<img src="/customer/wixcgr/images/wx/overlay.jpg" class="newProductOverlayImage" height="12" width="28" alt="">');
                    }
                    
                });
            }
        });
    }
    
});

function cleanDot(str){
    if(str.indexOf('.') > -1){
        //return str.replace('.', '\\.');
        return str.replace(/\./g, '\\.');
    }
    return str;
}




