﻿function calcTotal()
{
    var total = 0;

    var numberOfCalls = ($('.numberOfCalls').val() != "") ? parseInt($('.numberOfCalls').val()) : 0;
    var numberOfWorkDays = ($('.numberOfWorkDays').val() != "") ? parseInt($('.numberOfWorkDays').val()) : 0;
    var percentageOnHold = ($('.percentageOnHold').val() != "") ? parseInt($('.percentageOnHold').val()) : 0;
    var averageHoldTime = ($('.averageHoldTime').val() != "") ? parseInt($('.averageHoldTime').val()) : 0;

    var total = numberOfCalls * numberOfWorkDays * (percentageOnHold / 100) * averageHoldTime;
    
    /*$('.qty').each(function(){        
        if ($(this).attr('value') != '')
        {
            if(total == 0)
                total = 1;
            total *= parseInt($(this).attr('value'));
        }
    });*/
    $(".total").attr("innerHTML", total.toFixed(2) + " mins<br />(" + (total / 60).toFixed(2) + " hours)");
}

function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

$(document).ready(function () {    
    $(".qty").keyup(function(key_event) {calcTotal();});
    $(".qty").change(function(key_event) {calcTotal();});
    $(".qty").each(function(element_index) {calcTotal();});
});
