var timesRun = 0;
var valArray = new Array();
function the_bitrate(bitrate){
	document.calc.final_rate.value = bitrate;
}
function FIXER(mbVal){
	var kbVal = mbVal * 1024;
	return kbVal;
}
function calculate(){
	var x = document.calc.final_rate.value;
	if (x == ''){
		alert('Need MPEG Bit Rate, Try Again Please');
		return 0;
	}
	var y = document.calc.record_time.value;
	var content_type =  document.calc.record_time_unit.options[document.calc.record_time_unit.selectedIndex].value
	if (content_type == "hrs"){
		y = y * 60 * 60;
	} else if (content_type == "min"){
		y = y * 60;
	}
	if (y == ''){
		alert('Need Recording Time');
		return 0;
	}
	var size = (((x / 8) * y) / 1024);
	var sizek = (((x / 8) * y) );
	var sizeg = (((x / 8) * y) / 1024 / 1024);
	
	valArray[timesRun] = size;
	valArray[timesRun] = sizek;
	valArray[timesRun] = sizeg;
	timesRun++;
	document.calc.txt_result.value = size.toFixed(3);
	document.calc.txt_resultkb.value = sizek.toFixed(3);
	document.calc.txt_resultgb.value = sizeg.toFixed(3);
}

function calculatestream()
{
	var totalminutes = document.calc.viewers.value * document.calc.viewduration.value
	document.calc.totalminutes.value = totalminutes
	var bytespersecond =  (document.calc.final_rate.value / 8) 
	var bandwidthk=totalminutes * (bytespersecond * 60) 
	var bandwidthm=totalminutes * (bytespersecond * 60) / 1024
	var bandwidthg=totalminutes * (bytespersecond * 60) / 1024 / 1024 	
	document.calc.streambandwidthkb.value = bandwidthk.toFixed(3);
	document.calc.streambandwidthmb.value = bandwidthm.toFixed(3);
	document.calc.streambandwidthg.value = bandwidthg.toFixed(3);
	var mycost1 = 3.75 * document.calc.streambandwidthg.value
	document.calc.cost1.value = "$" + mycost1.toFixed(2);
	var mycost2 = 1.75 * document.calc.streambandwidthg.value
	document.calc.cost2.value = "$" + mycost2.toFixed(2);
	var mycost3 = 1.5 * document.calc.streambandwidthg.value
	document.calc.cost3.value = "$" + mycost3.toFixed(2);
	var mycost4 = 0.8 * document.calc.streambandwidthg.value
	document.calc.cost4.value = "$" + mycost4.toFixed(2);
	var mycost5 = 0.7 * document.calc.streambandwidthg.value
	document.calc.cost5.value = "$" + mycost5.toFixed(2);
	var mycost6 = 0.6 * document.calc.streambandwidthg.value
	document.calc.cost6.value = "$" + mycost6.toFixed(2);
	var mycost7 = 0.5 * document.calc.streambandwidthg.value
	document.calc.cost7.value = "$" + mycost7.toFixed(2);
	document.calc.perviewer1.value="$" + (mycost1/document.calc.viewers.value).toFixed(3);
	document.calc.perviewer2.value="$" + (mycost2/document.calc.viewers.value).toFixed(3);
	document.calc.perviewer3.value="$" + (mycost3/document.calc.viewers.value).toFixed(3);
	document.calc.perviewer4.value="$" + (mycost4/document.calc.viewers.value).toFixed(3);
	document.calc.perviewer5.value="$" + (mycost5/document.calc.viewers.value).toFixed(3);
	document.calc.perviewer6.value="$" + (mycost6/document.calc.viewers.value).toFixed(3);
	document.calc.perviewer7.value="$" + (mycost7/document.calc.viewers.value).toFixed(3);
	document.calc.balance1.value=(375/mycost1).toFixed(1);
	document.calc.balance2.value=(875/mycost2).toFixed(1);
	document.calc.balance3.value=(1500/mycost3).toFixed(1);
	document.calc.balance4.value=(4000/mycost4).toFixed(1);
	document.calc.balance5.value=(7000/mycost5).toFixed(1);
	document.calc.balance6.value=(30000/mycost6).toFixed(1);
	document.calc.balance7.value=(50000/mycost7).toFixed(1);
	if (document.calc.balance1.value < 1) {document.calc.cost1.value="N/A"; document.calc.perviewer1.value="N/A"; document.calc.balance1.value="N/A"};
	if (document.calc.balance2.value < 1) {document.calc.cost2.value="N/A"; document.calc.perviewer2.value="N/A"; document.calc.balance2.value="N/A"};
	if (document.calc.balance3.value < 1) {document.calc.cost3.value="N/A"; document.calc.perviewer3.value="N/A"; document.calc.balance3.value="N/A"};
	if (document.calc.balance4.value < 1) {document.calc.cost4.value="N/A"; document.calc.perviewer4.value="N/A"; document.calc.balance4.value="N/A"};	
	if (document.calc.balance5.value < 1) {document.calc.cost5.value="N/A"; document.calc.perviewer5.value="N/A"; document.calc.balance5.value="N/A"};
	if (document.calc.balance6.value < 1) {document.calc.cost6.value="N/A"; document.calc.perviewer6.value="N/A"; document.calc.balance6.value="N/A"};	
	if (document.calc.balance7.value < 1) {document.calc.cost7.value="N/A"; document.calc.perviewer7.value="N/A"; document.calc.balance7.value="N/A"};
	
}


