var busy = false;
function Add2ShopCart(form) {
	if (!busy) {
		busy = true;
		form.action="OrderItemAdd?orderItemId*=&orderId=.&allocate=*n&backorder=*n&remerge=*n&merge=*n&reverse=*n&check=*n";
		form.URL.value="OrderItemDisplay?contractId=&orderId=*&catEntryId*=&quantity*=&prod*=&backorder=&address*=&merge=&reverse=&primary=&country=&remerge=&check=&calculation*=&allocate=";
		form.submit();
	}
}
function setNickName(newNickName) {
	var nickNameFld;
	document.OrderItemAddForm.nickName.options[document.OrderItemAddForm.nickName.selectedIndex].value = newNickName;
	document.ShipToForm.newNickName.value = '';
	closeLayer('popup-ship-to');
	Add2ShopCart(document.OrderItemAddForm);
}
function checkNickName(form) {
	if (!busy) {
		if (form.nickName.options[form.nickName.selectedIndex].text == 'Other') {
			openLayer('popup-ship-to');
		}
		else {
			setNickName(form.nickName.options[form.nickName.selectedIndex].value);
		}
	}
}
function AddRelatedItem(aCatalogEntryIdField, aQuantityField, catalogEntryId)
{
	if (aQuantityField.value == '' || aQuantityField.value == '0') {
		aCatalogEntryIdField.value = '';
		aQuantityField.value = '';
	}
	else {
		aCatalogEntryIdField.value = catalogEntryId;
	}
}
function Add2GiftRegistry(form)
{
	if (!busy)
	{
		busy = true;
		form.action='GiftRegistryItemAddCntrl';
		form.submit();
	}
}
function checkRegistryQtyNeeded(quantityField, quantityNeeded)
{
	var quantityFieldNbr, quantityNeededNbr;
	/* if it is not a number allow the request to pass to the server where the
	 error will be detected.
	*/
	if (isNaN(quantityField)){
		return true;
	}
	quantityFieldNbr = parseInt(quantityField,10);
	if (quantityFieldNbr > quantityNeeded) {
		return confirm("Your order will give the registrant(s) more of an item than required. Are you sure you wish to continue?");
	}
	return true;
}
function BuyForRegistry(isRegistryItem, quantityField, quantityNeeded)
{
	document.OrderItemAddForm.BuyFromRegistryPIP.value = "registry";
	if (isRegistryItem)	{
		if (checkRegistryQtyNeeded(quantityField, quantityNeeded)) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return true;
	}
}

//SEO  Add new OPTIONAL parm (catId) and set catalog id if it gets passed (this is to accodomate the requirement of adding "Add to my List" 
//     on each related item on the PIP page
// function Add2WishList(form)  
function Add2WishList(form, catId)  
{
	if (!busy)
	{
		busy = true;
		form.action=wishListAction;
		form.URL.value='ProductDisplayErrorView';
		if (catId != null)  // catalog ID was passed in , set it in the form (that was also passed)
		{
			form.catEntryId_1.value = catId;
			form.productId.value = catId;
		}
		form.submit();
	}
}
