﻿function InitYear(pName,start,length,y)
{
  var selYear=document.getElementById(pName);
  var n=selYear.length;
  selYear.length=n+length+1;
  for (i=0;i<=length;i++)
  {
selYear.options[n+i].value=(i+start);
selYear.options[n+i].text=(i+start);
  }
  if (y==0)
  {
selYear.selectedIndex =0;
  }
  else
  {
if (y>start)
{
           if (y-start<=length)
   {
selYear.selectedIndex = n+y-start;
   }
   else
  {
selYear.selectedIndex = length;
  }
        }
  }
}

function InitMonth(pName,m)
{
  var selMonth=document.getElementById(pName);
  var n=selMonth.length;
  selMonth.length=n+12;
  for (i=1;i<10;i++)
  {
selMonth.options[n+i-1].value='0'+i;
selMonth.options[n+i-1].text=i;
  }
  for (i=10;i<=12;i++)
  {
selMonth.options[n+i-1].value=i;
selMonth.options[n+i-1].text=i;
  }
  if (m==0)
  {
selMonth.selectedIndex=0;
  }
  else
  {
selMonth.selectedIndex = n+m-1;
  }
}

function InitDay(pName,d)
{
  var selDay=document.getElementById(pName);
  var n=selDay.length;
  selDay.length=n+31;
  for (i=1;i<10;i++)
  {
selDay.options[n+i-1].value='0'+i;
selDay.options[n+i-1].text=i;
  }
  for (i=10;i<=31;i++)
  {
selDay.options[n+i-1].value=i;
selDay.options[n+i-1].text=i;
  }
  if (d==0)
  {
selDay.selectedIndex = 0;
  }
  else
  {
selDay.selectedIndex = n+d-1;
  }
  //dateChange(pName);
}

function dateChange(yearid,monthid,dayid)
{
 var selYear=document.getElementById(yearid);
 var year=selYear.options[selYear.selectedIndex].value;
 if (year!='')
 {
 var selMonth=document.getElementById(monthid);
 var month=selMonth.options[selMonth.selectedIndex].value;
 if (month!='')
 {
   var date=new Date(year,month,0);
   var day=date.getDate();
   var selDay=document.getElementById(dayid); 
   var tmp=1;
   if (selDay.selectedIndex>0)
   {
tmp=selDay.options[selDay.selectedIndex].value;
   }
   selDay.length=day;
   for (i=1;i<10;i++)
   {
selDay.options[i-1].value='0'+i;
selDay.options[i-1].text=i;
   }
   for (i=10;i<=day;i++)
   {
selDay.options[i-1].value=i;
selDay.options[i-1].text=i;
   }
   if (tmp>day)
   {
selDay.selectedIndex=day-1;
   }
   else
   {
selDay.selectedIndex=tmp-1;
   }
 }
 }
}