//
//-------------------------------------------------------------------
// 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.
//-------------------------------------------------------------------
//

var busy = false;
//
// ***
// * 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.
// ***
//

function Add2ShopCart(form, destURL)
{
       if (!busy) {
              busy = true;
              form.action="OrderItemAdd";
              if(form.forRegistry && form.forRegistry.value){
              	form.externalId.value=form.forRegistry.value;
              }
              form.URL.value='OrderCalculate?URL=' + destURL;

              form.submit();
	return false;
       }
}

// This javascript function is used by the 'Add to Wish List' button to set appropriate values before the form is submitted
function Add2WishList(form)
{
       if (!busy) {
              busy = true;
              form.action="InterestItemAdd";
              form.URL.value='InterestItemDisplay';
              form.submit();
	return false;
       }
}

//Used to determine if the "Defining Attributes" Quantity is changed
function QuantityChanged(form)
{
	quantitySelected = form.quantityOptions.options[form.quantityOptions.selectedIndex].value;
	form.quantity.value = quantitySelected;
}

function Add2ShopCartAccessoryItem(form, destURL, productId, optionBoxId)
{
	//optionBoxId = -1 when quantity drop down list is not defined
	if (optionBoxId == -1) {
		quantitySelected = 1;
	} else {
		index = eval("document.getElementById('quantityOptions' + '" + optionBoxId + "').selectedIndex");
		quantitySelected = eval("document.getElementById('quantityOptions' + '" + optionBoxId + "').options[index].value");
	}
	
	form.catEntryId.value = productId;
	form.productId.value = productId;
	form.quantity.value = quantitySelected
	
	if (!busy) {
		busy = true;
  		form.action="OrderItemAdd";
  		if(form.forRegistry && form.forRegistry.value){
  			form.externalId.value=form.forRegistry.value;
  		}
  		form.URL.value='OrderCalculate?URL=' + destURL;

  		form.submit();
	return false;
	}
}

function viewProductDetailsPopup(linkRef, windowname) 
{
	features = "width=270,height=340,directories=no,location=no,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=no,top=0,left=0";
	var newWindow=window.open(linkRef.href, windowname.value, features);
	linkRef.removeAttribute("target");
	newWindow.focus();
	return false;
}





