//
//-------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (c) Copyright IBM Corp. 2006
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//-------------------------------------------------------------------
//

function isPositiveNumeric(strVal)
{
	for(var i=0; i<strVal.length; i++) {
		var key = strVal.charCodeAt(i);
		if(((key < '48') || (key >'57')) && (key != '46') ) {
			return false;
		}
	}
	return (strVal > 0);
}


//
// ***
// * This javascript function is used by the 'Add to Shopcart' button.  Since the HTML form is shared by both 'Add to Shopcart' and 'Add to Wish List' button,
// * appropriate values are set using this javascript before the form is submitted.
// * The variable 'busy' is used to avoid submitting the same forms multiple times when users click the button more than once.
// ***
//
var busy = false;
function Add2ShopCart(form, catEntryId, catEntryQuantity)
{
	if(!isPositiveNumeric(catEntryQuantity)) {
		alert("Please enter a valid quantity");
		return;
	}
       if (!busy) {
              busy = true;
              form.action="OrderItemAdd";
              form.catEntryId.value = catEntryId;
              form.quantity.value = catEntryQuantity;
              form.URL.value='OrderCalculate?item_quantity*=&URL=ProductDisplay';
              form.submit();
       }
}
// This javascript function is used by the 'Add to Wish List' button to set appropriate values before the form is submitted
function Add2WishList(form, catEntryId)
{
       if (!busy) {
              busy = true;
              form.action="InterestItemAdd";
              form.catEntryId.value = catEntryId;
              form.URL.value='InterestItemDisplay';
              form.field2.value='1';
              form.submit();
       }
}

// This javascript function is used by the share product pages to an a share item to a share cart.
function Add2ShareCart(form, catEntryId, quantity, price)
{
	if(!isPositiveNumeric(quantity)) {
		alert("Please enter a valid quantity");
		return;
	}
	if (!busy) {
		busy = true;
		// set 3 values
		form.catEntryId.value = catEntryId;
		form.quantity.value = quantity;
		form.field1.value = price;
		form.submit();
	}
}


