// Non-Leap year Month days..
DOMonth = [0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
lDOMonth = [0,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendar_get_daysofmonth(monthNo, p_year) {
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return DOMonth[monthNo];

		return lDOMonth[monthNo];
	} else
		return DOMonth[monthNo];
}

function show_year(ttt,c_year) {
    var years='<select size="1" name="year'+ttt+'" onchange="yearSelect('+ttt+');">';
    for(i=0;i<110;i++){
        if ((1900+i)==c_year) selected="selected";
        else selected="";
        years+='<option value="'+ (1900+i) +'" '+ selected +'>'+ (1900+i) +'</option>';
    }
    years+='</select>';
    //alert(tt);
    //alert(years);
    eval("year"+ttt+".innerHTML='"+years+"'");
}

function show_year_se(ttt,c_year) {
  //alert('ttt : ' + ttt + ' c_year : ' + c_year);
    var years='<select size="1" name="year'+ttt+'" onchange="yearSelect_se('+ttt+');chsubject();">';
    for(i=0;i<110;i++){
        if ((1900+i)==c_year) selected="selected";
        else selected="";
        years+='<option value="'+ (1900+i) +'" '+ selected +'>'+ (1900+i) +'</option>';
    }
    years+='</select>';
    eval("year"+ttt+".innerHTML='"+years+"'");
}

function show_month(ttt,c_year,c_month) {
    //if (c_year == p_year){
    	//c_month=month=p_month;
    //}else{
    	month = 1;
    //}
    var months='<select size="1" name="month'+ttt+'" onchange="monthSelect('+ttt+');">';
    for(i=month;i<13;i++){
        if (i==c_month) selected="selected";
        else selected="";
        months+='<option value="'+ i +'" '+ selected +'>'+ i +'</option>';
    }
    months+='</select>';
    eval("month"+ttt+".innerHTML='"+months+"'");
}

function show_month_se(ttt,c_year,c_month) {
    //if (c_year == p_year){
    	//c_month=month=p_month;
    //}else{
    	month = 1;
    //}
    var months='<select size="1" name="month'+ttt+'" onchange="chsubject();">';
    for(i=month;i<13;i++){
        if (i==c_month) selected="selected";
        else selected="";
        months+='<option value="'+ i +'" '+ selected +'>'+ i +'</option>';
    }
    months+='</select>';
    eval("month"+ttt+".innerHTML='"+months+"'");
}

function show_date(ttt,c_year,c_month,c_date) {
    //if (c_year == p_year && c_month == p_month){
    	//day = p_date;
    //}else{
    	day=1;
    //}
    days = Calendar_get_daysofmonth(c_month, c_year);
    if (days < c_date) c_date = days;
    var dates='<select size="1" name="date'+ttt+'">';
    for(i = day;i <= days;i++){
        if (i == c_date) selected="selected";
        else selected="";
        dates+='<option value="'+ i +'" '+ selected +'>'+ i +'</option>';
    }
    dates += '</select>';
    eval("date"+ttt+".innerHTML='"+dates+"'");
}

function show_calendar(tt) {
    for (j=0;j<tt;j++){
        show_year(j,p_year);
        show_month(j,p_year,p_month);
        show_date(j,p_year,p_month,p_date);
    }
}

function show_calendar2(tt) {
	show_year(tt,p_year1);
  show_month(tt,p_year1,p_month1);
  show_date(tt,p_year1,p_month1,p_date1);
}

function show_calendar_single(tt) {

  var c_year = eval('p_year' + tt);
  var c_month = eval('p_month' + tt);

  show_year_se(tt,c_year);
  show_month_se(tt,c_year,c_month);
}

function set_calendar(tt,c_year,c_month,c_date) {
    show_year(tt,c_year);
    show_month(tt,c_year,c_month);
    show_date(tt,c_year,c_month,c_date);
}

function checkNow(ttt) {
    c_year=eval("document."+formName+".year"+ttt+".options[document."+formName+".year"+ttt+".selectedIndex].text");
    c_month=eval("document."+formName+".month"+ttt+".options[document."+formName+".month"+ttt+".selectedIndex].text");
    c_date=eval("document."+formName+".date"+ttt+".options[document."+formName+".date"+ttt+".selectedIndex].text");

    //alert('c_year : ' + c_year);
    //alert('c_month : ' + c_month);
    //alert('c_date : ' + c_date);
}

function checkNowYm(ttt) {
    c_year=eval("document."+formName+".year"+ttt+".options[document."+formName+".year"+ttt+".selectedIndex].text");
    c_month=eval("document."+formName+".month"+ttt+".options[document."+formName+".month"+ttt+".selectedIndex].text");
}

function yearSelect(tt) {
    checkNow(tt);
    show_month(tt,c_year,c_month);
    monthSelect(tt);
}

function yearSelect_se(tt) {
    checkNowYm(tt);
    show_month_se(tt,c_year,c_month);
    monthSelect_se(tt);
}

function monthSelect(tt) {
    checkNow(tt);
    show_date(tt,c_year,c_month,c_date);
}

function monthSelect_se(tt) {
    checkNowYm(tt);
    //show_date(tt,c_year,c_month,c_date);
}

function set_calendarBe(tt,c_time) {


	var c_year = c_time.substring(0,4);
	//alert(c_year);
	var c_month = c_time.substring(5,7);
	//alert(c_month);
	if(c_month.indexOf("0")==0){
		c_month=c_month.substring(1,2);
	}

	var c_date = c_time.substring(8,10);
	//alert(c_date);
    show_year(tt,c_year);
    show_month(tt,c_year,c_month);
    show_date(tt,c_year,c_month,c_date);

}
