PageRenderTime 49ms CodeModel.GetById 14ms app.highlight 28ms RepoModel.GetById 2ms app.codeStats 0ms

/aspnet_client/system_web/2_0_50727/CrystalReportWebFormViewer3/js/calendar_param.js

http://github.com/khaneh/Orders
JavaScript | 701 lines | 421 code | 150 blank | 130 comment | 79 complexity | 4d1d197967328c7ddc82d32f6ba8dac9 MD5 | raw file
  1// Modified Date: 11/30/1999
  2// Modified By:   Robert W. Husted
  3// Notes:  Added frameset support (changed reference for "newWin" to "top.newWin")
  4//         Also changed Spanish "March" from "Marcha" to "Marzo"
  5//         Fixed JavaScript Date Anomaly affecting days > 28
  6//
  7// Modified by Crystal Decisions
  8// Removed large amounts of comments to shrink file size.
  9// Removed multi language support as language set by user as accept-language and navigator.language don't necessarily match
 10// Removed formatting code as only format wanted is for Crystal Reports Date/DateTime parameters
 11// Moved resource strings to top of file for translation
 12// Added A.whatever:visited styles so that followed links appear as if they weren't followed
 13
 14
 15// BEGIN USER-EDITABLE SECTION -----------------------------------------------------
 16
 17// CALENDAR COLORS
 18topBackground    = "black";         // BG COLOR OF THE TOP FRAME
 19bottomBackground = "white";         // BG COLOR OF THE BOTTOM FRAME
 20tableBGColor     = "black";         // BG COLOR OF THE BOTTOM FRAME'S TABLE
 21cellColor        = "lightgrey";     // TABLE CELL BG COLOR OF THE DATE CELLS IN THE BOTTOM FRAME
 22headingCellColor = "white";         // TABLE CELL BG COLOR OF THE WEEKDAY ABBREVIATIONS
 23headingTextColor = "black";         // TEXT COLOR OF THE WEEKDAY ABBREVIATIONS
 24dateColor        = "blue";          // TEXT COLOR OF THE LISTED DATES (1-28+)
 25focusColor       = "#ff0000";       // TEXT COLOR OF THE SELECTED DATE (OR CURRENT DATE)
 26hoverColor       = "darkred";       // TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
 27fontStyle        = "12pt arial, helvetica";           // TEXT STYLE FOR DATES
 28headingFontStyle = "bold 12pt arial, helvetica";      // TEXT STYLE FOR WEEKDAY ABBREVIATIONS
 29
 30// FORMATTING PREFERENCES
 31bottomBorder  = false;        // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
 32tableBorder   = 0;            // SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none
 33
 34var DateTimeFormat = true;		//"DateTime" if true, else a "Date"
 35
 36// END USER-EDITABLE SECTION -------------------------------------------------------
 37
 38// DETERMINE BROWSER BRAND
 39var isNav = false;
 40var isIE  = false;
 41
 42// ASSUME IT'S EITHER NETSCAPE OR MSIE
 43if (navigator.appName == "Netscape") {
 44    isNav = true;
 45}
 46else {
 47    isIE = true;
 48}
 49
 50// global variable for top frame and bottom frame
 51var calDocTop;
 52var calDocBottom;
 53
 54// PRE-BUILD PORTIONS OF THE CALENDAR WHEN THIS JS LIBRARY LOADS INTO THE BROWSER
 55buildCalParts();
 56
 57// CALENDAR FUNCTIONS BEGIN HERE ---------------------------------------------------
 58
 59// SET THE INITIAL VALUE OF THE GLOBAL DATE FIELD
 60function setDateField(formName, dateField, hiddenField) {
 61
 62    // ASSIGN THE INCOMING FIELD OBJECT TO A GLOBAL VARIABLE
 63    thisform = document.forms[formName];
 64    calDateField = thisform[dateField];
 65    calHiddenField = thisform[hiddenField];
 66
 67    // GET THE VALUE OF THE INCOMING FIELD
 68    inDate = thisform[hiddenField].value;
 69
 70    // SET calDate TO THE DATE IN THE INCOMING FIELD OR DEFAULT TO TODAY'S DATE
 71    setInitialDate();
 72
 73    // THE CALENDAR FRAMESET DOCUMENTS ARE CREATED BY JAVASCRIPT FUNCTIONS
 74    calDocTop    = buildTopCalFrame();
 75    calDocBottom = buildBottomCalFrame();
 76}
 77
 78
 79// SET THE INITIAL CALENDAR DATE TO TODAY OR TO THE EXISTING VALUE IN dateField
 80function setInitialDate() {
 81
 82    calDate = ParseDate(inDate, DateTimeFormat);
 83    
 84    // IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
 85    if (isNaN(calDate)) {
 86
 87        // ADD CUSTOM DATE PARSING HERE
 88        // IF IT FAILS, SIMPLY CREATE A NEW DATE OBJECT WHICH DEFAULTS TO THE CURRENT DATE
 89        calDate = new Date();
 90    }
 91
 92    // KEEP TRACK OF THE CURRENT DAY VALUE
 93    calDay  = calDate.getDate();
 94
 95    // SET DAY VALUE TO 1... TO AVOID JAVASCRIPT DATE CALCULATION ANOMALIES
 96    // (IF THE MONTH CHANGES TO FEB AND THE DAY IS 30, THE MONTH WOULD CHANGE TO MARCH
 97    //  AND THE DAY WOULD CHANGE TO 2.  SETTING THE DAY TO 1 WILL PREVENT THAT)
 98    calDate.setDate(1);
 99}
100
101// CREATE THE TOP CALENDAR FRAME
102function buildTopCalFrame() {
103
104    // CREATE THE TOP FRAME OF THE CALENDAR
105    var calDoc =
106        "<HTML>" +
107        "<HEAD>" +
108        "</HEAD>" +
109        "<BODY BGCOLOR='" + topBackground + "'>" +
110        "<FORM NAME='calControl' onSubmit='return false;'>" +
111        "<CENTER>" +
112        "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0 WIDTH=100%>" +
113        "<TR><TD COLSPAN=7>" +
114        "<CENTER>" +
115        getMonthSelect() +
116        "<INPUT NAME='year' VALUE='" + calDate.getFullYear() + "'TYPE=TEXT SIZE=4 MAXLENGTH=4 onKeyDown='parent.opener.keydownfn(event, \"setYear\", \"\");' onChange='parent.opener.setYear()'>" +
117        "</CENTER>" +
118        "</TD>" +
119        "</TR>" +
120        "<TR>" +
121        "<TD COLSPAN=7>" +
122        "<CENTER>" +
123        "<INPUT " +
124        "TYPE=BUTTON NAME='previousYear' VALUE='<<'    onClick='parent.opener.setPreviousYear()'><INPUT " +
125        "TYPE=BUTTON NAME='previousMonth' VALUE=' < '   onClick='parent.opener.setPreviousMonth()'><INPUT " +
126        "TYPE=BUTTON NAME='today' VALUE='" + L_Today + "' onClick='parent.opener.setToday()'><INPUT " +
127        "TYPE=BUTTON NAME='nextMonth' VALUE=' > '   onClick='parent.opener.setNextMonth()'><INPUT " +
128        "TYPE=BUTTON NAME='nextYear' VALUE='>>'    onClick='parent.opener.setNextYear()'>" +
129        "</CENTER>" +
130        "</TD>" +
131        "</TR>" +
132        "</TABLE>" +
133        "</CENTER>" +
134        "</FORM>" +
135        "</BODY>" +
136        "</HTML>";
137
138    return calDoc;
139}
140
141// CREATE THE BOTTOM CALENDAR FRAME
142// (THE MONTHLY CALENDAR)
143function buildBottomCalFrame() {
144    // START CALENDAR DOCUMENT
145    var calDoc = calendarBegin;
146
147    // GET MONTH, AND YEAR FROM GLOBAL CALENDAR DATE
148    month   = calDate.getMonth();
149    year    = calDate.getFullYear();
150
151
152    // GET GLOBALLY-TRACKED DAY VALUE (PREVENTS JAVASCRIPT DATE ANOMALIES)
153    day     = calDay;
154
155    var i   = 0;
156
157    // DETERMINE THE NUMBER OF DAYS IN THE CURRENT MONTH
158    var days = getDaysInMonth();
159
160    // IF GLOBAL DAY VALUE IS > THAN DAYS IN MONTH, HIGHLIGHT LAST DAY IN MONTH
161    if (day > days) {
162        day = days;
163    }
164
165    // DETERMINE WHAT DAY OF THE WEEK THE CALENDAR STARTS ON
166    var firstOfMonth = new Date (year, month, 1);
167
168    // GET THE DAY OF THE WEEK THE FIRST DAY OF THE MONTH FALLS ON
169    var startingPos  = firstOfMonth.getDay();
170    days += startingPos;
171
172    // KEEP TRACK OF THE COLUMNS, START A NEW ROW AFTER EVERY 7 COLUMNS
173    var columnCount = 0;
174
175    // MAKE BEGINNING NON-DATE CELLS BLANK
176    for (i = 0; i < startingPos; i++) {
177
178        calDoc += blankCell;
179	columnCount++;
180    }
181
182    // SET VALUES FOR DAYS OF THE MONTH
183    var currentDay = 0;
184    var dayType    = "weekday";
185
186    // DATE CELLS CONTAIN A NUMBER
187    for (i = startingPos; i < days; i++) {
188
189	var paddingChar = "&nbsp;";
190
191        // ADJUST SPACING SO THAT ALL LINKS HAVE RELATIVELY EQUAL WIDTHS
192        if (i-startingPos+1 < 10) {
193            padding = "&nbsp;&nbsp;";
194        }
195        else {
196            padding = "&nbsp;";
197        }
198
199        // GET THE DAY CURRENTLY BEING WRITTEN
200        currentDay = i-startingPos+1;
201
202        // SET THE TYPE OF DAY, THE focusDay GENERALLY APPEARS AS A DIFFERENT COLOR
203        if (currentDay == day) {
204            dayType = "focusDay";
205        }
206        else {
207            dayType = "weekDay";
208        }
209
210        // ADD THE DAY TO THE CALENDAR STRING
211        calDoc += "<TD align=center bgcolor='" + cellColor + "'>" +
212                  "<a class='" + dayType + "' href='javascript:parent.opener.returnDate(" +
213                  currentDay + ")'>" + padding + currentDay + paddingChar + "</a></TD>";
214
215        columnCount++;
216
217        // START A NEW ROW WHEN NECESSARY
218        if (columnCount % 7 == 0) {
219            calDoc += "</TR><TR>";
220        }
221    }
222
223    // MAKE REMAINING NON-DATE CELLS BLANK
224    for (i=days; i<42; i++)  {
225
226        calDoc += blankCell;
227	columnCount++;
228
229        // START A NEW ROW WHEN NECESSARY
230        if (columnCount % 7 == 0) {
231            calDoc += "</TR>";
232            if (i<41) {
233                calDoc += "<TR>";
234            }
235        }
236    }
237
238    // FINISH THE NEW CALENDAR PAGE
239    calDoc += calendarEnd;
240
241    // RETURN THE COMPLETED CALENDAR PAGE
242    return calDoc;
243}
244
245
246// WRITE THE MONTHLY CALENDAR TO THE BOTTOM CALENDAR FRAME
247function writeCalendar() {
248	// CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEAR
249    calDocBottom = buildBottomCalFrame();
250
251	if (document.getElementById) { // ns6 & ie
252		top.newWin.frames['bottomCalFrame'].document.getElementById('bottomDiv').innerHTML = calDocBottom;
253	} else {
254		// WRITE THE NEW CALENDAR TO THE BOTTOM FRAME
255		top.newWin.frames['bottomCalFrame'].document.open();
256		top.newWin.frames['bottomCalFrame'].document.write(calDocBottom);
257		top.newWin.frames['bottomCalFrame'].document.close();
258	}
259}
260
261// SET THE CALENDAR TO TODAY'S DATE AND DISPLAY THE NEW CALENDAR
262function setToday() {
263
264    // SET GLOBAL DATE TO TODAY'S DATE
265    calDate = new Date();
266
267    // SET DAY MONTH AND YEAR TO TODAY'S DATE
268    var month = calDate.getMonth();
269    var year  = calDate.getFullYear();
270
271    // SET MONTH IN DROP-DOWN LIST
272    top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
273
274    // SET YEAR VALUE
275    top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
276
277	// SET THE DAY VALUE
278	calDay = calDate.getDate();
279
280	// DISPLAY THE NEW CALENDAR
281    writeCalendar();
282}
283
284
285// SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
286function setYear() {
287
288    // GET THE NEW YEAR VALUE
289    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
290
291    // IF IT'S A FOUR-DIGIT YEAR THEN CHANGE THE CALENDAR
292    if (isFourDigitYear(year)) {
293        calDate.setFullYear(year);
294        writeCalendar();
295        top.newWin.frames['topCalFrame'].document.calControl.year.blur();
296    }
297    else {
298        // HIGHLIGHT THE YEAR IF THE YEAR IS NOT FOUR DIGITS IN LENGTH
299        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
300        top.newWin.frames['topCalFrame'].document.calControl.year.select();
301    }
302}
303
304
305// SET THE GLOBAL DATE TO THE SELECTED MONTH AND REDRAW THE CALENDAR
306function setCurrentMonth() {
307
308    // GET THE NEWLY SELECTED MONTH AND CHANGE THE CALENDAR ACCORDINGLY
309    var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;
310
311    calDate.setMonth(month);
312    writeCalendar();
313}
314
315
316// SET THE GLOBAL DATE TO THE PREVIOUS YEAR AND REDRAW THE CALENDAR
317function setPreviousYear() {
318
319    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
320
321    if (isFourDigitYear(year) && year > 1000) {
322        year--;
323        calDate.setFullYear(year);
324        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
325        writeCalendar();
326    }
327}
328
329
330// SET THE GLOBAL DATE TO THE PREVIOUS MONTH AND REDRAW THE CALENDAR
331function setPreviousMonth() {
332
333    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
334    if (isFourDigitYear(year)) {
335        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;
336
337        // IF MONTH IS JANUARY, SET MONTH TO DECEMBER AND DECREMENT THE YEAR
338        if (month == 0) {
339            month = 11;
340            if (year > 1000) {
341                year--;
342                calDate.setFullYear(year);
343                top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
344            }
345        }
346        else {
347            month--;
348        }
349        calDate.setMonth(month);
350        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
351        writeCalendar();
352    }
353}
354
355
356// SET THE GLOBAL DATE TO THE NEXT MONTH AND REDRAW THE CALENDAR
357function setNextMonth() {
358
359    var year = top.newWin.frames['topCalFrame'].document.calControl.year.value;
360
361    if (isFourDigitYear(year)) {
362        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;
363
364        // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
365        if (month == 11) {
366            month = 0;
367            year++;
368            calDate.setFullYear(year);
369            top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
370        }
371        else {
372            month++;
373        }
374        calDate.setMonth(month);
375        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
376        writeCalendar();
377    }
378}
379
380
381// SET THE GLOBAL DATE TO THE NEXT YEAR AND REDRAW THE CALENDAR
382function setNextYear() {
383    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
384    if (isFourDigitYear(year)) {
385        year++;
386        calDate.setFullYear(year);
387        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
388        writeCalendar();
389    }
390}
391
392
393// GET NUMBER OF DAYS IN MONTH
394function getDaysInMonth()  {
395
396    var days;
397    var month = calDate.getMonth()+1;
398    var year  = calDate.getFullYear();
399
400    // RETURN 31 DAYS
401    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
402        month==10 || month==12)  {
403        days=31;
404    }
405    // RETURN 30 DAYS
406    else if (month==4 || month==6 || month==9 || month==11) {
407        days=30;
408    }
409    // RETURN 29 DAYS
410    else if (month==2)  {
411        if (isLeapYear(year)) {
412            days=29;
413        }
414        // RETURN 28 DAYS
415        else {
416            days=28;
417        }
418    }
419    return (days);
420}
421
422
423// CHECK TO SEE IF YEAR IS A LEAP YEAR
424function isLeapYear (Year) {
425
426    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
427        return (true);
428    }
429    else {
430        return (false);
431    }
432}
433
434
435// ENSURE THAT THE YEAR IS FOUR DIGITS IN LENGTH
436function isFourDigitYear(year) {
437
438    if (year == null || year.match(/^[0-9]{4}$/) == null){
439        top.newWin.frames['topCalFrame'].document.calControl.year.value = calDate.getFullYear();
440        top.newWin.frames['topCalFrame'].document.calControl.year.select();
441        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
442    }
443    else {
444        return true;
445    }
446}
447
448
449// BUILD THE MONTH SELECT LIST
450function getMonthSelect() {
451
452    monthArray = new Array(L_January, L_February, L_March, L_April, L_May, L_June,
453                           L_July, L_August, L_September, L_October, L_November, L_December);
454
455
456    // DETERMINE MONTH TO SET AS DEFAULT
457    var activeMonth = calDate.getMonth();
458
459    // START HTML SELECT LIST ELEMENT
460    monthSelect = "<SELECT NAME='month' onChange='parent.opener.setCurrentMonth()'>";
461
462    // LOOP THROUGH MONTH ARRAY
463    for (i in monthArray) {
464
465        // SHOW THE CORRECT MONTH IN THE SELECT LIST
466        if (i == activeMonth) {
467            monthSelect += "<OPTION SELECTED>" + monthArray[i] + "\n";
468        }
469        else {
470            monthSelect += "<OPTION>" + monthArray[i] + "\n";
471        }
472    }
473    monthSelect += "</SELECT>";
474
475    // RETURN A STRING VALUE WHICH CONTAINS A SELECT LIST OF ALL 12 MONTHS
476    return monthSelect;
477}
478
479
480// SET DAYS OF THE WEEK DEPENDING ON LANGUAGE
481function createWeekdayList() {
482
483 weekdayArray = new Array(L_Su,L_Mo,L_Tu,L_We,L_Th,L_Fr,L_Sa);
484
485
486    // START HTML TO HOLD WEEKDAY NAMES IN TABLE FORMAT
487    var weekdays = "<TR BGCOLOR='" + headingCellColor + "'>";
488
489    // LOOP THROUGH WEEKDAY ARRAY
490    for (i in weekdayArray) {
491
492        weekdays += "<TD class='heading' align=center>" + weekdayArray[i] + "</TD>";
493    }
494    weekdays += "</TR>";
495
496    // RETURN TABLE ROW OF WEEKDAY ABBREVIATIONS TO DISPLAY ABOVE THE CALENDAR
497    return weekdays;
498}
499
500
501// PRE-BUILD PORTIONS OF THE CALENDAR (FOR PERFORMANCE REASONS)
502function buildCalParts() {
503
504    // GENERATE WEEKDAY HEADERS FOR THE CALENDAR
505    weekdays = createWeekdayList();
506
507    // BUILD THE BLANK CELL ROWS
508    blankCell = "<TD align=center bgcolor='" + cellColor + "'>&nbsp;&nbsp;&nbsp;</TD>";
509
510    // BUILD THE TOP PORTION OF THE CALENDAR PAGE USING CSS TO CONTROL SOME DISPLAY ELEMENTS
511    calendarBegin =
512        "<HTML>" +
513        "<HEAD>" +
514        // STYLESHEET DEFINES APPEARANCE OF CALENDAR
515        "<STYLE type='text/css'>" +
516        "<!--" +
517        "TD.heading { text-decoration: none; color:" + headingTextColor + "; font: " + headingFontStyle + "; }" +
518        "A.focusDay:link { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
519        "A.focusDay:hover { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
520        "A.focusDay:visited { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
521        "A.weekday:link { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
522        "A.weekday:hover { color: " + hoverColor + "; font: " + fontStyle + "; }" +
523        "A.weekday:visited { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
524        "-->" +
525        "</STYLE>" +
526
527        "</HEAD>" +
528        "<BODY BGCOLOR='" + bottomBackground + "' onload='javascript:self.focus()'>";
529    if (document.getElementById) { // ns6 & ie
530        calendarBegin +=
531            "<DIV ID='bottomDiv'>";
532    }
533    calendarBegin +=
534        "<CENTER>";
535
536        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE TABLE OUTLINES PROPERLY
537        if (isNav) {
538            calendarBegin +=
539                "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'><TR><TD>";
540        }
541
542        // BUILD WEEKDAY HEADINGS
543        calendarBegin +=
544            "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'>" +
545            weekdays +
546            "<TR>";
547
548
549    // BUILD THE BOTTOM PORTION OF THE CALENDAR PAGE
550    calendarEnd = "";
551
552        // WHETHER OR NOT TO DISPLAY A THICK LINE BELOW THE CALENDAR
553        if (bottomBorder) {
554            calendarEnd += "<TR></TR>";
555        }
556
557        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE BORDERS PROPERLY
558        if (isNav) {
559            calendarEnd += "</TD></TR></TABLE>";
560        }
561
562        // END THE TABLE AND HTML DOCUMENT
563        calendarEnd +=
564            "</TABLE>" +
565            "</CENTER>";
566		if (document.getElementById) { // ns6 & ie
567            calendarEnd +=
568            "</DIV>";
569		}
570		calendarEnd +=
571            "</BODY>" +
572            "</HTML>";
573}
574
575
576// REPLACE ALL INSTANCES OF find WITH replace
577// inString: the string you want to convert
578// find:     the value to search for
579// replace:  the value to substitute
580//
581// usage:    jsReplace(inString, find, replace);
582// example:  jsReplace("To be or not to be", "be", "ski");
583//           result: "To ski or not to ski"
584//
585function jsReplace(inString, find, replace) {
586
587    var outString = "";
588
589    if (!inString) {
590        return "";
591    }
592
593    // REPLACE ALL INSTANCES OF find WITH replace
594    if (inString.indexOf(find) != -1) {
595        // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find
596        t = inString.split(find);
597
598        // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace
599        return (t.join(replace));
600    }
601    else {
602        return inString;
603    }
604}
605
606
607// JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR CALL)
608function doNothing() {
609}
610
611
612// ENSURE THAT VALUE IS TWO DIGITS IN LENGTH
613function makeTwoDigit(inValue) {
614
615    var numVal = parseInt(inValue, 10);
616
617    // VALUE IS LESS THAN TWO DIGITS IN LENGTH
618    if (numVal < 10) {
619
620        // ADD A LEADING ZERO TO THE VALUE AND RETURN IT
621        return("0" + numVal);
622    }
623    else {
624        return numVal;
625    }
626}
627
628
629// SET FIELD VALUE TO THE DATE SELECTED AND CLOSE THE CALENDAR WINDOW
630function returnDate(inDay)
631{
632    // inDay = THE DAY THE USER CLICKED ON
633    calDate.setDate(inDay);
634
635    // SET THE DATE RETURNED TO THE USER
636    var day           = calDate.getDate();
637    var month         = calDate.getMonth()+1;
638    var year          = calDate.getFullYear();
639    
640    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
641    var dt = new Date(year, month - 1, day, 0, 0, 0);
642    calDateField.value = GLDT(dt,true, false);
643
644    calHiddenField.value = "Date(";
645    calHiddenField.value += year;
646    calHiddenField.value += ",";
647    calHiddenField.value += month;
648    calHiddenField.value += ",";
649    calHiddenField.value += day;
650    calHiddenField.value += ")";
651
652    // GIVE FOCUS BACK TO THE DATE FIELD
653    calDateField.focus();
654
655    // CLOSE THE CALENDAR WINDOW
656    top.newWin.close()
657}
658
659var gHour = "0";
660var gMin  = "0";
661var gSec  = "0";
662var regDateTimePrompt  = /^(D|d)(A|a)(T|t)(E|e)(T|t)(I|i)(M|m)(E|e) *\( *\d{4} *, *(0?[1-9]|1[0-2]) *, *((0?[1-9]|[1-2]\d)|3(0|1)) *, *([0-1]?\d|2[0-3]) *, *[0-5]?\d *, *[0-5]?\d *\)$/
663function ParseDateTimePrompt(inDate)
664{
665    if ( regDateTimePrompt.test ( inDate ) )
666    {
667        var sDate = inDate.substr ( inDate.indexOf("(")+1 );    //move past "DateTime ("
668        sDate = sDate.substr ( 0, sDate.lastIndexOf(")") );     //remove trailing ")"
669        var dateArray = sDate.split (',');
670        var _date = new Date ( dateArray[0], Number(dateArray[1]) - 1, dateArray[2] );
671        gHour = dateArray[3]; gMin = dateArray[4]; gSec = dateArray[5];
672        return _date;
673    }
674    return new Date ();
675}
676
677var regDatePrompt = /^(D|d)(A|a)(T|t)(E|e) *\( *\d{4} *, *(0?[1-9]|1[0-2]) *, *((0?[1-9]|[1-2]\d)|3(0|1)) *\)$/
678function ParseDatePrompt(inDate)
679{
680    if ( regDatePrompt.test ( inDate ) )
681    {
682        var sDate = inDate.substr ( inDate.indexOf("(")+1 );    //move past "Date ("
683        sDate = sDate.substr ( 0, sDate.lastIndexOf(")") );     //remove trailing ")"
684        var dateArray = sDate.split (',');
685        return new Date ( dateArray[0], Number(dateArray[1]) - 1, dateArray[2] );
686    }
687    return new Date();
688}
689
690function ParseDate(inDate, bDateTimeFormat)
691{
692    var result;
693    
694    if (bDateTimeFormat == true) {
695        result = ParseDateTimePrompt(inDate);
696    } else {
697        result = ParseDatePrompt(inDate);
698    }
699    
700    return result;
701}