//<script>
/*
 Matthew Payne 04/1/2001
 
 Functionality presents an interactive calendar for a use to pick a date from.
 The current supported date format is 'mm/dd/yyyy'. Originally, the calendar was drawn in 
 a popup window(some of that code is left commented out.  I decided to create a calendar drop-down with similiar functionality to the 
 date picker used by expedia.com ie the calendar automatically is positioned below the object it is called from.
 
 To utilize this functionality for a text box, a call would look something like ->
 <INPUT id=cmdDisplayCalEnd  onclick="javascript:buildCal(frmDateSelect.txtEndDate);" name=cmdDisplayCalEnd type=button style="HEIGHT: 22px; WIDTH: 19px" value=...>
 
*/
function buildCal()
{
	var calDate = new Date();
	calDateField = arguments[0];
    //alert(window.event.srcElement.id); 
    calDateField.style.position = "relative";
	
	/* This section is IE 5+ specific.  
	   In order to run this in lower browsers, a span tag called 
	   "spCal" needs to be defined in the HTML document.  
	 
	 */  
	CalFrame = document.getElementById("spCal");
	if (CalFrame== undefined)
	 {
		
	    CalFrame =document.createElement("<iframe id='spCal' STYLE='display:none; border:ridge;position:absolute;width:200;height:150;z-index=100' MARGINHEIGHT='0' MARGINWIDTH='0' NORESIZE FRAMEBORDER='0' width:156 SCROLLING='NO'></iframe>"); 
    	//CalFrame =document.createElement("<span id='spCal' ></span>"); 
    	
    	document.body.insertBefore(CalFrame);
	 }
	else
	 {
		CalFrame = document.all.spCal;
    
	 }
	
    CalFrame.style.position = "absolute";
    CalFrame.style.left = calDateField.offsetLeft;
  
    
	
	var eT = calDateField.offsetTop; //window.event.srcElement.offsetTop;	var eH = calDateField.offsetHeight;//window.event.srcElement.offsetHeight;	var dH = CalFrame.style.pixelHeight;	var sT = document.body.scrollTop;	
	CalFrame.style.top = eT+eH;	
    if (calDateField.value == "")
		calDate = new Date();
	else
		calDate = new Date(calDateField.value);
	
	
	if (CalFrame.style.display == "block")
	{
		CalFrame.style.display = "none";
		return;
	}
	// First call to the calendar gets set to the current date
	//drawCal('02/15/2001');
  	drawCal((calDate.getUTCMonth() + 1) + '/' +  calDate.getDay() + '/' + calDate.getFullYear());
	//CalFrame.style.display = "inline";
	CalFrame.style.display = "none";
	CalFrame.style.display = "block";

}

function drawCal (sDate)
{
	var sHTML = new String();
	var lTargetYear;
	var lTargetMonth;
	var lTargetDay;
	
	var sSplitDate;
	
	var objPop;
	// ex: "02/15/2001" will get split into an array.  the '/' is the separator
	sSplitDate = sDate.split('/');
	
	lTargetYear = sSplitDate[2];
	lTargetDay = sSplitDate[1];
	lTargetMonth = sSplitDate[0] -1;
	
	//objPop= window.open('','Note','toobar=no,location=no, directories=no,status=yes,scrollbars=yes,resizable=yes, copyhistory=no,width=300,height=200')
          
 	//setup styles to define the look of the calendar
	sHTML += '<style>';
	sHTML += '.calHeading {background-color : Silver; border-top-style: outset; font: 8px Verdana;}'
	sHTML += '.calRegularDay {background-color : #FFEFD5;}';
	sHTML += 'A.calRegularDay.HOVER {background-color : #E6E6FA;}';
	sHTML += '.calReg, TD.calReg:ACTIVE, TD.calReg:FOCUS, TD.calReg:HOVER, TD.calReg:VISITED {';
	sHTML += 'background-color : #E6E6FA; cursor: hand; 	display : block;}';
	sHTML += 'TD.calReg:VISITED {	background-color : Blue;} </style>';
 //start grid	
	sHTML += '<table cellspacing=0 border=0 cellpadding=0>';
	sHTML += '<tr class="calHeading">';
	sHTML +=  '<td width=1><img src="dot.gif" width=1 height=1></td>';
	sHTML +=   '<td width=200><img src="dot.gif" width=200 height=1></td>';
	sHTML +=   '<td width=1><img src="dot.gif" width=1 height=1></td></tr>';
	sHTML +=  '<tr class="heading"><td width=1><img src="dot.gif" width=1 height="100%"></td>';
	sHTML +=  '<td width=200>';
    //document.write (sHTML);
    sHTML += DrawCalendarMonth(lTargetYear, lTargetMonth, lTargetDay);
    //DrawOtherDay(Date.getDay());
    // document.write (sHTML);
	sHTML +=  '</tr></table></td><td width=1><img src="dot.gif" width=1 height="100%"></td>';
	sHTML +=  '</tr>'; // & chr(13))
    sHTML +=  '<tr>';
    sHTML +=  '<td width=1><img src="dot.gif" width=1 height=1></td>'; //" & chr(13))
    sHTML +=  '<td width=200><img src="dot.gif" width=200 height=1></td>'; //" & chr(13))
    sHTML +=  '<td width=1><img src="dot.gif" width=1 height=1></td>'; //" & chr(13))
    sHTML +=  '</tr>' // & chr(13))
    sHTML +=  '</table>'; //" & chr(13))
    
    //spCal.innerHTML = sHTML;

   self.spCal.document.open();
   self.spCal.document.write(sHTML);
     self.spCal.document.close();
   
   //document.write (sHTML);
 
 //    objPop.document.write(sHTML)
 //    objPop.document.close()
     //self.aNoteWin = aPopUp

}

function DrawCalendarMonth(lYear, lMonth, lDay)
{
   var sCal = new String();
   var dcurrDate= new Date(lYear, lMonth, lDay);
   
	monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June',
                               'July', 'August', 'September', 'October', 'November', 'December');
    weekdayList  = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    weekdayArray = new Array('Su','Mo','Tu','We','Th','Fr','Sa');
    var lDaysInMonth = GetDaysInMonth(dcurrDate.getMonth()+1, dcurrDate.getYear());
    var thisMonthFirstDay = new Date(dcurrDate.getYear(), dcurrDate.getMonth(), 1);
   
    var sNextYear = (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear() +1);
    var sPrevYear = (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear() -1);    
    var sNextMonth = (thisMonthFirstDay.getUTCMonth()+ 2) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear());
    var sPrevMonth = (thisMonthFirstDay.getUTCMonth()+ 0) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear());
    
    //lDaysInMonth = GetDaysInMonth(dcurrDate.getMonth()+1, dcurrDate.getYear());
     
    // 'Set the Date variables
 
  
   sCal = '<table width=200 bordercolor="white" border=1 style="border-collapse:collapse">' + '<tr class="heading" bgcolor="beige">';
   sCal += '<td style="cursor:hand;" onmouseover="this.style.backgroundColor=\'white\';" onmouseout="this.style.backgroundColor=\'\';" onclick="javascript:parent.drawCal(\'' + sPrevYear +'\');" align=center><font face=verdana, arial size=2>&lt;&lt;</font></td>';
   sCal += '<td style="cursor:hand;" onmouseover="this.style.backgroundColor=\'white\';" onmouseout="this.style.backgroundColor=\'\';" onclick="parent.drawCal(\'' + sPrevMonth +'\');" align=center><font face="verdana, arial" size=2>&lt;</font></td>';
   sCal += '<td colspan=3 align=center><font face="verdana, arial" size=1>' + monthArray[dcurrDate.getMonth()] + ' ' + dcurrDate.getFullYear() + '</font></td>';
   //self.onerror = alert('Error in draw occured');
   sCal += '<td style="cursor:hand;" onmouseover="this.style.backgroundColor=\'white\';" onmouseout="this.style.backgroundColor=\'\';" onclick="parent.drawCal(\'' + sNextMonth +'\');" align=center><font face="verdana, arial" size=2>&gt;</font></td>';
   sCal += '<td style="cursor:hand;" onmouseover="this.style.backgroundColor=\'white\';" onmouseout="this.style.backgroundColor=\'\';" onclick="parent.drawCal(\'' + sNextYear +'\');" align=center><font face="verdana, arial" size=2>&gt;&gt;</font></td>';
   sCal += '</tr>';
   //document.write(sCal);
 weekdays = '<tr bgcolor="#aaaaaa">';
 // LOOP THROUGH WEEKDAY ARRAY
		for (i in weekdayArray) {
	
			weekdays += '<td align=center><font face="verdana, arial" size=1>' + weekdayArray[i] +'</font></td>';
		}
		weekdays += '</TR><TR>';
 
  sCal += weekdays;
   
  //document.write ('The start day for this month is' + thisMonthFirstDay.getDay() +'<TR>');
  
   
  for (i=0; i < thisMonthFirstDay.getDay(); i++)  
	{
		sCal += DrawOtherDay(thisMonthFirstDay.getDay() - i, dcurrDate);
	}
  
  for (i=1; i < lDaysInMonth+1; i++)  
	{
		dcurrDate.setDate(i);
		sCal += DrawNormalDay(i, dcurrDate);
		
		if (dcurrDate.getDay() ==6) 
		//start a new week if we are at the end
			{ 
				sCal +='</tr><tr>';      
    	    }
	
	}
  
 return sCal;

}

function DrawOtherDay(lDayOffset, dDate)
{
 var DayNumber;
 var dWorkingDate = new Date(dDate.getYear(), dDate.getMonth(), (- lDayOffset) + 1) 
 var sTemp = new String(); 
 
 DayNumber = dWorkingDate.getDate();
 
 //' Draws a day cell - date is in previous or next month
 //' The response.write's are separate lines for clarity only
 sTemp = '<td bgcolor="#eeeeee" align=center>';
 sTemp += '<font face="verdana, arial" size=2 color="darkgray">';
 sTemp += DayNumber + '</font></td>';
 return sTemp;
}

function DrawNormalDay(DayNumber, dDate)
{
 //' Draws a day cell - date is in current month
 //' The response.write's are separate lines for clarity only
  var sDayDate = new String();
  var sTemp = new String(); 
   
  sDayDate = (dDate.getMonth() + 1) + '/' + DayNumber + '/' + dDate.getFullYear();
  sTemp += '<td class="calReg" ';
  //sTemp += 'onclick="calDateField.value=(\'' + sDayDate + '\'); HideCal();"';
  sTemp += 'onclick="javascript:parent.calDateField.value=(\'' + sDayDate + '\'); parent.HideCal();"';
  
  
  //sTemp += 'onmouseover="this.style.backgroundColor=\'white\';"';
  //sTemp += 'onmouseout="this.style.backgroundColor=\'#cccccc\';" ';
  sTemp += ' align=center>';
  sTemp += '<font face="verdana, arial" size=2><a href="#" onclick="void(\'' + sDayDate + '\');">' + DayNumber + '</a>';
  sTemp +='</font></td>';
  return sTemp;
}

function HideCal()
{
	CalFrame.style.display = "none"
}

function GetNextMonth(dCurrentDate) {

	var lbmonth;
	var lbyear;
	
	    // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
        if (dCurrentDate.getMonth == 11) {
            dCurrentDate.setMonth(0);
            dCurrentDate.setYear(dCurrentDate.getYear() + 1);
            //dCurrentDate.setFullYear(glbyear);
        }
        else {
            dCurrentDate.setMonth(dCurrentDate.getMonth() + 1);
        }
        //dCurrentDate.setMonth(glbmonth);
        return dCurrentDate;
}


function GetDaysInMonth(iMonth, iYear) 
{
	//Returns the number of days in a month
	/*
		In: iMonth: Number of the Month -not zero based ie 3=March
		    iYear: four digit year
	*/
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}
//<body onload='drawCal("01/15/2001");'>

//-->



