//
// B2BSeller Extensions Javascript Library | Triactive Media
//
$(document).ready(function() {
	//////////// MISC ///////////////////
	$(".ContentItemDetailFeatureCell tr:nth-child(2) td table").attr('style', 'width:100%');;
	
	// Brands Table Alt Rows
	$("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/auwama/images/trash-icon.gif" /> ');
	
	/////////////  ITEM DETAIL ///////////////
	//if($(".ContentItemDetailFeatureCell").length!=0){}
	
	
	// Element Page Banner
	$(".ContentElementCreditCardEntryFeatureCell").prepend('<br><img src="/customer/auwama/images/titles/element_t.gif"><br>');   
	
	
	//////////////  SHOPPING CART  //////////////////
	$(".ContentShipBillInformationFeatureCell input:not(#ShipBillInformation_txtEmailAddress, #ShipBillInformationNotepadText)").keyup(function () {
		$(this).val($(this).val().toUpperCase());
	});
	
	//////////////  REGISTER  //////////////////
	$(".NewCustomerInnerTable input:not(#email, #password, #verify, #hint)").keyup(function () {
		$(this).val($(this).val().toUpperCase());
	});
	
	$(".NewShopperTable1 input:not(#email, #password, #verify, #hint)").keyup(function () {
		$(this).val($(this).val().toUpperCase());
	});
	

	// Fade out the suggestions box when not active
$(".ProductSearch_Input111").blur(function(){
	$('#suggestions').fadeOut();
});
	
	
});

// Search Box Check for Exact Item Match, Direct to Item Detail if True
function checkExactMatch(inputString) {

	$.get("/customer/auwama/b2bsellerextensions/handlers/SearchExactMatch.ashx", {searchString: ""+inputString+""}, function(xml) {
		$(xml).find('ExactMatch').each(function(){
			$("#i").html($(this).text());
				if($(this).text() == "True") {
					// Go Directly to Item Detail Page
					window.location='/default.aspx?page=item%20detail&itemcode=' + inputString;
				}
				else
				{
					window.location='/default.aspx?page=Item%20Search%20Results&txtSearchText=' + inputString + '&SearchFieldsList=Keyword&SearchSource=ProductSearch';
				}
		});		
	});	
}




// 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);



 
 
// Search Suggestion
function lookup(inputString) {
	delay(function(){
		if(inputString.length == 0) {
			$('#suggestions').fadeOut(); 
		}
		else if (inputString.length > 1) {
			$.get("/customer/auwama/B2BSellerExtensions/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);
	};
})();




// Item Detail Swap Image
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}










