var D_Opt = new Array();
function LengthOfMonth(Y, M) { // M=1..12 // OK in NS4? Mac?
  with (new Date(Y,M,1,12)) { setDate(0) ; return getDate() } }
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--) {
        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;
    
}

function DropReadYMD(Yr, Mo, Dy) {
    var Y = + Yr.options[Yr.selectedIndex].text;
    var M = Mo.selectedIndex;
    var D = Dy.selectedIndex + 1;
    return Y + "-" + Lz(M + 1) + "-" + Lz(D) + ", " + Day3[(new Date(Y, M, D)).getDay()];
}

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);
}

