/* <![CDATA[ */

function makeValidDate() {
  year = document.theForm.selYear.options[ document.theForm.selYear.selectedIndex ].value;
  month = document.theForm.selMonth.options[ document.theForm.selMonth.selectedIndex ].value;
  day = document.theForm.selDay.options[ document.theForm.selDay.selectedIndex ].value;
  maxDay = 31;
  if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
    maxDay = 30;
  } else if ( month == 2 ) {
    if ( year%100 != 0 && year%4 == 0 ) {
      maxDay = 29;
    } else {
      maxDay = 28;
    }
  }
  document.theForm.selDay.selectedIndex = Math.min(day, maxDay)-1;
}


function isBrowserSupp() {
    // Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
        return true;
    }                  
}


function isLeapYear(yrStr)
{
var leapYear=false;
// every fourth year is a leap year
if ((parseInt(yrStr, 10)%4) == 0)
        {
        leapYear=true;
        }
return leapYear;
}

function getDaysInMonth(mthIdx, YrStr)
{
//Default number of days in a month is 31
var maxDays=31
// expect Feb. 
if (mthIdx==2) 
        {
        if (isLeapYear(YrStr))
                {
                maxDays=29;
                }
        else 
                {
                maxDays=28;
                }
        }
// All the rest of the months have 30 days
if (mthIdx==4 || mthIdx==6 || mthIdx==9 || mthIdx==11)
        {
        maxDays=30;
        }
return maxDays;
}


function adjustDate(mthIdx, Dt, Yr) 
{
var value=0;            
var numDays=getDaysInMonth(mthIdx, Yr.options[Yr.options.selectedIndex].value);

if (mthIdx==2) 
        {
        if (Dt.options.selectedIndex < numDays)
                {
                return 0;
                }
        else 
                {
                //check for leap year
                Dt.options.selectedIndex=numDays;
                if (numDays==29)
                        {
                        return 99;
                        }
                else 
                        {
                        return 1;
                        }
                }
        }
if (Dt.options.selectedIndex < numDays)
        {
        value=0;
        }
else 
        {
        if (Dt.options.selectedIndex > numDays)
                {
                Dt.options.selectedIndex;
                value=3;
                }
        else 
                {
                //index is 31 or 30
                value=2;
                }
        }
return value;
}


function parseMonth(mth, inM)
{
var i=1;
var retval =1;
for (i=1;i<=12;i++)
        {
        if (mth == inM.options[i].value)
                {
                retval=i;       
                break;
                }       
        }
        return retval;
}

function parseDay(day, inD)
{
var i=1;
var retval =1;
for (i=1;i<=31;i++)
        {
        if (day == inD.options[i].value)
                {
                retval=i;       
                break;
                }       
        }
return retval;
}

function parseYear(year, inY)
{
var retval=0;
var i=0;
     for (i=0; i<=5; i++)
     {
   
        if (year == inY.options[i].value)
                {
                retval=i;       
                break;
                }       
     }
return retval;
}



//Calendar Section
//calculation functions
function nextMonth(month)
{
if (month==12)
        {
        return 1;
        }
else
        {
        return (month+1);
        }
}


function prevMonth(month) 
{
var prevMonth = (month-1)
if (month==1)
        {
        prevMonth = 12;
        }
return prevMonth
}

function changeYear(direction,month,year)
{
var theYear = year
if (direction=="next")
        {
        if (month == 12)
                {
                theYear = (year+1)
                }
        }
if (direction=="prev")
        {
        if (month == 1)
                {
                theYear = (year-1)
                }
        }
return theYear
}

/* ]]> */
