var today = new Date();
var year = today.getFullYear();
var month = today.getMonth() + 1;
var day = today.getDate();
function $(name){
    return document.getElementById(name)
}

function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11){
    this[0] = m0;
    this[1] = m1;
    this[2] = m2;
    this[3] = m3;
    this[4] = m4;
    this[5] = m5;
    this[6] = m6;
    this[7] = m7;
    this[8] = m8;
    this[9] = m9;
    this[10] = m10;
    this[11] = m11;
}

function GetDayPerMonth(year, month){
    var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) 
        monthDays[1] = 29;
    DaysPerMonth = monthDays[month];
}

function writedate(){
    var y = getSelectValue("txtYear");
    var m = getSelectValue("txtMonth");
    GetDayPerMonth(y, m - 1)
    generateoption(1, DaysPerMonth)
}

function getSelectValue(selectname){
    return $(selectname).options[$(selectname).options.selectedIndex].value
}
function generateoption(value, tovalue){
    var str = ""
    $("txtDay").innerHTML = ""
    for (var s = value; s <= tovalue; s++) {
        if (document.all) {
            var oOption = document.createElement("OPTION");
            $("txtDay").options.add(oOption);
            oOption.innerText = s;
            oOption.value = s;
        }
        else {
            str += "<option value=" + s + ">" + s + "</option>";
        }
    }
    if (!document.all) {
        $("txtDay").innerHTML = str
    }
}

