//
// JavaScript Calendar Component
// Author: Robert W. Husted  (robert.husted@iname.com)
// Date:   8/22/1999
// Modified Date: 11/30/1999
// Modified By:   Robert W. Husted
// Notes:  Added frameset support (changed reference for "newWin" to "top.newWin")
//         Also changed Spanish "March" from "Marcha" to "Marzo"
//         Fixed JavaScript Date Anomaly affecting days > 28
//
//
//
// Usage:  Add the following lines of code to your page to enable the Calendar
//         component.
//
//
//         // THIS LINE LOADS THE JS LIBRARY FOR THE CALENDAR COMPONENT
//
//         <SCRIPT LANGUAGE="JavaScript" SRC="calendar.js"><script>
//
//         // THIS LINE IS USED IN CONJUNCTION WITH A FORM FIELD (myDateField) IN A FORM (myForm).
//         // Replace "myForm" and "myDateField" WITH THE NAME OF YOUR FORM AND INPUT FIELD RESPECTIVELY
//         // WINDOW OPTIONS SET THE WIDTH, HEIGHT, AND X/Y POSITION OF THE CALENDAR WINDOW
//         // WITH TITLEBAR ON, ALL OTHER OPTIONS (TOOLBARS, ETC) ARE DISABLED BY DEFAULT
//
//         <A HREF="javascript:doNothing_local()" onClick="setDateField(document.myForm.myDateField);top.newWin = window.open('calendar.html','cal','dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes')">
//         <IMG SRC="calendar.gif" BORDER=0></A><font size=1>Popup Calendar</font>
//
//
//
// Required Files:
//
//         snippet_helper_calendar.js   - contains all JavaScript functions to make the calendar work
//
//         snippet_helper_calendar.html - frameset document (not required if you call the showCalendar()
//                         function.  However, calling showCalendar() directly causes
//                         the Java Virtual Machine (JVM) to start which slows down the
//                         loading of the calendar.)
//
//
// Files Generally Included:
//
//         calendar.gif  - image that looks like a little calendar
//
//         yourPage.html - page that contains a form and a date field which implements
//                         the calendar component
//



// BEGIN USER-EDITABLE SECTION -----------------------------------------------------



// SPECIFY DATE FORMAT RETURNED BY THIS CALENDAR
// (THIS IS ALSO THE DATE FORMAT RECOGNIZED BY THIS CALENDAR)

// DATE FORMAT OPTIONS:
//
// dd   = 1 or 2-digit Day
// DD   = 2-digit Day
// mm   = 1 or 2-digit Month
// MM   = 2-digit Month
// yy   = 2-digit Year
// YY   = 4-digit Year
// yyyy = 4-digit Year
// month   = Month name in lowercase letters
// Month   = Month name in initial caps
// MONTH   = Month name in captital letters
// mon     = 3-letter month abbreviation in lowercase letters
// Mon     = 3-letter month abbreviation in initial caps
// MON     = 3-letter month abbreviation in uppercase letters
// weekday = name of week in lowercase letters
// Weekday = name of week in initial caps
// WEEKDAY = name of week in uppercase letters
// wkdy    = 3-letter weekday abbreviation in lowercase letters
// Wkdy    = 3-letter weekday abbreviation in initial caps
// WKDY    = 3-letter weekday abbreviation in uppercase letters
//
// Examples:
//
// calDateFormat = "mm/dd/yy";
// calDateFormat = "Weekday, Month dd, yyyy";
// calDateFormat = "wkdy, mon dd, yyyy";
// calDateFormat = "DD.MM.YY";     // FORMAT UNSUPPORTED BY JAVASCRIPT -- REQUIRES CUSTOM PARSING
//

calDateFormat_local    = "mm/dd/yyyy";

// CALENDAR COLORS

tableBGColor_local     = "white";         // BG COLOR OF THE BOTTOM FRAME'S TABLE /* neetu */
cellColor_local        = "white";	    // TABLE CELL BG COLOR OF THE DATE CELLS IN THE BOTTOM FRAME

// FORMATTING PREFERENCES
bottomBorder_local  = false;        // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
tableBorder_local   = 0;            // SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none

// END USER-EDITABLE SECTION -------------------------------------------------------


// DETERMINE BROWSER BRAND
var isNav_local = false;
var isIE_local  = false;

// ASSUME IT'S EITHER NETSCAPE OR MSIE
if (navigator.appName == "Netscape") {
    isNav_local = true;
}else {
    isIE_local = true;
}

//TO COUNT THE NUMBER OF CLICKS ON NEXT PREV MONTH
count_local = 0;

//TO SET THE TIMER
var timerMonth_local;

// GET CURRENTLY SELECTED LANGUAGE
selectedLanguage_local = navigator.language;

// type = PLAIN FOR DISPLAY ON THE CALENDAR
// type = POPUP for POPUP THE CALENDAR
type_local='';
dateFieldName_local = '';

/*------------------------------------------------------------------------------------------------
Function that sets the Thumbnail calendar for all the three views
------------------------------------------------------------------------------------------------*/
function setValuesThumbNail_local(date1, type1)
{
	type_local = type1;
	setDateField_local(date1);
}
/*------------------------------------------------------------------------------------------------
Writes the top and bottom part of the calendar in case of popup
-------------------------------------------------------------------------------------------------*/
function RZpopupCalendar_local()
{
    // USE THE JAVASCRIPT-GENERATED DOCUMENTS (calDocTop_local, calDocBottom_local) IN THE FRAMESET
    calDocFrameset =
        "<HTML><HEAD><TITLE>JavaScript Calendar</TITLE></HEAD>\n" +
        "<FRAMESET ROWS='50,*' FRAMEBORDER='0'>\n" +
        "  <FRAME NAME='topCalFrame' SRC='javascript:parent.opener.calDocTop_local' SCROLLING='no'>\n" +
        "  <FRAME NAME='bottomCalFrame' SRC='javascript:parent.opener.calDocBottom_local' SCROLLING='no'>\n" +
        "</FRAMESET>\n";

    // DISPLAY THE CALENDAR IN A NEW POPUP WINDOW
    RZ.calendarwin = RZpopupUrl('Calendar',
	                            'javascript:parent.opener.calDocFrameset',190,180);
    return RZ.calendarwin;
}

/*------------------------------------------------------------------------------------------------
Function used in the popup calendar
-------------------------------------------------------------------------------------------------*/
function RZcalendar_local(dateFieldName1, RZ1, type1)
{
	type_local = type1;
	RZ = RZ1;
	dateField = new Date();
	dateFieldName_local = dateFieldName1;
	setDateField_local(dateField);
	RZ.calendarwin = RZpopupCalendar_local();
}

/*------------------------------------------------------------------------------------------------
Pre-build portions of the calendar when this js library loads into the browser
------------------------------------------------------------------------------------------------*/
buildCalParts_local();

/*------------------------------------------------------------------------------------------------
Set the initial value of the global date field
------------------------------------------------------------------------------------------------*/
function setDateField_local(dateField)
{
    // ASSIGN THE INCOMING FIELD OBJECT TO A GLOBAL VARIABLE
    calDateField_local = dateField;
    // GET THE VALUE OF THE INCOMING FIELD
    inDate_local = dateField.value;
    calDate_local = new Date(dateField);
    calDay_local = calDate_local.getDate();
    calDate_local.setDate(1);
    // THE CALENDAR FRAMESET DOCUMENTS ARE CREATED BY JAVASCRIPT FUNCTIONS
    calDocTop_local    = buildTopCalFrame_local();
    calDocBottom_local = buildBottomCalFrame_local();
}

/*--------------------------------------------------------------------------------------------------
Create the top frame for the Calendar Thumbnail
--------------------------------------------------------------------------------------------------*/
function buildTopCalFrame_local()
{
	var plainpop = "";

	//TOPFRAME FOR THE POPUP CALENDAR
	if ('plain' != type_local)
	{
		plainpop = "<td width=\"20\"><a href = \"javascript:parent.opener.setPreviousYear_local();\">" +
			"<img src=\"../images/leftdouble_arrow.gif\" alt=\"Previous Year\" border=\"0\"></a></td> "+
			"<td width=\"20\"><a  href = \"javascript:parent.opener.setPreviousMonth_local();\">" +
			"<img src=\"../images/left_arrow.gif\" alt=\"Previous Month\" border=\"0\"></a></td> "+
			"<td width=\"100\" align=\"center\"><span class=\"monthName\">" + getMonthSelect_local() + "</span></td>"+
			"<TD width=\"20\">" +
        	"<a href =\"javascript:parent.opener.setNextMonth_local();\">" +
        	"<img src=\"../images/right_arrow.gif\" alt=\"Next Month\" border=\"0\"></a></td>"+
        	"<TD width=\"20\">" +
        	"<a href =\"javascript:parent.opener.setNextYear_local();\">" +
        	"<img src=\"../images/rightdouble_arrow.gif\" alt=\"Next Year\" border=\"0\"></a>"
	}
	//topframe for calendar_app thumbnail calendar
	else
	{
		// CSS LOCATION FIX
		// var tmpLoc = location.href.replace(/index\.html\?.*/, "");
		
		var tmpRootLoc = location.href.replace(/\/calendar_app.*/, "");
		var tmpLoc = tmpRootLoc + "/calendar_app";
		
		//----- Double left arrow
		if (showNextPrevYear == 'yes')
			plainpop += '<td width=20><a href="javascript:'
					  + "parent.parent.parent.mainFrame.headerFrame.setNextPrev('back','year');"
					  + '"><img src="' + tmpLoc + '/images/leftdouble_arrow.gif" '
					  + 'alt="Previous Year" border="0"></a></td>'
		else
			plainpop += '<td width="20"></td>';

		//----- Single left arrow
		plainpop += '<td width=20><a href="javascript:'
				  + "parent.parent.parent.mainFrame.headerFrame.setNextPrev('back','month');"
				  + '"><img src="' + tmpLoc + '/images/left_arrow.gif" '
				  + 'alt="Previous Month" border="0"></a></td>'

		//----- Month Name
		plainpop += '<td width="100" align="center">'
				  + '<a class=monthName href="javascript:'
				  + "changeView('','month');"
				  + '">' + getMonthSelect_local() + '</a></td>'

		//----- Single right arrow
		plainpop += '<td width=20><a href="javascript:'
				  + "parent.parent.parent.mainFrame.headerFrame.setNextPrev('forward','month');"
				  + '"><img src="' + tmpLoc + '/images/right_arrow.gif" '
				  + 'alt="Next Month" border="0"></a></td>';

		//----- Double right arrow
		if (showNextPrevYear == 'yes')
			plainpop += '<td width=20><a href="javascript:'
					  + "parent.parent.parent.mainFrame.headerFrame.setNextPrev('forward','year');"
					  + '"><img src="' + tmpLoc + '/images/rightdouble_arrow.gif" '
					  + 'alt="Next Year" border="0"></td></a>';
		else
			plainpop += '<td width="20"></td>';
	}

	// CSS LOCATION FIX
	//var tmpLoc = location.href.replace(/index\.html\?.*/, "calendar_style.css");
	
	var tmpRootLoc = location.href.replace(/\/calendar_app.*/, "");
	var tmpLoc = tmpRootLoc + "/calendar_app/calendar_style.css";
	
    var calDoc =
        "<HTML>" +
        "<HEAD>" +
        "<link href = \"" + tmpLoc + "\" rel=\"stylesheet\" type=\"text/css\">" +
        "</HEAD>" +
        "<BODY class=\"lighterGrey\">" +
        "<FORM NAME=\"calControl\" onSubmit=\"return false;\">" +
        "<CENTER>" +
        "<TABLE width=200 CELLPADDING=0 CELLSPACING=0 border=\"0\" style=\"table-layout:fixed\">" +
        "<TR class = \"lighterGrey\" >" +
        "</TD>" +
        plainpop +
        "<TD>" +
        "</TD>" +
        "<TD>" +
        "</TD>" +
        "</TR>" +
        "</TABLE>" +
        "</CENTER>" +
        "</FORM>" +
        "</BODY>" +
        "</HTML>";
    return calDoc;
}

/*-----------------------------------------------------------------------------------------------
Create the bottom calendar frame
------------------------------------------------------------------------------------------------*/
function buildBottomCalFrame_local() {

    // START CALENDAR DOCUMENT
    var calDoc = calendarBegin_local;

    // GET MONTH, AND YEAR FROM GLOBAL CALENDAR DATE
    month   = calDate_local.getMonth();
    year    = calDate_local.getFullYear();

    // FOR CONTINUOUS HIGHLIGHT OF THE CURRENT DATE get the date for today
    todayDate = new Date();

    // GET GLOBALLY-TRACKED DAY VALUE (PREVENTS JAVASCRIPT DATE ANOMALIES)
    day  = calDay_local;
    var i   = 0;

    // DETERMINE THE NUMBER OF DAYS IN THE CURRENT MONTH
    // argument passed for the use of this function in week view
    var days = getDaysInMonth_local(month, year);

    // IF GLOBAL DAY VALUE IS > THAN DAYS IN MONTH, HIGHLIGHT LAST DAY IN MONTH
    if (day > days) {
        day = days;
    }

    // DETERMINE WHAT DAY OF THE WEEK THE CALENDAR STARTS ON
    var firstOfMonth = new Date (year, month, 1);
      // GET THE DAY OF THE WEEK THE FIRST DAY OF THE MONTH FALLS ON
    var startingPos  = firstOfMonth.getDay();
	days += startingPos;

    // KEEP TRACK OF THE COLUMNS, START A NEW ROW AFTER EVERY 7 COLUMNS
    var columnCount = 0;

    // MAKE BEGINNING NON-DATE CELLS BLANK
    for (i = 0; i < startingPos; i++) {
        calDoc += blankCell_local;
		columnCount++;
    }

    // SET VALUES FOR DAYS OF THE MONTH
    var currentDay = 0;

	//set the style for weekdays
    var dayType    = "weekday";

    // DATE CELLS CONTAIN A NUMBER
	var paddingChar = " ";
    for (i = startingPos; i < days; i++) {
        // ADJUST SPACING SO THAT ALL LINKS HAVE RELATIVELY EQUAL WIDTHS
        if (i - startingPos + 1 < 10) {
            padding = "  ";
        } else {
            padding = " ";
        }

        // GET THE DAY CURRENTLY BEING WRITTEN
        currentDay = i-startingPos+1;

        //TO DISPLAY THE WEEKENDS IN DIFFERENT COLOUR
        var iterDate = new Date(year, month, currentDay);
        var pos = iterDate.getDay();

        //SET THE TYPE OF DAY, THE focusDay GENERALLY APPEARS AS A DIFFERENT COLOR
        if (currentDay == day) {
            dayType = "selectedDay";
        } else if (todayDate.getMonth() == month && todayDate.getFullYear() == year
        	&& todayDate.getDate()==currentDay)
		{
            dayType = "currentDay";
        }
        else if (pos % 6 == 0) {
            dayType = "weekEnd";
        } else {
            dayType = "weekDay";
        }

		// if calendar is popupcalendar, then just return the date
		if( 'plain' != type_local ) {
			calDoc += "<TD width ='10' align=center bgcolor='" + cellColor_local + "'>" +
					  "<a class='" + dayType + "' href=\"javascript:parent.opener.returnDate_local(" +
						   currentDay + ");\">" + padding + currentDay + paddingChar + "</a></TD>";
		}
		// if calendar_app thumbnail calendar
		else
		{
			//ADD THE DAY TO THE CALENDAR STRING
			calDoc += '<TD width="10" align="center" bgcolor="' + cellColor_local + '">'
					+ '<a class="' + dayType + '" href="javascript:'
					+ "parent.parent.parent.mainFrame.headerFrame.changeDay(" + currentDay + ");"
					+ '">' + padding + currentDay + paddingChar
					+ '</a></TD>';
		}
		columnCount++;

		// START A NEW ROW WHEN NECESSARY
		if (columnCount % 7 == 0) {
			calDoc += "</TR><TR>";
		}
	  }

    // MAKE REMAINING NON-DATE CELLS BLANK
    for (i = days; i < 42; i++)  {
        calDoc += blankCell_local;
		columnCount++;
	    // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR>";
            if (i < 41) {
                calDoc += "<TR>";
            }
        }
    }

    // FINISH THE NEW CALENDAR PAGE
    calDoc += calendarEnd;
	
    // RETURN THE COMPLETED CALENDAR PAGE
    return calDoc;
}

/*------------------------------------------------------------------------------------------------
write the monthly calendar to the bottom calendar frame
-------------------------------------------------------------------------------------------------*/
function writeCalendar_local()
{
	if(type_local=='plain'){
		parentFrame = bodyFrame.fraCalThumbnail;
	}

   // CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEA
      calDocBottom_local = buildBottomCalFrame_local();

   //WRITE THE BOTTOM FRAME on change of month/ year in the thumbnail / popup calendar
    if('plain' != type_local)	{
		RZ.calendarwin.bottomCalFrame.document.open();
		RZ.calendarwin.bottomCalFrame.document.write(calDocBottom_local);
		RZ.calendarwin.bottomCalFrame.document.close();
		RZ.calendarwin.focus();
    }else {
		parentFrame.bottomCalFrame.document.open();
		parentFrame.bottomCalFrame.document.write(calDocBottom_local);
		parentFrame.bottomCalFrame.document.close();
    }
}

/*---------------------------------------------------------------------------------------------
Common function for the changing the month, year (Timeout implementation)
functionName - input - name of the function ( to move pre/next month/year)
----------------------------------------------------------------------------------------------*/
function setMonth_local(functionName)
{
	var monthStr = "";
	count_local++;
	if (undefined != timerMonth_local) {
		clearTimeout(timerMonth_local);
	}
	monthStr += functionName + "('" + count_local + "');";
	monthStr += "parent.parent.parent.location.href='../calendar_view_main.html'";
	timerMonth_local = setTimeout(monthStr, parent.parent.parent.RZtimeOut);
}

/*--------------------------------------------------------------------------------------------
Function to increment the year
---------------------------------------------------------------------------------------------*/
function setNextYear_local()
{
	var year = calDate_local.getFullYear();
	if (type_local == 'plain') {
		//increasing the number of year depending on the clicks
		for(monthC = 0; monthC < count_local; monthC++) {
			year++;
		}
	} else {
		year++;
    }
	calDate_local.setFullYear(year);

	if (type_local == 'plain') {
		dateMonth = new Date(topframe.RZ.calendar.date).getDate();
		calDate_local.setDate(dateMonth);
		//SETTING THE SELECTED DATE IN THE COOKIE
		topframe.RZ.calendar.date = calDate_local;
	}
	//WRITING THE TOP FRAME OF THE CALENDAR
	writeTopCal_local();
	//WRITING THE BOTTOM FRAME OF THE CALENDAR
	writeCalendar_local();
    count_local = 0;
}

/*--------------------------------------------------------------------------------------------
Function to go a year back
---------------------------------------------------------------------------------------------*/
function setPreviousYear_local()
{
	var year = calDate_local.getFullYear();
	if(type_local == 'plain') {
		for (monthC = 0;monthC < count_local; monthC++){
			year--;
		}
	} else {
		year--;
	}
	calDate_local.setFullYear(year);

	//ADDED TO CHANGE THE DATE AND MONTH FOR THE VARIOUS VIEWS
	if (type_local == 'plain') {
		dateMonth = new Date(topframe.RZ.calendar.date).getDate();
		calDate_local.setDate(dateMonth);

		//SETTING THE SELECTED DATE IN THE COOKIE
		topframe.RZ.calendar.date = calDate_local;
	}
	//WRITING THE TOP FRAME OF THE CALENDAR
	writeTopCal_local();
	//WRITING THE BOTTOM FRAME OF THE CALENDAR
	writeCalendar_local();
    count_local = 0;
}

/*-----------------------------------------------------------------------------------------------
Function to set the previous month
------------------------------------------------------------------------------------------------*/
function setPreviousMonth_local()
{
    var year  = calDate_local.getFullYear();
    if (isFourDigitYear_local(year)) {
        var month = calDate_local.getMonth();
        // IF MONTH IS JANUARY, SET MONTH TO DECEMBER AND DECREMENT THE YEAR
  		if (type_local == 'plain'){
        	for (monthC = 0; monthC < count_local; monthC++) {
				if (month == 0) {
				    month = 11;
				    if (year > 1000) {
						year--;
						calDate_local.setFullYear(year);
			    	}
				} else {
			    	month--;
				}
        	}
        } else {
        	if (month == 0) {
		    	month = 11;
		   		if (year > 1000) {
					year--;
					calDate_local.setFullYear(year);
		    	}
			} else {
		   		month--;
			}
        }
        //ADDED TO CHANGE THE DATE AND MONTH FOR THE VARIOUS VIEWS
        calDate_local.setMonth(month);
        if(type_local == 'plain'){
        	calDate_local.setDate(calDateField_local.getDate());
        	//SETTING THE SELECTED DATE IN THE COOKIE
			topframe.RZ.calendar.date = calDate_local;
		}
        //WRITING THE TOP FRAME OF THE CALENDAR
        writeTopCal_local();
        //WRITING THE BOTTOM FRAME OF THE CALENDAR
        writeCalendar_local();
        count_local = 0;
    }
}

/*-----------------------------------------------------------------------------------------------
Function to set the next month
------------------------------------------------------------------------------------------------*/
function setNextMonth_local()
{
    var year = calDate_local.getFullYear();

    if (isFourDigitYear_local(year)) {
        var month = calDate_local.getMonth();
        // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
        if(type_local == 'plain') {
        	for(monthC=0; monthC < count_local; monthC++) {
				if (month == 11) {
					month = 0;
					year++;
					calDate_local.setFullYear(year);
				} else {
					month++;
				}
        	}
        } else {
        	if (month == 11) {
			    month = 0;
			    year++;
			    calDate_local.setFullYear(year);
			} else {
		    	month++;
			}
        }
        calDate_local.setMonth(month);
        if (type_local == 'plain') {
			// ADDED TO CHANGE THE MONTH, DATE FOR THE VARIOUS VIEWS
			dateMonth = new Date(topframe.RZ.calendar.date).getDate();
			calDate_local.setDate(dateMonth);

			//SETTTING THE SELECTED DATE IN THE COOKIE
			topframe.RZ.calendar.date = calDate_local;
        }
        //WRITING THE TOP FRAME OF THE CALENDAR WITH THE NEW MONTH
    	writeTopCal_local();
    	//WRITING THE BOTTOM FRAME OF THE CALENDAR
        writeCalendar_local();
        count_local = 0;
    }
}

/* --------------------------------------------------------------------------------------------
To write the top portion of the calendar with the new month value
----------------------------------------------------------------------------------------------*/
function writeTopCal_local()
{
	if(type_local=='plain') {
		parentFrame = bodyFrame.fraCalThumbnail;
	}
	calDocTop_local = buildTopCalFrame_local();

	if (type_local != "plain") {
		RZ.calendarwin.topCalFrame.document.open();
		RZ.calendarwin.topCalFrame.document.write(calDocTop_local);
		RZ.calendarwin.topCalFrame.document.close();
		RZ.calendarwin.focus();
	} else {
		parentFrame.topCalFrame.document.open();
		parentFrame.topCalFrame.document.write(calDocTop_local);
		parentFrame.topCalFrame.document.close();
	}
}

/*------------------------------------------------------------------------------------------
Function to find the week number in a year according to the date
--------------------------------------------------------------------------------------------*/
function weekNumber_local(RZdate)
{
	var weekDate = new Date(RZdate);
	var RZweekDay = weekDate.getDate();
	var RZweekMonth = weekDate.getMonth();
	var RZweekYear = weekDate.getFullYear();
	var firstWeekDate = new Date(RZweekYear,0,1);
	var RZtotalDays = 0;
	var RZweekNumber = 1;

	var day = firstWeekDate.getDay();
	if (day == 0) day = 7;

	for (i = 0; i < RZweekMonth; i++) {
		RZtotalDays += getDaysInMonth_local(i,RZweekYear);
	}
	RZtotalDays += RZweekDay;
	for (u = 0; u < (RZtotalDays); u++) {
		if (day == 8) {
			RZweekNumber++;
			day = 1;
		}
		day++;
	}
	return RZweekNumber;
}

/*-------------------------------------------------------------------------------------------
Get number of days in month
Month argument is passed for the use of this function in week view
---------------------------------------------------------------------------------------------*/
function getDaysInMonth_local(month, year)
{
    var days;
    var month = month + 1;
    var year  = year;

    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
        month==10 || month==12)  {// RETURN 31 DAYS
        days=31;
    } else if (month==4 || month==6 || month==9 || month==11) {// RETURN 30 DAYS
        days=30;
    } else if (month==2)  {// RETURN 29 DAYS
        if (isLeapYear_local(year)) {
            days=29;
        } else {// RETURN 28 DAYS
            days=28;
        }
    }
    return (days);
}

/*-----------------------------------------------------------------------------------------
Check to see if year is a leap year
------------------------------------------------------------------------------------------*/
function isLeapYear_local (Year)
{
    if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) {
        return (true);
    } else {
        return (false);
    }
}

/*--------------------------------------------------------------------------------------------------
ENSURE THAT THE YEAR IS FOUR DIGITS IN LENGTH
---------------------------------------------------------------------------------------------------*/
function isFourDigitYear_local(year) {
    if (year.length != 4) {
        /*document.frames['topCalFrame'].document.calControl.year.value = calDate_local.getFullYear();
        document.frames['topCalFrame'].document.calControl.year.select();
        document.frames['topCalFrame'].document.calControl.year.focus();*/
    } else {
        return true;
    }
    return true;
}

/*--------------------------------------------------------------------------------------------------
Build the month select list
---------------------------------------------------------------------------------------------------*/
function getMonthSelect_local()
{
    // BROWSER LANGUAGE CHECK DONE PREVIOUSLY (navigator.language())
    // FIRST TWO CHARACTERS OF LANGUAGE STRING SPECIFIES THE LANGUAGE
    // (THE LAST THREE OPTIONAL CHARACTERS SPECIFY THE LANGUAGE SUBTYPE)
    // SET THE NAMES OF THE MONTH TO THE PROPER LANGUAGE (DEFAULT TO ENGLISH)

    if (selectedLanguage_local == "fr") { // IF FRENCH
        monthArray = new Array('Janvier', 'Fvrier', 'Mars', 'Avril', 'Mai', 'Juin',
                               'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Dcembre');
    } else if (selectedLanguage_local == "de") {// IF GERMAN
        monthArray = new Array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
                               'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
    } else if (selectedLanguage_local == "es") { // IF SPANISH
        monthArray = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
                               'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
    } else {// DEFAULT TO ENGLISH
        monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June',
                               'July', 'August', 'September', 'October', 'November', 'December');
    }

    // DETERMINE MONTH TO SET AS DEFAULT
    var activeMonth = calDate_local.getMonth();
    var activeYear = calDate_local.getFullYear();

    // RETURN A STRING VALUE WHICH CONTAINS THE NAME OF THE MONTH AND YEAR
    activeMonth = monthArray[activeMonth] + " " + activeYear;

    return activeMonth;
}

/*--------------------------------------------------------------------------------
Set days of the week depending on language
---------------------------------------------------------------------------------*/
function createWeekdayList_local()
{

    if (selectedLanguage_local == "fr") {// IF FRENCH
        weekdayList  = new Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi',
								 'Jeudi', 'Vendredi', 'Samedi');
        weekdayArray = new Array('Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa');
    } else if (selectedLanguage_local == "de") {// IF GERMAN
        weekdayList  = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch',
								 'Donnerstag', 'Freitag', 'Samstag');
        weekdayArray = new Array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
    } else if (selectedLanguage_local == "es") { // IF SPANISH
        weekdayList  = new Array('Domingo', 'Lunes', 'Martes', 'Mircoles',
								 'Jueves', 'Viernes', 'Sbado')
        weekdayArray = new Array('Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa');
    } else {
        weekdayList  = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday',
								 'Thursday', 'Friday', 'Saturday');
        weekdayArray = new Array('S','M','T','W','T','F','S');
    }

    // START HTML TO HOLD WEEKDAY NAMES IN TABLE FORMAT
    var weekdays = "<TR>";

    // LOOP THROUGH WEEKDAY ARRAY
    for (i in weekdayArray) {
        weekdays += "<TD class='dayName' align=center >" + weekdayArray[i] + "</TD>";
    }
    weekdays += "</TR>";

    // RETURN TABLE ROW OF WEEKDAY ABBREVIATIONS TO DISPLAY ABOVE THE CALENDAR
    return weekdays;
}

/*----------------------------------------------------------------------------------
Pre-build portions of the calendar (for performance reasons)
-----------------------------------------------------------------------------------*/
function buildCalParts_local()
{
    // GENERATE WEEKDAY HEADERS FOR THE CALENDAR
    weekdays = createWeekdayList_local();

    // BUILD THE BLANK CELL ROWS
    blankCell_local = "<TD width = 10 align=center bgcolor=\"" + cellColor_local + "\">   </TD>";

	// CSS LOCATION FIX
	var tmpLoc = location.href.replace(/index\.html\?.*/, "calendar_style.css");
	
    // BUILD THE TOP PORTION OF THE CALENDAR PAGE USING CSS TO CONTROL SOME DISPLAY ELEMENTS
    calendarBegin_local = "<HTML>" + "<HEAD>" +
        // STYLESHEET DEFINES APPEARANCE OF CALENDAR
        "<link href = \"" + tmpLoc + "\" rel=\"stylesheet\" type=\"text/css\">" +
        	"</HEAD>" + "<BODY>" + "<CENTER>";

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE TABLE OUTLINES PROPERLY
        if (isNav_local) {
            calendarBegin_local +=
                "<TABLE  width=150 CELLPADDING=0 CELLSPACING=0 BORDER=0 \"style=table-layout:fixed\""
				+  " BGCOLOR=\"" + tableBGColor_local + "\"><TR><TD>";
        }

        // BUILD WEEKDAY HEADINGS
        calendarBegin_local +=
				"<TABLE width=150 CELLPADDING=0 CELLSPACING=0 BORDER=0 \"style=table-layout:fixed\""
				+ " BGCOLOR=\"" + tableBGColor_local + "\">" + weekdays + "<TR class = \"weekDay\">";

		// BUILD THE BOTTOM PORTION OF THE CALENDAR PAGE
		calendarEnd = "";

        // WHETHER OR NOT TO DISPLAY A THICK LINE BELOW THE CALENDAR
        if (bottomBorder_local) {
            calendarEnd += "<TR></TR>";
        }

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE BORDERS PROPERLY
        if (isNav_local) {
            calendarEnd += "</TD></TR></TABLE>";
        }

        // END THE TABLE AND HTML DOCUMENT
        calendarEnd += "</TABLE>" + "</CENTER>" + "</BODY>" + "</HTML>";
}

// REPLACE ALL INSTANCES OF find WITH replace
// inString: the string you want to convert
// find:     the value to search for
// replace:  the value to substitute
//
// usage:    jsReplace(inString, find, replace);
// example:  jsReplace("To be or not to be", "be", "ski");
//           result: "To ski or not to ski"
//
function jsReplace_local(inString, find, replace)
{
    var outString = "";
    if (!inString) {
        return "";
    }
    // REPLACE ALL INSTANCES OF find WITH replace
    if (inString.indexOf(find) != -1) {
        // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find
        t = inString.split(find);
        // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace
        return (t.join(replace));
    } else {
        return inString;
    }
}
// JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR CALL)
function doNothing_local()
{
}

// ENSURE THAT VALUE IS TWO DIGITS IN LENGTH
function makeTwoDigit_local(inValue)
{
    var numVal = parseInt(inValue, 10);

    // VALUE IS LESS THAN TWO DIGITS IN LENGTH
    if (numVal < 10) {
        // ADD A LEADING ZERO TO THE VALUE AND RETURN IT
        return("0" + numVal);
    } else {
        return numVal;
    }
}

/*----------------------------------------------------------------------------------------
Set field value to the date selected and close the calendar window(in case of popup)
Writes the bottom part of the calendar for the thumbnail calendar in day/week view
-----------------------------------------------------------------------------------------*/
function returnDate_local(inDay)
{
    // inDay = THE DAY THE USER CLICKED ON
    calDate_local.setDate(inDay);

    // SET THE DATE RETURNED TO THE USER
    var day           = calDate_local.getDate();
    var month         = calDate_local.getMonth() + 1;
    var year          = calDate_local.getFullYear();
    var monthString   = monthArray[calDate_local.getMonth()];
    var monthAbbrev   = monthString.substring(0, 3);
    var weekday       = weekdayList[calDate_local.getDay()];
    var weekdayAbbrev = weekday.substring(0, 3);

    outDate = calDateFormat_local;

    // RETURN TWO DIGIT DAY
    if (calDateFormat_local.indexOf("DD") != -1) {
        day = makeTwoDigit_local(day);
        outDate = jsReplace_local(outDate, "DD", day);
    }
    // RETURN ONE OR TWO DIGIT DAY
    else if (calDateFormat_local.indexOf("dd") != -1) {
        outDate = jsReplace_local(outDate, "dd", day);
    }

    // RETURN TWO DIGIT MONTH
    if (calDateFormat_local.indexOf("MM") != -1) {
        month = makeTwoDigit_local(month);
        outDate = jsReplace_local(outDate, "MM", month);
    }
    // RETURN ONE OR TWO DIGIT MONTH
    else if (calDateFormat_local.indexOf("mm") != -1) {
        outDate = jsReplace_local(outDate, "mm", month);
    }

    // RETURN FOUR-DIGIT YEAR
    if (calDateFormat_local.indexOf("yyyy") != -1) {
        outDate = jsReplace_local(outDate, "yyyy", year);
    }
    // RETURN TWO-DIGIT YEAR
    else if (calDateFormat_local.indexOf("yy") != -1) {
        var yearString = "" + year;
        var yearString = yearString.substring(2,4);
        outDate = jsReplace_local(outDate, "yy", yearString);
    }
    // RETURN FOUR-DIGIT YEAR
    else if (calDateFormat_local.indexOf("YY") != -1) {
        outDate = jsReplace_local(outDate, "YY", year);
    }

    // RETURN DAY OF MONTH (Initial Caps)
    if (calDateFormat_local.indexOf("Month") != -1) {
        outDate = jsReplace_local(outDate, "Month", monthString);
    }
    // RETURN DAY OF MONTH (lowercase letters)
    else if (calDateFormat_local.indexOf("month") != -1) {
        outDate = jsReplace_local(outDate, "month", monthString.toLowerCase());
    }
    // RETURN DAY OF MONTH (UPPERCASE LETTERS)
    else if (calDateFormat_local.indexOf("MONTH") != -1) {
        outDate = jsReplace_local(outDate, "MONTH", monthString.toUpperCase());
    }

    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat_local.indexOf("Mon") != -1) {
        outDate = jsReplace_local(outDate, "Mon", monthAbbrev);
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat_local.indexOf("mon") != -1) {
        outDate = jsReplace_local(outDate, "mon", monthAbbrev.toLowerCase());
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat_local.indexOf("MON") != -1) {
        outDate = jsReplace_local(outDate, "MON", monthAbbrev.toUpperCase());
    }

    // RETURN WEEKDAY (Initial Caps)
    if (calDateFormat_local.indexOf("Weekday") != -1) {
        outDate = jsReplace_local(outDate, "Weekday", weekday);
    }
    // RETURN WEEKDAY (lowercase letters)
    else if (calDateFormat_local.indexOf("weekday") != -1) {
        outDate = jsReplace_local(outDate, "weekday", weekday.toLowerCase());
    }
    // RETURN WEEKDAY (UPPERCASE LETTERS)
    else if (calDateFormat_local.indexOf("WEEKDAY") != -1) {
        outDate = jsReplace_local(outDate, "WEEKDAY", weekday.toUpperCase());
    }

    // RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat_local.indexOf("Wkdy") != -1) {
        outDate = jsReplace_local(outDate, "Wkdy", weekdayAbbrev);
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat_local.indexOf("wkdy") != -1) {
        outDate = jsReplace_local(outDate, "wkdy", weekdayAbbrev.toLowerCase());
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat_local.indexOf("WKDY") != -1) {
        outDate = jsReplace_local(outDate, "WKDY", weekdayAbbrev.toUpperCase());
    }

    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
    calDateField_local = outDate;
    calDate_local = new Date(outDate);
	calDay_local = calDate_local.getDate();

    if (type_local == "plain")
    {
		//TODO: Dave Otto 07-15-2005 don't think we ever get here
		//		topframe.RZ.calendar.XXX setting not tested

		calDateField_local = outDate;
		//SETTING THE COOKIE VALUE WITH THE NEW SELECTED DATE
		topframe.RZ.calendar.date = calDate_local;
		//SETTING THE VIEW WITH THE DAY VIEW FOR NEW DATE SELECTED
		topframe.RZ.calendar.view = 'Day';
		//SETTING THE FORMTYPE TO MONTH/DAY
		topframe.RZ.calendar.type = '';
		writeCalendar_local();
    }
    else
    {
    		var formattedDate = RZmonthArray[calDate_local.getMonth()]
				+ " " + calDate_local.getDate() + " ," + calDate_local.getFullYear();

			//SETTING THE DATE IN THE FORMAT <MONTH DATE, YEAR>
			dateFieldName_local.value = formattedDate;

			// CLOSE THE CALENDAR WINDOW
			RZ.calendarwin.close();
    }
}