1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
| var weekend = [0, 6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;
var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function getAppName() {
var url = window.location.href.split('/');
return url[3];
}
function Calendar(p_item, p_WinCal, p_month, p_year) {
if ((p_month == null) && (p_year == null))
return;
if (p_WinCal == null)
this.gWinCal = ggWinCal;
else
this.gWinCal = p_WinCal;
this.gMonthName = Calendar.get_month(p_month);
this.gMonth = new Number(p_month);
this.gYear = p_year;
this.gFormat = "DD-MON-YY";
this.gBGColor = "white";
this.gFGColor = "black";
this.gTextColor = "black";
this.gHeaderColor = "black";
this.gReturnItem = p_item;
}
Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;
function Calendar_get_month(monthNo) {
return Calendar.Months[monthNo];
}
function Calendar_get_daysofmonth(monthNo, p_year) {
/*
Check for leap year ..
1.Years evenly divisible by four are normally leap years, except for...
2.Years also evenly divisible by 100 are not leap years, except for...
3.Years also evenly divisible by 400 are leap years.
*/
if ((p_year % 4) == 0) {
if ((p_year % 100) == 0 && (p_year % 400) != 0)
return Calendar.DOMonth[monthNo];
return Calendar.lDOMonth[monthNo];
} else
return Calendar.DOMonth[monthNo];
}
function Calendar_calc_month_year(p_Month, p_Year, incr) {
/*
Will return an 1-D array with 1st element being the calculated month
and second being the calculated year
after applying the month increment/decrement as specified by 'incr' parameter.
'incr' will normally have 1/-1 to navigate thru the months.
*/
var ret_arr = new Array();
if (incr == -1) {
// B A C K W A R D
if (p_Month == 0) {
ret_arr[0] = 11;
ret_arr[1] = parseInt(p_Year) - 1;
} else {
ret_arr[0] = parseInt(p_Month) - 1;
ret_arr[1] = parseInt(p_Year);
}
} else if (incr == 1) {
// F O R W A R D
if (p_Month == 11) {
ret_arr[0] = 0;
ret_arr[1] = parseInt(p_Year) + 1;
} else {
ret_arr[0] = parseInt(p_Month) + 1;
ret_arr[1] = parseInt(p_Year);
}
}
return ret_arr;
}
function Calendar_print() {
ggWinCal.print();
}
function Calendar_calc_month_year(p_Month, p_Year, incr) {
/*
Will return an 1-D array with 1st element being the calculated month
and second being the calculated year
after applying the month increment/decrement as specified by 'incr' parameter.
'incr' will normally have 1/-1 to navigate thru the months.
*/
var ret_arr = new Array();
if (incr == -1) {
// B A C K W A R D
if (p_Month == 0) {
ret_arr[0] = 11;
ret_arr[1] = parseInt(p_Year) - 1;
} else {
ret_arr[0] = parseInt(p_Month) - 1;
ret_arr[1] = parseInt(p_Year);
}
} else if (incr == 1) {
// F O R W A R D
if (p_Month == 11) {
ret_arr[0] = 0;
ret_arr[1] = parseInt(p_Year) + 1;
} else {
ret_arr[0] = parseInt(p_Month) + 1;
ret_arr[1] = parseInt(p_Year);
}
}
return ret_arr;
}
// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();
Calendar.prototype.getMonthlyCalendarCode = function () {
var vCode = "";
var vHeader_Code = "";
var vData_Code = "";
// Begin Table Drawing code here..
vCode = vCode + "<TABLE BORDER=0 bordercolor=#FFFFFF width=100%>";
vHeader_Code = this.cal_header();
vData_Code = this.cal_data();
vCode = vCode + vHeader_Code + vData_Code;
vCode = vCode + "</TABLE>";
return vCode;
}
Calendar.prototype.show = function () {
var vCode = "";
this.gWinCal.document.open();
// Setup the page...
this.wwrite("<html>");
this.wwrite("<head><title>Calendar</title><link href=/" + getAppName() + "/cmh/css/cmh.css rel=stylesheet type=text/css>");
this.wwrite("</head>");
this.wwrite("<body " +
"link=\"" + this.gLinkColor + "\" " +
"vlink=\"" + this.gLinkColor + "\" " +
"alink=\"" + this.gLinkColor + "\" " +
"text=\"" + this.gTextColor + "\">");
this.wwriteA("<table width=100%><tr><td align=left><FONT FACE='" + fontface + "' SIZE=2><B>");
this.wwriteA(this.gMonthName + " " + this.gYear);
this.wwriteA("</B><td><td><div align=right><img src=/" + getAppName() + "/cmh/image/calendar.gif></div></td></tr></table>");
// Show navigation buttons
var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
var prevMM = prevMMYYYY[0];
var prevYYYY = prevMMYYYY[1];
var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
var nextMM = nextMMYYYY[0];
var nextYYYY = nextMMYYYY[1];
this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=5 CELLPADDING=0><TR><TD width=10% ALIGN=left>");
this.wwrite("<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear) - 1) + "', '" + this.gFormat + "'" +
");" +
"\"><img src=/" + getAppName() + "/cmh/javascript/search_rr.gif border=0><\/A></TD><TD width=10% ALIGN=left>");
this.wwrite("<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
");" +
"\"><img src=/" + getAppName() + "/cmh/javascript/search_r.gif border=0><\/A></TD><TD width=60% ALIGN=center>");
this.wwrite("</TD><TD width=10% ALIGN=right>");
this.wwrite("<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
");" +
"\"><img src=/" + getAppName() + "/cmh/javascript/search_f.gif border=0><\/A></TD><TD width=10% ALIGN=right>");
this.wwrite("<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear) + 1) + "', '" + this.gFormat + "'" +
");" +
"\"><img src=/" + getAppName() + "/cmh/javascript/search_ff.gif border=0><\/A></TD></TR></TABLE>");
// Get the complete calendar code for the month..
vCode = this.getMonthlyCalendarCode();
this.wwrite(vCode);
this.wwrite("</font></body></html>");
this.gWinCal.document.close();
}
Calendar.prototype.wwrite = function (wtext) {
this.gWinCal.document.writeln(wtext);
}
Calendar.prototype.wwriteA = function (wtext) {
this.gWinCal.document.write(wtext);
}
Calendar.prototype.cal_header = function () {
var vCode = "";
vCode = vCode + "<TR class=TableTitle1>";
vCode = vCode + "<TD WIDTH='14%' align=center>Sun</TD>";
vCode = vCode + "<TD WIDTH='14%' align=center>Mon</TD>";
vCode = vCode + "<TD WIDTH='14%' align=center>Tue</TD>";
vCode = vCode + "<TD WIDTH='14%' align=center>Wed</TD>";
vCode = vCode + "<TD WIDTH='14%' align=center>Thu</TD>";
vCode = vCode + "<TD WIDTH='14%' align=center>Fri</TD>";
vCode = vCode + "<TD WIDTH='16%' align=center>Sat</TD>";
vCode = vCode + "</TR>";
return vCode;
}
Calendar.prototype.cal_data = function () {
var vDate = new Date();
vDate.setDate(1);
vDate.setMonth(this.gMonth);
vDate.setFullYear(this.gYear);
var vFirstDay = vDate.getDay();
var vDay = 1;
var vLastDay = Calendar.get_daysofmonth(this.gMonth, this.gYear);
var vOnLastDay = 0;
var vCode = "";
/*
Get day for the 1st of the requested month/year..
Place as many blank cells before the 1st day of the month as necessary.
*/
vCode = vCode + "<TR class=TableContent>";
for (i = 0; i < vFirstDay; i++) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + " align=center> </TD>";
}
// Write rest of the 1st week
for (j = vFirstDay; j < 7; j++) {
if (p_fieldNotInForm) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center>" +
"<A HREF='#' " +
"onClick=\"self.opener.document.getElementById('" + this.gReturnItem + "').value='" +
this.format_data(vDay) + "';" +
"self.opener.document.getElementById('" + this.gReturnItem + "').focus();" +
"var evt = document.createEvent('Event');" +
"evt.initEvent('change', true, true);" +
"self.opener.document.getElementById('" + this.gReturnItem + "').dispatchEvent(evt);" +
"window.close();\">" +
this.format_day(vDay) +
"</A>" +
"</TD>";
} else {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center>" +
"<A HREF='#' " +
"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
this.format_data(vDay) +
"';window.close();\">" +
this.format_day(vDay) +
"</A>" +
"</TD>";
}
vDay = vDay + 1;
}
vCode = vCode + "</TR>";
// Write the rest of the weeks
for (k = 2; k < 7; k++) {
vCode = vCode + "<TR class=TableContent>";
for (j = 0; j < 7; j++) {
if (p_fieldNotInForm) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center>" +
"<A HREF='#' " +
"onClick=\"self.opener.document.getElementById('" + this.gReturnItem + "').value='" +
this.format_data(vDay) + "';" +
"self.opener.document.getElementById('" + this.gReturnItem + "').focus();" +
"var evt = document.createEvent('Event');" +
"evt.initEvent('change', true, true);" +
"self.opener.document.getElementById('" + this.gReturnItem + "').dispatchEvent(evt);" +
"window.close();\">" +
this.format_day(vDay) +
"</A>" +
"</TD>";
} else {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center>" +
"<A HREF='#' " +
"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
this.format_data(vDay) +
"';window.close();\">"+
this.format_day(vDay) +
"</A>" +
"</TD>";
}
vDay = vDay + 1;
if (vDay > vLastDay) {
vOnLastDay = 1;
break;
}
}
if (j == 6)
vCode = vCode + "</TR>";
if (vOnLastDay == 1)
break;
}
// Fill up the rest of last week with proper blanks, so that we get proper square blocks
for (m = 1; m < (7 - j); m++) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j + m) +
" align=center>" + m + "</TD>";
}
return vCode;
}
Calendar.prototype.format_day = function (vday) {
var vNowDay = gNow.getDate();
var vNowMonth = gNow.getMonth();
var vNowYear = gNow.getFullYear();
if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
return ("<FONT COLOR=\"#FF9900\"><B>" + vday + "</B></FONT>");
else
return (vday);
}
Calendar.prototype.write_weekend_string = function (vday) {
var i;
// Return special formatting for the weekend day.
for (i = 0; i < weekend.length; i++) {
if (vday == weekend[i])
return (" BGCOLOR=\"" + weekendColor + "\"");
}
return "";
}
Calendar.prototype.format_data = function (p_day) {
var vData;
var vMon = Calendar.get_month(this.gMonth).substr(0, 1).toUpperCase();
vMon = vMon + Calendar.get_month(this.gMonth).substr(1, 2);
var vY2 = new String(this.gYear.substr(2, 2));
var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;
vData = vDD + "-" + vMon + "-" + vY2;
return vData;
}
function Build(p_item, p_month, p_year) {
var p_WinCal = ggWinCal;
gCal = new Calendar(p_item, p_WinCal, p_month, p_year);
// Customize your Calendar here..
gCal.gBGColor = "#E4EAEF";
gCal.gLinkColor = "black";
gCal.gTextColor = "black";
gCal.gHeaderColor = "black";
gCal.show();
}
function show_calendar() {
/*
p_month : 0-11 for Jan-Dec; 12 for All Months.
p_year : 4-digit year
p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
p_item : Return Item.
arguments[2] : does it have to make an action on equality between the ancien date and the new date
arguments[3] : the id of the element on which the property will be changed
arguments[4] : the property (like a key)
arguments[5] : the value of the
*/
p_item = arguments[0];
p_fieldNotInForm = arguments[1];
if (p_fieldNotInForm) {
p_currentDate = p_item.value;
} else {
p_currentDate = eval('document.' + p_item + '.value');
}
if (p_currentDate != "") {
var flag = checkFormat(p_currentDate);
if (flag === false) {
var date = new Date();
var month = date.getMonth();
var day = date.getDate();
var year = date.getYear();
year = year - 2000;
var strMonth = intMonthToStrMonth(month);
var currentdate = day + "-" + strMonth + "-" + year;
p_currentDate = currentdate;
}
var firstDash = p_currentDate.indexOf("-");
var secondDash = p_currentDate.indexOf("-", firstDash + 1);
var inputDay = parseInt(p_currentDate.substring(0, firstDash), 10);
var inputYear = parseInt(p_currentDate.substring(secondDash + 1), 10) + 2000;
var inputMonth = p_currentDate.substring(firstDash + 1, secondDash);
var intMonth = strMonthToIntMonth(inputMonth);
gNow.setYear(inputYear);
gNow.setMonth(intMonth);
gNow.setDate(inputDay);
}
p_month = new String(gNow.getMonth());
p_year = new String(gNow.getFullYear().toString());
ns4 = (document.layers) ? true : false
ie4 = (document.all) ? true : false
try {
var a = event;
} catch (e) {
event = null;
}
if (event === null) {
var height = screen.height;
var width = screen.width;
height = height - height / 2;
width = width / 2;
mouseY = height - 100;
mouseX = width - 125;
} else if (ns4) {
var mouseX = e.pageX;
var mouseY = e.pageY
} else if (ie4) {
var mouseX = event.x - 125;
var mouseY = event.y - (200 / 8)
} else
{
var mouseX = event.clientX - 125;
var mouseY = event.clientY - (200 / 8)
}
var p_parameters = 'width=250,height=200,status=no,resizable=no,top=' + mouseY + ',left=' + mouseX;
vWinCal = window.open("", "Calendar", p_parameters);
vWinCal.opener = window.self;
ggWinCal = vWinCal;
if (p_fieldNotInForm) {
// TODO p_item.name changed for p_item.id => to check in jsp
p_item = p_item.id;
}
Build(p_item, p_month, p_year);
}
// STRMONTHTOINTMONTH
// Convert a String Month in an Integer Month (from 0 to 11)
function strMonthToIntMonth(monthToConvert) {
var strMonth = monthToConvert.toLowerCase();
var intMonth;
switch (strMonth) {
case "jan":
intMonth = 0;
break;
case "feb":
intMonth = 1;
break;
case "mar":
intMonth = 2;
break;
case "apr":
intMonth = 3;
break;
case "may":
intMonth = 4;
break;
case "jun":
intMonth = 5;
break;
case "jul":
intMonth = 6;
break;
case "aug":
intMonth = 7;
break;
case "sep":
intMonth = 8;
break;
case "oct":
intMonth = 9;
break;
case "nov":
intMonth = 10;
break;
case "dec":
intMonth = 11;
break;
default:
return null;
}
return intMonth;
}
function intMonthToStrMonth(monthToConvert) {
var strMonth;
var intMonth;
switch (monthToConvert) {
case 0:
strMonth = "jan";
break;
case 1:
strMonth = "feb";
break;
case 2:
strMonth = "mar";
break;
case 3:
strMonth = "apr";
break;
case 4:
strMonth = "may";
break;
case 5:
strMonth = "jun";
break;
case 6:
strMonth = "jul";
break;
case 7:
strMonth = "aug";
break;
case 8:
strMonth = "sep";
break;
case 9:
strMonth = "oct";
break;
case 10:
strMonth = "nov";
break;
case 11:
strMonth = "dec";
break;
default:
return null;
}
return strMonth;
}
// CHECKFORMAT
// Check that the format of the date is DD-MMM-YY
function checkFormat(inputDate) {
var firstDash = inputDate.indexOf("-");
var secondDash = inputDate.indexOf("-", firstDash + 1);
if (firstDash == -1 || secondDash == -1) {
return false;
}
var inputDay = parseInt(inputDate.substring(0, firstDash), 10);
var inputMonth = inputDate.substring(firstDash + 1, secondDash);
var inputYear = parseInt(inputDate.substring(secondDash + 1), 10);
var intMonth = strMonthToIntMonth(inputMonth);
if (inputDate.substring(secondDash + 1).length != 2 || inputDate.substring(0, firstDash).length != 2) {
return false;
}
if (isNaN(inputYear) || inputYear < 0 || inputYear > 99) {
return false;
}
if (inputYear < 10) {
var val = parseInt(inputDate.substring(secondDash + 2), 10);
if (isNaN(val)) {
return false;
}
}
if (isNaN(intMonth) || intMonth == null) {
return false;
}
if (isNaN(inputDay) || inputDay < 1 || inputDay > Calendar.DOMonth[inputMonth]) {
return false;
}
if (inputDay < 10) {
var val = parseInt(inputDate.substring(1, firstDash), 10);
if (isNaN(val)) {
return false;
}
}
return true;
} |
Partager