//
// B2BSeller Extensions Javascript Library | Triactive Media
//
$(document).ready(function() {
	// Sign In Out Text
	$('.imgSignIn[src$="Logonbutton.gif"]').replaceWith('Sign In / Register');
	$('.imgSignIn[src$="LogOffbutton.gif"]').replaceWith('Sign Out');
	
	
	// Brands Table Alts
	$("table.BrandsList_Table td.BrandsList_ColData:even").addClass("BrandsList_ColHeaderAlt");
	
	// Shopping Cart Alt Rows
	$(".ShoppingCart_Table tr:nth-child(4n+2)").addClass("BrandsList_ColHeaderAlt");   
	
	// Shopping Cart Remove Line Icon
	$('.ShoppingCart_RemoveLink').html('<img src="/customer/macomp/images/trash-icon.gif" /> ');
	
	
	// USC Link
	if($(".MyAccountProfile_Table002").length!=0)
	{
		$.get("/customer/macomp/b2bsellerextensions/handlers/GetUSCLink.ashx", function(data) {
			$('.MyAccountProfile_Table002').after(data);
		});
		
	}
	
	// USC Populate Drop Down Box
	if($("#ddUSCMfg").length!=0)
	{
		$.get("/customer/macomp/b2bsellerextensions/handlers/GetUSCMFG.ashx", function(data) {
			$('#ddUSCMfg').append(data);
		});
	}
	
	
	
	// Longview Fiber Checkout Passthru
	if($(".ContentShipBillInformationFeatureCell").length!=0)
	{
		if(document.ShipBill_Information_Content.txtShipToCompany.value == 'LONGVIEW FIBRE FR')
		{
			$('.ShipBillInformation_ButtonTable').hide();
			$('.ShipBillInformation_ShipTable').hide();
			$('.ShipBillInformation_BillToDescTable').hide();
			var poNumber = $('#ShipBillInformation_txtEmailAddress').val()
			$('input[name="txtPONumber"]').val(poNumber);
			$('input[name="ButtonContinueCheckout"]').trigger('click');
			$('.ShipBillInformation_ShipToDesc').html('<div style="padding:100px 0;width:100%;text-align:center"><img src="/customer/macomp/images/ajax-loading.gif" /></div>'); 
			}
	}
	var shipToText = $('.OrderSummary_ShipToText').html();
	if (shipToText == 'LONGVIEW FIBRE FR')
	{
		$('.OrderSummary_PaymentMethodText').html('Paid By Longview FR'); 
	}
	
	
	// Register Table
	$(".LogonCaptionImageName").parent().parent().parent().parent().attr('width', '100%');
	

});


// Load Shopping Cart
var randomnumber=Math.floor(Math.random()*1001)
$.get("/customer/macomp/b2bsellerextensions/handlers/ShoppingCartInfo.ashx", function(data) {
	$("#shoppingCartInfo").html(data);
});


// Search Suggestion
function lookupUSC(inputString, uscMFG) {
	delay(function(){
		if(inputString.length == 0) {
			$('#resultsUSC').fadeOut(); 
		}
		else if (inputString.length > 2) {
			$('#resultsUSC').fadeIn();
			$('#resultsUSC').html('<div style="padding:100px 0;width:100%;text-align:center"><img src="/customer/macomp/images/ajax-loading.gif" /></div>'); 
			$.get("/customer/macomp/B2BSellerExtensions/handlers/GetUSCItems.ashx", {q: ""+inputString+"", mfg: ""+uscMFG+""}, function(data) { 													
				$('#resultsUSC').html(data);
				$("#tblUSCItems tr:nth-child(2n+2)").addClass("altRow");
				
			});
		}
	}, 250 );
}



	
	

// Delay Function
var delay = (function(){
	var timer = 0;
	return function(callback, ms){
		clearTimeout (timer);
		timer = setTimeout(callback, ms);
	};
})();



