﻿
function calculatePrice() {
    
    var instanceType = $("#calc-instanceType").val();
    var storageType = $("#calc-storageType").val();
    var storageCount = $("#calc-storage").val();
    var processorCount = $("#calc-processor").val();
    var memoryCount = $("#calc-memory").val();
    
  

    //set pricing
    var standardStoragePrice = 0.0014;
    var premiumStoragePrice = 0.003;
    var processorPrice = 0.14;
    var memoryPrice = 0.08;
    var windowsPrice = 0.04;
    var storageTotal = 0;
    var osTotal = 0;

    //do cleanup
    if (isNaN(storageCount)) {
        $("#calc-storage").val(0);
        storageCount = 24;
    }

    if (storageCount < 24) {
        storageCount = 24;
    }

    if (isNaN(processorCount)) {
        $("#calc-processor").val(0);
        instanceCount = 1;
    }

    if (isNaN(memoryCount)) {
        $("#calc-memory").val(0);
        memoryCount = 1;
    }

    if (instanceType == "Windows") {
        osTotal = windowsPrice * processorCount;
    }

    if (storageType == "Premium") {
        storageTotal = storageCount * premiumStoragePrice;
    }
    else {
        storageTotal = storageCount * standardStoragePrice;
    }


    //add up the total cost
    var totalPrice = 0.00;

    totalPrice = ((storageTotal) + (osTotal) + (memoryCount * memoryPrice) + (processorCount * processorPrice)) * 720;
    
    //set the price value
    $("#calc-total").html(totalPrice);
    $("#calc-total").formatCurrency({format:'us', symbol:'$'});
}