//Scripts ©2001 Charles Houghton-Webb
var BtnArray=new Array();
var BitDepth=16;SmplRt=44100;Tracks=1;RecTim=60;spaceUnit=1000000;oldspaceUnit=1000000;
var bytes=2; FixWot="time";DskSpc=5290000;timeUnit=60;oldtimeUnit=60;TransRt=0.09;
//
function Opener(){	
BitDepth=16;SmplRt=44100;Tracks=1;RecTim=60;spaceUnit=1000000;
bytes=2;DskSpc=5290000;timeUnit=60;oldtimeUnit=60;oldspaceUnit=1000000;
document.Calc.Status.readOnly = true;
document.Calc.BytesTxt.readOnly = true;
document.Calc.TransferRate.readOnly = true;
document.Calc.TimeUnits.readOnly = true;
document.Calc.RecordingTime.readOnly = false;
document.Calc.DiskSpace.readOnly = true;
}
//
function BitsHandler(){
a=document.Calc.Bits.selectedIndex;
BitDepth=eval(document.Calc.Bits.options[a].value);
bytes=Math.ceil(BitDepth/8);
var pl=")";
if (bytes!=1) pl="s)";
document.Calc.BytesTxt.value="(occupies " + String(bytes) + " byte" + pl;
if (FixWot=="time") CalcDiskSpace(); else CalcRecTime();
CalcTransRt();
}
//
function CalcDiskSpace(){
if (FixWot=="space") return;
DskSpc=(bytes*SmplRt*Tracks*RecTim);
DisplayDiskSpace();
Summary();
}
//
function CalcRecTime(){
if (FixWot=="time") return;
RecTim=(DskSpc)/(bytes*SmplRt*Tracks);
if (RecTim>3599){
	timeUnit=3600;
	document.Calc.TimeUnits.options[2].selected=true;}
else if  (RecTim>59){
	timeUnit=60;
	document.Calc.TimeUnits.options[1].selected=true;}
else {
	timeUnit=1;
	document.Calc.TimeUnits.options[0].selected=true;
}
RecTimDisp = (Math.round(RecTim*100/timeUnit))/100;
document.Calc.RecordingTime.value=RecTimDisp;
oldtimeUnit=timeUnit;
Summary();
}
//
function CalcTransRt(){
  TransRt=bytes*SmplRt*Tracks/1000000;
  TransRt = (Math.round(TransRt*100))/100;
  document.Calc.TransferRate.value=TransRt;
}
//
function DisplayDiskSpace(){
var theunits=0;
if(DskSpc>=1000000){theunits=1};
if(DskSpc>=1000000000){theunits=2};
if(DskSpc>=1000000000000){theunits=3};
if(DskSpc>=1000000000000000){theunits=4};
spaceUnit=1000* Math.pow(1000,theunits);
document.Calc.SpaceUnits.options[theunits].selected=true;
document.Calc.DiskSpace.value=(Math.round(DskSpc*1000/spaceUnit))/1000;
}
//
function fixIt(n){
FixWot=n;
if (n=="time") {document.Calc.reset();
eval(docstr+"tstar").src=PicArray[5].src;
eval(docstr+"sstar").src=PicArray[4].src;
Opener();
}else {
document.Calc.RecordingTime.readOnly = true;
document.Calc.DiskSpace.readOnly = false;
eval(docstr+"tstar").src=PicArray[4].src;
eval(docstr+"sstar").src=PicArray[5].src;
}
Summary();
}
//
function IsNumber(num,mini,maxi){
	if(num<mini||num>maxi||isNaN(num)){
	alert("I need a number between " + mini + " and " + maxi + " here!");
	return false;
	} else {return true;}
}
//
function RatesHandler(){
a=document.Calc.Rates.selectedIndex;
SmplRt=eval(document.Calc.Rates.options[a].value);
if (FixWot=="time") CalcDiskSpace(); else CalcRecTime();
CalcTransRt();
}
//
function SpaceHandler(){
if (FixWot=="time") {	
	document.Calc.DiskSpace.value=DskSpc/spaceUnit;
	alert("You cannot change the disk size - it is calculated automatically since the recording time is fixed");
	} else {
	r=document.Calc.DiskSpace.value;
	if (IsNumber(r,1,999)){DskSpc=r*spaceUnit;} else {document.Calc.DiskSpace.value=DskSpc/spaceUnit;}
	}
CalcRecTime();
Summary();
}
//
function SpaceUnitHandler(){
a=document.Calc.SpaceUnits.selectedIndex;
spaceUnit=eval(document.Calc.SpaceUnits.options[a].value);
if (FixWot=="time") {
	if (spaceUnit!=oldspaceUnit){
	b=3*(oldspaceUnit==1000000000000)+2*(oldspaceUnit==1000000000)+1*(oldspaceUnit==1000000);
	document.Calc.SpaceUnits.options[b].selected=true;
	spaceUnit=oldspaceUnit;
	alert("You cannot change the disk size units - they are calculated automatically since the recording time is fixed");		
	}
	return;
}
oldspaceUnit=spaceUnit;
DskSpc=document.Calc.DiskSpace.value*spaceUnit;
CalcRecTime();
}
//
function Summary(){
var fxd=" Recording time is fixed.";
if (FixWot=="space") fxd=" Disk space is fixed.";
  	var sec = (Math.round(RecTim*100+1))/100;
  	var mnt = Math.floor(sec/60);
  	sec = (Math.round(sec - mnt*60));
  	var hrs = Math.floor(mnt/60);
  	mnt = mnt - (hrs*60);
	var dys = Math.floor(hrs/24);
  	hrs = hrs - (dys*24);
	var daystr=""; if (dys==1) daystr=String(dys) + " day, ";
		else if (dys>1) daystr=String(dys) + " days, ";
	var hrstr=""; if (hrs==1) hrstr=String(hrs) + " hour, ";
		else if (hrs>1) hrstr=String(hrs) + " hours, ";		
	var mnstr=""; if (mnt==1) mnstr=String(mnt) + " min, ";
		else if (mnt>1) mnstr=String(mnt) + " mins, ";		
	var secstr=""; if (sec==1) secstr=String(sec) + " sec";
		else if (sec>1) secstr=String(sec) + " secs";			
 document.Calc.Status.value=daystr+hrstr+mnstr+secstr+fxd;
}
//
function TimeHandler(){
if (FixWot=="space") {
	document.Calc.RecordingTime.value=RecTim/timeUnit;
	alert("You cannot change the time - it is calculated automatically since the disk space is fixed");
	} else {
	r=document.Calc.RecordingTime.value
		if (IsNumber(r,1,999)){RecTim=r*timeUnit;} else {document.Calc.RecordingTime.value=RecTim/timeUnit;}
	}
CalcDiskSpace();
CalcTransRt();
}
//
function TimeUnitHandler(){
a=document.Calc.TimeUnits.selectedIndex;
timeUnit=eval(document.Calc.TimeUnits.options[a].value);
if (FixWot=="space") {
	if (timeUnit!=oldtimeUnit){
	b=3*(oldtimeUnit==86400)+2*(oldtimeUnit==3600)+1*(oldtimeUnit==60);
	document.Calc.TimeUnits.options[b].selected=true;
	timeUnit=oldtimeUnit;
	alert("You cannot change the time units - they are calculated automatically since the disk space is fixed");
	} return;
	}
oldtimeunit=timeUnit;
RecTim=document.Calc.RecordingTime.value*timeUnit;
CalcDiskSpace();
}
//
function TracksHandler(){
Tracks=document.Calc.NumberOfTracks.value;
if (FixWot=="time") CalcDiskSpace(); else CalcRecTime();
CalcTransRt();
//alert("OK!  " + Tracks + "  FixWot=" + FixWot);
return;
}
//
function Ooops(){
document.Calc.TransferRate.value = TransRt;
alert("You cannot change the transfer rate - it is calculated automatically");
}