Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
// calendar
2
 
3
var weekend = [0,6];
4
var weekendColor = "#e0e0e0";
5
var fontface = "tahoma,sans-serif";
6
var fontsize = 2;
7
 
8
var gNow = new Date();
9
var ggWinCal;
10
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
11
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
12
 
13
Calendar.Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
14
 
15
// Non-Leap year Month days..
16
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
17
// Leap year Month days..
18
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
19
 
20
function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
21
	if ((p_month == null) && (p_year == null))	return;
22
 
23
	if (p_WinCal == null)
24
		this.gWinCal = ggWinCal;
25
	else
26
		this.gWinCal = p_WinCal;
27
 
28
	if (p_month == null) {
29
		this.gMonthName = null;
30
		this.gMonth = null;
31
		this.gYearly = true;
32
	} else {
33
		this.gMonthName = Calendar.get_month(p_month);
34
		this.gMonth = new Number(p_month);
35
		this.gYearly = false;
36
	}
37
 
38
	this.gYear = p_year;
39
	this.gFormat = p_format;
40
	this.gBGColor = "white";
41
	this.gFGColor = "black";
42
	this.gTextColor = "black";
43
	this.gHeaderColor = "black";
44
	this.gReturnItem = p_item;
45
}
46
 
47
Calendar.get_month = Calendar_get_month;
48
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
49
Calendar.calc_month_year = Calendar_calc_month_year;
50
 
51
function Calendar_get_month(monthNo) {
52
	return Calendar.Months[monthNo];
53
}
54
 
55
function Calendar_get_daysofmonth(monthNo, p_year) {
56
	/* 
57
	Check for leap year ..
58
	1.Years evenly divisible by four are normally leap years, except for... 
59
	2.Years also evenly divisible by 100 are not leap years, except for... 
60
	3.Years also evenly divisible by 400 are leap years. 
61
	*/
62
	if ((p_year % 4) == 0) {
63
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
64
			return Calendar.DOMonth[monthNo];
65
 
66
		return Calendar.lDOMonth[monthNo];
67
	} else
68
		return Calendar.DOMonth[monthNo];
69
}
70
 
71
function Calendar_calc_month_year(p_Month, p_Year, incr) {
72
	/* 
73
	Will return an 1-D array with 1st element being the calculated month 
74
	and second being the calculated year 
75
	after applying the month increment/decrement as specified by 'incr' parameter.
76
	'incr' will normally have 1/-1 to navigate thru the months.
77
	*/
78
	var ret_arr = new Array();
79
 
80
	if (incr == -1) {
81
		// B A C K W A R D
82
		if (p_Month == 0) {
83
			ret_arr[0] = 11;
84
			ret_arr[1] = parseInt(p_Year) - 1;
85
		}
86
		else {
87
			ret_arr[0] = parseInt(p_Month) - 1;
88
			ret_arr[1] = parseInt(p_Year);
89
		}
90
	} else if (incr == 1) {
91
		// F O R W A R D
92
		if (p_Month == 11) {
93
			ret_arr[0] = 0;
94
			ret_arr[1] = parseInt(p_Year) + 1;
95
		}
96
		else {
97
			ret_arr[0] = parseInt(p_Month) + 1;
98
			ret_arr[1] = parseInt(p_Year);
99
		}
100
	}
101
 
102
	return ret_arr;
103
}
104
 
105
function Calendar_calc_month_year(p_Month, p_Year, incr) {
106
	/* 
107
	Will return an 1-D array with 1st element being the calculated month 
108
	and second being the calculated year 
109
	after applying the month increment/decrement as specified by 'incr' parameter.
110
	'incr' will normally have 1/-1 to navigate thru the months.
111
	*/
112
	var ret_arr = new Array();
113
 
114
	if (incr == -1) {
115
		// B A C K W A R D
116
		if (p_Month == 0) {
117
			ret_arr[0] = 11;
118
			ret_arr[1] = parseInt(p_Year) - 1;
119
		}
120
		else {
121
			ret_arr[0] = parseInt(p_Month) - 1;
122
			ret_arr[1] = parseInt(p_Year);
123
		}
124
	} else if (incr == 1) {
125
		// F O R W A R D
126
		if (p_Month == 11) {
127
			ret_arr[0] = 0;
128
			ret_arr[1] = parseInt(p_Year) + 1;
129
		}
130
		else {
131
			ret_arr[0] = parseInt(p_Month) + 1;
132
			ret_arr[1] = parseInt(p_Year);
133
		}
134
	}
135
 
136
	return ret_arr;
137
}
138
 
139
// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
140
new Calendar();
141
 
142
Calendar.prototype.getMonthlyCalendarCode = function() {
143
	var vCode = "";
144
	var vHeader_Code = "";
145
	var vData_Code = "";
146
 
147
	// Begin Table Drawing code here..
148
	vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
149
 
150
	vHeader_Code = this.cal_header();
151
	vData_Code = this.cal_data();
152
	vCode = vCode + vHeader_Code + vData_Code;
153
 
154
	vCode = vCode + "</TABLE>";
155
 
156
	return vCode;
157
}
158
 
159
Calendar.prototype.show = function() {
160
	var vCode = "";
161
 
162
	this.gWinCal.document.open();
163
 
164
	// Setup the page...
165
	this.wwrite("<html>");
166
	this.wwrite("<head><title>Calendar</title>");
167
	this.wwrite("</head>");
168
 
169
	this.wwrite("<body " + 
170
		"link=\"" + this.gLinkColor + "\" " + 
171
		"vlink=\"" + this.gLinkColor + "\" " +
172
		"alink=\"" + this.gLinkColor + "\" " +
173
		"text=\"" + this.gTextColor + "\">");
174
	this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
175
	this.wwriteA(this.gMonthName + " " + this.gYear);
176
	this.wwriteA("</B><BR>");
177
 
178
	// Show navigation buttons
179
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
180
	var prevMM = prevMMYYYY[0];
181
	var prevYYYY = prevMMYYYY[1];
182
 
183
	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
184
	var nextMM = nextMMYYYY[0];
185
	var nextYYYY = nextMMYYYY[1];
186
 
187
	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
188
	this.wwrite("[<A HREF=\"" +
189
		"javascript:window.opener.Build(" + 
190
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
191
		");" +
192
		"\"><<<\/A>]</TD><TD ALIGN=center>");
193
	this.wwrite("[<A HREF=\"" +
194
		"javascript:window.opener.Build(" + 
195
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
196
		");" +
197
		"\"><<\/A>]</TD><TD ALIGN=center>");
198
	this.wwrite("[<A HREF=\"" +
199
		"javascript:window.opener.Build(" + 
200
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
201
		");" +
202
		"\">><\/A>]</TD><TD ALIGN=center>");
203
	this.wwrite("[<A HREF=\"" +
204
		"javascript:window.opener.Build(" + 
205
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
206
		");" +
207
		"\">>><\/A>]</TD></TR></TABLE><BR>");
208
 
209
	// Get the complete calendar code for the month..
210
	vCode = this.getMonthlyCalendarCode();
211
	this.wwrite(vCode);
212
 
213
	this.wwrite("</font></body></html>");
214
	this.gWinCal.document.close();
215
}
216
 
217
Calendar.prototype.showY = function() {
218
	var vCode = "";
219
	var i;
220
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
221
	var vxf = 285;			// X-Factor
222
	var vyf = 200;			// Y-Factor
223
	var vxm = 10;			// X-margin
224
	var vym;				// Y-margin
225
	if (isIE)	vym = 75;
226
	else if (isNav)	vym = 25;
227
 
228
	this.gWinCal.document.open();
229
 
230
	this.wwrite("<html>");
231
	this.wwrite("<head><title>Calendar</title>");
232
	this.wwrite("<style type='text/css'>\n<!--");
233
	for (i=0; i<12; i++) {
234
		vc = i % 3;
235
		if (i>=0 && i<= 2)	vr = 0;
236
		if (i>=3 && i<= 5)	vr = 1;
237
		if (i>=6 && i<= 8)	vr = 2;
238
		if (i>=9 && i<= 11)	vr = 3;
239
 
240
		vx = parseInt(vxf * vc) + vxm;
241
		vy = parseInt(vyf * vr) + vym;
242
 
243
		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
244
	}
245
	this.wwrite("-->\n</style>");
246
	this.wwrite("</head>");
247
 
248
	this.wwrite("<body " + 
249
		"link=\"" + this.gLinkColor + "\" " + 
250
		"vlink=\"" + this.gLinkColor + "\" " +
251
		"alink=\"" + this.gLinkColor + "\" " +
252
		"text=\"" + this.gTextColor + "\">");
253
	this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
254
	this.wwrite("Year : " + this.gYear);
255
	this.wwrite("</B><BR>");
256
 
257
	// Show navigation buttons
258
	var prevYYYY = parseInt(this.gYear) - 1;
259
	var nextYYYY = parseInt(this.gYear) + 1;
260
 
261
	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
262
	this.wwrite("[<A HREF=\"" +
263
		"javascript:window.opener.Build(" + 
264
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
265
		");" +
266
		"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
267
	this.wwrite("[<A HREF=\"" +
268
		"javascript:window.opener.Build(" + 
269
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
270
		");" +
271
		"\">>><\/A>]</TD></TR></TABLE><BR>");
272
 
273
	// Get the complete calendar code for each month..
274
	var j;
275
	for (i=11; i>=0; i--) {
276
		if (isIE)
277
			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
278
		else if (isNav)
279
			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
280
 
281
		this.gMonth = i;
282
		this.gMonthName = Calendar.get_month(this.gMonth);
283
		vCode = this.getMonthlyCalendarCode();
284
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
285
		this.wwrite(vCode);
286
 
287
		if (isIE)
288
			this.wwrite("</DIV>");
289
		else if (isNav)
290
			this.wwrite("</LAYER>");
291
	}
292
 
293
	this.wwrite("</font><BR></body></html>");
294
	this.gWinCal.document.close();
295
}
296
 
297
Calendar.prototype.wwrite = function(wtext) {
298
	this.gWinCal.document.writeln(wtext);
299
}
300
 
301
Calendar.prototype.wwriteA = function(wtext) {
302
	this.gWinCal.document.write(wtext);
303
}
304
 
305
Calendar.prototype.cal_header = function() {
306
	var vCode = "";
307
 
308
	vCode = vCode + "<TR>";
309
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
310
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
311
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
312
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
313
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
314
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
315
	vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
316
	vCode = vCode + "</TR>";
317
 
318
	return vCode;
319
}
320
 
321
Calendar.prototype.cal_data = function() {
322
	var vDate = new Date();
323
	vDate.setDate(1);
324
	vDate.setMonth(this.gMonth);
325
	vDate.setFullYear(this.gYear);
326
 
327
	var vFirstDay=vDate.getDay();
328
	var vDay=1;
329
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
330
	var vOnLastDay=0;
331
	var vCode = "";
332
 
333
	/*
334
	Get day for the 1st of the requested month/year..
335
	Place as many blank cells before the 1st day of the month as necessary. 
336
	*/
337
 
338
	vCode = vCode + "<TR>";
339
	for (i=0; i<vFirstDay; i++) {
340
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
341
	}
342
 
343
	// Write rest of the 1st week
344
	for (j=vFirstDay; j<7; j++) {
345
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
346
			"<A HREF='#' " + 
347
				"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
348
				this.format_data(vDay) + 
349
				"';window.close();\">" + 
350
				this.format_day(vDay) + 
351
			"</A>" + 
352
			"</FONT></TD>";
353
		vDay=vDay + 1;
354
	}
355
	vCode = vCode + "</TR>";
356
 
357
	// Write the rest of the weeks
358
	for (k=2; k<7; k++) {
359
		vCode = vCode + "<TR>";
360
 
361
		for (j=0; j<7; j++) {
362
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
363
				"<A HREF='#' " + 
364
					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
365
					this.format_data(vDay) + 
366
					"';window.close();\">" + 
367
				this.format_day(vDay) + 
368
				"</A>" + 
369
				"</FONT></TD>";
370
			vDay=vDay + 1;
371
 
372
			if (vDay > vLastDay) {
373
				vOnLastDay = 1;
374
				break;
375
			}
376
		}
377
 
378
		if (j == 6)
379
			vCode = vCode + "</TR>";
380
		if (vOnLastDay == 1)
381
			break;
382
	}
383
 
384
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
385
	for (m=1; m<(7-j); m++) {
386
		if (this.gYearly)
387
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
388
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
389
		else
390
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
391
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
392
	}
393
 
394
	return vCode;
395
}
396
 
397
Calendar.prototype.format_day = function(vday) {
398
	var vNowDay = gNow.getDate();
399
	var vNowMonth = gNow.getMonth();
400
	var vNowYear = gNow.getFullYear();
401
 
402
	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
403
		return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
404
	else
405
		return (vday);
406
}
407
 
408
Calendar.prototype.write_weekend_string = function(vday) {
409
	var i;
410
 
411
	// Return special formatting for the weekend day.
412
	for (i=0; i<weekend.length; i++) 
413
	{
414
		if (vday == weekend[i])
415
			return (" BGCOLOR=\"" + weekendColor + "\"");
416
	}
417
 
418
	return "";
419
}
420
 
421
Calendar.prototype.format_data = function(p_day) {
422
	var vData;
423
	var vMonth = 1 + this.gMonth;
424
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
425
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
426
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
427
	var vY4 = new String(this.gYear);
428
	var vY2 = new String(this.gYear.substr(2,2));
429
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;
430
 
431
	switch (this.gFormat) {
432
		case "MM\/DD\/YYYY" :
433
			vData = vMonth + "\/" + vDD + "\/" + vY4;
434
			break;
435
		case "MM\/DD\/YY" :
436
			vData = vMonth + "\/" + vDD + "\/" + vY2;
437
			break;
438
		case "MM-DD-YYYY" :
439
			vData = vMonth + "-" + vDD + "-" + vY4;
440
			break;
441
		case "MM-DD-YY" :
442
			vData = vMonth + "-" + vDD + "-" + vY2;
443
			break;
444
 
445
		case "DD\/MON\/YYYY" :
446
			vData = vDD + "\/" + vMon + "\/" + vY4;
447
			break;
448
		case "DD\/MON\/YY" :
449
			vData = vDD + "\/" + vMon + "\/" + vY2;
450
			break;
451
		case "DD-MON-YYYY" :
452
			vData = vDD + "-" + vMon + "-" + vY4;
453
			break;
454
		case "DD-MON-YY" :
455
			vData = vDD + "-" + vMon + "-" + vY2;
456
			break;
457
 
458
		case "DD\/MONTH\/YYYY" :
459
			vData = vDD + "\/" + vFMon + "\/" + vY4;
460
			break;
461
		case "DD\/MONTH\/YY" :
462
			vData = vDD + "\/" + vFMon + "\/" + vY2;
463
			break;
464
		case "DD-MONTH-YYYY" :
465
			vData = vDD + "-" + vFMon + "-" + vY4;
466
			break;
467
		case "DD-MONTH-YY" :
468
			vData = vDD + "-" + vFMon + "-" + vY2;
469
			break;
470
 
471
		case "DD\/MM\/YYYY" :
472
			vData = vDD + "\/" + vMonth + "\/" + vY4;
473
			break;
474
		case "DD\/MM\/YY" :
475
			vData = vDD + "\/" + vMonth + "\/" + vY2;
476
			break;
477
		case "DD-MM-YYYY" :
478
			vData = vDD + "-" + vMonth + "-" + vY4;
479
			break;
480
		case "DD-MM-YY" :
481
			vData = vDD + "-" + vMonth + "-" + vY2;
482
			break;
483
 
484
		default :
485
			vData = vMonth + "\/" + vDD + "\/" + vY4;
486
	}
487
 
488
	return vData;
489
}
490
 
491
function Build(p_item, p_month, p_year, p_format) {
492
	var p_WinCal = ggWinCal;
493
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);
494
 
495
	// Customize your Calendar here..
496
	gCal.gBGColor="white";
497
	gCal.gLinkColor="black";
498
	gCal.gTextColor="black";
499
	gCal.gHeaderColor="#004080";
500
 
501
	// Choose appropriate show function
502
	if (gCal.gYearly)	gCal.showY();
503
	else	gCal.show();
504
}
505
 
506
function show_calendar() {
507
	/* 
508
		p_month : 0-11 for Jan-Dec; 12 for All Months.
509
		p_year	: 4-digit year
510
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
511
		p_item	: Return Item.
512
	*/
513
 
514
	p_item = arguments[0];
515
	if (arguments[1] == null)
516
		p_month = new String(gNow.getMonth());
517
	else
518
		p_month = arguments[1];
519
	if (arguments[2] == "" || arguments[2] == null)
520
		p_year = new String(gNow.getFullYear().toString());
521
	else
522
		p_year = arguments[2];
523
	if (arguments[3] == null)
524
		p_format = "DD\/MM\/YYYY";
525
	else
526
		p_format = arguments[3];
527
 
528
	vWinCal = window.open("", "Calendar", 
529
		"width=250,height=250,status=no,resizable=no,top=200,left=200");
530
	vWinCal.opener = self;
531
	ggWinCal = vWinCal;
532
 
533
	Build(p_item, p_month, p_year, p_format);
534
}
535
/*
536
Yearly Calendar Code Starts here
537
*/
538
function show_yearly_calendar(p_item, p_year, p_format) {
539
	// Load the defaults..
540
	if (p_year == null || p_year == "")
541
		p_year = new String(gNow.getFullYear().toString());
542
	if (p_format == null || p_format == "")
543
		p_format = "MM/DD/YYYY";
544
 
545
	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
546
	vWinCal.opener = self;
547
	ggWinCal = vWinCal;
548
 
549
	Build(p_item, null, p_year, p_format);
550
}
551