﻿//Function to update all the costs,
//updated a billion times now, ffs,
//all values, client ids and costs
//are pulled from a script block in the user control
//which are pulled form the survey object
function updateCosts(){
    var employees = parseInt(employeesTXT.value);
    if(isNaN(employees) || employees < 1){
        alert("Please specify the numbers of employees.");
        return;
    }
    var currentCost = costSetupAdmin;
    
    //check and update benchmarking
    if(benchmarkCB.checked){
        if(benchmarkHolderPanel.style.display != 'block'){
            benchmarkStandardCB.checked = true;
            benchmarkCustomCB.checked   = false;
        }
        benchStandardLBL.style.marginTop    = '18px';
        benchCustomLBL.style.display        = 'block';
        benchmarkHolderPanel.style.display  = 'block';
        //go down into standard
        if(benchmarkStandardCB.checked){
            currentCost                 += costBenchmarkStandard;
            benchStandardLBL.innerHTML   = formatCurrency(costBenchmarkStandard);
        }
        else
            benchStandardLBL.innerHTML = formatCurrency(0);
        
        //and then customised
        if(benchmarkCustomCB.checked){
            currentCost             += costBenchmarkCustom;
            benchCustomLBL.innerHTML = formatCurrency(costBenchmarkCustom);
        }
        else
            benchCustomLBL.innerHTML = formatCurrency(0);
    }
    else {
        benchCustomLBL.style.display        = 'none';
        benchmarkHolderPanel.style.display  = 'none';
        benchStandardLBL.innerHTML          = formatCurrency(0);
        benchStandardLBL.style.marginTop    = '0';
    }
    
    if(demographicCB.checked){
        var demoCost = 0;
        if(employees <= 50)
            demoCost = costDemographicReporting[0];
        else if(employees <= 100)
            demoCost = costDemographicReporting[1];
        else if(employees <= 250)
            demoCost = costDemographicReporting[2];
        else if(employees <= 500)
            demoCost = costDemographicReporting[3];
        else if(employees <= 1000)
            demoCost = costDemographicReporting[4];
        else if(employees <= 1500)
            demoCost = costDemographicReporting[5];
        else if(employees <= 2000)
            demoCost = costDemographicReporting[6];
        else if(employees <= 2500)
            demoCost = costDemographicReporting[7];
        else if(employees <= 3000)
            demoCost = costDemographicReporting[8];
        else if(employees <= 3500)
            demoCost = costDemographicReporting[9];
        else if(employees <= 4000)
            demoCost = costDemographicReporting[10];
        else if(employees <= 4500)
            demoCost = costDemographicReporting[11];
        else if(employees <= 5000)
            demoCost = costDemographicReporting[12];
            
        if(demoCost > 0){
            currentCost             += demoCost;
            demographicLBL.innerHTML = formatCurrency(demoCost);
        }
        else
            demographicLBL.innerHTML = "POA";
    }
    else
        demographicLBL.innerHTML = formatCurrency(0);
        
    //check add extra questions
    if(extraCB.checked){
        extraQuestionsPanel.style.display = 'block';
        var extraCost = 0;
        switch(extraDDL.selectedIndex){
            case 0: extraCost = costExtra10; break;
            case 1: extraCost = costExtra20; break;
            case 2: extraCost = costExtra50; break;
        }
        if(extraCost > 0){
            currentCost         += extraCost;
            extraLBL.innerHTML  = formatCurrency(extraCost);
        }
        else
            extraLBL.innerHTML = "POA";
    }
    else {
        extraQuestionsPanel.style.display   = 'none';
        extraLBL.innerHTML                  = formatCurrency(0);
    }
    
    //check trending
    if(trendingCB.checked){
        currentCost         += costTrending;
        trendingLBL.innerHTML = formatCurrency(costTrending);    
    }
    else
        trendingLBL.innerHTML = formatCurrency(0);

    //check key driver detailed first, force check key driver if so
    if (keyDriverDetailedCB.checked) {
        keyDriverCB.disabled = true;
        keyDriverCB.checked = true;
        keyDriverlBL.innerHTML = formatCurrency(0);
        currentCost += costKeyDriverDetailed;
        keyDriverDetailedLBL.innerHTML = formatCurrency(costKeyDriverDetailed);
    } //if not detailed key driver, check for stock key driver
    else if (keyDriverCB.checked && keyDriverCB.disabled) {
        keyDriverCB.disabled = false;
        keyDriverCB.checked = false;
        keyDriverDetailedLBL.innerHTML = formatCurrency(0);
    }
    else if (keyDriverCB.checked) {
        //key driver is checked, but key driver detailed isn't
        currentCost += costKeyDriver;
        keyDriverDetailedLBL.innerHTML = formatCurrency(0);
        keyDriverlBL.innerHTML = formatCurrency(costKeyDriver);
    }
    else {
        //neither key driver or key driver detailed is checked, make sure they are all enabled
        keyDriverDetailedLBL.innerHTML = formatCurrency(0);
        keyDriverlBL.innerHTML = formatCurrency(0);
        keyDriverCB.disabled = false;
    }
    
     
    
    //check presentation
    if(presentationCB.checked){
        currentCost                 += costPresentation;
        presentationLBL.innerHTML    = formatCurrency(costPresentation);
    }
    else
        presentationLBL.innerHTML = formatCurrency(0);
    
    //update the main shit
    subTotalLBL.innerHTML   = formatCurrency(currentCost);
    gstLBL.innerHTML        = formatCurrency(currentCost * costTax);
    totalLBL.innerHTML      = formatCurrency( (currentCost * costTax) + currentCost);           
}