<!--

/* Juice Prices per Bottle */
var acai_unit_price = 1495;
var aloe_unit_price = 1195;
var conc_unit_price = 1195;
var goji_unit_price = 1495;
var mango_unit_price = 1495;
var noni_unit_price = 1347;
var mwnoni_unit_price = 1495;
var juice100_unit_price = 2495;

/* Parcel Delivery Prices */
var prod_sing_uk_delv = 550;
var prod_sing_eu_delv = 1100;
var juice100_shipping_discount = 800;

/* Price per parcel (up to 20 untis) according to destination country */

var delivery_country = ["England, Scotland, Wales", "Scottish Islands", "Isle of Man", "Jersey, Guernsey", "Northern Ireland", "Ireland (Republic)", "Austria", "Belgium", "Denmark", "Finland", "France", "Germany", "Gibraltar", "Italy", "Luxembourg", "Netherlands", "Poland", "Portugal", "Spain (Mainland)", "Sweden" ];

var delivery_price = [800, 1500, 1800, 1500, 1500, 1650, 4000, 2000, 2000, 4000, 1750, 1750, 4000, 2900, 2000, 1650, 4100, 3000, 3000, 4100 ];

function updatePrice()
{
  var postage = 0;
  var juicePrice =0;
  var bottles = 0;
  var numParcels = 0;
  var delivery = "";
  
  /* Bottle counts for each type of juice */
  var acaiCount = 0;
  var aloeNatCount = 0;
  var aloeStrawCount = 0;
  var aloeOrangeCount = 0;
  var blueCount = 0;
  var cherryCount = 0;
  var cranCount = 0;
  var elderCount = 0;
  var gojiCount = 0;
  var mangoCount = 0;
  var noniCount = 0;
  var mnoniCount = 0;
  var wnoniCount = 0;
  var pomeCount = 0;
  var acai100Count = 0;
  var goji100Count = 0;
  var mango100Count = 0;
  var noni100Count = 0;
  var yum100Count = 0;
  var juice100TotalCount = 0;

  if (document.mixedjuices.acaiCount != null) acaiCount = Math.abs(document.mixedjuices.acaiCount.value);
  if (document.mixedjuices.aloeNatCount != null) aloeNatCount = Math.abs(document.mixedjuices.aloeNatCount.value);
  if (document.mixedjuices.aloeStrawCount != null) aloeStrawCount = Math.abs(document.mixedjuices.aloeStrawCount.value);
  if (document.mixedjuices.aloeOrangeCount != null) aloeOrangeCount = Math.abs(document.mixedjuices.aloeOrangeCount.value);
  if (document.mixedjuices.blueCount != null) blueCount = Math.abs(document.mixedjuices.blueCount.value);
  if (document.mixedjuices.cherryCount != null) cherryCount = Math.abs(document.mixedjuices.cherryCount.value);
  if (document.mixedjuices.cranCount != null) cranCount = Math.abs(document.mixedjuices.cranCount.value);
  if (document.mixedjuices.elderCount != null) elderCount = Math.abs(document.mixedjuices.elderCount.value);
  if (document.mixedjuices.gojiCount != null) gojiCount = Math.abs(document.mixedjuices.gojiCount.value);
  if (document.mixedjuices.mangoCount != null) mangoCount = Math.abs(document.mixedjuices.mangoCount.value);
  if (document.mixedjuices.noniCount != null) noniCount = Math.abs(document.mixedjuices.noniCount.value);
  if (document.mixedjuices.mnoniCount != null) mnoniCount = Math.abs(document.mixedjuices.mnoniCount.value);
  if (document.mixedjuices.wnoniCount != null) wnoniCount = Math.abs(document.mixedjuices.wnoniCount.value);
  if (document.mixedjuices.pomeCount != null) pomeCount = Math.abs(document.mixedjuices.pomeCount.value);
  if (document.mixedjuices.acai100Count != null) acai100Count = Math.abs(document.mixedjuices.acai100Count.value);
  if (document.mixedjuices.goji100Count != null) goji100Count = Math.abs(document.mixedjuices.goji100Count.value);
  if (document.mixedjuices.mango100Count != null) mango100Count = Math.abs(document.mixedjuices.mango100Count.value);
  if (document.mixedjuices.noni100Count != null) noni100Count = Math.abs(document.mixedjuices.noni100Count.value);
  if (document.mixedjuices.yum100Count != null) yum100Count = Math.abs(document.mixedjuices.yum100Count.value);

  /* Total 100% Juice Count Required for Shipping Cost */
  juice100TotalCount = acai100Count + goji100Count + mango100Count + noni100Count + yum100Count;

  /* Add up the bottles selected so far */
  bottles = acaiCount + aloeNatCount + aloeStrawCount + aloeOrangeCount + gojiCount + mangoCount + noniCount + mnoniCount + wnoniCount + pomeCount + blueCount + cherryCount + cranCount + elderCount +
    acai100Count + goji100Count + mango100Count + noni100Count + yum100Count;
    
  /* How many full parcels of 20 */  
  numParcels = Math.floor(bottles / 20);

  /* Do we need another parcel for remainder ? */
  if ((bottles % 20) != 0)
  {
    numParcels++;
  }
  
  /* Update Shipping Cost */
  if (bottles == 1) /* Post by Royal Mail */
  {
    if (document.mixedjuices.prodDelv.value <= 4) /* UK Delivery */
    {
      postage = prod_sing_uk_delv;
    }
    else /* EU Delivery */
    {
      postage = prod_sing_eu_delv;
    }
    
    /* Take away discount for 100% Pure Juice */
    if (juice100TotalCount > 0) 
    { 
      if (postage <= juice100_shipping_discount)
        postage = 0;
      else
        postage -= juice100_shipping_discount; 
    }
  }
  else /* Parcel by ParcelForce, price depends on country */
  {
    postage = delivery_price[document.mixedjuices.prodDelv.value] * numParcels;

    /* Take away discount for 100% Pure Juice */
    if (juice100TotalCount >= numParcels)
    {
      postage -= (numParcels * juice100_shipping_discount);
    }
    else
    {
      postage -= (juice100TotalCount * juice100_shipping_discount);
    }
  }
  document.mixedjuices.postageCost.value = " £ " + toPounds(postage);
  
  /* Update the juice price */
  juicePrice =
    (acaiCount * acai_unit_price) +
    (aloeNatCount * aloe_unit_price) +
    (aloeStrawCount * aloe_unit_price) +
    (aloeOrangeCount * aloe_unit_price) +
    (blueCount * conc_unit_price) +
    (cherryCount * conc_unit_price) +
    (cranCount * conc_unit_price) +
    (elderCount * conc_unit_price) +
    (gojiCount * goji_unit_price) +
    (mangoCount * mango_unit_price) +
    (noniCount * noni_unit_price) +
    (mnoniCount * mwnoni_unit_price) +
    (wnoniCount * mwnoni_unit_price) +
    (pomeCount * conc_unit_price) +
    (acai100Count * juice100_unit_price) +
    (goji100Count * juice100_unit_price) +
    (mango100Count * juice100_unit_price) +
    (noni100Count * juice100_unit_price) +
    (yum100Count * juice100_unit_price);

  document.mixedjuices.prodCost.value = " £ " + toPounds(juicePrice);
    
  return true;
}

function verifyOrder()
{
  var postage = 0;
  var juicePrice =0;
  var totalPence = 0;
  var bottles = 0;
  var numParcels = 0;
  var deliveryString = "";
  var separator = "";

  /* Bottle counts for each type of juice */
  var acaiCount = 0;
  var aloeNatCount = 0;
  var aloeStrawCount = 0;
  var aloeOrangeCount = 0;
  var aloeTotalCount = 0;
  var blueCount = 0;
  var cherryCount = 0;
  var cranCount = 0;
  var elderCount = 0;
  var gojiCount = 0;
  var mangoCount = 0;
  var noniCount = 0;
  var mnoniCount = 0;
  var wnoniCount = 0;
  var pomeCount = 0;
  var acai100Count = 0;
  var goji100Count = 0;
  var mango100Count = 0;
  var noni100Count = 0;
  var yum100Count = 0;
  var juice100TotalCount = 0;

  if (document.mixedjuices.acaiCount != null) acaiCount = Math.abs(document.mixedjuices.acaiCount.value);
  if (document.mixedjuices.aloeNatCount != null) aloeNatCount = Math.abs(document.mixedjuices.aloeNatCount.value);
  if (document.mixedjuices.aloeStrawCount != null) aloeStrawCount = Math.abs(document.mixedjuices.aloeStrawCount.value);
  if (document.mixedjuices.aloeOrangeCount != null) aloeOrangeCount = Math.abs(document.mixedjuices.aloeOrangeCount.value);
  if (document.mixedjuices.blueCount != null) blueCount = Math.abs(document.mixedjuices.blueCount.value);
  if (document.mixedjuices.cherryCount != null) cherryCount = Math.abs(document.mixedjuices.cherryCount.value);
  if (document.mixedjuices.cranCount != null) cranCount = Math.abs(document.mixedjuices.cranCount.value);
  if (document.mixedjuices.elderCount != null) elderCount = Math.abs(document.mixedjuices.elderCount.value);
  if (document.mixedjuices.gojiCount != null) gojiCount = Math.abs(document.mixedjuices.gojiCount.value);
  if (document.mixedjuices.mangoCount != null) mangoCount = Math.abs(document.mixedjuices.mangoCount.value);
  if (document.mixedjuices.noniCount != null) noniCount = Math.abs(document.mixedjuices.noniCount.value);
  if (document.mixedjuices.mnoniCount != null) mnoniCount = Math.abs(document.mixedjuices.mnoniCount.value);
  if (document.mixedjuices.wnoniCount != null) wnoniCount = Math.abs(document.mixedjuices.wnoniCount.value);
  if (document.mixedjuices.pomeCount != null) pomeCount = Math.abs(document.mixedjuices.pomeCount.value);
  if (document.mixedjuices.acai100Count != null) acai100Count = Math.abs(document.mixedjuices.acai100Count.value);
  if (document.mixedjuices.goji100Count != null) goji100Count = Math.abs(document.mixedjuices.goji100Count.value);
  if (document.mixedjuices.mango100Count != null) mango100Count = Math.abs(document.mixedjuices.mango100Count.value);
  if (document.mixedjuices.noni100Count != null) noni100Count = Math.abs(document.mixedjuices.noni100Count.value);
  if (document.mixedjuices.yum100Count != null) yum100Count = Math.abs(document.mixedjuices.yum100Count.value);

  /* Total Aloe Count and 100% Juice Count Required for Later */
  aloeTotalCount = aloeNatCount + aloeStrawCount + aloeOrangeCount;
  juice100TotalCount = acai100Count + goji100Count + mango100Count + noni100Count + yum100Count;
  
  /* Total num of bottles ordered */
  bottles = acaiCount + aloeTotalCount + gojiCount + mangoCount + 
            noniCount + mnoniCount + wnoniCount + pomeCount + acai100Count + blueCount + cherryCount + cranCount + elderCount +
            goji100Count + mango100Count + noni100Count + yum100Count;
  
  if (bottles == 0)
  {
    alert("No bottles selected!");
    return false;
  }

  /* How many full parcels of 20 */  
  numParcels = Math.floor(bottles / 20);

  /* Do we need another parcel for remainder ? */
  if ((bottles % 20) != 0)
  {
    numParcels++;
  }
  
  /* Calculate Shipping Cost */
  if (bottles == 1) /* Post by Royal Mail */
  {
    if (document.mixedjuices.prodDelv.value <= 4) /* UK Delivery */
    {
      postage = prod_sing_uk_delv;
    }
    else /* EU Delivery */
    {
      postage = prod_sing_eu_delv;
    }
    
    /* Take away discount for 100% Pure Juice */
    if (juice100TotalCount > 0)
    { 
      if (postage <= juice100_shipping_discount)
        postage = 0;
      else
        postage -= juice100_shipping_discount; 
    }
  }
  else /* Parcel by ParcelForce, price depends on country */
  {
    postage = delivery_price[document.mixedjuices.prodDelv.value] * numParcels;

    /* Take away discount for 100% Pure Juice */
    if (juice100TotalCount >= numParcels)
    {
      postage -= (numParcels * juice100_shipping_discount);
    }
    else
    {
      postage -= (juice100TotalCount * juice100_shipping_discount);
    }
  }

  /* Add delivery location to shopping basket description */
  deliveryString = "<br>(Delivery, " + delivery_country[document.mixedjuices.prodDelv.value] + ")";

  /* Calc the juice price */
  juicePrice =
    (acaiCount * acai_unit_price) +
    (aloeTotalCount * aloe_unit_price) +
    (blueCount * conc_unit_price) +
    (cherryCount * conc_unit_price) +
    (cranCount * conc_unit_price) +
    (elderCount * conc_unit_price) +
    (gojiCount * goji_unit_price) +
    (mangoCount * mango_unit_price) +
    (noniCount * noni_unit_price) +
    (mnoniCount * mwnoni_unit_price) +
    (wnoniCount * mwnoni_unit_price) +
    (pomeCount * conc_unit_price) +
    (acai100Count * juice100_unit_price) +
    (goji100Count * juice100_unit_price) +
    (mango100Count * juice100_unit_price) +
    (noni100Count * juice100_unit_price) +
    (yum100Count * juice100_unit_price);

  /* Calc TOTAL price */
  totalPence = postage + juicePrice;
  
  /* Set Product Price for Basket */
  prodPrice = toPounds(totalPence);
  
  /* Set Product Code for Basket */
  /* Check whether all bottles are of one type */
  if (acaiCount == bottles)
  {
    prodCode = "ACAI" + acaiCount;
    prodDesc = acaiCount + " bottle(s) of Acai Berry Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (aloeTotalCount == bottles)
  {
    prodCode = "ALOE" + bottles;
    prodDesc = aloeTotalCount + " bottle(s) of Whole Leaf Aloe Vera Juice<br>(1 litre per bottle)" + deliveryString;

    if (aloeNatCount > 0)
    {
      prodDesc += ", " + aloeNatCount + "x Natural";
    }
    if (aloeStrawCount > 0)
    {
      prodDesc += ", " + aloeStrawCount + "x Strawberry";
    }
    if (aloeOrangeCount > 0)
    {
      prodDesc += ", " + aloeOrangeCount + "x Orange";
    }
  }
  else if (blueCount == bottles)
  {
    prodCode = "BLUEB" + bottles;
    prodDesc = blueCount + " bottle(s) of Blueberry Juice<br>(500ml per bottle, each bottle make 2.5 litres)" + deliveryString;
  }
  else if (cherryCount == bottles)
  {
    prodCode = "CHERRY" + bottles;
    prodDesc = cherryCount + " bottle(s) of Black Cherry Juice<br>(500ml per bottle, each bottle make 2.5 litres)" + deliveryString;
  }
  else if (cranCount == bottles)
  {
    prodCode = "CRANB" + bottles;
    prodDesc = cranCount + " bottle(s) of Cranberry Juice<br>(500ml per bottle, each bottle make 2.5 litres)" + deliveryString;
  }
  else if (elderCount == bottles)
  {
    prodCode = "ELDER" + bottles;
    prodDesc = elderCount + " bottle(s) of Black Elderberry Juice<br>(500ml per bottle, each bottle make 2.5 litres)" + deliveryString;
  }
  else if (gojiCount == bottles)
  {
    prodCode = "GOJI" + bottles;
    prodDesc = gojiCount + " bottle(s) of Goji Berry Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (mangoCount == bottles)
  {
    prodCode = "MANGO" + bottles;
    prodDesc = mangoCount + " bottle(s) of Mangosteen Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (noniCount == bottles)
  {
    prodCode = "NONI" + bottles;
    prodDesc = noniCount + " bottle(s) of Organic Noni Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (mnoniCount == bottles)
  {
    prodCode = "MNONI" + bottles;
    prodDesc = mnoniCount + " bottle(s) of Men's Fortified Noni Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (wnoniCount == bottles)
  {
    prodCode = "WNONI" + bottles;
    prodDesc = wnoniCount + " bottle(s) of Women's Fortified Noni Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (pomeCount == bottles)
  {
    prodCode = "POME" + bottles;
    prodDesc = pomeCount + " bottle(s) of Pomegranate Juice<br>(500ml per bottle, each bottle make 3.5 litres)" + deliveryString;
  }
  else if (acai100Count == bottles)
  {
    prodCode = "ACAI100X" + bottles;
    prodDesc = acai100Count + " bottle(s) of 100% Pure Organic Acai Berry Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (goji100Count == bottles)
  {
    prodCode = "GOJI100X" + bottles;
    prodDesc = goji100Count + " bottle(s) of 100% Pure Organic Goji Berry Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (mango100Count == bottles)
  {
    prodCode = "MANGO100X" + bottles;
    prodDesc = mango100Count + " bottle(s) of 100% Pure Organic Mangosteen Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (noni100Count == bottles)
  {
    prodCode = "NONI100X" + bottles;
    prodDesc = noni100Count + " bottle(s) of 100% Pure Organic Noni Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else if (yum100Count == bottles)
  {
    prodCode = "YUM100X" + yum100Count;
    prodDesc = yum100Count + " bottle(s) of 100% Pure Organic Yumberry Juice<br>(1 litre per bottle)" + deliveryString;
  }
  else
  {  
    prodCode = "XMIXED";
  
    /* Set Product Description */
    prodDesc = "Mixed Juices Order<br>";
    if (acaiCount > 0)
    {
      prodDesc += separator + acaiCount + "x Acai";
      separator = ", ";
    }
  
    if (acai100Count > 0)
    {
      prodDesc += separator + acai100Count + "x Pure 100% Acai";
      separator = ", ";
    }
  
    if (aloeNatCount > 0)
    {
      prodDesc += separator + aloeNatCount + "x Aloe(Natural)";
      separator = ", ";
    }
  
    if (aloeStrawCount > 0)
    {
      prodDesc += separator + aloeStrawCount + "x Aloe(Strawberry/Kiwi)";
      separator = ", ";
    }
  
    if (aloeOrangeCount > 0)
    {
      prodDesc += separator + aloeOrangeCount + "x Aloe(Orange/Papaya)";
      separator = ", ";
    }
  
    if (blueCount > 0)
    {
      prodDesc += separator + blueCount + "x Blueberry";
      separator = ", ";
    }

    if (cherryCount > 0)
    {
      prodDesc += separator + cherryCount + "x Black Cherry";
      separator = ", ";
    }

    if (cranCount > 0)
    {
      prodDesc += separator + cranCount + "x Cranberry";
      separator = ", ";
    }

    if (elderCount > 0)
    {
      prodDesc += separator + elderCount + "x Black Elderberry";
      separator = ", ";
    }

    if (gojiCount > 0)
    {
      prodDesc += separator + gojiCount + "x Goji";
      separator = ", ";
    }
  
    if (goji100Count > 0)
    {
      prodDesc += separator + goji100Count + "x Pure 100% Goji";
      separator = ", ";
    }
  
    if (mangoCount > 0)
    {
      prodDesc += separator + mangoCount + "x Mangosteen";
      separator = ", ";
    }
  
    if (mango100Count > 0)
    {
      prodDesc += separator + mango100Count + "x Pure 100% Mangosteen";
      separator = ", ";
    }
  
    if (noniCount > 0)
    {
      prodDesc += separator + noniCount + "x Noni";
      separator = ", ";
    }
  
    if (noni100Count > 0)
    {
      prodDesc += separator + noni100Count + "x Pure 100% Noni";
      separator = ", ";
    }

    if (mnoniCount > 0)
    {
      prodDesc += separator + mnoniCount + "x Men's Noni";
      separator = ", ";
    }
  
    if (wnoniCount > 0)
    {
      prodDesc += separator + wnoniCount + "x Women's Noni";
      separator = ", ";
    }
  
    if (pomeCount > 0)
    {
      prodDesc += separator + pomeCount + "x Pomegranate";
      separator = ", ";
    }
    
    if (yum100Count > 0)
    {
      prodDesc += separator + yum100Count + "x Pure 100% Yumberry";
      separator = ", ";
    }
  
    prodDesc += "<br>";
    prodDesc += deliveryString;
  }
  
  return true;
}

function toPounds(costInPence)
{
  var pounds = Math.floor(costInPence / 100);
  var pence = costInPence % 100;
  var poundString = "";

  poundString = pounds + ".";

  if (pence < 10)
  {
    poundString = poundString + "0" + pence;
  }
  else
  {
    poundString = poundString + pence;
  }

  return poundString;
}

//-->

