function Calculate() {

	base_price           = 39.95;
	fifty_more_streams   = 15
	bandwidth_extra_gig  = 0.1536
	storage_extra_gig    = 0.8192

	base_streams = 100;
	base_gig     = 300;
        base_storage = 30;

	WINDOWS_unit_Kbps_normal = 512;
	WINDOWS_unit_Kbps_church = 3072;
	WINDOWS_price_per_unit = 9.95;

	var f = document.calcform;

	var hours   = f.hours.value;
	var bitrate = f.bitrate.value;
	var streams = f.streams.value;
	var storage = f.storage.value;

	if (hours == '' || bitrate == '' || streams == '') {return;}

	if (! hours)   {hours = 0;}
	if (! bitrate) {bitrate = 0;}
	if (! streams) {streams = 0;}

	bps = bitrate * 1024;
	GBps = bitrate / 1024 / 1024 / 8;

	seconds_per_hour = 60 * 60
	seconds_broadcast_per_month = seconds_per_hour * hours
	bits_per_month_per_stream = bps * seconds_broadcast_per_month;

	GB_per_month_per_stream  = GBps * seconds_broadcast_per_month;
	GB_per_month_all_streams = GBps * seconds_broadcast_per_month * streams
	f.GB_per_month_per_stream.value  = Commify(RoundNumber(GB_per_month_per_stream,2));
	f.GB_per_month_all_streams.value = Commify(RoundNumber(GB_per_month_all_streams,2));

	f.FLASH_base_price.value = base_price;

	if (GB_per_month_all_streams <= base_gig) {
		f.FLASH_extra_bandwidth_price.value = '0.00';
	} else {
		f.FLASH_extra_bandwidth_price.value = Math.round(((GB_per_month_all_streams - base_gig) * bandwidth_extra_gig) * 100) / 100;
	}

	if (storage <= base_storage) {
		f.FLASH_extra_storage_price.value = '0.00';
	} else {
		f.FLASH_extra_storage_price.value = Math.round(((storage - base_storage) * storage_extra_gig) * 100) / 100;
	}

	if (streams <= base_streams) {
		f.FLASH_extra_streams_price.value = '0.00';
	} else {
		f.FLASH_extra_streams_price.value = (fifty_more_streams * Math.ceil((streams - base_streams) / 50)).toFixed(2);
	}

	f.FLASH_total_price.value           = '$' + (parseFloat(f.FLASH_base_price.value) + parseFloat(f.FLASH_extra_bandwidth_price.value) + parseFloat(f.FLASH_extra_streams_price.value) + parseFloat(f.FLASH_extra_storage_price.value)).toFixed(2);
	f.FLASH_base_price.value            = '$' + f.FLASH_base_price.value;
	f.FLASH_extra_bandwidth_price.value = '$' + (f.FLASH_extra_bandwidth_price.value).toFixed(2);
	f.FLASH_extra_streams_price.value   = '$' + f.FLASH_extra_streams_price.value;
	f.FLASH_extra_storage_price.value   = '$' + f.FLASH_extra_storage_price.value;

	f.WM_normal_bandwidth_price.value = '$' + (WINDOWS_price_per_unit * Math.ceil(bitrate * streams / WINDOWS_unit_Kbps_normal)).toFixed(2);

	if (hours <= 25) {
		ShowSpecialPricing();
		f.WM_church_bandwidth_price.value = '$' + (WINDOWS_price_per_unit * Math.ceil(bitrate * streams / WINDOWS_unit_Kbps_church)).toFixed(2);
	} else {
		HideSpecialPricing();
	}

}

function Commify(nStg) {
	nStg += '';
	i = nStg.split('.');
	j = i[0];
	k = i.length > 1 ? '.' + i[1] : '';
	var regExp = /(\d+)(\d{3})/;
	while (regExp.test(j)) {
		j = j.replace(regExp, '$1' + ',' + '$2');
	}
	return j + k;
}

function RoundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function ShowSpecialPricing() {
	document.getElementById("churchprice").innerHTML =
		'- or -<br />' +
		'<input type="text" name="WM_church_bandwidth_price" size="6" class="costs">' +
		' ($9.95 per 3,072Kbps)<br>' + 
		'<div class="specialrate">' + 
		'<b>SPECIAL RATE!  To qualify, you must:</b><br><ol>' + 
		'<li>be a church</li>' +
		'<li>stream 25 hours or less per month</li>' +
		'<li>stream only live events from the church</li>' +
		'</ol></div>';
}

function HideSpecialPricing() {
	document.getElementById("churchprice").innerHTML = '';
}

