//PLEASE DO NOT USE THIS FILE ANY LONGER. LOOK IN /en/common/js/ FOR THIS FILE AND USE IT INSTEAD

// ******************************************************
//	Author:	Breck Morrison
//	Date:	07-22-1999
// ******************************************************

// Defining global variable elements
var elementA;
var elementB;
var elementC;
var the_Mon;
var the_Day;
var the_Year;
var monthName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")

// ******************************************************
//	FUNCTION createCalendar
//	opens a new window for the calendar
// ******************************************************
function createCalendar(A, B, C, A2, B2, C2, dateType) {
elementA = A;
elementB = B;
elementC = C;
elementA2 = A2;
elementB2 = B2;
elementC2 = C2;
//populate arrays
mon = new Array(12);
day = new Array(31);
year = new Array(5);

for (i=0; i<elementA.length; i++){
 
 mon[i] = elementA.options[i].value;
}
for (i=0; i<elementB.length; i++){

 day[i] = elementB.options[i].value;
 
}
for (i=0; i<elementC.length; i++){

 year[i] = elementC.options[i].value;
 
}

calendarWindow = window.open(".","Calendar",'width=167,height=160,top='+getWindowTop()+',left='+getWindowLeft()+',scrollbars=no,resizable=no');
// Get todays Date Object
var today = new Date();

// Allows them to select which month to start with on calendar from drop down box named month
var mth = elementA.selectedIndex;

// Allows them to select which year to start with on calendar from drop down box named year
var yearVal = today.getFullYear()+elementC.selectedIndex;

// call the function to populate the window
generateCalendar(calendarWindow, mth, yearVal, dateType)
}


// ******************************************************
// FUNCTION generateCalendar
// generates the meat of the calendar
// ******************************************************

function generateCalendar(target, mth, year, dateType) {

// begin table for calendar
target.document.open()
calendar = "<html><head><title>calendar</title></head><body bgcolor=#ffffff topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>"
calendar +="<table align=center border=0 cellspacing=0 cellpadding=0 width=167>"
calendar +="<tr valign=top height=21 width=166>"

var endday = getDaysInMonth(mth, year)
var goPrevMonth = prevMonth(mth)
var goNextMonth = nextMonth(mth)
var nextYear = changeYear("next",mth,parseInt(year))
var prevYear = changeYear("prev",mth,parseInt(year))

//writes month and next and back buttons

if (displayMoveBack(mth, year)) {
		calendar +="<td width=24 height=21 bgcolor=#cccccc><a href='javascript:opener.generateCalendar(self, " + goPrevMonth + ", " + prevYear + ", " + "\"" + dateType +  "\"" + ")'><img src='/en/common/media/images/nav/nav_left_arrow.gif' width=24 height=21 border=0></a></td>"
	} else {
		calendar +="<td width=24 height=21 bgcolor=#cccccc>&nbsp;</td>"
	}
	calendar +="<td width=118 height=21 bgcolor=#cccccc align='center'><STRONG><FONT COLOR='#000000' SIZE='2' FACE='Arial,Helvetica'>" + monthName[mth] + " " + year + "</FONT></STRONG></td>"
	calendar +="<td width=24 height=21 bgcolor=#cccccc><a href='javascript:opener.generateCalendar(self, " + goNextMonth + ", " + nextYear + ", " + "\"" + dateType +  "\"" + ")'><img src='/en/common/media/images/nav/nav_right_arrow.gif' width=24 height=21 border=0></a></td></tr>"
	calendar +="</table></body></html>"
	target.document.close();

//writes in the day of the week labels
calendar +="<table align=center border=0 cellspacing=0 cellpadding=0 width=167>"
calendar +="<tr align=center>"
calendar +="<td width=167 align=center><img src='/en/common/media/images/headers/header_days.gif' width=167 height=12 border=0></td>"

calendar +="</tr></table></center>"

// get the first day of the month
thedate = new Date (year, mth, 1);
firstDay = thedate.getDay()

selectedmonth = mth;
var today = new Date();
var thisyear = today.getYear() + 1900;
selectedyear = year

var lastDay = (endday + firstDay+1)

calendar +="<table align=center border=0 cellspacing=1 cellpadding=0 width=167><tr>"
for (var i = 1; i < lastDay; i++)
	{
	if (i <= firstDay)
		{
		// 'empty' boxes prior to first day
		calendar +="<td bgcolor='#e8e8e7'>&nbsp;</td>"
		}
	else  
	 
		{
		// enter date number
		var lookd = today.getDate()
		var lookm = today.getMonth()
		if (( selectedmonth == lookm ) && ( lookd == (i-firstDay) )) {
		calendar +="<td align=center bgcolor='#cccccc'><FONT SIZE='2' FACE='Arial,Helvetica'><a href='JavaScript:opener.closeCalendar(" + selectedmonth + ", " + (i-firstDay) + ", " + selectedyear + ", " + "\"" + dateType +  "\"" + ");self.close()'> " + (i-firstDay) + "</a></FONT>&nbsp;</td>\n"
		} else {
		calendar +="<td align=center bgcolor='#e8e8e7'><FONT SIZE='2' FACE='Arial,Helvetica'><a href='JavaScript:opener.closeCalendar(" + selectedmonth + ", " + (i-firstDay) + ", " + selectedyear + ", " + "\"" + dateType +  "\"" + ");self.close()'> " + (i-firstDay) + "</a></FONT>&nbsp;</td>\n"
	}}
	//must start new row after each week
	if (i % 7 == 0 &&  i != lastDay)
		{
		calendar +="</tr><tr>"
		}
	}
calendar +="</tr></table>"

target.document.write(calendar);
target.document.close()	
}

// ******************************************************
// FUNCTION closeCalendar
// changes date field when a date is clicked
// ******************************************************
function closeCalendar(m, d, y, dateType)  {
	
	 the_Mon = -1;
	 for(i=0; i<mon.length; i++){
	 if(monthName[m] == mon[i]){
	  the_Mon = i;
	  }
	 } 
	 if (the_Mon == -1) 
		the_Mon = m;
	 for(i=0; i<day.length; i++){
	 if(d == day[i]){
	  the_Day = i;
	  }
	 }
	 for(i=0; i<year.length; i++){
	 if(y == year[i]){
	  the_Year = i;
	  }
	 }
	var date = m + "-" + d + "-" + y
	elementA.selectedIndex = the_Mon;
	elementB.selectedIndex  = the_Day;
	elementC.selectedIndex  = the_Year;
	
	if (dateType == "checkIn") {
	
		if (elementB.selectedIndex == getDaysInMonth(m, y)-1) {
			elementA2.selectedIndex = the_Mon + 1;
			elementB2.selectedIndex = 0;
		}
		else {
			elementA2.selectedIndex = the_Mon;
			elementB2.selectedIndex  = the_Day + 1;
		}	
		elementC2.selectedIndex = the_Year;
	}
}

// ******************************************************
// FUNCTION getDaysInMonth
// finds the number of days in the month (mthldx)
// ******************************************************

function getDaysInMonth(mth, YrStr)
{

// all the rest have 31
var maxDays=31

// expect Feb. (of course)
if (mth==1) 
	{
	if (isLeapYear(YrStr))
		{
		maxDays=29;
		}
	else 
		{
		maxDays=28;
		}
	}

// thirty days hath...
if (mth==3 || mth==5 || mth==8 || mth==10)
	{
	maxDays=30;
	}
return maxDays;
}


// ******************************************************
// FUNCTION isLeapYear
// finds if the year (yrStr) is a leap year
// ******************************************************
function isLeapYear(yrStr)
{
var leapYear=false;
var year = parseInt(yrStr, 10);
// every fourth year is a leap year
if (year%4 == 0)
	{
	leapYear=true;
	// unless it's a multiple of 100
	if (year%100 == 0)
		{
		leapYear=false;
		// unless it's a multiple of 400
		if (year%400 == 0)
			{
			leapYear=true;
			}
		}
	}
return leapYear;
}


// ******************************************************
// FUNCTION nextMonth
// finds the next month
// ******************************************************
function nextMonth(month) 
{
if (month==11)
	{
	return 0;
	}
else
	{
	return (month+1);
	}
}


// ******************************************************
// FUNCTION prevMonth
// finds the previous month
// ******************************************************
function prevMonth(month) 
{
var prevMonth = (month-1)
if (month==0)
	{
	prevMonth = 11;
	}
return prevMonth
}


// ******************************************************
// FUNCTION changeYear
// increments or decrements month when it goes past Jan or Dec
// ******************************************************

function changeYear(direction,month,year)
{
var theYear = year
if (direction=="next")
	{
	if (month == 11)
		{
		theYear = (year+1)
		}
	}
if (direction=="prev")
	{
	if (month == 0)
		{
		theYear = (year-1)
		}
	}
return theYear
 }
 
 //for positioning of calendar window
 
function getWindowLeft() {

    winW = (ie) ? screen.width : window.outerWidth;
	bLeft = (ie) ? 0 : this.window.screenX;
	
	winL = (winW/2) + bLeft;

	return winL;		
}

function getWindowTop() {

	winH = (ie) ? screen.Availheight : window.outerHeight;
	bTop = (ie) ? 0 : this.window.screenY;
	
	winT = (winH/2) + bTop;

	return winT;
} 

// returns true if we should display a "previous month" icon for the given month, year
function displayMoveBack( month, year ) {
  var today = new Date()
  var parm  = new Date( year, month, 1 )
  return ( parm.getFullYear() == today.getFullYear() && parm.getMonth() > today.getMonth() ) ||
           parm.getFullYear() > today.getFullYear();
}