
var Freq, Vel_Factor;

//**************************************************************************
//**************************************************************************

function setCellBgColor (tableId, rowIndex, cellIndex, bgColor) {
  if (document.layers)
    document[tableId + 'Row' + rowIndex + 'Cell' + cellIndex].bgColor = bgColor;
  else if (document.all)
    document.all[tableId].rows[rowIndex].cells[cellIndex].style.backgroundColor = bgColor;
  else if (document.getElementById)
    document.getElementById(tableId).rows[rowIndex].cells[cellIndex].style.backgroundColor = bgColor;
}

//**************************************************************************
// See which type of coaxial cable is selected.
//**************************************************************************

function Get_Coax_Checked() {

   if ( document.yagi_feed.Coax_Type_1.checked == 1 ) { Set_Coax_Checkbox( "RG-59", 0.66 ) }
   else if ( document.yagi_feed.Coax_Type_2.checked == 1 ) { Set_Coax_Checkbox( "RG-59/U Foam", 0.79 ) }
   else if ( document.yagi_feed.Coax_Type_3.checked == 1 ) { Set_Coax_Checkbox( "RG-11/U", 0.66 ) }
   else if ( document.yagi_feed.Coax_Type_4.checked == 1 ) { Set_Coax_Checkbox( "RG-11/U Foam", 0.80 ) }
   else if ( document.yagi_feed.Coax_Type_5.checked == 1 ) { Set_Coax_Checkbox( "RG-6", 0.75 ) }
   else if ( document.yagi_feed.Coax_Type_6.checked == 1 ) { Set_Coax_Checkbox( "RG-58", 0.66 ) }
   else if ( document.yagi_feed.Coax_Type_7.checked == 1 ) { Set_Coax_Checkbox( "RG-8", 0.66 ) }
   else if ( document.yagi_feed.Coax_Type_8.checked == 1 ) { Set_Coax_Checkbox( "RG-8x", 0.78 ) }
   else if ( document.yagi_feed.Coax_Type_9.checked == 1 ) { Set_Coax_Checkbox( "RG-8/U Foam", 0.80 ) }
   else if ( document.yagi_feed.Coax_Type_10.checked == 1 ) { Set_Coax_Checkbox( "RG-213", 0.66 ) }
}

//**************************************************************************
// When one box is checked, turn off all the other boxes.
//**************************************************************************

function Set_Coax_Checkbox( Box_Name, Vel_Factor ) {

   if ( Box_Name == "RG-59" ) {
      document.yagi_feed.Coax_Type_1.checked = 1;
      setCellBgColor ("coax_select", 1, 0, "#fff2d2");
      setCellBgColor ("coax_select", 1, 1, "#fff2d2");
      setCellBgColor ("coax_select", 1, 2, "#fff2d2");
      setCellBgColor ("coax_select", 1, 3, "#fff2d2");
      }
   else {
      document.yagi_feed.Coax_Type_1.checked = 0;
      setCellBgColor ("coax_select", 1, 0, '');
      setCellBgColor ("coax_select", 1, 1, '');
      setCellBgColor ("coax_select", 1, 2, '');
      setCellBgColor ("coax_select", 1, 3, '');
      }

   if ( Box_Name == "RG-59/U Foam" ) {
      setCellBgColor ("coax_select", 2, 0, "#fff2d2");
      setCellBgColor ("coax_select", 2, 1, "#fff2d2");
      setCellBgColor ("coax_select", 2, 2, "#fff2d2");
      setCellBgColor ("coax_select", 2, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_2.checked = 1;
      }
   else {
      document.yagi_feed.Coax_Type_2.checked = 0;
      setCellBgColor ("coax_select", 2, 0, '');
      setCellBgColor ("coax_select", 2, 1, '');
      setCellBgColor ("coax_select", 2, 2, '');
      setCellBgColor ("coax_select", 2, 3, '');
      }

   if ( Box_Name == "RG-11/U" ) {
      setCellBgColor ("coax_select", 3, 0, "#fff2d2");
      setCellBgColor ("coax_select", 3, 1, "#fff2d2");
      setCellBgColor ("coax_select", 3, 2, "#fff2d2");
      setCellBgColor ("coax_select", 3, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_3.checked = 1;
      }
   else {
      document.yagi_feed.Coax_Type_3.checked = 0;
      setCellBgColor ("coax_select", 3, 0, '');
      setCellBgColor ("coax_select", 3, 1, '');
      setCellBgColor ("coax_select", 3, 2, '');
      setCellBgColor ("coax_select", 3, 3, '');
      }

   if ( Box_Name == "RG-11/U Foam" ) {
      setCellBgColor ("coax_select", 4, 0, "#fff2d2");
      setCellBgColor ("coax_select", 4, 1, "#fff2d2");
      setCellBgColor ("coax_select", 4, 2, "#fff2d2");
      setCellBgColor ("coax_select", 4, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_4.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 4, 0, '');
      setCellBgColor ("coax_select", 4, 1, '');
      setCellBgColor ("coax_select", 4, 2, '');
      setCellBgColor ("coax_select", 4, 3, '');
      document.yagi_feed.Coax_Type_4.checked = 0;
      }

   if ( Box_Name == "RG-6" ) {
      setCellBgColor ("coax_select", 5, 0, "#fff2d2");
      setCellBgColor ("coax_select", 5, 1, "#fff2d2");
      setCellBgColor ("coax_select", 5, 2, "#fff2d2");
      setCellBgColor ("coax_select", 5, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_5.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 5, 0, '');
      setCellBgColor ("coax_select", 5, 1, '');
      setCellBgColor ("coax_select", 5, 2, '');
      setCellBgColor ("coax_select", 5, 3, '');
      document.yagi_feed.Coax_Type_5.checked = 0;
      }

   if ( Box_Name == "RG-58" ) {
      setCellBgColor ("coax_select", 6, 0, "#fff2d2");
      setCellBgColor ("coax_select", 6, 1, "#fff2d2");
      setCellBgColor ("coax_select", 6, 2, "#fff2d2");
      setCellBgColor ("coax_select", 6, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_6.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 6, 0, '');
      setCellBgColor ("coax_select", 6, 1, '');
      setCellBgColor ("coax_select", 6, 2, '');
      setCellBgColor ("coax_select", 6, 3, '');
      document.yagi_feed.Coax_Type_6.checked = 0;
      }

   if ( Box_Name == "RG-8" ) {
      setCellBgColor ("coax_select", 7, 0, "#fff2d2");
      setCellBgColor ("coax_select", 7, 1, "#fff2d2");
      setCellBgColor ("coax_select", 7, 2, "#fff2d2");
      setCellBgColor ("coax_select", 7, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_7.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 7, 0, '');
      setCellBgColor ("coax_select", 7, 1, '');
      setCellBgColor ("coax_select", 7, 2, '');
      setCellBgColor ("coax_select", 7, 3, '');
      document.yagi_feed.Coax_Type_7.checked = 0;
      }

   if ( Box_Name == "RG-8x" ) {
      setCellBgColor ("coax_select", 8, 0, "#fff2d2");
      setCellBgColor ("coax_select", 8, 1, "#fff2d2");
      setCellBgColor ("coax_select", 8, 2, "#fff2d2");
      setCellBgColor ("coax_select", 8, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_8.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 8, 0, '');
      setCellBgColor ("coax_select", 8, 1, '');
      setCellBgColor ("coax_select", 8, 2, '');
      setCellBgColor ("coax_select", 8, 3, '');
      document.yagi_feed.Coax_Type_8.checked = 0;
      }

   if ( Box_Name == "RG-8/U Foam" ) {
      setCellBgColor ("coax_select", 9, 0, "#fff2d2");
      setCellBgColor ("coax_select", 9, 1, "#fff2d2");
      setCellBgColor ("coax_select", 9, 2, "#fff2d2");
      setCellBgColor ("coax_select", 9, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_9.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 9, 0, '');
      setCellBgColor ("coax_select", 9, 1, '');
      setCellBgColor ("coax_select", 9, 2, '');
      setCellBgColor ("coax_select", 9, 3, '');
      document.yagi_feed.Coax_Type_9.checked = 0;
      }

   if ( Box_Name == "RG-213" ) {
      setCellBgColor ("coax_select", 10, 0, "#fff2d2");
      setCellBgColor ("coax_select", 10, 1, "#fff2d2");
      setCellBgColor ("coax_select", 10, 2, "#fff2d2");
      setCellBgColor ("coax_select", 10, 3, "#fff2d2");
      document.yagi_feed.Coax_Type_10.checked = 1;
      }
   else {
      setCellBgColor ("coax_select", 10, 0, '');
      setCellBgColor ("coax_select", 10, 1, '');
      setCellBgColor ("coax_select", 10, 2, '');
      setCellBgColor ("coax_select", 10, 3, '');
      document.yagi_feed.Coax_Type_10.checked = 0;
      }

   Calc_Coax_Length( Box_Name, parseFloat(Vel_Factor) );
}

//**************************************************************************
// Calculate the required length of coax and print everything out.
//**************************************************************************

function Calc_Coax_Length( Coax_Type, Vel_Factor ) {

   Freq = parseFloat(document.yagi_feed.Des_Freq.value);
   Coax_Loop_Data = "Operating Frequency = " + Freq + " MHz\n";
   Coax_Loop_Data += "Cable Type = " + Coax_Type + "\n";

// 491.8/f

//   Length_US = ( 468/Freq ) * parseFloat(Vel_Factor);
//   Length_Metric = ( 143/Freq ) * parseFloat(Vel_Factor);
   Length_US = ( 491.8/Freq ) * parseFloat(Vel_Factor);
   Length_Metric = Length_US *12 * 25.4;
   Coax_Loop_Data += "Velocity Factor = " + Vel_Factor + "\n\n";

   Coax_Loop_Data += "1/2 Wavelength\nPhasing Section (L)\n";
   if ( Length_Metric <= 1000 ) {
      Coax_Loop_Data += DFTtoFTIN( Length_US,1,32 ) + " (" + Rnd(Length_Metric/10,1) + " CM)\n"; }
//      Coax_Loop_Data += DFTtoFTIN( Length_US,1,32 ) + " (" + Rnd(Length_Metric*100,1) + " CM)\n"; }
   else {
      Coax_Loop_Data += DFTtoFTIN( Length_US,1,32 ) + " (" + Rnd(Length_Metric/1000,3) + " Meters)\n"; }
//      Coax_Loop_Data += DFTtoFTIN( Length_US,1,32 ) + " (" + Rnd(Length_Metric,3) + " Meters)\n"; }

//   Coax_Loop_Data += "1/2 Wavelength Phasing Section = " + Length + "\n";
   document.yagi_feed.Coax_Loop_Data.value = Coax_Loop_Data;

}

