
// FUNCTION: 	daysAgo( days );
// DESCRIPTION: Returns the timestamp for the date the specified number of days ago.
//
// IN:		days - the number of days to go back in time
// OUT:		the timestamp for the number of days back
//

function daysAgo( days ) {

// Get the date
// Subtract specified number of days

  var date = new Date();
  date.setDate( date.getDate()-days );

// Get the year
// Get the month
// Get the day of the month

  theYear  = date.getYear(); 
  theMonth = date.getMonth()+1+""; 
  theDay   = date.getDate()+""; 

// Make sure month has 2 digits
// Make sure day of month has 2 digits
// Make sure we don't suffer from Y2K bug... (identified in at least NS 4.08... )
// Reconstruct the date

  if( theMonth.length < 2 ) theMonth = '0'+theMonth;
  if( theDay.length < 2 ) theDay = '0'+theDay;
  theYear = 1900>theYear ? theYear+1900 : theYear;
  theDate = ""+theYear+theMonth+theDay;

// Return the result
return theDate;
}

// FUNCTION: 	monthsAgo( days );
// DESCRIPTION: Returns the timestamp for the date the specified number of months ago.
//
// IN:		months - the number of months to go back in time
// OUT:		the timestamp for the number of months back
//

function monthsAgo( months ) {

// Get the date
// Subtract specified number of months

  var date = new Date();
  date.setMonth( date.getMonth()-months );

// Get the year
// Get the month
// Get the day of the month

  theYear  = date.getYear(); 
  theMonth = date.getMonth()+1+""; 
  theDay   = date.getDate()+""; 

// Make sure month has 2 digits
// Make sure day of month has 2 digits
// Make sure we don't suffer from Y2K bug... (identified in at least NS 4.08... )
// Reconstruct the date

  if( theMonth.length < 2 ) theMonth = '0'+theMonth;
  if( theDay.length < 2 ) theDay = '0'+theDay;
  theYear = 1900>theYear ? theYear+1900 : theYear;
  theDate = ""+theYear+theMonth+theDay;

// Return the result
return theDate;
}

// FUNCTION: 	checkInput( );
// DESCRIPTION: 	checks if the specified fields are filled when form is submitted
//
// IN:		1. the form object
//   		2. array of fields to check
// OUT:		3. flag indicating it's okay to submit
//
function checkInput( obj, fields, names ){
  var toFill = '';

// For each field specified  
//  If the field is empty, Add to the list
// If there is  at least one required field not filled
//  Show message
//  Return false indicating failure
// Else
//  Return true
     
  for( var i=0; i<fields.length; i++ ){
    if( obj[fields[i]].value=="" ) toFill += toFill=="" ? names[i] : ", "+names[i];
  }
  if( toFill != "" ){
    alert( "De volgende velden moeten nog worden ingevuld: " + toFill );
    return false;
  }else{
    return true;
  }
}
