<!--


var gNow = new Date();
var ggWinCal;

var weekend = [5,6];

Calendar.Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Calendar.Weekdays = ["Su", "Mo","Tu","We","Th","Fr","Sa"];

// 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 Calendar(p_WinCal, p_month, p_year, p_field, p_format) {
  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.gField = p_field;
  this.gFormat = p_format;
  if (p_field == null)
     this.gFixed = true;
  else
     this.gFixed = false;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_weekday = Calendar_get_weekday;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;

function Calendar_get_month(monthNo) {
  return Calendar.Months[monthNo];
}

function Calendar_get_weekday(dayNo) {
	return Calendar.Weekdays[dayNo];
}

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];
    else 
      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;
}

// 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 = "";
        
        // Begin Table Drawing code here..

        vCode = vCode + "    <table cellspacing=\"0\" border=\"0\" id=\"cells\">";
        
        vCode = vCode + this.cal_header();
        vCode = vCode + this.cal_data();

        vCode = vCode + "    </table>";
        
        return vCode;
}



Calendar.prototype.show = function() {
        var vCode = "";
        
        this.gWinCal.document.open();

        // Setup the page...
        this.writeln("<html>");
        this.writeln("<style type=\"text/css\">");
        this.writeln("  body { color: black; background: purple; }");
        this.writeln("  table { width: 100%; }");
        this.writeln("  table tr td { color:black; background: white; font-family: Verdana,Arial,Helvetica,sans-serif }");
        this.writeln("  tr#banner td, tr#banner a { color: white; background: blue; font-size: 12px; font-weight: bold; text-decoration: none; text-align: center; }");
        this.writeln("  tr#banner a:hover { color: black; background: yellow; }");
        this.writeln("  table#cells th {   border-bottom: 1px solid silver; font-size: 11px; text-align: center; }");
        this.writeln("  table#cells th.weekend { color: red; }");
        this.writeln("  table#cells td { padding: 3px 2px; font-size: 11px; text-align: right; }");
        this.writeln("  table#cells a {  color: black; padding: 2px; text-decoration: none }");
        this.writeln("  table#cells td#today a { background-color: lightblue; font-weight: bold; }");
        this.writeln("  table#cells a:hover { background-color: silver;   }");
        this.writeln("  tr#footer td { color: silver; padding: 3px; font-size: 10px; text-align: right; }");
        this.writeln("</style>");
        this.writeln("</head>");
        this.writeln("<body>");

        // 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.writeln("<table border=\"0\" cellspacing=\"0\">");
        var myMonth = gNow.getMonth();
        myMonth++;
        if (myMonth < 10)
                myMonth = "0" + myMonth;
        var myYear = gNow.getFullYear();
        var myCheck = myYear + "" + myMonth;
        var tmpMonth = this.gMonth;
        tmpMonth++;
        if (tmpMonth < 10)
                tmpMonth = "0" + tmpMonth;
        var myTmp = this.gYear + "" + tmpMonth;
     
        // show_calender
        this.write("  <tr id=\"banner\">");
        if (this.gFixed == false && ((myTmp != myCheck) || (typeof myBack != 'undefined'))) {
                this.write("<td><a href=\"javascript:window.opener.Build(" + 
                "'" + prevMM + "', '" + prevYYYY + "', " + 
                "'" + this.gField + "', '" + this.gFormat + "'" + 
                ");" +
                "\">&nbsp;-</a></td>");
        } else {
                this.write("<td>&nbsp;</td>");
        }

        this.write("<td>" + this.gMonthName + " " + this.gYear + "</td>");

        if (this.gFixed == false) 
        {
        this.write("<td><a href=\"javascript:window.opener.Build(" + 
                "'" + nextMM + "', '" + nextYYYY + "', " + 
                "'" + this.gField + "', '" + this.gFormat + "'" + 
                ");" +
                "\">+</a></td>");
        }
        else
                this.write("<td>&nbsp;</td>");

        this.writeln("</tr>");
        this.writeln("  <tr><td colspan=\"3\">");

        // Get the complete calendar code for the month..
        this.writeln(this.getMonthlyCalendarCode());

        this.writeln("  </td></tr>");
        this.writeln("  <tr id=\"footer\"><td colspan=\"3\">www.skinnyski.com</td></tr>");
        this.writeln("</table>");
        this.writeln("</body></html>");

        this.gWinCal.document.close();
}

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

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


Calendar.prototype.cal_header = function() {
        var vCode = "";
        
        vCode = vCode + "<tr>";
        vCode = vCode + "<th class=\"weekend\">" + Calendar.get_weekday(0) + "</td>";
        vCode = vCode + "<th>" + Calendar.get_weekday(1) + "</td>";
        vCode = vCode + "<th>" + Calendar.get_weekday(2) + "</td>";
        vCode = vCode + "<th>" + Calendar.get_weekday(3) + "</td>";
        vCode = vCode + "<th>" + Calendar.get_weekday(4) + "</td>";
        vCode = vCode + "<th>" + Calendar.get_weekday(5) + "</td>";
        vCode = vCode + "<th class=\"weekend\">" + Calendar.get_weekday(6) + "</td>";
        vCode = vCode + "</tr>";

        return vCode;
}

Calendar.prototype.cal_data = function() {

  pFieldName = "testForm.testDate1";

        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>";

        for (i=0; i<vFirstDay; i++) {
          vCode = vCode + "<td>&nbsp;</td>";
        }

        // Write rest of the 1st week
        for (j=vFirstDay; j<7; j++) {
                vCode = vCode + "<td "+ this.format_day(vDay) + ">"; 
                if (this.gFixed == false)
                  vCode = vCode + "<a href=\"javascript:self.opener.document." + this.gField +".value='" + this.format_data(vDay) + "';self.window.close();\">"; 
                else
                  vCode = vCode + "<a href=\"#\">";
                vCode = vCode + vDay + "</a></td>";
                vDay=vDay + 1;
        }

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

                for (j=0; j<7; j++) {
                   vCode = vCode + "<td " + this.format_day(vDay) + ">";
                   if (this.gFixed == false)
                     vCode = vCode + "<a href=\"javascript:self.opener.document." + this.gField +".value='" + this.format_data(vDay) + "';self.window.close();\">"; 
                   else
                     vCode = vCode + "<a href=\"#\">" ;
                   vCode = vCode + vDay + "</a></td>";
                   vDay=vDay + 1;


                   if (vDay > vLastDay) {
                     vOnLastDay = 1;
                     for (x=j; x<6; x++) {
                       vCode = vCode + "<td>&nbsp;</td>";
                     }
                     break;
                   }
                }

                if (vOnLastDay == 1)
                  break;
        }
        
        return vCode;
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.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 "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;
		case "YYYY-MM-DD" :
			vData = vY4 + "-" + vMonth + "-" + vDD;
			break;
		case "MON DD YYYY" :
			vData = vMon + " " + vDD + " " + vY4;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

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

	return vData;
}


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 ("id=\"today\"");
        return ("");
}


function Build(p_month, p_year, p_field, p_format) {
        var p_WinCal = ggWinCal;

        gCal = new Calendar(p_WinCal, p_month, p_year, p_field, p_format);

        gCal.show();
}

function show_calendar() {
        /* 
		args: initial-date, form-field, format
		- initial date must be yyyy-mm-dd format, or null
                   - if empty/null, use the current date
                - if form-field is null, fixed is true
                - default format is "yyyy-mm-dd"
        */


        // read arguments from search form, and get value from the from-field.

        // initial date
        if (arguments[0] != null) 
        {
          initdate = (arguments[0].split("-"));
          // initial date is yyyy-mm-dd format
          if (initdate.length == 3)
          {
            if (initdate[0] == null)
              p_year = new String(gNow.getFullYear().toString());
            else
              p_year = initdate[0];
            if (initdate[1] == null)
              p_month = new String(gNow.getMonth());
            else
              p_month = --initdate[1];
          }
          else 
          {
              p_month = new String(gNow.getMonth());
              p_year = new String(gNow.getFullYear().toString());
          }
        } 
        else
        {
           p_month = new String(gNow.getMonth());
           p_year = new String(gNow.getFullYear().toString());
        }

        p_field = null;
        if (arguments[1] != null) p_field = arguments[1];
        p_format = "";
        if (arguments[2] != null) p_format = arguments[2];

        myBack=true;

        var vWinCal = window.open("", "Calendar", "width=205,height=200,scrollbars=no,resizable=yes,status=no");
        if (vWinCal.opener == null) vWinCal.opener = self;
        ggWinCal = vWinCal;

        Build(p_month, p_year, p_field, p_format);
}




//-->


