/*
* Bazillyo's Spiffy DHTML Popup Calendar Control - version 2.1
* 2001 S. Ousta
* see the included readme.htm file for license information and release notes.
*
* For more information see:
* http://www.geocities.com/bazillyo/spiffy/calendar/index.htm or
* http://groups.yahoo.com/group/spiffyDHTML or
* email me: bazillyo@yahoo.com
*
*/
// GLOBAL variables
var scImgPath = './includes/javascript/spiffyCal/images/';
var scIE=((navigator.appName == "Microsoft Internet Explorer") || ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5)));
var scNN6=((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5));
var scNN=((navigator.appName == "Netscape")&&(document.layers));
var img_Del=new Image();
var img_Close=new Image();
img_Del.src= scImgPath +"btn_del_small.gif";
img_Close.src= scImgPath +"btn_close_small.gif";
var scBTNMODE_DEFAULT=0;
var scBTNMODE_CUSTOMBLUE=1;
var scBTNMODE_CALBTN=2;
var focusHack;
/*================================================================================
* Calendar Manager Object
*
* the functions:
* isDate(), formatDate(), _isInteger(), _getInt(), and getDateFromFormat()
* are based on ones courtesy of Matt Kruse (mkruse@netexpress.net) http://www.mattkruse.com/javascript/
* with some modifications by myself and Michael Brydon
*
*/
function spiffyCalManager() {
this.showHelpAlerts = false;
this.defaultDateFormat='dd-MMM-yyyy';
this.lastSelectedDate=new Date();
this.calendars=new Array();
this.matchedFormat="";
this.DefBtnImgPath=scImgPath; //'./js/common/calendar/';
// methods ----------------------------------------------------------------------
this.getCount= new Function("return this.calendars.length;");
function addCalendar(objWhatCal) {
var intIndex = this.calendars.length;
this.calendars[intIndex] = objWhatCal;
}
this.addCalendar=addCalendar;
function hideAllCalendars(objExceptThisOne) {
var i=0;
for (i=0;i1) {
if (this.AllowedFormats[i].substr(0,1)!=this.AllowedFormats[firstMatchAt].substr(0,1)) {
secondMatchAt=i; break;
}
else { // don't count same format with padded zeros as a different format
formatMatchCount=1;
}
}
}
}
}
alert('formatMatchCount='+formatMatchCount);
if (formatMatchCount>1) {
if (this.showHelpAlerts) {
var date1=getDateFromFormat(eInput.value,this.AllowedFormats[firstMatchAt]);
var choice1 = MONTH_NAMES[date1.getMonth()]+'-'+date1.getDate()+'-'+date1.getFullYear();
var date2=getDateFromFormat(eInput.value,this.AllowedFormats[secondMatchAt]);
var choice2 = MONTH_NAMES[date2.getMonth()]+'-'+date2.getDate()+'-'+date2.getFullYear();
if (date1.getTime()!=date2.getTime()) {
var Msg='You have entered an ambiguous date.\n\n Click OK for:\n'+ choice1 +'\n\nor Click Cancel for:\n'+choice2;
if (confirm(Msg)) {
bOK=true;
}
else {
firstMatchAt=secondMatchAt;
bOK=true;
//return false;
}
eInput.focus();
eInput.select();
}
}
else {
// continue and take first match in list
bOK=true;
}
}
alert('TEST '+dThis.getDate()+"-"+dThis.getMonth());
if (bOK==true) {
eInput.className = "cal-TextBox";
//Check for Start/End Dates
if (dStartDate!=null) {
var dThis = getDateFromFormat(eInput.value,this.AllowedFormats[i]);
if (dStartDate>dThis){
eInput.className = "cal-TextBoxInvalid";
if (this.showHelpAlerts) { alert(rangeMsg + 'earlier than '+ strStart + '.');}
eInput.focus();
eInput.select();
return false;
}
}
if (dEndDate!=null) {
var dThis = getDateFromFormat(eInput.value,this.AllowedFormats[i]);
if (dEndDate=minlength; x--) {
var token = str.substring(i,i+x);
if (_isInteger(token)) {
return token;
}
}
return null;
}
function getDateFromFormat(val,format) {
val = val+"";
format = format+"";
var i_val = 0;
var i_format = 0;
var c = "";
var token = "";
var token2= "";
var x,y;
var year = 0;
var month = 0;
var date = 0;
var bYearProvided = false;
while (i_format < format.length) {
// Get next token from format string
c = format.charAt(i_format);
token = "";
while ((format.charAt(i_format) == c) && (i_format < format.length)) {
token += format.charAt(i_format);
i_format++;
}
// Extract contents of value based on format token
if (token=="yyyy" || token=="yy" || token=="y") {
if (token=="yyyy") { x=4;y=4; }// 4-digit year
if (token=="yy") { x=2;y=2; }// 2-digit year
if (token=="y") { x=2;y=4; }// 2-or-4-digit year
year = _getInt(val,i_val,x,y);
bYearProvided = true;
if (year == null) {
return 0;
//Default to current year
}
if (year.length != token.length){
return 0;
}
i_val += year.length;
}
else if (token=="MMM") { // Month name
month = 0;
for (var i=0; i12) { month -= 12; }
i_val += month_name.length;
break;
}
}
if (month == 0) { return 0; }
if ((month < 1) || (month>12)) {
return 0
}
}
else if (token=="MM" || token=="M") {
x=token.length; y=2;
month = _getInt(val,i_val,x,y);
if (month == null) { return 0; }
if ((month < 1) || (month > 12)) { return 0; }
i_val += month.length;
}
else if (token=="dd" || token=="d") {
x=token.length; y=2;
date = _getInt(val,i_val,x,y);
if (date == null) { return 0; }
if ((date < 1) || (date>31)) { return 0; }
i_val += date.length;
}
else {
if (val.substring(i_val,i_val+token.length) != token) {
return 0;
}
else {
i_val += token.length;
}
}
}
// If there are any trailing characters left in the value, it doesn't match
if (i_val != val.length) {
return 0;
}
// Is date valid for month?
if (month == 2) {
// Check for leap year
if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) { // leap year
if (date > 29){ return false; }
}
else {
if (date > 28) { return false; }
}
}
if ((month==4)||(month==6)||(month==9)||(month==11)) {
if (date > 30) { return false; }
}
//JS dates uses 0 based months.
month = month - 1;
if (bYearProvided==false) {
//Default to current
var dCurrent = new Date();
year = dCurrent.getFullYear();
}
var lYear = parseInt(year);
if (lYear<=20) {
year = 2000 + lYear;
}
else if (lYear >=21 && lYear<=99) {
year = 1900 + lYear;
}
var newdate = new Date(year,month,date,0,0,0);
return newdate;
}
this.getDateFromFormat=getDateFromFormat;
}
var calMgr = new spiffyCalManager();
//================================================================================
// Calendar Object
function ctlSpiffyCalendarBox(strVarName, strFormName, strTextBoxName, strBtnName, strDefaultValue, intBtnMode) {
var msNames = new makeArray0('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var msDays = new makeArray0(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var msDOW = new makeArray0('S','M','T','W','T','F','S');
var blnInConstructor=true;
var img_DateBtn_UP=new Image();
var img_DateBtn_OVER=new Image();
var img_DateBtn_DOWN=new Image();
var img_DateBtn_DISABLED=new Image();
var strBtnW;
var strBtnH;
var strBtnImg;
var dteToday=new Date;
var dteCur=new Date;
var dteMin=new Date;
var dteMax=new Date;
var scX=4; // default where to display calendar
var scY=4;
// Defaults
var strDefDateFmt='dd-MMM-yyyy';
var intDefBtnMode=0;
var strDefBtnImgPath=calMgr.DefBtnImgPath;
/* PROPERTIES =============================================================
*
*/
// Generic Properties
this.varName=strVarName;
this.enabled=true;
this.readonly=false;
this.focusClick=false;
this.hideButton=false;
this.visible=false;
this.displayLeft=false;
this.displayTop=false;
// Name Properties
this.formName=strFormName;
this.textBoxName=strTextBoxName;
this.btnName=strBtnName;
this.required=false;
this.x=scX;
this.y=scY;
this.imgUp=img_DateBtn_UP;
this.imgOver=img_DateBtn_OVER;
this.imgDown=img_DateBtn_DOWN;
this.imgDisabled=img_DateBtn_DISABLED;
// look
this.showWeekends=true;
this.showHolidays=true;
this.disableWeekends=false;
this.disableHolidays=false;
this.textBoxWidth=160;
this.textBoxHeight=20;
this.btnImgWidth=strBtnW;
this.btnImgHeight=strBtnH;
if ((intBtnMode==null)||(intBtnMode<0 && intBtnMode>2)) {
intBtnMode=intDefBtnMode
}
switch (intBtnMode) {
case 0 :
strBtnImg=strDefBtnImgPath+'btn_date_up.gif';
img_DateBtn_UP.src=strDefBtnImgPath+'btn_date_up.gif';
img_DateBtn_OVER.src=strDefBtnImgPath+'btn_date_over.gif';
img_DateBtn_DOWN.src=strDefBtnImgPath+'btn_date_down.gif';
img_DateBtn_DISABLED.src=strDefBtnImgPath+'btn_date_disabled.gif';
strBtnW = '18';
strBtnH = '20';
break;
case 1 :
strBtnImg=strDefBtnImgPath+'btn_date1_up.gif';
img_DateBtn_UP.src=strDefBtnImgPath+'btn_date1_up.gif';
img_DateBtn_OVER.src=strDefBtnImgPath+'btn_date1_over.gif';
img_DateBtn_DOWN.src=strDefBtnImgPath+'btn_date1_down.gif';
img_DateBtn_DISABLED.src=strDefBtnImgPath+'btn_date1_disabled.gif';
strBtnW = '22';
strBtnH = '17';
break;
case 2 :
strBtnImg=strDefBtnImgPath+'btn_date2_up.gif';
img_DateBtn_UP.src=strDefBtnImgPath+'btn_date2_up.gif';
img_DateBtn_OVER.src=strDefBtnImgPath+'btn_date2_over.gif';
img_DateBtn_DOWN.src=strDefBtnImgPath+'btn_date2_down.gif';
img_DateBtn_DISABLED.src=strDefBtnImgPath+'btn_date2_disabled.gif';
strBtnW = '34';
strBtnH = '21';
break;
}
// Date Properties
this.dateFormat=strDefDateFmt;
this.useDateRange=false;
this.minDate=new Date;
this.maxDate=new Date(dteToday.getFullYear()+1, dteToday.getMonth(), dteToday.getDate());
this.minDay = function() {
return this.minDate.getDate();
}
this.minMonth = function() {
return this.minDate.getMonth();
}
this.minYear = function() {
return this.minDate.getFullYear();
}
this.maxDay = function() {
return this.maxDate.getDate();
}
this.maxMonth = function() {
return this.maxDate.getMonth();
}
this.maxYear = function() {
return this.maxYear.getFullYear();
}
function setMinDate(intYear, intMonth, intDay) {
this.minDate = new Date(intYear, intMonth-1, intDay);
}
this.setMinDate=setMinDate;
function setMaxDate(intYear, intMonth, intDay) {
this.maxDate = new Date(intYear, intMonth-1, intDay);
}
this.setMaxDate=setMaxDate;
this.minYearChoice=dteToday.getFullYear()-10;
this.maxYearChoice=dteToday.getFullYear()+10;
this.textBox= function() {
if (!blnInConstructor) {
return eval('document.'+this.formName+'.'+this.textBoxName);
}
}
this.getSelectedDate = function () {
var strTempVal=''; var objEle;
if ((typeof this.formName !='undefined') && (typeof this.textBoxName!='undefined')) {
objEle=eval('document.'+this.formName+'.'+this.textBoxName);
if (objEle && !blnInConstructor) {
strTempVal=eval('document.'+this.formName+'.'+this.textBoxName+'.value');
}
else {
strTempVal=strDefaultValue;
}
}
else {
strTempVal=strDefaultValue;
}
return strTempVal;
}
function setSelectedDate(strWhat) {
var strTempVal=''; var objEle;
eval('document.'+this.formName+'.'+this.textBoxName).value=strWhat;
if (!calMgr.isDate(quote(strWhat),quote(this.dateFormat))) {
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBoxInvalid";
}
else {
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBox";
}
}
this.setSelectedDate=setSelectedDate;
function disable() {
this.hide();
calMgr.swapImg(this,'.imgDisabled',false);
this.enabled=false;
eval('document.'+this.formName+'.'+this.textBoxName).disabled=true;
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBoxDisabled";
if (scNN) {
eval('document.'+this.formName+'.'+this.textBoxName).onFocus= function() {this.blur();};
}
}
this.disable=disable;
function enable() {
this.enabled=true;
calMgr.swapImg(this,'.imgUp',false);
eval('document.'+this.formName+'.'+this.textBoxName).disabled=false;
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBox";
if (scNN) {
eval('document.'+this.formName+'.'+this.textBoxName).onFocus= null;
}
if (!calMgr.isDate(quote(this.getSelectedDate()),quote(this.dateFormat))) {
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBoxInvalid";
}
}
this.enable=enable;
// behavior Properties
this.JStoRunOnSelect='';
this.JStoRunOnClear='';
this.JStoRunOnCancel='';
this.hideCombos=true;
/* METHODS ===============================================================
*
*/
function makeCalendar(intWhatMonth,intWhatYear,bViewOnly) {
if (bViewOnly) {intWhatMonth-=1;}
var strOutput = '';
var intStartMonth=intWhatMonth;
var intStartYear=intWhatYear;
var intLoop;
var strTemp='';
var strDateColWidth;
var isWE = false;
dteCur.setMonth(intWhatMonth);
dteCur.setFullYear(intWhatYear);
dteCur.setDate(dteToday.getDate());
dteCur.setHours(0);dteCur.setMinutes(0);dteCur.setSeconds(0);dteCur.setMilliseconds(0);
if (!(bViewOnly)) {
strTemp='