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