function estimate_cost() {
        // check input fields
        var regex_nums = /[^0-9]/;
        var regex_float = /[^0-9\.]/;
	document.calcform.num_domains.value = parseInt(document.calcform.num_domains.value.replace(regex_nums,''));
	if (parseInt(document.calcform.num_domains.value) < 1) {
		document.calcform.num_domains.value = 1;
	}
        document.calcform.total_messages.value = parseInt(document.calcform.total_messages.value.replace(regex_float,''));
        
        // Set up the basic assumptions
        var monthly_domain_cost = 20.00;
	var addtl_domain_cost = 15.00;
        var base_msgs_per_month = 5000;
        var addtl_per_1k_charge = 2.5;
        var days_in_a_month = 30;
	var num_domains = document.calcform.num_domains.value;
        var total_messages = (document.calcform.total_messages.value * days_in_a_month) * num_domains;
        var msgs_over_base = total_messages - (base_msgs_per_month * num_domains);
        var cost_over_base = 0;
        if (msgs_over_base <= 0) {
                msgs_over_base = 0;
                cost_over_base = 0;
        } else {                
                //alert("(" + msgs_over_base + " / 1000) * " + addtl_per_1k_charge);
                cost_over_base = (msgs_over_base / 1000) * addtl_per_1k_charge;
        }
	var total_domain_cost = (addtl_domain_cost * num_domains) + (monthly_domain_cost - addtl_domain_cost);
        var cost_of_SpamEater_per_month = monthly_domain_cost + cost_over_base;
	document.calcform.cost_of_SpamEater_per_month.value = calcRound(cost_of_SpamEater_per_month);
} 

function run_calculator() 
    {
	// check input fields
	var regex_nums = /[^0-9]/;
	var regex_float = /[^0-9\.]/;
	document.calcform.total_messages.value = parseInt(document.calcform.total_messages.value.replace(regex_float,''));
	document.calcform.hourly_cost_of_employee.value = parseFloat(document.calcform.hourly_cost_of_employee.value.replace(regex_float,''));
	document.calcform.seconds_to_delete_a_SPAM.value = parseInt(document.calcform.seconds_to_delete_a_SPAM.value.replace(regex_float,''));
	document.calcform.SPAM_messages_per_day.value = parseInt(document.calcform.SPAM_messages_per_day.value.replace(regex_float,''));
	document.calcform.number_of_viruses_each_month.value = parseInt(document.calcform.number_of_viruses_each_month.value.replace(regex_float,''));
	document.calcform.employees_needed_for_virus_attack.value = parseInt(document.calcform.employees_needed_for_virus_attack.value.replace(regex_float,''));
	document.calcform.hourly_salary_for_employee_combating_attack.value = parseFloat(document.calcform.hourly_salary_for_employee_combating_attack.value.replace(regex_float,''));
	document.calcform.hours_required_to_fight_virus_attack.value = parseFloat(document.calcform.hours_required_to_fight_virus_attack.value.replace(regex_float,''));

	// Set up the basic assumptions
	var monthly_domain_cost = 20.00;
	var base_msgs_per_month = 5000;
	var addtl_per_1k_charge = 2.5;
	var days_in_a_month = 30;
	var total_messages = document.calcform.total_messages.value * days_in_a_month;
	var hourly_cost_of_employee = document.calcform.hourly_cost_of_employee.value;
	var seconds_to_delete_a_SPAM = document.calcform.seconds_to_delete_a_SPAM.value;
	//var SPAM_messages_per_day = document.calcform.SPAM_messages_per_day.value;
	var SPAM_messages_per_day = document.calcform.SPAM_messages_per_day.value;
	var Spam_msgs_per_month = SPAM_messages_per_day * days_in_a_month;
	var msgs_over_base = total_messages - base_msgs_per_month;
	var cost_over_base = 0;
	if (msgs_over_base <= 0) {
		msgs_over_base = 0;
		cost_over_base = 0;
	} else {
		//alert("(" + msgs_over_base + " / 1000) * " + addtl_per_1k_charge);
		cost_over_base = (msgs_over_base / 1000) * addtl_per_1k_charge;
	}
 	//var SpamEater_cost_per_employee = pricePerMailbox(total_employees);
	var number_of_viruses_each_month = document.calcform.number_of_viruses_each_month.value;
	var employees_needed_for_virus_attack = document.calcform.employees_needed_for_virus_attack.value;
	var hourly_salary_for_employee_combating_attack = document.calcform.hourly_salary_for_employee_combating_attack.value;
	var hours_required_to_fight_virus_attack = document.calcform.hours_required_to_fight_virus_attack.value;
	
	// Perform calculations
	var SPAM_cost_per_month = (SPAM_messages_per_day * (seconds_to_delete_a_SPAM/60/60) * days_in_a_month * hourly_cost_of_employee );
	var cost_of_virus_attack_per_month = (number_of_viruses_each_month * (hours_required_to_fight_virus_attack * hourly_salary_for_employee_combating_attack * 
		employees_needed_for_virus_attack));
 	//var cost_of_virus_attack_per_month = (number_of_viruses_each_month *
	// ((hours_required_to_fight_virus_attack * hourly_salary_for_employee_combating_attack * employees_needed_for_virus_attack) +
	// (hourly_cost_of_employee * (total_employees - employees_needed_for_virus_attack))) );	
	//var cost_of_SpamEater_per_month =(total_employees * SpamEater_cost_per_employee);
	var cost_of_SpamEater_per_month = monthly_domain_cost + cost_over_base;
	var cost_desc = "Estimated SpamEater.Net cost per month based on 1 domain at $" + parseFloat(calcRound(monthly_domain_cost)) + "/month";
	if (msgs_over_base > 0) {
		cost_desc += ' plus $' + calcRound(cost_over_base) + '/month for ' + calcRound(msgs_over_base) + ' msgs over base ' + calcRound(base_msgs_per_month);
		cost_desc += ' msgs/month for the total estimated cost of $' + calcRound(cost_of_SpamEater_per_month) + '/month.';
	} else {
		cost_desc += ' with included base of ' + base_msgs_per_month + ' messages per month.';
	}
 	
	// write out the final calculations
	document.calcform.SPAM_cost_per_month.value = dollarRound(SPAM_cost_per_month);
	document.calcform.cost_of_virus_attack_per_month.value = dollarRound(cost_of_virus_attack_per_month);
	document.calcform.cost_of_SpamEater_per_month.value = dollarRound(cost_of_SpamEater_per_month);
	document.calcform.savings_with_SpamEater.value = dollarRound((SPAM_cost_per_month + cost_of_virus_attack_per_month) - cost_of_SpamEater_per_month);
	document.all.msg.innerHTML = "<sup>2</sup>" + cost_desc;
	document.all.fnote.innerHTML = "<sup>2</sup>";
 	}
 
 function pricePerMailbox(num)
 	{
	// Should return a cost per mailbox based on the number of mailboxes.
	// As of 12/30/02, the formula is:
	// 1-99 mailboxes = $150/month flat fee
	// 100-999 mailboxes = $1.50/month per mailbox
	// 1000+ = $1.00/month per mailbox
	//
	// As of 01/18/04, the formular is:
	// $2 per user for over 100 users, 
	// from 50 to 100 users it $200 per month 
	// for 50 and under its $150 per month
	
	if (num > 0 && num < 50)
		{ return 150/num }
	else if (num >= 50 && num < 100)
		{ return 200/num }
	else if (num >= 100 )
		{ return 2.00; }
	else
		// In theory, we should never reach this point.
		{ return 2.00; }
	}	
	

 function dollarRound(num)
	{
	// round numbers to the dollar decimal point
	//	return Math.round(num * 10) /10;
	//	return Math.round(num)
		return "$" + calcRound(num);
	}


 function calcRound(num) 
	{
 	// result="$"+Math.floor(num)+"." 
   	result=""+Math.floor(num)
   	n = result.length
   	if (num>=1000 && num<999999) {  
     		result=""+result.substring(0,n-3)+","+result.substring(n-3,n)
    	}
    	if (num>1000000) {  
     		result = ""+result.substring(0,n-6)+","+result.substring(n-6,n-3)+","+result.substring(n-3,n)
    	}
	   // var cents=100*(num-Math.floor(num))+0.5
   	// result += Math.floor(cents/10)
   	// result += Math.floor(cents%10)
   	return(result)
	}


