//WD DATE SCRIPT

// Get current date
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()] + " " +
              date + "th " +
               months[now.getMonth()] + ", " +
                (y2k(now.getYear())) ;

// WD SHORT DATE SCRIPT

// List the months
var shortmonths = new Array

('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');

var mnths = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

// Join it all together
todayshort = date + shortmonths[now.getMonth()] + (y2k(now.getYear())) ;

// Calendar Script

	var ie4 = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4 ? 1 : 0;
	var ns5 = navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5 ? 1 : 0;

    var thisMonth = (new Date().getFullYear()*12) + new Date().getMonth();
    var monthsArray = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    var fullMonthsArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    var daysArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    var stndrdArray = ["","st","nd","rd","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","st","nd","rd","th","th","th","th","th","th","th","st"];
    var whichFields = "start";
    var fieldsToHide = new Array();
    var targetDay;
    var targetMonth;
    var targetYear;


	function PopulateCalendar( monthOffset, calendarId) {
		thisMonth += monthOffset;
		
		theDate = new Date( Math.floor( thisMonth / 12), thisMonth % 12);
		targetMonth = theDate.getMonth( );
		targetYear = theDate.getFullYear( );

		daysInMonth = GetDaysInMonth( theDate);
		outHtml = '<table class="contents" border="0px" cellspacing="1px" cellpadding="0px">';
		
		outHtml += '<tr>' + "\n";
		outHtml += '<td class="cell">' + "\n";
		outHtml += '<a href="Javascript: PopulateCalendar( -12, \'' + calendarId + '\');">&lt;&lt;</a>' + "\n";
		outHtml += '</td>' + "\n";
		outHtml += '<td class="cell">' + "\n";
		outHtml += '<a href="Javascript: PopulateCalendar( -1, \'' + calendarId + '\');">&lt;</a>' + "\n";
		outHtml += '</td>' + "\n";
		outHtml += '<td colspan="3">' + "\n"; // Start outputting the header
		outHtml += monthsArray[theDate.getMonth()] + " " + theDate.getFullYear();
		outHtml += '</td>' + "\n";
		outHtml += '<td class="cell">' + "\n";
		outHtml += '<a href="Javascript: PopulateCalendar( 1, \'' + calendarId + '\');">&gt;</a>' + "\n";
		outHtml += '</td>' + "\n";
		outHtml += '<td class="cell">' + "\n";
		outHtml += '<a href="Javascript: PopulateCalendar( 12, \'' + calendarId + '\');">&gt;&gt;</a>';
		outHtml += '</td>' + "\n";
		outHtml += '</tr>' + "\n";
		outHtml += '<tr>' + "\n";
		outHtml += '<td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>' + "\n";
		outHtml += '</tr>' + "\n";

		// Now output the dates
		
		outHtml += '<tr>' + "\n"; //Start the first new row!

		for( idx = 0; idx < 42; idx++) {
			currentDate = (idx - new Date(Math.floor(thisMonth/12), thisMonth%12).getDay()) + 1;

			if( (idx % 7) == 0) 
				outHtml += '</tr><tr>' + "\n";
			
			if( currentDate > 0 && currentDate <= daysInMonth) 
                        {
				currDate = new Date(targetYear, targetMonth, currentDate,"23","59","59");
				LastDateAllowed = new Date("2006","11","31","23","59","59");

//				if (currDate < new Date()) or (currDate > LastDateAllowed)
				if (currDate < new Date())
				{
					outHtml += '<td class="dayx">' + currentDate + '</td>' + "\n";
				}
				else
				{
					if (currDate > LastDateAllowed)
					{
						outHtml += '<td class="dayx">' + currentDate + '</td>' + "\n";
					}
					else
					{
//						if( (idx % 7) == 0)
//						{
//							outHtml += '<td class="dayx">' + currentDate + '</td>' + "\n";
//						}
//						else
//						{
//							if( (idx % 7) == 6)
//							{
//								outHtml += '<td class="dayx">' + currentDate + '</td>' + "\n";
//							}
//							else
//							{
								outHtml += '<td class="day" onclick="SelectDate( '+currentDate +');">' + currentDate + '</td>' + "\n";
//							}
//						}
					}
				}
			} 
                        else
                        {
				outHtml += '<td>&nbsp;</td>' + "\n";
			}
		}
		outHtml += '</tr>' + "\n";
		outHtml += '</table>' + "\n";

		if( document.getElementById) 
			document.getElementById( calendarId).innerHTML = outHtml;
		else
			document.all[ calendarId].innerHTML = outHtml;
	}
	
	function SelectDate( theDay) {
                  document.EntryPage.bkDay.options[(theDay-1)].selected = true;
                  changethemonthyeardropdown((monthsArray[ targetMonth].toUpperCase()) + ("" + targetYear).substring(2,4));
//                  document.EntryPage.bkMonthandYear.value = (monthsArray[ targetMonth].toUpperCase()) + ("" + targetYear).substring(2,4);

//		document.theForm.day.value = theDay;
//		document.theForm.month.value = monthsArray[ targetMonth];
//		document.theForm.year.value = targetYear;
		
		toggleCalendar( ); // Hide the calendar!
  	        changedatelist();
	}
	
	function GetDaysInMonth(date)
    {
       temp = new Date(date.valueOf());

       return new Date(temp.setMonth(temp.getMonth()+1).valueOf() - (24*60*60*1000)).getDate();
    }
    
    function toggleCalendar( ) {
	    if( document.getElementById) 
	    	document.getElementById( "calendar_a").style.display = document.getElementById( "calendar_a").style.display == "none" ? "" : "none";
	    else
	    	document.all[ "calendar_a"].style.display = document.all[ "calendar_a"].style.display == "none" ? "" : "none";
	    	
	    return true;
    }

    function PadLeft(str)
    {
       while(str.length < 2)
          str = "0" + str;

       return str;
    }

function MonthChanger(monthnamein)
{
switch (monthnamein)
{

  case "JAN": return "0"; break;
  case "FEB": return "1"; break;
  case "MAR": return "2"; break;
  case "APR": return "3"; break;
  case "MAY": return "4"; break;
  case "JUN": return "5"; break;
  case "JUL": return "6"; break;
  case "AUG": return "7"; break;
  case "SEP": return "8"; break;
  case "OCT": return "9"; break;
  case "NOV": return "10"; break;
  case "DEC": return "11"; break;
}
}


function changedatelist()
{
   var thisDay = document.EntryPage.bkDay.value;
   var thisYear = '20' + (document.EntryPage.bkMonthandYear.value).substring(3,5);
   var thisMonth = MonthChanger((document.EntryPage.bkMonthandYear.value).substring(0,3));

   var oneDay = 24*3600*1000;
   var startDate = new Date(thisYear, thisMonth, thisDay);
   var endDate = new Date(thisYear, thisMonth, thisDay);
   endDate.setTime(endDate.getTime()+(oneDay * parseInt(document.EntryPage.bkNights.value)));



// Clear target select list(s)
 
   document.EntryPage.wsDayMonthYear.length = 0;
   var optionNum = 0;

   for (var optionNum = 0; optionNum <= parseInt(document.EntryPage.bkNights.value); optionNum++)
  {
 
     // Populate target select list(s) with formatted text and value from tmpDate   

     tmpDate = new Date(thisYear, thisMonth, thisDay);
     tmpDate.setTime(tmpDate.getTime()+(oneDay * optionNum));
     
     var selText = daysArray[tmpDate.getDay()] + ", " + tmpDate.getDate() + stndrdArray[tmpDate.getDate()];
     selText += " ";
     selText += fullMonthsArray[tmpDate.getMonth()];
     selText += " ";
     selText += tmpDate.getFullYear();
     
     var selValue = tmpDate.getDate();
     selValue = PadLeft("" + selValue);
     selValue += monthsArray[tmpDate.getMonth()];
     tmpValue = tmpDate.getFullYear();
//     tmpValue = ("" + tmpValue).substring(2,4);

     selValue += tmpValue;
 
     document.EntryPage.wsDayMonthYear.options[optionNum] = new Option(selText, selValue);

   }
}