﻿function _$C(tag){return document.createElement(tag);}
function _$E(tag){return document.getElementById(tag);}
function _$P(o){
	var a = new Array();
	t = o.offsetTop;
	l = o.offsetLeft;
	w = o.offsetWidth;
	h = o.offsetHeight;
	//alert(o.offsetParent.tagName);	
	while(o=o.offsetParent)
	{
		l+=o.offsetLeft;
		t+=o.offsetTop;
	}
	a[0] = l; a[1] = t; a[2] = w; a[3] = h;
	return a;	
}
function _$DV(dblc){return dblc.options[dblc.selectedIndex].value;}
function _$ADDOPT(dblc, t, v){
    var o = _$C("OPTION");
    dblc.options.add(o);    
    o.value = v;
    o.innerText = t;
}
function _$INTOPT(dblc, t, v, index){
    var o = _$C("OPTION");
    dblc.options.add(o, index);    
    o.value = v;
    o.innerText = t;
}

function getGLDaysByMonty(y, m){
    var res = 0
    switch(parseInt(m)){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            res = 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            res = 30;
            break;
        case 2:
            if(y%400 == 0 ||(y%4 == 0 && y%100 != 0))
                res = 29;
            else
                res = 28;
            break;
    }
    return res;
}

function getDaysByMonty(type, y, m, dblc){   //type 0:公历 1农历
    dblc.innerHTML = "";
    if(m == -1){return;}
    
    var days  = 0;
    var leapM = 0; //0 is none
    
    if(type == 0)
        days = getGLDaysByMonty(y, m);
    else{
        if(m > 100)
            days = leapDays(y);
        else
            days  = monthDays(y, m)
    }
        
    for(var i=1; i<=days; i++){
        _$ADDOPT(dblc, i+"", i+"");
    }
}

function getMonthByYear(type, y, dblc){
    var leapM = 0;
    var cm = new Array('正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二');
    dblc.innerHTML = "";
    if(y == -1){return;}    
    if(type == 0){
        _$ADDOPT(dblc, "1月", "1");
        _$ADDOPT(dblc, "2月", "2");
        _$ADDOPT(dblc, "3月", "3");
        _$ADDOPT(dblc, "4月", "4");
        _$ADDOPT(dblc, "5月", "5");
        _$ADDOPT(dblc, "6月", "6");
        _$ADDOPT(dblc, "7月", "7");
        _$ADDOPT(dblc, "8月", "8");
        _$ADDOPT(dblc, "9月", "9");
        _$ADDOPT(dblc, "10月", "10");
        _$ADDOPT(dblc, "11月", "11");
        _$ADDOPT(dblc, "12月", "12");
    }
    else{
        _$ADDOPT(dblc, "正月", "1");
        _$ADDOPT(dblc, "二月", "2");
        _$ADDOPT(dblc, "三月", "3");
        _$ADDOPT(dblc, "四月", "4");
        _$ADDOPT(dblc, "五月", "5");
        _$ADDOPT(dblc, "六月", "6");
        _$ADDOPT(dblc, "七月", "7");
        _$ADDOPT(dblc, "八月", "8");
        _$ADDOPT(dblc, "九月", "9");
        _$ADDOPT(dblc, "十月", "10");
        _$ADDOPT(dblc, "十一月", "11");
        _$ADDOPT(dblc, "腊月", "12");
        var leapM = leapMonth(y);
        if(leapM > 0){
            var o = _$C("OPTION");
            dblc.options.add(o, leapM);
            o.value = (leapM + 100);
            o.innerText = "闰" + cm[leapM-1] + "月";
        }
    }
}

function setNextDay(type, objY, objM, objD){
    alert(objD.options.length);
    if(objD.options.length == (objD.selectedIndex + 1)){
        objM.selectedIndex += 1;
        alert('ttttt');
    }
}

