//------------------------------------------------------- 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
var offsetToday;
calDateFormat = 'YYYY-MM-DD';
// CALENDAR COLORS
topBackground = '#b03427'; // BACKGROUND COLOR OF THE TOP FRAME
bottomBackground = '#b03427'; // BACKGROUND COLOR OF THE BOTTOM FRAME
tableBGColor = '#000000'; // BACKGROUND COLOR OF THE BOTTOM FRAME'S table
cellColor = '#b03427'; // TABLE CELL BACKGROUND COLOR OF THE DATE CELLS IN THE BOTTOM FRAME
dateColor = '#FFFFFF'; // TEXT COLOR OF THE LISTED DATES (1-28+)
focusColor = '#000000'; // TEXT COLOR OF THE SELECTED DATE
todayColor = '#0000FF'; // TEXT COLOR OF THE CURRENT DATE == TODAY
todayCellColor = '#FFFFFF'; // BACKGROUND COLOR OF THE CURRENT DATE == TODAY
disabledColor = '#000000'; // TEXT COLOR OF THE DISABLED DAYS
disabledFontStyle = '8pt arial, helvetica'; // TEXT STYLE FOR THE DISABLED DAYS
hoverColor = '#000000'; // TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
fontStyle = '8pt arial,helvetica'; // TEXT STYLE FOR DATES
headingCellColor = '#FFFFFF'; // TABLE CELL BACKGROUND COLOR OF THE WEEKDAY ABBREVIATIONS
headingTextColor = '#000000'; // TEXT COLOR OF THE WEEKDAY ABBREVIATIONS
headingFontStyle = 'bold 8pt arial,helvetica'; // TEXT STYLE FOR WEEKDAY ABBREVIATIONS
cancelColor = '#FFFFFF'; // TEXT COLOR FOR CANCEL/CLOSE BUTTON
cancelBackground = '#b03427'; // BACKGROUND COLOR FOR CANCEL/CLOSE BUTTON
//cancelImage = '/images/btn_Xclose.gif';
cancelImage = '';
// FORMATTING PREFERENCES
bottomborder = false; // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR border)
tableborder = 0; // SIZE OF CALENDAR table border (BOTTOM FRAME) 0=none
//------------------------------------------------------- END USER-EDITABLE SECTION -------------------------------------------------------
// GET CURRENTLY SELECTED LANGUAGE
var selectedLanguage = navigator.language;
var calStartConstraint;
var calEndConstraint;
ResetConstraints();
var calDateField;
var tflag = false;
var calDate;
var monthList;
var dayList;
var abbrDayList;
var todayLocale;
var noDateLocale;
var popup = false;
// IF FRENCH
if (selectedLanguage == 'fr')
{
monthList = new Array('Janvier', 'F?vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'D?cembre');
dayList = new Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
abbrDayList = new Array('Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa');
todayLocale = 'Aujourd\'hui';
noDateLocale = 'Aucune Date';
}
// IF GERMAN
else if (selectedLanguage == 'de')
{
monthList = new Array('Januar', 'Februar', 'M?rz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
dayList = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag');
abbrDayList = new Array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
todayLocale = 'Heute';
noDateLocale = 'Kein Datum';
}
// IF SPANISH
else if (selectedLanguage == 'es')
{
monthList = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
dayList = new Array('Domingo', 'Lunes', 'Martes', 'Mi?rcoles', 'Jueves', 'Viernes', 'S?bado')
abbrDayList = new Array('Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa');
todayLocale = 'Hoy';
noDateLocale = 'Ninguna Fecha';
}
else
{
monthList = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
dayList = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
abbrDayList = new Array('Su','Mo','Tu','We','Th','Fr','Sa');
todayLocale = 'Today';
noDateLocale = 'No Date';
}
function ResetConstraints()
{
calStartConstraint = new Date(1900,0,1,00,00,00,000);
calEndConstraint = new Date(3000,11,31,23,59,59,999);
}
function ShowCalendarWithConstraints(dateField, startDate, endDate)
{
ResetConstraints();
var RE = /^\d\d\d\d-\d\d-\d\d$/;
if (RE.test(startDate))
{
tmp = startDate.split("-");
calStartConstraint.setFullYear(parseInt(tmp[0]),parseInt(tmp[1]-1),parseInt(tmp[2]-0),00,00,00,000);
}
if (RE.test(endDate))
{
tmp = endDate.split("-");
calEndConstraint.setFullYear(parseInt(tmp[0]),parseInt(tmp[1]-1),parseInt(tmp[2]-0),23,59,59,999);
}
showCalendar(dateField);
}
function showCalendar(dateField)
{
calDateField = dateField;
SetInitialDate();
if (navigator.appName == "Microsoft Internet Explorer")
{
temp = navigator.appVersion.split('MSIE');
if (parseInt(temp[1]) == 6)
popup = true;
}
if (popup == true)
PopupCalendar();
else
InlineCalendar()
}
function InlineCalendar()
{
var leftTop = FindPos(calDateField);
if (calDate < calStartConstraint)
calDate = new Date(calStartConstraint);
else if (calDate > calEndConstraint)
calDate = new Date(calEndConstraint);
var activeMonth = calDate.getMonth();
var activeYear = calDate.getFullYear();
calendar = "
\n" +
BuildCalendarBottom();
if (document.getElementById('divCalendar'))
CloseCalendar();
var div = document.createElement('div');
div.setAttribute('id', 'divCalendar');
div.style.width = '210px';
div.style.height = '225px';
div.style.left = leftTop[0] + 'px';
div.style.top = leftTop[1] + 'px';
div.style.zindex = 5;
div.style.position = 'absolute';
div.style.border = '1px solid #b03427';
div.style.background = topBackground;
div.display = 'table-cell';
div.innerHTML = calendar;
document.body.appendChild(div);
//document.write(calendar);
}
function PopupCalendar()
{
var leftTop = FindPos(calDateField);
if (calDate < calStartConstraint)
calDate = new Date(calStartConstraint);
else if (calDate > calEndConstraint)
calDate = new Date(calEndConstraint);
var activeMonth = calDate.getMonth();
var activeYear = calDate.getFullYear();
calendar = "" +
"\n" +
" \n" +
" Calendar\n" +
" \n" +
" \n" +
" \n" +
" ";
"
\n" +
BuildCalendarBottom() +
"
\n" +
"";
if(top.calendarWindow)
top.calendarWindow.close();
top.calendarWindow = window.open("javascript:parent.opener.calendar", "calWin", "width=200,height=215,screenX=" + leftTop[1] + ",screenY=" + leftTop[0] + ",left=" + leftTop[0] + ",top=" + leftTop[1]);
top.calendarWindow.focus();
}
function FindPos(obj)
{
var curLeft = 0;
var curTop = 0;
var screenLeft = 0;
if (obj.offsetParent)
{
curLeft = obj.offsetLeft
curTop = obj.offsetTop
while (obj = obj.offsetParent)
{
curLeft += obj.offsetLeft
curTop += obj.offsetTop
}
}
if (popup == true)
{
if (window.screenLeft)
screenLeft = window.screenLeft;
else if (window.screenX)
screenLeft = window.screenX;
curLeft = curLeft + screenLeft;
}
return [curLeft, curTop];
}
function SetInitialDate()
{
calDate = null;
// CREATE A NEW DATE OBJECT (WILL GENERALLY PARSE CORRECT DATE EXCEPT WHEN "." IS USED AS A DELIMITER)
// (THIS ROUTINE DOES *NOT* CATCH ALL DATE FORMATS, IF YOU NEED TO PARSE A CUSTOM DATE FORMAT, DO IT HERE)
var RE = /^\d\d\d\d-\d\d-\d\d$/;
if (RE.test(calDateField.value))
{
tmp = calDateField.value.split("-");
calDate = new Date();
calDate.setFullYear(parseInt(tmp[0]),parseInt(tmp[1]-1),parseInt(tmp[2]-0),12,00,00,000); // the '-0' on day removes leading '0'
}
else if (calDateField.value != '')
calDate = new Date(calDateField.value);
// IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
if (calDate == null || isNaN(calDate))
calDate = new Date();
if(tflag == true)
{
calDate = new Date();
tflag = false;
}
calDay = calDate.getDate();
calMonth = calDate.getMonth();
calYear = calDate.getFullYear();
// SET DAY VALUE TO 1... TO AVOID JAVASCRIPT DATE CALCULATION ANOMALIES
// (IF THE MONTH CHANGES TO FEB AND THE DAY IS 30, THE MONTH WOULD CHANGE TO MARCH
// AND THE DAY WOULD CHANGE TO 2. SETTING THE DAY TO 1 WILL PREVENT THAT)
calDate.setDate(1);
}
function RebuildCalendarBottom()
{
if (popup == true)
top.calendarWindow.document.getElementById('calBottom').innerHTML = BuildCalendarBottom();
else
document.getElementById('calBottom').innerHTML = BuildCalendarBottom();
}
function BuildCalendarBottom()
{
var returnDate = "ReturnDate";
if (popup == true)
returnDate = "parent.opener." + returnDate;
var calDoc = " \n";
return calDoc;
}
function GetYear()
{
if (popup == true)
return top.calendarWindow.document.getElementById('year');
else
return document.getElementById('year');
}
function GetMonth()
{
if (popup == true)
return top.calendarWindow.document.getElementById('month');
else
return document.getElementById('month');
}
function SetToday()
{
tflag = true;
// SET GLOBAL DATE TO TODAY'S DATE
calDate = new Date();
if (popup == true)
{
top.calendarWindow.document.getElementById('month').selectedIndex = calDate.getMonth();
top.calendarWindow.document.getElementById('year').value = calDate.getFullYear();
top.calendarWindow.document.getElementById('calBottom').innerHTML = BuildCalendarBottom();
}
else
{
document.getElementById('month').selectedIndex = calDate.getMonth();
document.getElementById('year').value = calDate.getFullYear();
document.getElementById('calBottom').innerHTML = BuildCalendarBottom();
}
// A bit of a hack to get the calendar to close on click of today, instead of redrawing it to show today if user has prgressed thru the calendar.
ReturnDate(offsetToday);
}
// SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
function SetYear()
{
FourDigitYear();
var year = GetYear();
calDate.setFullYear(year.value);
RebuildCalendarBottom();
}
function SetPreviousYear()
{
FourDigitYear();
var year = GetYear();
year.value--;
calDate.setFullYear(year.value);
RebuildCalendarBottom();
if (popup == true)
top.calendarWindow.document.getElementById('month').selectedIndex = calDate.getMonth(); // Anomaly with leap year
else
document.getElementById('month').selectedIndex = calDate.getMonth(); // Anomaly with leap year
}
function SetNextYear()
{
FourDigitYear();
var year = GetYear();
year.value++;
calDate.setFullYear(year.value);
RebuildCalendarBottom();
if (popup == true)
top.calendarWindow.document.getElementById('month').selectedIndex = calDate.getMonth(); // Anomaly with leap year
else
document.getElementById('month').selectedIndex = calDate.getMonth(); // Anomaly with leap year
}
function SetMonth()
{
var month = GetMonth();
calDate.setMonth(month.selectedIndex);
RebuildCalendarBottom();
}
function SetPreviousMonth()
{
FourDigitYear();
var year = GetYear();
var month = GetMonth();
if (month.selectedIndex == 0)
{
month.selectedIndex = 11;
year.value--;
calDate.setFullYear(year.value);
}
else
month.selectedIndex--;
calDate.setDate(1);
calDate.setMonth(month.selectedIndex);
RebuildCalendarBottom();
}
function SetNextMonth()
{
FourDigitYear();
var year = GetYear();
var month = GetMonth();
if (month.selectedIndex == 11)
{
month.selectedIndex = 0;
year.value++;
calDate.setFullYear(year.value);
}
else
month.selectedIndex++;
calDate.setDate(1);
calDate.setMonth(month.selectedIndex);
RebuildCalendarBottom();
}
function GetDaysInMonth()
{
var days;
var month = calDate.getMonth()+1;
var year = calDate.getFullYear();
if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
days=31;
else if (month==4 || month==6 || month==9 || month==11)
days=30;
else if (month==2)
{
if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0))
days=29;
else
days=28;
}
return (days);
}
function FourDigitYear()
{
year = GetYear();
if (year.value.length != 4)
{
today = new Date();
year.value = today.getFullYear();
if (popup == true)
top.calendarWindow.document.getElementById('month').selectedIndex = today.getMonth();
else
document.getElementById('month').selectedIndex = today.getMonth();
}
}
function MakeTwoDigit(inValue)
{
var outVal = parseInt(inValue, 10);
if (outVal < 10)
outVal = '0' + outVal;
return outVal;
}
function CloseCalendar()
{
if (popup == true)
top.calendarWindow.close();
else
{
ResetConstraints();
document.body.removeChild(document.getElementById('divCalendar'));
}
}
// SET FIELD VALUE TO THE DATE SELECTED AND CLOSE THE CALENDAR WINDOW
function ReturnDate(inDay)
{
// inDay = THE DAY THE USER CLICKED ON
calDate.setDate(inDay);
// SET THE DATE RETURNED TO THE USER
var day = calDate.getDate();
var month = calDate.getMonth()+1;
var year = calDate.getFullYear();
var monthString = monthList[calDate.getMonth()];
var monthAbbrev = monthString.substring(0,3);
var weekday = dayList[calDate.getDay()];
var weekdayAbbrev = weekday.substring(0,3);
var outDate = '';
if(inDay != 0)
{
outDate = calDateFormat;
// RETURN TWO DIGIT DAY
if (calDateFormat.match(/DD/))
outDate = outDate.replace(/DD/g, MakeTwoDigit(day));
// RETURN ONE OR TWO DIGIT DAY
else if (calDateFormat.match(/dd/))
outDate.replace(/dd/g, day);
// RETURN TWO DIGIT MONTH
if (calDateFormat.match(/MM/))
outDate = outDate.replace(/MM/g, MakeTwoDigit(month));
// RETURN ONE OR TWO DIGIT MONTH
else if (calDateFormat.match(/mm/))
outDate = outDate.replace(/mm/g, month);
// RETURN FOUR-DIGIT YEAR
if (calDateFormat.match(/yyyy/i))
outDate = outDate.replace(/yyyy/gi, year);
// RETURN TWO-DIGIT YEAR
else if (calDateFormat.match(/yy/))
{
var yearString = '' + year;
outDate = outDate.replace(/yy/g, yearString.substring(2,4));
}
// RETURN FOUR-DIGIT YEAR
else if (calDateFormat.match(/YY/))
outDate = outDate.replace(/YY/g, year);
// RETURN DAY OF MONTH (Initial Caps)
if (calDateFormat.match(/Month/))
outDate = outDate.replace(/Month/g, monthString);
// RETURN DAY OF MONTH (lowercase letters)
else if (calDateFormat.match(/month/))
outDate = outDate.replace(/month/g, monthString.toLowerCase());
// RETURN DAY OF MONTH (UPPERCASE LETTERS)
else if (calDateFormat.match(/MONTH/))
outDate = outDate.replace(/MONTH/g, monthString.toUpperCase());
// RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps)
if (calDateFormat.match(/Mon/))
outDate = outDate.replace(/Mon/g, monthAbbrev);
// RETURN DAY OF MONTH 3-DAY ABBREVIATION (lowercase letters)
else if (calDateFormat.match(/mon/))
outDate = outDate.replace(/mon/g, monthAbbrev.toLowerCase());
// RETURN DAY OF MONTH 3-DAY ABBREVIATION (UPPERCASE LETTERS)
else if (calDateFormat.match(/MON/))
outDate = outDate.replace(/MON/g, monthAbbrev.toUpperCase());
// RETURN WEEKDAY (Initial Caps)
if (calDateFormat.match(/Weekday/))
outDate = outDate.replace(/Weekday/g, weekday);
// RETURN WEEKDAY (lowercase letters)
else if (calDateFormat.match(/weekday/))
outDate = outDate.replace(/weekday/, weekday.toLowerCase());
// RETURN WEEKDAY (UPPERCASE LETTERS)
else if (calDateFormat.match(/WEEKDAY/))
outDate = outDate.replace(/WEEKDAY/g, weekday.toUpperCase());
// RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps)
if (calDateFormat.match(/Wkdy/))
outDate = outDate.replace(/Wkdy/g, weekdayAbbrev);
// RETURN WEEKDAY 3-DAY ABBREVIATION (lowercase letters)
else if (calDateFormat.match(/wkdy/))
outDate = outDate.replace(/wkdy/g, weekdayAbbrev.toLowerCase());
// RETURN WEEKDAY 3-DAY ABBREVIATION (UPPERCASE LETTERS)
else if (calDateFormat.match(/WKDY/))
outDate = outDate.replace(/WKDY/g, weekdayAbbrev.toUpperCase());
}
calDateField.value = outDate;
CloseCalendar();
}