function addCartItems(obj) {
	var str = new String();
	var omn = '';

	for(var i=1; $("input[name='packageId" + i + "']") && ($("input[name='packageId" + i + "']").attr('name') != undefined) && (i < 10); i++) {
		var q = parseInt($("input[name='quantity" + i + "']").val());
		var p = $("input[name='price" + i + "']").val();
		if(q) str += ($("input[name='packageId" + i + "']").val() + '.' + $("input[name='productId" + i + "']").val() + '.' + $("input[name='itemId" + i + "']").val() + ':' + q + '|');
		if(q) omn += ';' + $("input[name='sku" + i + "']").val() + ';' + q + ';' + p;
	}

	if(typeof(s) == 'undefined') s={t:function(){return;}};
	s.pageName = 'ShoppingCart';
	s.events = 'scAdd';
	s.products = omn;
	try { void(s.t()); } catch(e) { ; };

	if(str.charAt(str.length-1) == '|') str = str.substr(0,str.length-1);

/*
	csOrderType = 'Cart - Add';
	csOrderNum = 'ADD-' + tagStruct.orderId;
	csAjaxTracking = true;
	setTimeout(function() { csExecuteShoppingCart(); csExecuteTracker(); }, 100);
*/

	pauseExec(300);  // pause execution for 300 milliseconds to ensure that tagging fires off
	document.location.href = '/ShoppingCart?action=add!' + str.toString();
}

function validate_msg() {
	$('#notifications').html("<span class='alert'>Please check the quantity of items selected before putting them in your cart</span>");
	$('#notifications').slideDown('fast');
	$('#notifications').animate({marginLeft: 0}, 3000, function() {
		$('#notifications').slideUp('fast');
		$('div.spinner-loader').hide();
		$('input#addCart').fadeTo('fast',1);
	});
	return(false);
}

function validate(obj) {
	Broadway.showSpinner($('input#addCart'),-38,-3);

	$('span.form-error-reason').remove();
	$('label').removeClass('form-error');

	var count = 0;
	$('td.product-content-body-buy-input input.input-text').each(function() {
		if(parseInt($(this).val()))	count += parseInt($(this).val());
	});

	if(count) {
		addCartItems(obj);
	} else {
//		$('div.spinner-loader').hide();
//		$(obj).fadeTo('fast',1);
		validate_msg();
	}
}
