function calculateLostTime() {

//this function will calculate lost time

  minutes = StripNonNumeric(document.getElementById('wastedMinutes').value);

  dasalary = StripNonNumeric(document.getElementById('salary').value);

  

//apply formula [D * 1.3 /124,800 ] x M x 5 x 50 = Result

  wasted = round(((dasalary * 1.3) / 124800) * minutes * 5 * 50,2);

  wastedDollars = formatCurrency(wasted);

  lostTimeObj = document.getElementById('lostTime');

  lostTimeObj.style.display = '';

  msg = 'You have wasted ' + wastedDollars;

  lostTimeObj.innerHTML = msg;

      

} //end calculateLostTime



function StripNonNumeric( str ) {

	var 	resultStr = "";

			

	// Return immediately if an invalid value was passed in

	if (str+"" == "undefined" || str == null)	

		return null;

	

	// Make sure the argument is a string

	str += "";



	// Loop through entire string, adding each character from the original

	// string if it is a number

	for (var i=0; i < str.length; i++)

	{

   	if ( (str.charAt(i) >= "0") && (str.charAt(i) <= "9") )

     			resultStr = resultStr + str.charAt(i);

 

   } // end for loop      

			

   return resultStr;

}  // end StripNonNumeric



function round(number,X) {

// rounds number to X decimal places, defaults to 2

    X = (!X ? 2 : X);

    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);

} //end round             



function formatCurrency(num) {

num = num.toString().replace(/\$|\,/g,'');

if(isNaN(num))

num = "0";

sign = (num == (num = Math.abs(num)));

num = Math.floor(num*100+0.50000000001);

cents = num%100;

num = Math.floor(num/100).toString();

if(cents<10)

cents = "0" + cents;

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)

num = num.substring(0,num.length-(4*i+3))+','+

num.substring(num.length-(4*i+3));

return (((sign)?'':'-') + '$' + num + '.' + cents);

} //end formatCurrency

              