﻿
function calculatePrice() {
    
    var storageCount = $("#txb_storage").val();
    var bandwidthCount = $("#txb_bandwidth").val();

    //set pricing
    var storagePrice = 0.50;
    var bandwidthPrice = 0.18;

    //set scales
    if (storageCount >= 50000) {
        storagePrice = 0.48;
    }

    if (storageCount >= 200000) {
        storagePrice = 0.46;
    }

    if (storageCount >= 400000) {
        storagePrice = 0.44;
    }

    if (bandwidthCount >= 40000) {
        bandwidthPrice = 0.15;
    }

    if (bandwidthCount >= 100000) {
        bandwidthPrice = 0.12;
    }

    if (bandwidthCount >= 250000) {
        bandwidthPrice = 0.09;
    }

    if (bandwidthCount >= 500000) {
        bandwidthPrice = 0.06;
    }

    //do cleanup
    if (isNaN(storageCount)) {
        $("#txb_storage").val(0);
        storageCount = 0;
    }

    if (isNaN(bandwidthCount)) {
        $("#txb_bandwidth").val(0);
        bandwidthCount = 0;
    }

    //add up the total cost
    var totalPrice = 0.00;

    totalPrice = (bandwidthCount * bandwidthPrice) + (storageCount * storagePrice)
    
    //set the price value
    $("#total_amount").html(totalPrice);
    $("#total_amount").formatCurrency({format:'us', symbol:'$'});
}