function getIndexGB(subGB) {
//============================================================================= 
var testGB;
var subGB;
var amttotGB;
var runitGB;
var fGB = "amtGB" + subGB;
var qtyGB=document.getElementById("AmtGB" + subGB).value;


//get index from drop down list    
var fldGB = "SelectProductGB" + subGB;
var xGB=document.getElementById(fldGB)
zGB = (xGB.options[xGB.selectedIndex].index)

//Initialize quantity to 1 unless "Make a Selection" was chosen instead of a product 
if (zGB == 0) {
   document.getElementById("amtGB" + subGB).value = 0;
   qtyGB = 0;
    }
else {
   document.getElementById("amtGB" + subGB).value = 1;
   qtyGB = 1;
    }
 

chosenIndex[subGB] = zGB;
// ****************************************************************************************************
if (subGB == 1) {
priceItGB.T1GB.value=itemCode[zGB]
}
if (subGB == 2) {
priceItGB.T2GB.value=itemCode[zGB]
}
if (subGB == 3) {
priceItGB.T3GB.value=itemCode[zGB]
}
if (subGB == 4) {
priceItGB.T4GB.value=itemCode[zGB]
}



//get associated product price and number in arrays
var ppGB = productprice[zGB]
var pnGB = productno[zGB]

//Place values from tables into elements
document.getElementById("pnGB" + subGB).value = pnGB
document.getElementById("ppGB" + subGB).value = formatDollar(ppGB);
document.getElementById("pphGB" + subGB).value = ppGB

//Calculate extended price
document.getElementById("epGB" + subGB).value = 
  document.getElementById("amtGB" + subGB).value * 
  document.getElementById("pphGB" + subGB).value

//keep extended price in hidden field
document.getElementById("ephGB" + subGB).value = 
   document.getElementById("epGB" + subGB).value
  
//format extended price for screen
document.getElementById("epGB" + subGB).value = formatDollar(document.getElementById("epGB" + subGB).value);

//initialize AmttotalGB to zero if not numeric
if (document.getElementById("AmttotalGB").value== "" || 
  document.getElementById("AmttotalGB").value == null || 
  isNaN(document.getElementById("AmttotalGB").value) ||  
  document.getElementById("AmttotalGB").value.charAt(0) == ' ') {
  document.getElementById("AmttotalGB").value = 0;
  }

//Calculate qty and dollar totals
 runitGB=totalFldsGB();
 
paypalSubmitGB.item_number.value="20007 ("  + document.getElementById("ephtotalGB").value + ")" 


paypalSubmitGB.item_name.value = "Mix and Match Gift Box - " +
priceItGB.T1GB.value + "/" + 
priceItGB.T2GB.value + "/" + 
priceItGB.T3GB.value + "/" + 
priceItGB.T4GB.value + " plus $4.25 for Gift Box."


 
}

//============================================================================= 
function totalFldsGB() {
//============================================================================= 
//Sum up quantity
document.getElementById("AmttotalGB").value = 0;
var amttotGB = 0;
var i;

 for (i=1; i<5; i++)  {
 if (document.getElementById("AmtGB" + i).value== "" || 
  document.getElementById("AmtGB" + i).value == null || 
  isNaN(document.getElementById("AmtGB" + i).value) ||  
  document.getElementById("AmtGB" + i).value.charAt(0) == ' ') {
  }
  else {
       qtyGB = parseInt(document.getElementById("AmtGB" + i).value);
       amttotGB = amttotGB +  qtyGB;
       document.getElementById("AmttotalGB").value = amttotGB;
       }
 }
 
 
 if (amttotGB > 4) {
alert("The quantity entered  is more than the 4-pack being built.  Please enter quantity of 4 for the case");
} 


//Sum up dollars
document.getElementById("eptotalGB").value = 0.00;
var eptotGB = 0.00;
var epamtGB = 0.00;
 
 for (i=1; i<5; i++)  {
 if (document.getElementById("ephGB" + i).value== "" || 
  document.getElementById("ephGB" + i).value == null || 
  isNaN(document.getElementById("ephGB" + i).value) ||  
  document.getElementById("ephGB" + i).value.charAt(0) == ' ') {
  }
  else {
       document.getElementById("epGB" + i).value = 
         document.getElementById("amtGB" + i).value * 
         document.getElementById("pphGB" + i).value
         
       document.getElementById("ephGB" + i).value = 
         document.getElementById("epGB" + i).value
         
       document.getElementById("epGB" + i).value = 
             formatDollar(document.getElementById("epGB" + i).value)
  

       epamtGB = parseFloat(document.getElementById("ephGB" + i).value);
       eptotGB = eptotGB + epamtGB;
       }
 }
 
var stringGB;
var stringGBPP;
var giftBoxValue = 4.25;
document.getElementById("ephtotalGB").value = Math . round (100 * (eptotGB + giftBoxValue)); 
stringGB = document.getElementById("ephtotalGB").value;
stringGB = stringGB.substring(0, stringGB.length - 2) + "." + stringGB.substring(stringGB.length - 2, stringGB.length);
document.getElementById("ephtotalGB").value = stringGB;
eptotGBPP = Math . round (100 * (eptotGB + giftBoxValue));  
eptotGB = Math . round (100 * eptotGB);
  
       
       stringGB = "$" + eptotGB;
       stringGB = stringGB.substring(0, stringGB.length - 2) + "." + stringGB.substring(stringGB.length - 2, stringGB.length);
       eptotGB = stringGB;
	   
	   stringGBPP = "$" + eptotGBPP;
       stringGBPP = stringGBPP.substring(0, stringGBPP.length - 2) + "." + stringGBPP.substring(stringGBPP.length - 2, stringGBPP.length);
       eptotGBPP = stringGBPP;
       
document.getElementById("eptotalGB").value = eptotGB;
paypalSubmitGB.amount.value=eptotGBPP;


if (document.getElementById("AmttotalGB").value == 4) { 
   document.getElementById("submititGB").style.visibility = "visible"; 
   }
else {
   document.getElementById("submititGB").style.visibility = "hidden"; 
}
 
}

//============================================================================= 
function formatDollar(amtGB) {
//============================================================================= 
var subGB;
var amtGB; 
var stringGB;

amtGB = Math . round (100 * amtGB);
stringGB = "$" + amtGB;
stringGB = stringGB.substring(0, stringGB.length - 2) + "." + stringGB.substring(stringGB.length - 2, stringGB.length);
amtGB = stringGB;
       
return amtGB;

}


//============================================================================= 
function verifyPackGB() {
//============================================================================= 
var stringGB;
var neededGB;

stringGB = itemCode[chosenIndex[1]] + ", " +
         itemCode[chosenIndex[2]] + ", " +
         itemCode[chosenIndex[3]] + ", " +
         itemCode[chosenIndex[4]]  

document.getElementById("itemNameGB").value = stringGB;

runitGB=totalFldsGB();
 
if (document.getElementById("AmttotalGB").value == 4) {
 document.paypalSubmitGB.submit();
 document.priceItGB.reset();
 document.getElementById("submititGB").style.visibility = "hidden"; 
 }
else {
    neededGB =   4 - document.getElementById("AmttotalGB").value; 
    stringGB = "You must order a quantity of 4.  " + neededGB +
     " can(s) are needed to complete the 4-pack case.";
     alert(stringGB);
 } 
         
}