<!--
/* <![CDATA[ */

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;

CalendarPopUp.Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
CalendarPopUp.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
CalendarPopUp.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function CalendarPopUp(p_item_prefix, p_item, p_WinCal, p_month, p_year, p_format, p_currm, p_currd, p_curry, p_limtm, p_limtd, p_limty, p_dispcd) {

        if ((p_month == null) && (p_year == null))      return;

        if (p_WinCal == null)
                this.gWinCal = ggWinCal;
        else
                this.gWinCal = p_WinCal;

        if (p_month == null) {
                this.gMonthName = null;
                this.gMonth = null;
                this.gYearly = true;
        } else {
                this.gMonthName = CalendarPopUp.get_month(p_month);
                this.gMonth = new Number(p_month);
                this.gYearly = false;
        }

        this.gYear = p_year;
        this.gFormat = p_format;
        this.gBGColor = "black";
        this.gFGColor = "white";
         this.gBGColorNav = "black";
        this.gFGColorNav = "#E0E0E0";
        this.gTextColor = "black";
        this.gHeaderColor = "black";
        this.gReturnItemPrefix = p_item_prefix;
	  this.gReturnItem = p_item;
        this.gCurrMonth = p_currm;
        this.gCurrDay = p_currd;
        this.gCurrYear = p_curry;
        this.gLimtMonth = p_limtm;
        this.gLimtDay = p_limtd;
        this.gLimtYear = p_limty;
        this.gDispCode = p_dispcd;

//alert("In  CalendarPopUp");
//alert("this.gCurrMonth " + this.gCurrMonth);
//alert("this.gCurrDay " + this.gCurrDay);
//alert("this.gCurrYear " + this.gCurrYear);
//alert("this.gLimtMonth " + this.gLimtMonth);
//alert("this.gLimtDay " + this.gLimtDay);
//alert("this.gLimtYear " + this.gLimtYear);
//alert("this.gDispCode " + this.gDispCode);
}

CalendarPopUp.get_month = CalendarPopUp_get_month;
CalendarPopUp.get_daysofmonth = CalendarPopUp_get_daysofmonth;
CalendarPopUp.calc_month_year = CalendarPopUp_calc_month_year;
CalendarPopUp.print = CalendarPopUp_print;

function CalendarPopUp_get_month(monthNo) {
        return CalendarPopUp.Months[monthNo];
}

function CalendarPopUp_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 CalendarPopUp.DOMonth[monthNo];

                return CalendarPopUp.lDOMonth[monthNo];
        } else
                return CalendarPopUp.DOMonth[monthNo];
}

function CalendarPopUp_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 CalendarPopUp_print() {
        ggWinCal.print();
}

function CalendarPopUp_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 CalendarPopUp();

CalendarPopUp.prototype.getMonthlyCalendarPopUpCode = function() {

        var vCode = "";
        var vHeader_Code = "";
        var vData_Code = "";

        // Begin Table Drawing code here..
        vCode = vCode + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"1\" bgcolor=\"" + this.gBGColor + "\">";

        vHeader_Code = this.cal_header();
        vData_Code = this.cal_data();
        vCode = vCode + vHeader_Code + vData_Code;

        vCode = vCode + "</table>";

        return vCode;
}

CalendarPopUp.prototype.show = function() {

        var vCode = "";

//alert("this.gCurrDay is " + this.gCurrDay);
//alert("this.gCurrYear is " + this.gCurrYear);
//alert("this.gDispCode is " + this.gDispCode);

        if(this.gCurrMonth != '')
           var CurrDtParms = ", '" + this.gCurrMonth + "', '" + this.gCurrDay + "', '" + this.gCurrYear +"', '" + this.gLimtMonth + "', '" + this.gLimtDay + "', '" + this.gLimtYear + "', '" + this.gDispCode + "'";
        else
           var CurrDtParms = ", '', '', '', '', '', '', '" + this.gDispCode + "'";

//alert("CurrDtParms is " + CurrDtParms);

        this.gWinCal.document.open();

        // Setup the page...
        this.wwrite("<html>");
        this.wwrite("<head><title>CalendarPopUp</title>");
        this.wwrite("</head>");

        this.wwrite("<body " +
                "link=\"" + this.gLinkColor + "\" " +
                "vlink=\"" + this.gLinkColor + "\" " +
                "alink=\"" + this.gLinkColor + "\" " +
                "text=\"" + this.gTextColor + "\">");
        this.wwriteA("<font face='" + fontface + "' size=\"2\"><b>");
        this.wwriteA(this.gMonthName + " " + this.gYear);
        this.wwriteA("</b><br />");

		var showPrevMMNav = 'true';
		var showPrevYYNav = 'true';
		var showNextMMNav = 'true';
		var showNextYYNav = 'true';


        // display nav according to display code passed
        switch (this.gDispCode) {
                case "A" :
                        showPrevMMNav = 'true';
                        showPrevYYNav = 'true';
                        showNextMMNav = 'true';
                        showNextYYNav = 'true';
                        break;
                case "G" :
                       if (this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showPrevMMNav = 'false';
                        showPrevYYNav = 'false';
                        }
                       if (this.gMonth > this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showPrevYYNav = 'false';
                        }
                       if (this.gMonth < this.gLimtMonth && this.gYear == (parseInt(this.gLimtYear) + 1)) {
                        showPrevYYNav = 'false';
                        }
                        break;
                case "GE" :
                       if (this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showPrevMMNav = 'false';
                        showPrevYYNav = 'false';
                        }
                       if (this.gMonth > this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showPrevYYNav = 'false';
                        }
                       if (this.gMonth < this.gLimtMonth && this.gYear == (parseInt(this.gLimtYear) + 1)) {
                        showPrevYYNav = 'false';
                        }
                        break;
                case "L" :
                       if (this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showNextMMNav = 'false';
                        showNextYYNav = 'false';
                        }
                       if (this.gMonth < this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showNextYYNav = 'false';
                        }
                       if (this.gMonth > this.gLimtMonth && this.gYear == (parseInt(this.gLimtYear) - 1)) {
                        showNextYYNav = 'false';
                        }
                        break;

                case "LE" :
                       if (this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showNextMMNav = 'false';
                        showNextYYNav = 'false';
                        }
                       if (this.gMonth < this.gLimtMonth && this.gYear == this.gLimtYear) {
                        showNextYYNav = 'false';
                        }
                       if (this.gMonth > this.gLimtMonth && this.gYear == (parseInt(this.gLimtYear) - 1)) {
                        showNextYYNav = 'false';
                        }
                        break;

                default :
                        showPrevMMNav = 'true';
                        showPrevYYNav = 'true';
                        showNextMMNav = 'true';
                        showNextYYNav = 'true';
        }


        // Show navigation buttons
        var prevMMYYYY = CalendarPopUp.calc_month_year(this.gMonth, this.gYear, -1);
        var prevMM = prevMMYYYY[0];
        var prevYYYY = prevMMYYYY[1];

        var nextMMYYYY = CalendarPopUp.calc_month_year(this.gMonth, this.gYear, 1);
        var nextMM = nextMMYYYY[0];
        var nextYYYY = nextMMYYYY[1];

        this.wwrite("<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#e0e0e0\"><tr><td align=\"center\">");
        if (showPrevYYNav == 'true') {
          this.wwrite("[<a href=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItemPrefix + "', '" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '"  + this.gFormat + "'" + CurrDtParms +
                ");" +
                "\"><<<\/a>]</td><td align=\"center\">");
        }
        else {
          this.wwrite("&nbsp;&nbsp;&nbsp;&nbsp;</td><td align=\"center\">");
        }

        if (showPrevMMNav == 'true') {
          this.wwrite("[<a href=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItemPrefix + "', '" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY  + "', '"  + this.gFormat + "'" + CurrDtParms +
                ");" +
                "\"><<\/a>]</td>");
        }
        else {
          this.wwrite("&nbsp;&nbsp;&nbsp;</TD>");
        }

        this.wwrite("<td align=\"center\">&nbsp;&nbsp;&nbsp;&nbsp;</td><td align=\"center\">");
        if (showNextMMNav ==  'true') {
          this.wwrite("[<a href=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItemPrefix + "', '" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '"  + this.gFormat + "'" + CurrDtParms +
                ");" +
                "\">><\/a>]</td><td align=\"center\">");
        }
        else {
          this.wwrite("&nbsp;&nbsp;&nbsp;&nbsp;</td><td align=\"center\">");
        }
        if (showNextYYNav ==  'true') {
          this.wwrite("[<a href=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItemPrefix + "', '" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '"  + this.gFormat + "'" + CurrDtParms +
                ");" +
                "\">>><\/a>]</td>");
        }
        else {
          this.wwrite("&nbsp;&nbsp;&nbsp;</td>");
        }

        this.wwrite("</Tr></table><br>");

        // Get the complete calendar code for the month..
        vCode = this.getMonthlyCalendarPopUpCode();
        this.wwrite(vCode);

        this.wwrite("</font></body></html>");
        this.gWinCal.document.close();
}

CalendarPopUp.prototype.showY = function() {
        var vCode = "";
        var i;
        var vr, vc, vx, vy;             // Row, Column, X-coord, Y-coord
        var vxf = 285;                  // X-Factor
        var vyf = 200;                  // Y-Factor
        var vxm = 10;                   // X-margin
        var vym;                                // Y-margin
        if (isIE)       vym = 75;
        else if (isNav) vym = 25;

        this.gWinCal.document.open();

        this.wwrite("<html>");
        this.wwrite("<head><title>CalendarPopUp</title>");
        this.wwrite("<style type='text/css'>\n<!--");
        for (i=0; i<12; i++) {
                vc = i % 3;
                if (i>=0 && i<= 2)      vr = 0;
                if (i>=3 && i<= 5)      vr = 1;
                if (i>=6 && i<= 8)      vr = 2;
                if (i>=9 && i<= 11)     vr = 3;

                vx = parseInt(vxf * vc) + vxm;
                vy = parseInt(vyf * vr) + vym;

                this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
        }
        this.wwrite("-->\n</style>");
        this.wwrite("</head>");

        this.wwrite("<body " +
                "link=\"" + this.gLinkColor + "\" " +
                "vlink=\"" + this.gLinkColor + "\" " +
                "alink=\"" + this.gLinkColor + "\" " +
                "text=\"" + this.gTextColor + "\">");
        this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
        this.wwrite("Year : " + this.gYear);
        this.wwrite("</B><BR>");

        // Show navigation buttons
        var prevYYYY = parseInt(this.gYear) - 1;
        var nextYYYY = parseInt(this.gYear) + 1;

        this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
        this.wwrite("[<A HREF=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItemPrefix + "', '" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
                ");" +
                "\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
        this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
        this.wwrite("[<A HREF=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItemPrefix + "', '" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
                ");" +
                "\">>><\/A>]</TD></TR></TABLE><BR>");

        // Get the complete calendar code for each month..
        var j;
        for (i=11; i>=0; i--) {
                if (isIE)
                        this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
                else if (isNav)
                        this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

                this.gMonth = i;
                this.gMonthName = CalendarPopUp.get_month(this.gMonth);
                vCode = this.getMonthlyCalendarPopUpCode();
                this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
                this.wwrite(vCode);

                if (isIE)
                        this.wwrite("</DIV>");
                else if (isNav)
                        this.wwrite("</LAYER>");
        }

        this.wwrite("</font><BR></body></html>");
        this.gWinCal.document.close();
}

CalendarPopUp.prototype.wwrite = function(wtext) {
        this.gWinCal.document.writeln(wtext);
}

CalendarPopUp.prototype.wwriteA = function(wtext) {
        this.gWinCal.document.write(wtext);
}

CalendarPopUp.prototype.cal_header = function() {
        var vCode = "";

        vCode = vCode + "<TR>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
        vCode = vCode + "</TR>";

        return vCode;
}

CalendarPopUp.prototype.cal_data = function() {

//alert("In CalendarPopUp.prototype.cal_data Function");
//alert("this.gCurrMonth " + this.gCurrMonth);
//alert("this.gCurrDay " + this.gCurrDay);
//alert("this.gCurrYear " + this.gCurrYear);
//alert("this.gDispCode " + this.gDispCode);

        var vDate = new Date();
        vDate.setDate(1);
        vDate.setMonth(this.gMonth);
        vDate.setFullYear(this.gYear);

        var vFirstDay=vDate.getDay();
        var vDay=1;
        var vLastDay=CalendarPopUp.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>";
        for (i=0; i<vFirstDay; i++) {
                vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'>&nbsp;</FONT></TD>";
        }

        // Write rest of the 1st week
        for (j=vFirstDay; j<7; j++) {



  		  var BuildHref = 'true';

          // display nav according to display code passed
          switch (this.gDispCode) {
                case "G" :
                       if (vDay <= this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        BuildHref = 'false';
                        }
                        break;
                case "GE" :
                       if (vDay < this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        BuildHref = 'false';
                        }
                        break;
                case "L" :
                       if (vDay >= this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        BuildHref = 'false';
                        }
                        break;

                case "LE" :
                       if (vDay > this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
                        BuildHref = 'false';
                        }
                        break;

                default :
                        BuildHref = 'true';
          }
document.forms[0].elements['Variables.fieldname']
          if (BuildHref ==  'true') {
                vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
                        "<A HREF='#' " +
                                "onClick=\"self.opener.document.forms[0].elements['"  + this.gReturnItem + "'].value='" +
                                this.format_data(vDay) +
                                "';window.close();\">" +
                                this.format_day(vDay) +
                        "</A>" +
                        "</FONT></TD>";
          }
          else {
                vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
                        this.format_day(vDay) +
                        "</FONT></TD>";
          }
                vDay=vDay + 1;
        }
        vCode = vCode + "</TR>";

        // Write the rest of the weeks
        for (k=2; k<7; k++) {
                vCode = vCode + "<TR>";

                for (j=0; j<7; j++) {
				  var BuildHref = 'true';

				  // display nav according to display code passed
				  switch (this.gDispCode) {
						case "G" :
							   if (vDay <= this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
								BuildHref = 'false';
								}
								break;
						case "GE" :
							   if (vDay < this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
								BuildHref = 'false';
								}
								break;
						case "L" :
							   if (vDay >= this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
								BuildHref = 'false';
								}
								break;

						case "LE" :
							   if (vDay > this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear) {
								BuildHref = 'false';
								}
								break;

						default :
								BuildHref = 'true';
				  }

				  if (BuildHref ==  'true') {
                        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
                                "<A HREF='#' " +
                                        "onClick=\"self.opener.document.forms[0].elements['"  + this.gReturnItem + "'].value='" +
                                        this.format_data(vDay) +
                                        "';self.opener.document.forms[0].elements['"  + this.gReturnItem + "'].focus()" +
                                        ";window.close();\">" +
                                this.format_day(vDay) +
                                "</A>" +
                                "</FONT></TD>";
				  }
				  else {
                        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
                                this.format_day(vDay) +
                                "</FONT></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++) {
                if (this.gYearly)
                        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
                        "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>&nbsp;</FONT></TD>";
                else
                        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
                        "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
        }

        return vCode;
}

CalendarPopUp.prototype.format_day = function(vday) {
        var vNowDay = gNow.getDate();
        var vNowMonth = gNow.getMonth();
        var vNowYear = gNow.getFullYear();

//alert("In CalendarPopUp prototype.format_day Function");
//alert("vday " + vday + " this.gMonth " + this.gMonth + " this.gYear " + this.gYear);
//alert(" this.gCurrMonth " + this.gCurrMonth + " this.gCurrDay " + this.gCurrDay + " this.gCurrYear " + this.gCurrYear);
//alert(" this.gDispCode " + this.gDispCode);

        if (vday == this.gLimtDay && this.gMonth == this.gLimtMonth && this.gYear == this.gLimtYear)
              return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
        else {
          if (vday == this.gCurrDay && this.gMonth == this.gCurrMonth && this.gYear == this.gCurrYear)
                return ("<FONT COLOR=\"BLUE\"><B>" + vday + "</B></FONT>");
          else {
            if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
                  return ("<FONT COLOR=\"GREEN\"><B>" + vday + "</B></FONT>");
            else {
                 return (vday);
            }
          }
        }
}

CalendarPopUp.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 "";
}

CalendarPopUp.prototype.format_data = function(p_day) {
        var vData;
        var vMonth = 1 + this.gMonth;
        vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
        var vMon = CalendarPopUp.get_month(this.gMonth).substr(0,3).toUpperCase();
        var vFMon = CalendarPopUp.get_month(this.gMonth).toUpperCase();
        var vY4 = new String(this.gYear);
        var vY2 = new String(this.gYear.substr(2,2));
        var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

        switch (this.gFormat) {
                case "MM\/DD\/YYYY" :
                        vData = vMonth + "\/" + vDD + "\/" + vY4;
                        break;
                case "MM\/DD\/YY" :
                        vData = vMonth + "\/" + vDD + "\/" + vY2;
                        break;
                case "MM-DD-YYYY" :
                        vData = vMonth + "-" + vDD + "-" + vY4;
                        break;
                case "YYYY-MM-DD" :
                        vData = vY4 + "-" + vMonth + "-" + vDD;
                        break;
                case "MM-DD-YY" :
                        vData = vMonth + "-" + vDD + "-" + vY2;
                        break;

                case "DD\/MON\/YYYY" :
                        vData = vDD + "\/" + vMon + "\/" + vY4;
                        break;
                case "DD\/MON\/YY" :
                        vData = vDD + "\/" + vMon + "\/" + vY2;
                        break;
                case "DD-MON-YYYY" :
                        vData = vDD + "-" + vMon + "-" + vY4;
                        break;
                case "DD-MON-YY" :
                        vData = vDD + "-" + vMon + "-" + vY2;
                        break;

                case "DD\/MONTH\/YYYY" :
                        vData = vDD + "\/" + vFMon + "\/" + vY4;
                        break;
                case "DD\/MONTH\/YY" :
                        vData = vDD + "\/" + vFMon + "\/" + vY2;
                        break;
                case "DD-MONTH-YYYY" :
                        vData = vDD + "-" + vFMon + "-" + vY4;
                        break;
                case "DD-MONTH-YY" :
                        vData = vDD + "-" + vFMon + "-" + vY2;
                        break;

                case "DD\/MM\/YYYY" :
                        vData = vDD + "\/" + vMonth + "\/" + vY4;
                        break;
                case "DD\/MM\/YY" :
                        vData = vDD + "\/" + vMonth + "\/" + vY2;
                        break;
                case "DD-MM-YYYY" :
                        vData = vDD + "-" + vMonth + "-" + vY4;
                        break;
                case "DD-MM-YY" :
                        vData = vDD + "-" + vMonth + "-" + vY2;
                        break;

                default :
                        vData = vMonth + "\/" + vDD + "\/" + vY4;
        }

        return vData;
}

function Build(p_item_prefix, p_item, p_month, p_year, p_format, p_currm, p_currd, p_curry, p_limtm, p_limtd, p_limty, p_dispcd) {
        var p_WinCal = ggWinCal;
        gCal = new CalendarPopUp(p_item_prefix,p_item, p_WinCal, p_month, p_year, p_format, p_currm, p_currd, p_curry, p_limtm, p_limtd, p_limty, p_dispcd);

        // Customize your CalendarPopUp here..
        gCal.gBGColor="white";
        gCal.gLinkColor="black";
        gCal.gTextColor="black";
        gCal.gHeaderColor="darkgreen";

        // Choose appropriate show function
        if (gCal.gYearly)       gCal.showY();
        else    gCal.show();
}

function show_calendar() {
        /*
                p_item  : Return Item.
                p_month : 0-11 for Jan-Dec; 12 for All Months.
                p_year  : 4-digit year
                p_currdt: Current value of the date field
                p_limitdt: value of the date that cannot be passed
                p_dispcd: Display code (A = click any days,
                                        G = click days > currdt,
                                        GE = click days >= currdt,
                                        L = click days < currdt,
                                        LE = click days <= currdt)
                p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
        */

//        alert("arguments[0] " + arguments[0]);
//        alert("arguments[1] " + arguments[1]);
//        alert("arguments[2] " + arguments[2]);
//        alert("arguments[3] " + arguments[3]);
//        alert("arguments[4] " + arguments[4]);
//        alert("arguments[5] " + arguments[5]);
//        alert("arguments[6] " + arguments[6]);

        p_item = arguments[0];
	  p_item_prefix = arguments[7];
        if (arguments[1] == null || arguments[1] == 'X')
                p_month = new String(gNow.getMonth());
        else
                p_month = arguments[1];
        if (arguments[2] == "" || arguments[2] == "X" ||arguments[2] == null)
                p_year = new String(gNow.getFullYear().toString());
        else
                p_year = arguments[2];
        if (arguments[3] == null || arguments[3] == ""){
                p_currm = "";
                p_currd = "";
                p_curry = "";
        }
        else {
                p_currdt = arguments[3];
                var ParseDate = p_currdt.split('-');
                
                var p_currm = ParseDate[1];
      		//Bug in parseInt - LBeuchat 22-08-2002
	       if(p_currm == "08")
	       		p_currm = 7;
	       else if(p_currm == "09")
	        	p_currm = 8;
	       else
	       		p_currm = parseInt(p_currm) - 1; //subtract 1 from month
      
                var p_currd = ParseDate[2];
                var p_curry = ParseDate[0];
//     alert("p_currdt " + p_currdt);
//     alert("p_currm " + p_currm + " p_currd " + p_currd + " p_curry " + p_curry);
                if (arguments[1] == 'X') {
                     p_month = p_currm;
                }
                if (arguments[2] == 'X') {
                     p_year = p_curry;
                }
        }
        if (arguments[4] == null || arguments[4] == ""){
                p_limtm = "";
                p_limtd = "";
                p_limty = "";
        }
        else {
                p_limtdt = arguments[4];
                var ParseDate = p_limtdt.split('/');
                var p_limtm = ParseDate[0];
                    p_limtm = parseInt(p_limtm) - 1; //subtract 1 from month
                var p_limtd = ParseDate[1];
                var p_limty = ParseDate[2];
//        alert("p_limtdt " + p_limtdt);
//       alert("p_limtm " + p_limtm + " p_limtd " + p_limtd + " p_limty " + p_limty);
        }
        if (arguments[5] == null)
                p_dispcd = "A";
        else
                p_dispcd = arguments[5];
        if (arguments[6] == null)
                p_format = "MM/DD/YYYY";
        else
                p_format = arguments[6];

       if (p_limtm == '') {
                p_dispcd = "A";
         }
//        alert("p_dispcd " + p_dispcd);

       if (p_dispcd == 'G' || p_dispcd == 'GE') {
          if (p_currm == "" && p_limtm != '') {
                p_currm = p_limtm;
                p_currd = p_limtd;
                p_curry = p_limty;
          }         
         }
         
         
        vWinCal = window.open("", "CalendarPopUp",
                "width=250,height=250,status=no,resizable=no,top=200,left=200");
        vWinCal.opener = self;
        ggWinCal = vWinCal;

        Build(p_item_prefix, p_item, p_month, p_year, p_format, p_currm, p_currd, p_curry, p_limtm, p_limtd, p_limty, p_dispcd);
}
/*
Yearly CalendarPopUp Code Starts here
*/
function show_yearly_calendar(p_item_prefix, p_item, p_year, p_format) {
        // Load the defaults..
        if (p_year == null || p_year == "")
                p_year = new String(gNow.getFullYear().toString());
        if (p_format == null || p_format == "")
                p_format = "MM/DD/YYYY";

        var vWinCal = window.open("", "CalendarPopUp", "scrollbars=yes");
        vWinCal.opener = self;
        ggWinCal = vWinCal;

        Build(p_item_prefix, p_item, null, p_year, p_format);
}

// Call checkDate for the specified date. If the date 
// is not well-formed, alert the users
function alertDate(datestr)
{
	res = checkDate(datestr);
	if ( res < 0 ) {
		alert("The date " + datestr + " is not a valid date. \nFormat the date as YYYY-MM-DD HH:MI:SS \ne.g. 1998-12-09 12:30:00");
		return false;
	} else {
		return true;
	}	
}

// Call formatDate on the specified date string
// Then set the form field with the formatted date
function formatSetDate(datestr, obj, formfield)
{
	if (datestr == "")
	{
		obj.form.elements[formfield].value = "";
		return true;
	}
	if (alertDate(datestr) == false)
	{
		str = "The date " + datestr + " is not a valid date. \nFormat the date as YYYY-MM-DD HH:MI:SS \ne.g. 1998-12-09 12:30:00"
		obj.form.elements[formfield].value = str;
		return false;
	}
	else
	{
		str = formatDate(datestr);
		obj.form.elements[formfield].value = str;
		//alert("set field to:" + obj.form.elements[formfield].value);
		return true;
	}
}

// Check that the date is in a good format
// The variations of the allowed formats are
// 	yyyy-mm-dd hh:mi:ss
//	yyyy-mm-dd hh:mi
//	yyyy-mm-dd
//
// The test checks:
// 1. that the date has an allowed length
// 2. that known characters '-', ' ', and ':'
//    appear in the right places
// 3. that the date values are in valid range
// If these 3 conditions are met. we assume everything is good. 
function checkDate(datestr, dateformat)
{
	fulllen 	= 19;
	midlen 		= 16;
	shortlen 	= 10;

	// Check that the length looks ok
	len = datestr.length;
	if (len!=fulllen && len!=midlen && len!=shortlen)
		return -1;
		
	if (datestr.charAt(4) != '-' || datestr.charAt(7) != '-')
		return -1;

	yyyy = datestr.substring(0,4) - 0;
	mm = datestr.substring(5,7) - 0;
	dd = datestr.substring(8,10) - 0;
	leapyear = (yyyy%4 == 0) && (yyyy%100 != 0 || yyyy%400 == 0);
	dpm = new Array();
	dpm[1] = dpm[3] = dpm[5] = dpm[7] = dpm[8] = dpm[10] = dpm[12] = 31;
	dpm[2] = leapyear? 29 : 28;
	dpm[4] = dpm[6] = dpm[9] = dpm[11] = 30;
	if ( yyyy < 1 || mm < 1 || mm > 12 || dd < 1 || dd > dpm[mm] ) 
		return -1;	

	if (len > 10)
	{
		if (datestr.charAt(10) != ' ' || datestr.charAt(13) != ':')
			return -1;
			
		// hour (11,12) , minute(14,15)
		if ( datestr.charAt(11) > '2' || (datestr.charAt(11) == '2' && datestr.charAt(12) > '4') ||
			 datestr.charAt(14) > '5')
			return 	-1;
	}
			
	if (len > 16)
	{
		if (datestr.charAt(16) != ':')
			return -1;
			
			// second (17,18)
			if ( datestr.charAt(17) > '5')
				return 	-1;
	}	
	
	// Passed all the tests, return non-negative number for success :-)
	return 0;
}

// Format the date string so it can be used in SQL comparisons.
// For Oracle, this means wrapping the date string in the
// to_date() function 
// Return the formatted string
//
// Note formatDate assumes the date is in one of the
// accepted formats i.e. that checkdate has already run
//
function formatDate(datestr)
{
	dbtype = "Oracle";
	if (dbtype=="Oracle")
	{
		len = datestr.length;
		if (len == 10)
			dateformat = "YYYY-MM-DD";
		
		if (len == 16)
			dateformat = "YYYY-MM-DD HH24:MI";

		if (len == 19)
			dateformat = "YYYY-MM-DD HH24:MI:SS";
		outstr = "to_date('" + datestr + "', '" + dateformat + "')";
	}	
	else
		outstr = "'" + datestr + "'";
		
	return outstr;	
}

// Format the date string so it can be used in SQL comparisons.
// For Oracle, this means wrapping the date string in the
// to_date() function 
// Return the formatted string
//
// Note formatDate assumes the date is in one of the
// accepted formats i.e. that checkdate has already run
//
function padDate(datestr, obj, formfield )
{
	if (datestr == "")
	{
		obj.form.elements[formfield].value = "";
		return true;
	}
	if (alertDate(datestr) == false)
	{
		return false;
	}

	len = datestr.length;
	if (len == 10)
		obj.form.elements[formfield].value = datestr + " 00:00:00";
	
	if (len == 16)
		obj.form.elements[formfield].value = datestr + ":00";
		
	return true;
}
/* ]]> */
//-->
