

<!-- Begin
function Starth(page) {
OpenWin = this.open(page, "CtrlWindow5", "toolbar=no,menubar=no,location=no,scrollbars=no,resize=no,width=392,height=400");
}
// End -->





var SelIdx = 0;
var MaxFrames = 0;
var FileSize = 0;
var RecordRate = 0;
var RoundedDiskSizeInBytes = 0.0;
var TotalSecs = 0;
var SelectedOption = 3;

function FillFrameRateList()
{
		var i = 0;
		var strTitle = "";

		// Get selected index
		SelIdx = document.frmDisplay.cboNumOfFrames.options[document.frmDisplay.cboNumOfFrames.selectedIndex].value -1;

		for(i=0 ; i < document.frmDisplay.cboNumOfFrames.options.length ; i++)
		{
					document.frmDisplay.cboNumOfFrames.options[0].value= "";
					document.frmDisplay.cboNumOfFrames.options[0]= null;
		}

		//		MaxFrames = document.frmDisplay.cboVideoStandard.options[document.frmDisplay.cboVideoStandard.selectedIndex].value;
		MaxFrames = 120;

		for(i=1 ; i <= MaxFrames; i++)
		{
				strTitle = i.toString();
				document.frmDisplay.cboNumOfFrames.options[i-1] = new Option(strTitle, i);	
		}

		if(SelIdx > MaxFrames - 1)
		{
				SelIdx = MaxFrames - 1;
		}

		document.frmDisplay.cboNumOfFrames.options[SelIdx].selected = true;

}

// ################################# Clear functions #####################################

function ClearFrames()
{
		//document.frmDisplay.cboNumOfFrames.options[0].selected = true;
}

function ClearDiskSize()
{
		//document.frmDisplay.cboDiskSize.options[0].selected = true;				
}

function ClearFileSize()
{
		//document.frmDisplay.txtFileSize.value = "";
}


function ClearTime()
{
				document.frmDisplay.txtHours.value = "";
				document.frmDisplay.txtMins.value = "";
}


// ################################# Get values and convert to correct units #####################################

function GetFrame()
{
			RecordRate = parseInt(document.frmDisplay.cboNumOfFrames.options[document.frmDisplay.cboNumOfFrames.selectedIndex].value, 10);
			//alert('GetFrame() reports RecordRate = ' + RecordRate);
			return true;
}

function GetFilesize()
{
			FileSize = parseInt(document.frmDisplay.cboFileSize.options[document.frmDisplay.cboFileSize.selectedIndex].value, 10);

			FileSize *= 1024;

			//alert('GetFilesize() reports FileSize = ' + FileSize);

			return true;
}


function GetDisksize()
{
			var TempDiskSize    = 0.0;
			var DiskSizeInBytes = 0.0;

			TempDiskSize  = parseInt(document.frmDisplay.cboDiskSize.options[document.frmDisplay.cboDiskSize.selectedIndex].value, 10);
			
			if(isNaN(TempDiskSize))
			{
						alert('You must enter a numeric disk size specified in Gigabytes');
						document.frmDisplay.cboDiskSize.focus();
						return false;
			}


			TempDiskSize *= 1000000000;

			DiskSizeInBytes = (TempDiskSize - 1024 * 1024 * 1024);
			
			RoundedDiskSizeInBytes = DiskSizeInBytes - DiskSizeInBytes % 10000000;

			//alert('GetDisksize() reports RoundedDiskSizeInBytes = ' + RoundedDiskSizeInBytes);

			return true;
}


function GetTime()
{
			var TotalMins = 0;
			var Days = 0;
			var Hours = 0;
			var Mins = 0;

			if(document.frmDisplay.txtDays.value == "")
			{
						alert('You must enter a time value');
						document.frmDisplay.txtDays.focus();
						return false;
			}

			if(document.frmDisplay.txtDays.value != "" && document.frmDisplay.txtHours.value == "")
			{
						document.frmDisplay.txtHours.value = "00";
			}

			Days = parseInt(document.frmDisplay.txtDays.value, 10);
			Hours = parseInt(document.frmDisplay.txtHours.value, 10);			
			//Mins = parseInt(document.frmDisplay.txtMins.value, 10);			

			if(Hours < 0)
			{
						Hours = 0;
						document.frmDisplay.txtHours.value = "00";
			}

			if(Hours > 23)
			{
						Hours = 23;
						document.frmDisplay.txtHours.value = "23";
			}
			
   //alert('Days = ' + Days);
   //alert('Hours = ' + Hours);
   //alert('Mins = ' + Mins);

			TotalMins = (Days * 24 * 60) + (Hours * 60) + Mins;
			TotalSecs = TotalMins * 60;

			return true;

}

// ################################# Calculate new values #####################################

function CalculateRecordRate()
{
			var NewFrameRate = 0;

   //alert('Calculating Record Rate');			
			NewFrameRate = RoundedDiskSizeInBytes / (FileSize * TotalSecs);

			NewFrameRate = Math.floor(NewFrameRate);
						
   		if(NewFrameRate > MaxFrames)
			   NewFrameRate = MaxFrames;
			
			
			if(NewFrameRate < 1)
			{
				alert('With the current settings the Record Rate would be less than 1Pic/s which is not supported.\n\nTry reducing the Image size or using a larger hard disk');
				NewFrameRate = 1;
			}

			document.frmDisplay.cboNumOfFrames.options[NewFrameRate-1].selected = true;
}

function CalculateFilesize()
{
			var Temp1 = 0;


			//alert('Calculating File Size');

			Temp1  = RoundedDiskSizeInBytes / (TotalSecs * RecordRate);
			Temp1 /= 1000;							// Convert to KB


			Temp1 = Math.floor(Temp1);

			//alert('Filesize = ' + Temp1);
			//alert('Rounded Filesize = ' + Temp1);

			if(Temp1 < 6)
			{
						alert('With the current settings the Image Size would be less than 6KB which is not supported.\n\n Try reducing the Recording Time or Record Rate');
						return;
			}

			if(Temp1 > 45)
			{
						alert('With the current settings the Image Size would be greater than 45KB which is not supported.\n\n Try increasing the Recording Time or Record Rate');
						Temp1 = 45;
   		}
		

			document.frmDisplay.cboFileSize.options[Temp1-6].selected = true;	
}

function CalculateDisksize()
{
			var Temp1 = 0;

			//alert('Calculating Disk Size');

			//alert('Record Rate = ' + RecordRate);
			//alert('Total Secs = ' + TotalSecs);
			//alert('FileSize = ' + FileSize);


			Temp1  = RecordRate * TotalSecs * FileSize;
			Temp1 += 1024 * 1024 * 1024;					// Add on space for DOS partition
			Temp1 /= 1000000000;							// Convert to GB

			//alert('DiskSize = ' + Temp1);
			//alert('Rounded DiskSize = ' + Math.ceil(Temp1));

			ProposedDiskSize = Math.ceil(Temp1);

			if(ProposedDiskSize > 320)
			{
				//alert('Raid required');

				if(ProposedDiskSize > (2250 + 320))
				{
					alert('This requires ' + ProposedDiskSize + ' GB of storage which is not supported at present');
					return;
				}

				RaidListIndex = 29;
				ProposedRaidSize = 2250;
				if(ProposedDiskSize <= 2250) 
				{
					ProposedRaidSize = 2175;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 2175) 
				{
					ProposedRaidSize = 2100;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 2100) 
				{
					ProposedRaidSize = 2025;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 2025) 
				{
					ProposedRaidSize = 1950;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1950) 
				{
					ProposedRaidSize = 1875;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1875) 
				{
					ProposedRaidSize = 1800;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1800) 
				{
					ProposedRaidSize = 1725;
					RaidListIndex--;  
				}		
				if(ProposedDiskSize <= 1725) 
				{
					ProposedRaidSize = 1650;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1650) 
				{
					ProposedRaidSize = 1575;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1575) 
				{
					ProposedRaidSize = 1500;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1500) 
				{
					ProposedRaidSize = 1425;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1425) 
				{
					ProposedRaidSize = 1350;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1350) 
				{
					ProposedRaidSize = 1275;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1275) 
				{
					ProposedRaidSize = 1200;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1200) 
				{
					ProposedRaidSize = 1125;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1125) 
				{
					ProposedRaidSize = 1050;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 1050) 
				{
					ProposedRaidSize = 975;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 975) 
				{
					ProposedRaidSize = 900;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 900) 
				{
					ProposedRaidSize = 825;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 825) 
				{
					ProposedRaidSize = 750;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 750) 
				{
					ProposedRaidSize = 675;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 675) 
				{
					ProposedRaidSize = 600;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 600) 
				{
					ProposedRaidSize = 525;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 525) 
				{
					ProposedRaidSize = 450;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 450) 
				{
					ProposedRaidSize = 375;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 375) 
				{
					ProposedRaidSize = 300;
					RaidListIndex--;  
				}
				if(ProposedDiskSize <= 300)
				{
					ProposedRaidSize = 225;
					RaidListIndex--;  
				}


				ProposedDiskSize -= ProposedRaidSize;

				ListIndex = 3;
				if(ProposedDiskSize <= 120) ListIndex--; 
				if(ProposedDiskSize <= 80) ListIndex--;   
				if(ProposedDiskSize <= 40) ListIndex--;   


				
				//alert('ListIndex = ' + ListIndex);
				//alert('RaidListIndex = ' + RaidListIndex);

				document.frmDisplay.cboDiskSize.options[ListIndex].selected = true;	
		


				
			}
			else
			{
				ListIndex = 3;
				if(ProposedDiskSize <= 120) ListIndex--; 
				if(ProposedDiskSize <= 80) ListIndex--;  
				if(ProposedDiskSize <= 40) ListIndex--; 
				
				// alert('ListIndex = ' + ListIndex);

				document.frmDisplay.cboDiskSize.options[ListIndex].selected = true;	
		
				
			}






}

function CalculateRecordTime()
{
						//alert('Calculating Time');

						//alert('Disk space = ' + RoundedDiskSizeInBytes);
						//alert('FileSize   = ' + FileSize);
						//alert('RecordRate = ' + RecordRate);

						var SizeByFrames = 0;
						SizeByFrames = FileSize * RecordRate;
						
						//alert('SizeByFrames = ' + SizeByFrames);
						RecTime = (RoundedDiskSizeInBytes / SizeByFrames);
						RecTime -= RecTime % 1;						

						//alert('TimeRoundedToSecs = ' + RecTime);

						if(RecTime > 0)
						{
							TempDays = RecTime / (3600 * 24);
							TempDays = TempDays - (RecTime % RecTime);
							
							DaysRemain = (RecTime % (3600 * 24));
							TempHours = DaysRemain / 3600;
							TempHours = TempHours - (RecTime % RecTime);


					   		HoursRemain  = (RecTime % 3600);
							TempMins  = (HoursRemain / 60);


							TempDays = Math.floor(TempDays);
							TempHours = Math.floor(TempHours);
							TempMins = Math.floor(TempMins);

							document.frmDisplay.txtDays.value = TempDays;
							document.frmDisplay.txtHours.value = TempHours;
							document.frmDisplay.txtMins.value  = TempMins;
						}
						else
						{
							document.frmDisplay.txtDays.value = "00";
							document.frmDisplay.txtHours.value = "00";
							document.frmDisplay.txtMins.value  = "00";
						}
}


// ###################################### Value changed functions



function FramesChanged()
{
		RequestSelectedOption();
		if(SelectedOption != 0)
					ProcessIt();
}

function DiskSizeChanged()
{
		RequestSelectedOption();
		if(SelectedOption != 3)
					ProcessIt();
}

function FileSizeChanged()
{
		RequestSelectedOption();
		if(SelectedOption != 1)
					ProcessIt();
}

function TimeChanged()
{
  RequestSelectedOption();
		if(SelectedOption != 2)
					ProcessIt();
}


function RequestSelectedOption()
{
   for(i = 0; i < document.frmDisplay.optCalculate.length ; i++)
   {
		   if(document.frmDisplay.optCalculate[i].checked)
					   break;
   }

			SelectedOption = i;
}

function ProcessIt()
{

			RequestSelectedOption();
			
			switch(SelectedOption)
			{
						case 0:
														ClearFrames();
														if(!GetDisksize()) return;
														if(!GetFilesize()) return;
														if(!GetTime()) return;
														CalculateRecordRate();
														break;
						case 1:
														ClearFileSize();
														if(!GetFrame()) return;
														if(!GetDisksize()) return;
														if(!GetTime()) return;
														CalculateFilesize();
														break;
						case 2:
														ClearTime();
														if(!GetFrame()) return;
														if(!GetDisksize()) return;
														if(!GetFilesize()) return;
														CalculateRecordTime();
														break;

						case 3:
														ClearDiskSize();
														if(!GetFrame()) return;
														if(!GetFilesize()) return;
														if(!GetTime()) return;
														CalculateDisksize();
														break;

						default:
														ClearTime();
														if(!GetFrame()) return;
														if(!GetDisksize()) return;
														if(!GetFilesize()) return;
														CalculateRecordTime();
														break;
			}

   return;

}

function Initialise()
{
		FillFrameRateList();
		ProcessIt();
}



