
//*****************************************************************************************
//*The function "displayUntil(arg,text,atext)" takes three arguments, separated by commas.*              
//*The first argument "arg" is the date (format: "yyyy/mm/dd") until when the             *
//*  argument "text" should display.                                                      *
//*The second argument "text" is the text which will be displayed up to and including     *
//*  the date specified as the first argument.                                            *
//*The third argument "atext" is the text which will be displayed after the date          *
//*****************************************************************************************

function displayUntil(arg,text,atext){
var now = new Date(); 
var then = new Date(arg); 
var gap = then.getTime() - now.getTime(); 
gap = 1+ Math.floor(gap / (1000 * 60 * 60 * 24));
var arg2 = "'This message expires in "+gap+" days on "+arg+"'"
if (gap < 0) {return atext}
else {return '<a style="cursor: default;" onMouseOver="self.status='+arg2+'; return true;" onMouseOut="self.status=\'\'; return true;">'+text+'</a>'}
} 

//********************************************************************************************
//*The function "daysUntil(arg,ltext,rtext,atext)" takes four arguments, separated by commas.*              
//*The first argument "arg" is the target date (format: "yyyy/mm/dd") and will               *
//*  cause the display of the number of days until that date. If the number of days          *
//*  is greater than 1 or equals 0 then it will say  nn days, if it equal to 1 it will       *
//*  say   1 day.  If the date is past, thus the number of days is negative, the             *
//*  after text "atext" will be displayed.                                                   *
//*The second argument "ltext" is the text which will be displayed to the left of the        *
//*  number of days until the event.                                                         *
//*The third argument "rtext" is the text which will be displayed to the right of the        *
//*  number of days until the event.                                                         *
//********************************************************************************************

function daysUntil(arg,ltext,rtext,atext){ 
var now = new Date(); 
var then = new Date(arg); 
var gap = then.getTime() - now.getTime(); 
gap = 1+ Math.floor(gap / (1000 * 60 * 60 * 24));
if (gap < 0) {return atext}
if (gap == 1) {gap = gap + " day"}
else {gap = gap + " days"}
return ltext+gap+rtext
} 

//********************************************************************************************
//*The function "weeksUntil(arg,ltext,rtext,atext)" takes four arguments, separated by commas.*              
//*The first argument "arg" is the target date (format: "yyyy/mm/dd") and will               *
//*  cause the display of the number of weeks and days until that date. If the number of days*
//*  is greater than 1 or equals 0 then it will say  nn days, if it equal to 1 it will       *
//*  say   1 day.  If the date is past, thus the number of days is negative, the             *
//*  after text "atext" will be displayed.                                                   *
//*The second argument "ltext" is the text which will be displayed to the left of the        *
//*  number of days until the event.                                                         *
//*The third argument "rtext" is the text which will be displayed to the right of the        *
//*  number of days until the event.                                                         *
//********************************************************************************************

function weeksUntil(arg,ltext,rtext,atext){ 
  var now = new Date(); 
  var then = new Date(arg); 
  var gap = then.getTime() - now.getTime(); 
  gap = 1+ Math.floor(gap / (1000 * 60 * 60 * 24));
  if (gap < 0) {return atext}
  days = gap%7
  weeks = (gap - days)/7
  gap = ""
  if ((weeks == 0) && (days == 0)){return ltext+"today"+rtext}
  if (weeks == 1) {gap = "1 week"}
  else if (weeks !=0) {gap = weeks + " weeks"}
  if ((days != 0) && (weeks != 0)) {gap = gap + " and "}
  if (days == 1) {gap = gap + "1 day"}
  else if (days !=0) {gap = gap + days + " days"}
  return ltext+gap+rtext
} 


 
// --------------------------Get current date-----------------
function getToday(){
var now = new Date();
// List the days
var days = new Array('Sunday','Monday','Tuesday','Wednesday',
                      'Thursday','Friday','Saturday');
// List the months
var months = new Array('January','February','March','April',
                         'May','June','July','August','September',
                            'October','November','December');
// What day number is it
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
// Convert year to four figure format
function y2k(number){return (number < 1000) ? number + 1900 : number;}
// Join it all together
today =  days[now.getDay()] + ", " +
               months[now.getMonth()] + " " +
                 date + ", " +
                (y2k(now.getYear())) ;
return today
}

// ---------------------------------------------------------- 

function dateFormat(aDate, displayPat){
    /********************************************************
    *   Valid Masks:
    *   !mmmm = Long month (eg. January)
    *   !mmm = Short month (eg. Jan)
    *   !mm = Numeric date (eg. 07)
    *   !m = Numeric date (eg. 7)
    *   !dddd = Long day (eg. Monday)
    *   !ddd = Short day (eg. Mon)
    *   !dd = Numeric day (eg. 07)
    *   !d = Numeric day (eg. 7)
    *   !yyyy = Year (eg. 1999)
    *   !yy = Year (eg. 99)
   ********************************************************/

    intMonth = aDate.getMonth();
    intDate = aDate.getDate();
    intDay = aDate.getDay();
    intYear = aDate.getFullYear();

    var months_long =  new Array ('January','February','March','April',
       'May','June','July','August','September','October','November',
       'December')
    var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun',
       'Jul','Aug','Sep','Oct','Nov','Dec')
    var days_long = new Array('Sunday','Monday','Tuesday','Wednesday',
       'Thursday','Friday','Saturday')
    var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri',
        'Sat')

    var mmmm = months_long[intMonth]
    var mmm = months_short[intMonth]
    var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+'';
    var m = 1+intMonth+'';
    var dddd = days_long[intDay];
    var ddd = days_short[intDay];
    var dd = intDate<10?'0'+intDate+'':intDate+'';
    var d = intDate+'';
    var yyyy = intYear;

    century = 0;
    while((intYear-century)>=100)
        century = century + 100;

    var yy = intYear - century
    if(yy<10)
        yy = '0' + yy + '';

    displayDate = new String(displayPat);

    displayDate = displayDate.replace(/!mmmm/i,mmmm);
    displayDate = displayDate.replace(/!mmm/i,mmm);
    displayDate = displayDate.replace(/!mm/i,mm);
    displayDate = displayDate.replace(/!m/i,m);
    displayDate = displayDate.replace(/!dddd/i,dddd);
    displayDate = displayDate.replace(/!ddd/i,ddd);
    displayDate = displayDate.replace(/!dd/i,dd);
    displayDate = displayDate.replace(/!d/i,d);
    displayDate = displayDate.replace(/!yyyy/i,yyyy);
    displayDate = displayDate.replace(/!yy/i,yy);

    return displayDate;
}

function fullDate(yy,mm,dd){
var d = new Date(yy,mm-1,dd)
var weekday=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var year = d.getFullYear()
document.write(weekday[d.getDay()]+" "+(1+d.getMonth())+"/"+d.getDate()+"/"+year)
}

var today = new Date();
var date = today.getDate()  //this is the day number of the month 1-31
var month = today.getMonth()  //this is the month number 0 based
var day = today.getDay()  //this is the day of the week number 0-6 sunday is 0
