﻿<!-- //
function FormatDate(strDate, strFormat)
    {
    var strFormatDate = new String(strFormat)
    var dtDate = new Date(strDate);
    var strHour = new String(dtDate.getHours());
    var strMinute = new String(dtDate.getMinutes());
    if(dtDate.getHours() < 10) strHour = "0" + dtDate.getHours();
    if(dtDate.getMinutes() < 10) strMinute = "0" + dtDate.getMinutes();
    strFormatDate = strFormatDate.replace("yyyy", dtDate.getFullYear());
    strFormatDate = strFormatDate.replace("mm", dtDate.getMonth());
    strFormatDate = strFormatDate.replace("dd", dtDate.getDate());
    strFormatDate = strFormatDate.replace("wd", dtDate.getDay());
    strFormatDate = strFormatDate.replace("hr", strHour);
    strFormatDate = strFormatDate.replace("mi", strMinute);
    strFormatDate = strFormatDate.replace("ml", g_astrLongMonthNames[dtDate.getMonth()]);
    strFormatDate = strFormatDate.replace("ms", g_astrShortMonthNames[dtDate.getMonth()]);
    strFormatDate = strFormatDate.replace("wl", g_astrLongDayNames[dtDate.getDay()]);
    strFormatDate = strFormatDate.replace("ws", g_astrShortDayNames[dtDate.getDay()]);
    return strFormatDate;
    }

function GetDaysInMonth(nMonth, nYear)
    {
    var nDaysInMonth = 0;
    switch(nMonth)
        {
        case 4:
        case 6:
        case 9:
        case 11:
		    nDaysInMonth = 30;
		    break;
        case 2:
		    nDaysInMonth = (nYear % 4 == 0  && (nYear % 100 != 0 || nYear % 400 == 0)) ? 29 : 28;
		    break;
        default:
            nDaysInMonth = 31;
        }
    return nDaysInMonth;
    }
    
function OnChangeMonth(strCtrlID, bNoIncAnswer)
    {
    var selYear = document.getElementById(strCtrlID + "Year");
    var nYear = parseInt(selYear.options[selYear.options.selectedIndex].value);
    var selMonth = document.getElementById(strCtrlID + "Month");
    var nMonth = parseInt(selMonth.options[selMonth.options.selectedIndex].value);
    var selDate = document.getElementById(strCtrlID + "Date");
    var nDate = parseInt(selDate.options[selDate.options.selectedIndex].value);
    selDate.options.length = 0;
    selDate.size = 0;
    
    if(nYear == -1)
        {
        selYear.options[1].selected = true;    
        selYear.options.selectedIndex = 1;
        nYear = parseInt(selYear.options[selYear.options.selectedIndex].value);
        }
    
    var nSelectedIndex;
    nSelectedIndex = 0;
    
    if(bNoIncAnswer)
		selDate.options[selDate.options.length] = new Option("No Answer", -1, false, false);
    
    if(nMonth != -1)
        {
        var nIndex, nDaysInMonth, bDateFound, strDay;
        nDaysInMonth = GetDaysInMonth(nMonth, nYear);
        nSelectedIndex = 1;
        bDateFound = false;
        for(nIndex = 1; nIndex <= nDaysInMonth; nIndex++)
            {
            strDay = (nIndex < 10) ? "0" + nIndex : nIndex;
            selDate.options[selDate.options.length] = new Option(strDay, nIndex, false, false);
            if(nIndex == nDate)
                {
                nSelectedIndex = (bNoIncAnswer) ? nIndex : nIndex - 1;
                bDateFound = true;
                }
            }
        
        if(nDate != -1 && bDateFound == false) nSelectedIndex = (nDaysInMonth - 1);
        }
    else
        {
        selYear.options[0].selected = true;    
        selYear.options.selectedIndex = 0;
        }
    
    selDate.options[nSelectedIndex].selected = true;    
    selDate.options.selectedIndex = nSelectedIndex;
    selDate.size = 1;
    }
    
function OnChangeDate(strCtrlID, bNoIncAnswer)
    {
    var selDate = document.getElementById(strCtrlID + "Date");
    var nDate = parseInt(selDate.options[selDate.options.selectedIndex].value);
    if(nDate == -1)
        {
        var selYear = document.getElementById(strCtrlID + "Year");    
        selYear.options[0].selected = true;    
        selYear.options.selectedIndex = 0;
        var selMonth = document.getElementById(strCtrlID + "Month");
        selMonth.options[0].selected = true;    
        selMonth.options.selectedIndex = 0;
        OnChangeMonth(strCtrlID, bNoIncAnswer);
        }
    }
    
function OnChangeYear(strCtrlID, bNoIncAnswer)
    {
    var selYear = document.getElementById(strCtrlID + "Year");
    var nYear = parseInt(selYear.options[selYear.options.selectedIndex].value);
    if(nYear == -1)
        {
        var selDate = document.getElementById(strCtrlID + "Date");
        selDate.options[0].selected = true;    
        selDate.options.selectedIndex = 0;
        var selMonth = document.getElementById(strCtrlID + "Month");
        selMonth.options[0].selected = true;    
        selMonth.options.selectedIndex = 0;
        }
    OnChangeMonth(strCtrlID, bNoIncAnswer);
    }
// -->