$(document).ready(function(){   
   	
	$(document).pngFix();
	
	var s = $("#searchInput");
	var stxt = 'search for item...';
	s.focus(function() {
		if(s.val() == stxt) {
			s.val("");

		}
	});
	s.blur(function() {
		if(s.val() == "") {
			s.val(stxt);
		}
	});
	
	
	
	$('p.error').fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
	
	
	
	var itemQtyInput = $("p input#itemQty");
	var defQty = '1';
		itemQtyInput.focus(function() {
		if(itemQtyInput.val() == defQty) {
			itemQtyInput.val("");

		}
	});
	itemQtyInput.blur(function() {
		if(itemQtyInput.val() == "") {
			itemQtyInput.val(defQty);
		}
	});
	
	
	
	
	
	
	//Simple client side checks when add to cart button is clicked
	$("#addTocart").click(function() { 	
		var itemQtyFV = $('input#itemQty').val();
		var itemQty = $.trim(itemQtyFV.replace(' ', ''));
		var itemSize = $("select#itemSize").val();
		
		if (itemQty == '' || isNaN(itemQty)) {
			alert('ERROR: Please enter a numeric quantity!');
			$('input#itemQty').css('background-color','#ffbaba');
			return false;
		} else { } 
		
		/*if (itemSize == 0) {
			alert('ERROR: Please select a size from the drop down list!');
			$("select#itemSize").css('background-color','#ffbaba');
			return false;
		} */
		
		//$('div#search-bar').fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
		$('div#search-bar').slideUp().slideDown();
		
		//console.log('Qty = ' + itemQty + '    Size = ' + itemSize);  	
	});
	
	$("#btnCheckoutGo").attr("disabled", "disabled");
	$("#btnCheckoutGo").fadeTo("fast", 0.33);

	
	$("#termsAgree").bind("click", function(e){

		if ($('#termsAgree').attr('checked')) {
			$('#termsAgree').attr('checked', true);
			$("#btnCheckoutGo").removeAttr("disabled");
			$("#btnCheckoutGo").fadeTo("slow", 1.0);						  
		} else {
			$("div#disclaimer").fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
			$("#btnCheckoutGo").attr("disabled", "disabled");
			$("#btnCheckoutGo").fadeTo("fast", 0.33);
		}
		
	});
	
	
	$('span.promCodeErr').hide();
	$('input#btnCode').click(function() { 
		
		if( $('input#cartPromotionalCode2').val() == '' ) {
			$('span.promCodeErr').show();
			$('input#cartPromotionalCode2').css('background-color','#ffbaba');
			return false;
		}
		
	});
	
	
	$('p#catDesc').hide();
	$('a#readFullCatDesc').click(function() { 
		$('p#catDescSummary').remove();
		$('p#catDesc').show();
	});

});