//
//-------------------------------------------------------------------
// 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;
var displayedConfirmBoxId = "";

//
// ***
// * 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 checkthis()
{
	
}
//this is used by dutalier section - a.ravji
function accessoryChecked(form, nextpage)
{
    var checkedfound = 0;
    var i = 0;
	while( i < form.elements.length && checkedfound < 2)
  {
  	if(form.elements[i].checked ==true)
  	{
  		checkedfound = checkedfound +1;
  	}
  	i++;
  }
	if(checkedfound <2){
		alert("You need to select 1 Wood and 1 Fabric to add the Dutalier product to the basket");
	}else{
		Add2ShopCart(form, nextpage);
	
	}


}

function Add2ShopCart(form, nextpage)
{
		
       if (!busy) {
              busy = true;
              form.action="OrderItemAdd";
              if(form.forRegistry && form.forRegistry.value){
              	form.externalId.value=form.forRegistry.value;
              }
              // form.URL.value = nextpage;
   			  form.URL.value='OrderCalculate?URL=OrderItemDisplay'
              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='ProductDisplay';
              form.submit();
       }
       return false;
}


// This javascript function reveals the add to basket confirm pop-up window.
function displayConfirmAddition(div_to_show) 
{
		if (displayedConfirmBoxId != "") {
			document.getElementById(displayedConfirmBoxId).style.display = "none";
		}
		document.getElementById(div_to_show).style.display = "block";
		displayedConfirmBoxId = div_to_show;
}


// Used to add multiple products to the basket - but first checks that one has been
// ticked in a checkbox
function MultipleCheckboxAdd2ShopCart(form, nextpage) {
    var checkedfound = 0;
    var i = 0;
	while( i < form.elements.length && checkedfound < 2) {
	  	if(form.elements[i].checked ==true) {
  			checkedfound = checkedfound +1;
	  	}
	  	i++;
	  }
	if(checkedfound <1){
		alert("Please select one or more items to add to your basket");
		return false;
	}else{
		Add2ShopCart(form, nextpage);
	}
}