
$(document).ready(function() {
	// Table Alts
	$("table.BrandsList_Table td.BrandsList_ColData:even").addClass("BrandsList_ColHeaderAlt");
						   
	// Replace "Will ship in 0 days"
	if ($('.ItemSearchResults_Table').length ) {
		ItemSearchResults_Table = $('.ItemSearchResults_Table').html();
		var match = new RegExp("Will ship in 0 days", "ig");     
		replaced = ItemSearchResults_Table.replace(match, "Call 888-881-5420");
		$('.ItemSearchResults_Table').html(replaced);
			//$('.ItemSearchResults_Table').html($('.ItemSearchResults_Table').html().replace(RegExp("Will ship in 0 days", "ig"), "Call for availability"));
	}

	
	
	
	// Load Salesrep
	var randomnumber=Math.floor(Math.random()*1001)
	$.get("/customer/incoco/salesrep.aspx", {q: ""+randomnumber+""}, function(data) {
		$("#rsideMenuSalesrep").html(data);
	});
	
	
	// Load Item Detail Suggestion If DIV exists
	if ($("#itemDetailSuggestion").length != 0) {
		var itemId = $.trim($(".ItemDetailattribute:first").text());
		$.get("/customer/incoco/ItemDetailSuggestion.aspx", {q: ""+itemId+""}, function(data) {
			$("#itemDetailSuggestion").html(data);
		})
	}
	

	// Shopping List Item Notes
	if ($('.ShoppingList_Table').length ) {
		$(".ShoppingList_ItemCodeTextAlign").each(function(){
			var row = $(this);
			var itemCode = $(this).find(".ShoppingList_ItemCode").text().trim();
			
			$.get("/customer/incoco/javascripts/handlers/shoppinglistitemnotes.ashx", {itemCode: ""+itemCode+""}, function(data) {
				var $titles = row.find(".ShoppingList_Description");
				$titles.append("<br/>" + "<span style=\"background-color:red;color:white\">" + data + "</span>");
			})
		});
		
		$('.ShoppingList_Table tr:first ').prepend("<th class='ShoppingList_ItemCodeDescriptionHeaderAlign'>Category</th>");
		$('.ShoppingList_Table tbody tr td.ShoppingList_ItemCodeTextAlign').each(function(){
			$(this).before("<td class='tdMiddleCells'>Data</td>");	
		})


	}
	


	
		
	
});


	
// Safely inject CSS3 and give the search results a shadow
var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
	'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
	'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
$("#suggestions").css(cssObj);


// Fade out the suggestions box when not active
$("input").blur(function(){
	$('#suggestions').fadeOut();
});
 
 
// Search Suggestion
function lookup(inputString) {
	delay(function(){
		if(inputString.length == 0) {
			$('#suggestions').fadeOut(); 
		}
		else if (inputString.length > 1) {
			$.get("/customer/incoco/javascripts/handlers/SearchSuggestion.ashx", {q: ""+inputString+""}, function(data) { 													 
				$('#suggestions').fadeIn(); 
				$('#suggestions').html(data); 
			});
		}
	}, 250 );
}


// Delay Function
var delay = (function(){
	var timer = 0;
	return function(callback, ms){
		clearTimeout (timer);
		timer = setTimeout(callback, ms);
	};
})();

