//This function takes a display name and the value for the new element and then adds it to the dropdown specified in the other parameter
function addOption(whichDD,name,value)
{
   //Create a reference to the form
   var theDD=eval(whichDD);

   // create the new OPTION
   var newOption;
   newOption= new Option (name,value);

   // position
   var insertAt = theDD.options.length;

   // create the space
   theDD.options.length = theDD.options.length + 1;

   // add the option
   theDD.options[insertAt] = newOption;
}

//populate the Start day dropdown for the month of Feb
function SleapYear()
{
   //get dropdown values
   var yearDD = document.query.Syear.value;
   var monthDD = document.query.Smonth.value;
   var dayDD = document.query.Sday.value;

   //if month is Feb
   if(monthDD==02)
   {
      //if max num days is not 29 and it is a leap year
      if(dayDD != 29 && (yearDD % 4 == 0 && (yearDD % 100 != 0 || yearDD % 400 == 0)))
      {
         //reset the dropdown
         document.query.Sday.length=0;
         
         //populates the day field 1-29
         for (var i=1; i<=29; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Sday',i,i);
         }
      }
   
      //if max num days is 29 and it is not a leap year
      if(dayDD == 29 && (yearDD % 4 !=0 && (yearDD % 100 == 0 || yearDD % 400 !=0)))
      {
         //reset the dropdown
         document.query.Sday.length=0;
         
         //populates the day field 1-28
         for (var i=1; i<=28; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Sday',i,i);
         }
      }

   }//if		
}//SleapYear

//populates the End day dropdown for the month of Feb
function EleapYear()
{
   //get dropdown values
   var yearDD = document.query.Eyear.value;
   var monthDD = document.query.Emonth.value;
   var dayDD = document.query.Eday.value;
   
   //if month is Feb
   if(monthDD==02)
   {
      //if max num days is not 29 and it is a leap year
      if(dayDD != 29 && (yearDD % 4 == 0 && (yearDD % 100 != 0 || yearDD % 400 == 0)))
      {
        //reset the dropdown
        document.query.Eday.length=0;i

        //populates the day field 1-29
        for (var i=1; i<=29; i++) {
           var a='0';
           if (i<10)
              i=a+i;
           addOption('document.query.Eday',i,i);
        }
      }
      
      //if max num days is 29 and it is not a leap year
      if(dayDD == 29 && (yearDD % 4 !=0 && (yearDD % 100 == 0 || yearDD % 400 !=0)))
      {
         //reset the dropdown
         document.query.Eday.length=0;

         //populates the day field 1-28
         for (var i=1; i<=28; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Eday',i,i);
         }
      }

   }//if		
}//EleapYear

//This function links the two dropdowns and then calls addOption to insert the value in the second dropdown 
function populateSD()
{
   //get dropdown values
   var firstDD = document.query.Smonth.value;
   var yearDD = document.query.Syear.value;

   //Resets the dropdown
   document.query.Sday.length=0;

   //if Month is Jan, Mar, May, Jul, Aug, Oct, or Dec set the num of days 1-31
   if (firstDD=='01' || firstDD=='03' || firstDD=='05' || firstDD=='07' || firstDD=='08' || firstDD=='10' || firstDD=='12')
   {
      for (var i=1; i<=31; i++) {
         var a='0';
         if (i<10)
            i=a+i;
         addOption('document.query.Sday',i,i);
      }
   }
   //if Month is Apr, Jun, Sep, or Nov set the num of days 1-30
   else if (firstDD=='04' || firstDD=='06' || firstDD=='09' || firstDD=='11')
   {
      for (var i=1; i<=30; i++) {
         var a='0';
         if (i<10)
            i=a+i;
         addOption('document.query.Sday',i,i);
      }
   }
   //if Month is Feb set the num of days
   else
   {
      //if leap year set num of days 1-29
      if(yearDD % 4 == 0 && (yearDD % 100 != 0 || yearDD % 400 == 0))
      {
         for (var i=1; i<=29; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Sday',i,i);
         }
      }
      //if not leap year set num of days 1-28
      else 
      {
         for (var i=1; i<=28; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Sday',i,i);
         }
      }
   }
}//populateSD

//This function links the two dropdowns and then calls addOption to insert the value in the second dropdown 
function populateED()
{
   //get dropdown values
   var firstDD = document.query.Emonth.value;
   var yearDD = document.query.Eyear.value;

   //Resets the dropdown
   document.query.Eday.length=0;

   //if Month is Jan, Mar, May, Jul, Aug, Oct, or Dec set the num of days 1-31   
   if (firstDD=='01' || firstDD=='03' || firstDD=='05' || firstDD=='07' || firstDD=='08' || firstDD=='10' || firstDD=='12')
   {
      for (var i=1; i<=31; i++) {
         var a='0';
         if (i<10)
            i=a+i;
         addOption('document.query.Eday',i,i);
      }
   }
   //if Month is Apr, Jun, Sep, or Nov set the num of days 1-30
   else if (firstDD=='04' || firstDD=='06' || firstDD=='09' || firstDD=='11')
   {
      for (var i=1; i<=30; i++) {
         var a='0';
         if (i<10)
            i=a+i;
         addOption('document.query.Eday',i,i);
      }
   }
   //if Month is Feb set the num of days
   else
   {
      //if leap year set num of days 1-29
      if(yearDD % 4 == 0 && (yearDD % 100 != 0 || yearDD % 400 == 0))
      {
         for (var i=1; i<=29; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Eday',i,i);
         }
      }
      //if not leap year set num of days 1-28
      else
      {
         for (var i=1; i<=28; i++) {
            var a='0';
            if (i<10)
               i=a+i;
            addOption('document.query.Eday',i,i);
         }
      }
   }
}//populateED
