/*<!---
Page Name:			/shared/pop_up_calendar.js
Author:				Patrick Kramer
Created:			1/26/2005
Purpose: 			split apart from the pop_up_calendar module.
					Before we would duplicate code to allow for multiple calendars on one page.
					We now just have the functions defined once for each calendar which lessens the amount
					of code that needs to be returned to the broswerws.
Input Parameters: 	
Output Parameters: 	

DO NOT FILL IN THE FOLLOWING COMMENTS.  THEY WILL BE FILLED IN AUTOMATICALLY
BY SOURCE CONTROL

Date of Last Check-In: $Date: $ 
Version: $Revision: $
Last Change By: $Author: $
--->

<!---Variable Declarations --->


<!--- SQL Section --->


<!--- Begin Code --->*/

function openCalWin(v_target)
{ 
	stats='toolbar=no,location=no,directories=no,status=no,menubar=no,';
	stats += 'scrollbars=no,resizable=no,width=310,height=250';
	CalWin = window.open ("","Calendar",stats);
			
	theDate = new Date(calYear, (calMonth - 1), 1);
	
	buildCal(v_target,theDate);
	
	CalWin.focus();
}

function buildCal(v_target, theDate) 
{
	var startDay = theDate.getDay();
	var printDays = false;
	var currDay = 1;
	var rowsNeeded = 5;

	if (startDay + totalDays[theDate.getMonth()] > 35)
		rowsNeeded++;

	CalWin.document.write('<html><head><Title>Select a Date</title>');
	CalWin.document.write('<STYLE TYPE="text/css">');
	CalWin.document.write('A { color: #000000; font-family:Arial,Helvetica;font-size:12pt; font-weight: bold; text-decoration: none}');
	CalWin.document.write('TD.today A { color: ' + cal_tr_color + '; font-family:Arial,Helvetica;font-size:12pt; font-weight: bold; text-decoration: none}');
	CalWin.document.write('A:hover { color: red; }');
	CalWin.document.write('</STYLE></head>');
	CalWin.document.write('<body><a name="this"></a>');
	CalWin.document.write('<table align="center" height=100% width=100% border=2 bordercolor=Black cellpadding=0 cellspacing=0>');
	CalWin.document.write('<tr><th bgcolor=' + cal_th_color + ' colspan=7><font face=Arial color=' + cal_th_font_color + '>' + months[theDate.getMonth()] + ' ' + theDate.getFullYear() + '</font></th></tr>');
	CalWin.document.write('<tr bgcolor=' + cal_tr_color + '><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_sunday + '</font></th><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_monday + '</font></th><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_tuesday + '</font></th><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_wednesday + '</font></th><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_thursday + '</font></th><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_friday + '</font></th><th><font face=Arial color=' + cal_tr_font_color + '>' + cal_saturday + '</font></th></tr>');
	for (x=1; x<=rowsNeeded; x++)
	{
		CalWin.document.write('<tr>')
		for (y=0; y<=6; y++)
		{
			if (currDay == 1 && !printDays && startDay == y)
				printDays = true;

			if (theDate.getMonth()+1 + '/' + currDay + '/' + theDate.getFullYear() == cal_today)
				CalWin.document.write('<td class="today" align="center" width=14.28% bgcolor="' + cal_th_color + '">');
			else
				CalWin.document.write('<td align="center" width=14.28%>');

			if (printDays)
			{
				CalWin.document.write('<a href="javascript:opener.placeDate(opener.' + v_target + ',' + theDate.getMonth() + ',' +  currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
				if (currDay > totalDays[theDate.getMonth()])
					printDays = false;
			}
			else
				CalWin.document.write('&nbsp;</td>');
		}		
		CalWin.document.write('</tr>');
	}	

	CalWin.document.write('<form><tr bgcolor="' + cal_tr_color + '"><td colspan=7 align="center"><nobr><input type="Button" size="2" name="Back" value="<<" onClick="opener.getNewCal(\'' + v_target + '\', -1)"><font face=Arial color=' + cal_tr_font_color + ' size="1">' + cal_display_text + '</font> <input type="Button" size="2" name="Forward" value=">>" onClick="opener.getNewCal(\'' + v_target + '\', 1)"></nobr></td></tr></form>');
	CalWin.document.write('</table></body></html>');
	CalWin.document.close();
}

function getNewCal(v_target, newDir) 
{	
	if (newDir == -1)
	{
		theDate.setMonth(theDate.getMonth() - 1);
	}
	else if (newDir == 1)
	{
		theDate.setMonth(theDate.getMonth() + 1);		
	}			

	CalWin.document.clear();
	buildCal(v_target, theDate);	
}

function placeDate(v_target, monthNum, dayNum, yearNum)
{	
	if (v_target.disabled == false)
	{			
		var dateString = '';

		if (monthNum < 9) 
		{
			var dateString = '0' ;
		}			

		var dateString = dateString + (monthNum + 1) + '/';

		if (dayNum < 10) 
		{
			var dateString = dateString + '0';
		}

		var dateString = dateString + dayNum + '/' + yearNum;

		v_target.value = dateString;
	}
	CalWin.close();
}
