//-----------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (C) Copyright IBM Corp. 2006, 2009 All Rights Reserved.
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with
// IBM Corp.
//-----------------------------------------------------------------

//
//

//
// ***
// * 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, action,count,visitorType)
{
		var stat=false;
        for(var i=1;i<=count;i++){    
          if((document.getElementById("qty_"+i).value) != 0) {
    			 stat=true;
    		}
		} 
		if(stat) {
	              form.action="MEProcessRedirection?calledFrom=VisitorType"; //The calledFrom value should match page name defined in MECommonConstants
	              form.URL.value=action;
	              form.submit();
       } else {
       		alert(document.getElementById("errorMsg").value);
       		document.getElementById("quantity").setAttribute("className","fieldError");
       }   
			       
}
// 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.submit();
       }
}

