
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

/*
============================================================
DateSelector script
============================================================
*/
<!-- Begin
//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

//function for returning how many days there are in a month including leap years
function DateSelector_DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

//function to change the available days in a months
function DateSelector_ChangeOptionDays(Which)
{
  DaysObject = eval("document.forms[0]." + Which + "_Day");
  MonthObject = eval("document.forms[0]." + Which + "_Month");
  YearObject = eval("document.forms[0]." + Which + "_Year");

  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;

  DaysForThisSelection = DateSelector_DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;
  if (CurrentDaysInSelection > DaysForThisSelection)
  {
    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//function to set options to today
function DateSelector_SetToToday(Which)
{
  DaysObject = eval("document.forms[0]." + Which + "_Day");
  MonthObject = eval("document.forms[0]." + Which + "_Month");
  YearObject = eval("document.forms[0]." + Which + "_Year");

  YearObject[0].selected = true;
  MonthObject[NowMonth].selected = true;

  DateSelector_ChangeOptionDays(Which);

  DaysObject[NowDay-1].selected = true;
}

//function to set options to today
function DateSelector_Set(Which, Day, Month, Year)
{
  DaysObject = eval("document.forms[0]." + Which + "_Day");
  MonthObject = eval("document.forms[0]." + Which + "_Month");
  YearObject = eval("document.forms[0]." + Which + "_Year");

  for (x = 0; x < YearObject.options.length; x++){
    if (YearObject[x].value == Year){
		YearObject[x].selected = true;
	}
  }

  for (y = 0; y < MonthObject.options.length; y++){
    if (MonthObject[y].value == Month)
		MonthObject[y].selected = true;
  }

  DateSelector_ChangeOptionDays(Which);

  for (z = 0; z < DaysObject.options.length; z++){
    if (DaysObject[z].value == Day)
		DaysObject[z].selected = true;
  }

}

//function to disable date selector
function DateSelector_Disable(Which)
{
	document.getElementById(Which + "_Day").disabled = true;
	document.getElementById(Which + "_Month").disabled = true;
	document.getElementById(Which + "_Year").disabled = true;
}

//function to enable date selector
function DateSelector_Enable(Which)
{
	document.getElementById(Which + "_Day").disabled = false;
	document.getElementById(Which + "_Month").disabled = false;
	document.getElementById(Which + "_Year").disabled = false;
}
//  End -->
