﻿// JScript File
    
    function ResetFreight(freight1, freight2, freightArea)
    {
        // Reset the non selected freight methods
        if (freight1 == "International" || freight2 == "International")
        {
            var seloption1 = document.getElementById('ddInternationalArea');
            seloption1.selectedIndex=0; 
        }
        
        if (freight1 == "Local" || freight2 == "Local")
        {
            var seloption2 = document.getElementById('ddLocalArea');
            seloption2.selectedIndex=0; 
        }
        
        if (freight1 == "Other" || freight2 == "Other")
        {
            var seloption3 = document.getElementById('txtFreightOther');
            seloption3.value = '';
        }    
        
        CalculateFreightCost(freightArea);            
    }
    
    function CalculateFreightCost(freightArea)
    {        
        Calculate('dontCalculateFreight');
        
        // ==== Now calculate grandtotal (subtotal + shipping cost) =====       
        var grandTotal =  parseFloat(document.getElementById("subTotalIncGst").innerHTML);
        var itemChosen = 0;   
        var chosen = "";
        
        // Check to see how much quantity in total
        if (document.form1.txt1020Black.value != "" && document.form1.txt1020Black.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1020Black.value); }         
        if (document.form1.txt1020Gold.value != "" && document.form1.txt1020Gold.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1020Gold.value); } 
        if (document.form1.txt1020Silver.value != "" && document.form1.txt1020Silver.value > 0)  { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1020Silver.value); } 
        if (document.form1.txt1170Black.value != "" && document.form1.txt1170Black.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1170Black.value); } 
        if (document.form1.txt1170Gold.value != "" && document.form1.txt1170Gold.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1170Gold.value); } 
        if (document.form1.txt1170Silver.value != "" && document.form1.txt1170Silver.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1170Silver.value); } 
        if (document.form1.txt1320Black.value != "" && document.form1.txt1320Black.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1320Black.value); }  
        if (document.form1.txt1320Gold.value != "" && document.form1.txt1320Gold.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1320Gold.value); }  
        if (document.form1.txt1320Silver.value != "" && document.form1.txt1320Silver.value > 0) { itemChosen = parseInt(itemChosen) + parseInt(document.form1.txt1320Silver.value); } 
  
        // Check to see if small has been selected
        if (document.form1.txt1020Black.value != "" || document.form1.txt1020Gold.value != "" || document.form1.txt1020Silver.value != "") 
        { chosen = "Small"; }
        
        // Check to see if medium has been selected
        if (document.form1.txt1170Black.value != "" || document.form1.txt1170Gold.value != "" || document.form1.txt1170Silver.value != "") 
        { chosen = "Medium"; }
        
        // Check to see if large has been selected
        if (document.form1.txt1320Black.value != "" || document.form1.txt1320Gold.value != "" || document.form1.txt1320Silver.value != "") 
        { chosen = "Large"; }
        
        
        
        // Calculate prices for local shipping
        if (freightArea == "Local")
        {                       
            var seloptionLocal = document.getElementById('ddLocalArea');
            if(seloptionLocal.value == "Sydney" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(125.00) + ((itemChosen - 1) * 80)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(125.00) + ((itemChosen - 1) * 80)).toFixed(2);}
            if(seloptionLocal.value == "Melbourne" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(170.00) + ((itemChosen - 1) * 85)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(170.00) + ((itemChosen - 1) * 85)).toFixed(2);}
            if(seloptionLocal.value == "Brisbane" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(180.00) + ((itemChosen - 1) * 90)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(180.00) + ((itemChosen - 1) * 90)).toFixed(2);}
            if(seloptionLocal.value == "Gold Coast" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(180.00) + ((itemChosen - 1) * 90)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(180.00) + ((itemChosen - 1) * 90)).toFixed(2);}
            if(seloptionLocal.value == "Adelaide" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(185.00) + ((itemChosen - 1) * 95)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(185.00) + ((itemChosen - 1) * 95)).toFixed(2);}
            if(seloptionLocal.value == "Perth" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(215.00) + ((itemChosen - 1) * 125)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(215.00) + ((itemChosen - 1) * 125)).toFixed(2);}
            if(seloptionLocal.value == "Darwin" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(265.00) + ((itemChosen - 1) * 175)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(265.00) + ((itemChosen - 1) * 175)).toFixed(2);}                                                                      
            if(seloptionLocal.value == "Sydney" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(130.00) + ((itemChosen - 1) * 80)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(130.00) + ((itemChosen - 1) * 80)).toFixed(2);}
            if(seloptionLocal.value == "Melbourne" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(175.00) + ((itemChosen - 1) * 85)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(175.00) + ((itemChosen - 1) * 85)).toFixed(2);}
            if(seloptionLocal.value == "Brisbane" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(185.00) + ((itemChosen - 1) * 90)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(185.00) + ((itemChosen - 1) * 90)).toFixed(2);}
            if(seloptionLocal.value == "Gold Coast" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(185.00) + ((itemChosen - 1) * 90)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(185.00) + ((itemChosen - 1) * 90)).toFixed(2);}
            if(seloptionLocal.value == "Adelaide" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(190.00) + ((itemChosen - 1) * 95)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(190.00) + ((itemChosen - 1) * 95)).toFixed(2);}
            if(seloptionLocal.value == "Perth" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(220.00) + ((itemChosen - 1) * 125)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(220.00) + ((itemChosen - 1) * 125)).toFixed(2);}
            if(seloptionLocal.value == "Darwin" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(270.00) + ((itemChosen - 1) * 175)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(270.00) + ((itemChosen - 1) * 175)).toFixed(2);}                                                                      
            if(seloptionLocal.value == "Sydney" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(135.00) + ((itemChosen - 1) * 80)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(135.00) + ((itemChosen - 1) * 80)).toFixed(2);}
            if(seloptionLocal.value == "Melbourne" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(180.00) + ((itemChosen - 1) * 85)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(180.00) + ((itemChosen - 1) * 85)).toFixed(2);}
            if(seloptionLocal.value == "Brisbane" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(190.00) + ((itemChosen - 1) * 90)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(190.00) + ((itemChosen - 1) * 90)).toFixed(2);}
            if(seloptionLocal.value == "Gold Coast" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(190.00) + ((itemChosen - 1) * 90)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(190.00) + ((itemChosen - 1) * 90)).toFixed(2);}
            if(seloptionLocal.value == "Adelaide" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(195.00) + ((itemChosen - 1) * 95)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(195.00) + ((itemChosen - 1) * 95)).toFixed(2);}
            if(seloptionLocal.value == "Perth" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(225.00) + ((itemChosen - 1) * 125)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(225.00) + ((itemChosen - 1) * 125)).toFixed(2);}
            if(seloptionLocal.value == "Darwin" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(275.00) + ((itemChosen - 1) * 175)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(275.00) + ((itemChosen - 1) * 175)).toFixed(2);}                                                                      
        }
        
        // Calculate prices for international shipping
        if (freightArea == "International")
        {
            var seloptionInt = document.getElementById('ddInternationalArea');
            if(seloptionInt.value == "UK" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(395.00) + ((itemChosen - 1) * 220)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(395.00) + ((itemChosen - 1) * 220)).toFixed(2)}
            if(seloptionInt.value == "USA" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(370.00) + ((itemChosen - 1) * 215)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(370.00) + ((itemChosen - 1) * 215)).toFixed(2)}
            if(seloptionInt.value == "NZ" && chosen == "Small")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(320.00) + ((itemChosen - 1) * 195)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(320.00) + ((itemChosen - 1) * 195)).toFixed(2)}      
            if(seloptionInt.value == "UK" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(410.00) + ((itemChosen - 1) * 220)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(410.00) + ((itemChosen - 1) * 220)).toFixed(2)}
            if(seloptionInt.value == "USA" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(385.00) + ((itemChosen - 1) * 215)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(385.00) + ((itemChosen - 1) * 215)).toFixed(2)}
            if(seloptionInt.value == "NZ" && chosen == "Medium")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(335.00) + ((itemChosen - 1) * 195)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(335.00) + ((itemChosen - 1) * 195)).toFixed(2)}            
            if(seloptionInt.value == "UK" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(450.00) + ((itemChosen - 1) * 220)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(450.00) + ((itemChosen - 1) * 220)).toFixed(2)}
            if(seloptionInt.value == "USA" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(425.00) + ((itemChosen - 1) * 215)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(425.00) + ((itemChosen - 1) * 215)).toFixed(2)}
            if(seloptionInt.value == "NZ" && chosen == "Large")
            { document.getElementById("totalIncGst").innerHTML = (parseFloat(grandTotal) + parseFloat(380.00) + ((itemChosen - 1) * 195)).toFixed(2); document.getElementById("freightIncGst").innerHTML = (parseFloat(380.00) + ((itemChosen - 1) * 195)).toFixed(2)}                  
        }
        
        if (freightArea == "Other") 
        {      
            document.getElementById("freightIncGst").innerHTML = "0";      
            document.getElementById("totalIncGst").innerHTML = grandTotal.toFixed(2);            
        }
        
        // Total GST
        document.getElementById("gst").innerHTML = (parseFloat(document.getElementById("totalIncGst").innerHTML) / 11).toFixed(2);    
    }
    
    function Calculate(calculateFreight)
    {  
        var subtotal = 0;
        
        // Large
        if (document.form1.txt1320Black.value != "" && document.form1.txt1320Black.value > 0) 
            { subtotal += document.form1.txt1320Black.value * 995; }
        if (document.form1.txt1320Gold.value != "" && document.form1.txt1320Gold.value > 0) 
            { subtotal += document.form1.txt1320Gold.value * 1595; }
        if (document.form1.txt1320Silver.value != "" && document.form1.txt1320Silver.value > 0) 
            { subtotal += document.form1.txt1320Silver.value * 1595 }    
         
        // Medium
        if (document.form1.txt1170Black.value != "" && document.form1.txt1170Black.value > 0) 
            { subtotal += document.form1.txt1170Black.value * 895; }
        if (document.form1.txt1170Gold.value != "" && document.form1.txt1170Gold.value > 0) 
            { subtotal += document.form1.txt1170Gold.value * 1495; }
        if (document.form1.txt1170Silver.value != "" && document.form1.txt1170Silver.value > 0) 
            { subtotal += document.form1.txt1170Silver.value * 1495; }    
         
        // Small
        if (document.form1.txt1020Black.value != "" && document.form1.txt1020Black.value > 0) 
            { subtotal += document.form1.txt1020Black.value * 795; }
        if (document.form1.txt1020Gold.value != "" && document.form1.txt1020Gold.value > 0) 
            { subtotal += document.form1.txt1020Gold.value * 1395; }
        if (document.form1.txt1020Silver.value != "" && document.form1.txt1020Silver.value > 0) 
            { subtotal += document.form1.txt1020Silver.value * 1395; } 
             
        // Honeycomb 
        if (document.form1.txtHoneycomb10.value != "" && document.form1.txtHoneycomb10.value > 0) 
            { subtotal += document.form1.txtHoneycomb10.value * 39.95; }   
        if (document.form1.txtHoneycomb15.value != "" && document.form1.txtHoneycomb15.value > 0) 
            { subtotal += document.form1.txtHoneycomb15.value * 54.95; }    
         
        //document.form1.subtotal.value = subtotal.toFixed(2);
        document.getElementById("subTotalIncGst").innerHTML = subtotal.toFixed(2);
        
        
        if (calculateFreight == "calFreight")
        {
            FindFreightMethod();
        }
        
        return subtotal.toFixed(2);
    }
    
    
    function FindFreightMethod()
    {
        var freightArea = "Other";
        
        if (document.getElementById('ddInternationalArea').value != "")
        { freightArea = "International"; }
        else if (document.getElementById('ddLocalArea').value != "")
        { freightArea = "Local"; }
        
        CalculateFreightCost(freightArea)
    }
