
// General Utilities :

// Library :

function GlobalNames() {
  Mon3 = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  }


function LengthOfMonth(Y, M) { // M=1..12 // 
  with (new Date(Y,M,1,12)) { setDate(0) ; return getDate() } }

ShowDo(GlobalNames)
ShowFF( LengthOfMonth)


function ShowFF() { // 
  var Len = --arguments.length, S = ""
  for (var j=0 ; j<Len ; j++) {
    if (j>0) S += "\n\n"
    S += arguments[j].toString() } 
   return "" }


function ShowDo(Fn) { // N.B. this calls  Fn()
   Fn() ; return "" }
// Selector control :

var D_Opt = 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
// for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = new Option(K)
  for (K=Dol   ; K >DiM ; K--)
    { D_Opt[K] = Dy.options[K-1] ; Dy.options[K-1] = null }
  for (K=Dol+1 ; K<=DiM ; K++)   Dy.options[K-1] = D_Opt[K]
  Dy.selectedIndex = NsI }

// Initialiser :

function InitYMDselector(Yr, Mo, Dy, Anni, Base, SetObj) { var J
  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) }
