// JavaScript Document

// Selector control :

var D_Opt = new Array() // 29..31
var D_Optb = new Array() // 29..31

function MonLen(Yr, Mo, Dy) { var Dol, K, DiM, NsI
  DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text, Mo.selectedIndex+1)
  Dol = Dy.options.length
  if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1
// for (K=Dol   ; K >DiM ; K--) Dy.options[K-1] = null          // shrink
// for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = new Option(K) // or grow
  for (K=Dol   ; K >DiM ; K--)
    { D_Opt[K] = Dy.options[K-1] ; Dy.options[K-1] = null } // shrink
  for (K=Dol+1 ; K<=DiM ; K++)   Dy.options[K-1] = D_Opt[K] // or grow
  Dy.selectedIndex = NsI }
  
 function MonLenb(Yr, Mo, Dy) { var Dol, K, DiM, NsI
  DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text, Mo.selectedIndex+1)
  Dol = Dy.options.length
  if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1
// for (K=Dol   ; K >DiM ; K--) Dy.options[K-1] = null          // shrink
// for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = new Option(K) // or grow
  for (K=Dol   ; K >DiM ; K--)
    { D_Optb[K] = Dy.options[K-1] ; Dy.options[K-1] = null } // shrink
  for (K=Dol+1 ; K<=DiM ; K++)   Dy.options[K-1] = D_Optb[K] // or grow
  Dy.selectedIndex = NsI }

// Initialiser :

function InitYMDselector(Yr, Mo, Dy, Anni, Base, SetObj) { var J

  // uses var Mon3 = ["Gen", ..., "Dic"]

  if (!Base) Base = new Date().getFullYear()

  for (J=0; J<Anni; J++) Yr.options[J] = new Option(Base+J)
  for (J=0;  J<12 ; J++) Mo.options[J] = new Option(Mon3[J])
  for (J=0;  J<31 ; J++) Dy.options[J] = new Option(J+1)

  if (SetObj) with (SetObj) {
    Yr.selectedIndex = getFullYear()-Base
    Mo.selectedIndex = getMonth()
    Dy.selectedIndex = getDate()-1 }
  else Yr.selectedIndex = Mo.selectedIndex = Dy.selectedIndex = 0

  MonLen(Yr, Mo, Dy) }
  
function InitYMDselectorb(Yr, Mo, Dy, Anni, Base, SetObj) { var J

  // uses var Mon3 = ["Gen", ..., "Dic"]

  if (!Base) Base = new Date().getFullYear()

  for (J=0; J<Anni; J++) Yr.options[J] = new Option(Base+J)
  for (J=0;  J<12 ; J++) Mo.options[J] = new Option(Mon3[J])
  for (J=0;  J<31 ; J++) Dy.options[J] = new Option(J+1)

  if (SetObj) with (SetObj) {
    Yr.selectedIndex = getFullYear()-Base
    Mo.selectedIndex = getMonth()
    Dy.selectedIndex = getDate()-1 }
  else Yr.selectedIndex = Mo.selectedIndex = Dy.selectedIndex = 0

  MonLenb(Yr, Mo, Dy) }
  

// Initialising ( Argument Now (optional) must be in BaseYear+YearSpan-1 ) :

var Now, YearSpan = 8,
  BaseYear = (Now = new Date()).getFullYear() - 0

with (document.forms['Frm1'])
  InitYMDselector(YrSel, MoSel, DySel, YearSpan, BaseYear, Now)
with (document.forms['Frm1'])
  InitYMDselectorb(YrSelb, MoSelb, DySelb, YearSpan, BaseYear, Now)