/* www.webico.co.uk */

 //Set up an associative array 
 //The keys represent the paper weight
 //The value represents the cost
 //We use this this array when the user selects paper weight from the form
 var quantity_prices= new Array();
 quantity_prices["A6 leaflets 10,000 copies (£75)"]=75;
 quantity_prices["A6 leaflets 5000 copies (£63)"]=63;
 quantity_prices["A6 leaflets 2500 copies (£55)"]=55;
 quantity_prices["A6 leaflets 500 copies (£50)"]=50;
 


 //Set up an associative array 
 //The keys represent the paper weight
 //The value represents the cost
 //We use this this array when the user selects paper weight from the form
 var paper_prices= new Array();
 paper_prices["115 gsm printing paper"]=0;
 paper_prices["135 gsm printing paper (£10)"]=10;
 paper_prices["170 gsm printing paper (£20)"]=20;
 paper_prices["250 gsm printing paper (£40)"]=40;

 
 
 //Set up an associative array 
 //The keys represent the design
 //The value represents the cost
 //We use this this array when the user selects design from the form
 var design_prices= new Array();
 design_prices["Own design/s"]=0;
 design_prices["1 side (£20)"]=20;
 design_prices["2 sides (£30)"]=30;



 //Set up an associative array 
 //The keys represent the delivery terms
 //The value represents the cost
 //We use this this array when the user selects delivery terms from the form
 var delivery_prices= new Array();
 delivery_prices["5 working days"]=0;
 delivery_prices["3 working days (£15)"]=15;
 delivery_prices["1 working day (£50)"]=50;



 //Set up an associative array 
 //The keys represent the payment method
 //The value represents the cost
 //We use this this array when the user selects payment method from the form
 var payment_prices= new Array();
 payment_prices["Bank"]=0;
 payment_prices["PayPal/Card (£5)"]=5;



//This function finds the filling price based on the 
//drop down selection
function getQuantityPrice()
{
    var cakeQuantityPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the select id="quantity"
     var selectedQuantity = theForm.elements["quantity"];
     
    //set cakeFilling Price equal to value user chose
    //For example quantity_prices["Lemon".value] would be equal to 5
    cakeQuantityPrice = quantity_prices[selectedQuantity.value];

    //finally we return cakeQuantityPrice
    return cakeQuantityPrice;
}




//This function finds the filling price based on the 
//drop down selection
function getPaperPrice()
{
    var cakePaperPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the select id="filling"
     var selectedPaper = theForm.elements["paper"];
     
    //set cakeFilling Price equal to value user chose
    //For example filling_prices["Lemon".value] would be equal to 5
    cakePaperPrice = paper_prices[selectedPaper.value];

    //finally we return cakeFillingPrice
    return cakePaperPrice;
}



//This function finds the design price based on the drop down selection
function getDesignPrice()
{
    var cakeDesignPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the select id="design"
     var selectedDesign = theForm.elements["design"];
     
    //set cakeDesign Price equal to value user chose
    cakeDesignPrice = design_prices[selectedDesign.value];

    //finally we return cakeDesignPrice
    return cakeDesignPrice;
}



//This function finds the delivery price based on the drop down selection
function getDeliveryPrice()
{
    var cakeDeliveryPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the select id="delivery"
     var selectedDelivery = theForm.elements["delivery"];
     
    //set cakeDelivery Price equal to value user chose
    cakeDeliveryPrice = delivery_prices[selectedDelivery.value];

    //finally we return cakeDeliveryPrice
    return cakeDeliveryPrice;
}



//This function finds the payment price based on the drop down selection
function getPaymentPrice()
{
    var cakePaymentPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the select id="payment"
     var selectedPayment = theForm.elements["payment"];
     
    //set cakePayment Price equal to value user chose
    cakePaymentPrice = payment_prices[selectedPayment.value];

    //finally we return cakePaymentPrice
    return cakePaymentPrice;
}



//sidesPrice() finds the candles price based on a check box selection
function sidesPrice()
{
    var sidesPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the checkbox id="sides"
    var sides = theForm.elements["sides"];

    //If they checked the box set candlePrice to 5
    if(sides.checked==true)
    {
        sidesPrice=20;
    }
    //finally we return the sidesPrice
    return sidesPrice;
}



function roundingPrice()
{
    //This local variable will be used to decide whether or not to charge for the rounding
    //If the user checked the box this value will be 50
    //otherwise it will remain at 0
    var roundingPrice=0;
    //Get a refernce to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the checkbox id="rounding"
    var rounding = theForm.elements["rounding"];
    //If they checked the box set roundingPrice to 50
    if(rounding.checked==true){
        roundingPrice=50;
    }
    //finally we return the inscriptionPrice
    return roundingPrice;
}
  
  
        
function calculateTotal()
{
    //Here we get the total price by calling our function
    //Each function returns a number so by calling them we add the values they return together
    var cakePrice = getQuantityPrice() + getPaperPrice() + getDeliveryPrice() +getDesignPrice() + getPaymentPrice() + sidesPrice() + roundingPrice();
    
    //display the result
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='block';
    divobj.innerHTML = "Total price &pound; "+cakePrice;

}

function hideTotal()
{
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='none';
}
