
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var totalDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function winStatus(m)
{
	window.status = m;
	return;
}

function showHide(t, a)
{
	var tmp = document.getElementById(t);
	if(a != 'block' && a != 'none')
		tmp.style.display='block';
	else
		tmp.style.display=a;
	return;
}

function showHideToggle(t)
{
	document.getElementById(t).style.display = document.getElementById(t).style.display!='block' ? 'block':'none';
	return;
}

function RoundValue(n)
{
	fValue = document.forms[0][n].value;
	if(isNaN(fValue))
		document.forms[0][n].value = '';
	else
	{
		if(fValue != '')
		{
			tmpInt = parseInt(fValue / 15) * 15;
			if(fValue % 15)
				tmpInt += 15;
			document.forms[0][n].value = tmpInt;
		}
		CalMinutes();
	}
}

function openCalWin(frmName, frmTarget, calMonth, calYear)
{ 
	stats="toolbar=no";
	stats +=",location=no";
	stats +=",directories=no";
	stats +=",status=no";
	stats +=",menubar=no";
	stats +=",scrollbars=no";
	stats +=",resizable=no";
	stats +=",width=300";
	stats +=",height=250";
	
	CalWin = window.open ("","calendar", stats);
	theDate = new Date(calYear, (calMonth - 1), 1);
	if(arguments.length == 5)
		buildCal(theDate, frmName, frmTarget, 1);
	else
		buildCal(theDate, frmName, frmTarget, 0);
}

function buildCal(theDate, frmName, frmTarget, concat) 
{
	var now = new Date()
	var now_day = now.getDate();
	var now_month = now.getMonth()+1;
	var now_year = now.getYear();
	
	var startDay = theDate.getDay();
	var printDays = false;
	var currDay = 1;
	var rowsNeeded = 5;
	
	if (startDay + totalDays[theDate.getMonth()] > 35)
		rowsNeeded++;
	
	CalWin.document.write("<html>\n\t<head>\n\t\t<title>Select a Date</title>\n\t\t");
	CalWin.document.write("<style type='text/css'>\n\t\t\t");
	CalWin.document.write("a {color : black; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-decoration : none; font-size : 10 px;}\n\t\t\t");
	CalWin.document.write("a:hover {color: red;}\n\t\t");
	CalWin.document.write("</style>\n\t</head>\n\t")
	CalWin.document.write("<body><a name='this'></a>\n");
	CalWin.document.write("<table align=center height=100% width=100% border=0 cellpadding=0 cellspacing=1>\n\t")
	CalWin.document.write("<tr>\n\t\t<td bgcolor=black>\n\t\t");
	
	CalWin.document.write("<table align=center height=100% width=100% border=0 cellpadding=0 cellspacing=1>\n\t\t\t")
	CalWin.document.write("<tr>\n\t\t\t\t<th bgcolor=99CCFF colspan=7><font face=Arial color=black>" + months[theDate.getMonth()] + " " + theDate.getFullYear() + "</font></th>\n\t\t\t</tr>\n\t\t");
	CalWin.document.write('<tr bgcolor="ccffcc"><th><font face=Arial color=black>Su</font></th><th><font face=Arial color=black>Mo</font></th><th><font face=Arial color=black>Tu</font></th><th><font face=Arial color=black>We</font></th><th><font face=Arial color=black>Th</font></th><th><font face=Arial color=black>Fr</font></th><th><font face=Arial color=black>Sa</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 (now_day==currDay && now_month==theDate.getMonth()+1){
			CalWin.document.write('<td align="center" width=14.28% bgcolor="ccffcc">')
			}
			else {
			CalWin.document.write('<td align="center" width=14.28% bgcolor="eeeeee">')
			}	
			
			if (printDays)
			{
					CalWin.document.write('<a href=javascript:opener.placeDate(' + theDate.getMonth() + ',' +  currDay + ',' + theDate.getFullYear() + ',\'' + frmName + '\',\'' + frmTarget + '\',' + concat + ')>' + 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="99CCFF"><td colspan=7 align="center"><input type="Button" size="2" name="Back" value="&lt;&lt;" onClick="opener.getNewCal(-1' + ',\'' + frmName + '\',\'' + frmTarget + '\',\'' + concat + '\')" style="font-size:10pt;border: 1px solid;background=ccffcc;"><font face=Arial color=black size="1"> Use the arrows to browse through the months.</font> <input type="Button" size="2" name="Forward" value="&gt;&gt;" onClick="opener.getNewCal(1' + ',\'' +  frmName + '\',\'' + frmTarget + '\',\'' + concat + '\')" style="font-size:10pt;border: 1px solid;background=ccffcc;"></td></tr></form>')
	CalWin.document.write('</table></td></tr></table></body></html>')
	CalWin.document.close()
	
}

function getNewCal(newDir, frmName, frmTarget, concat) 
{
	if (newDir == -1){
		theDate.setMonth(theDate.getMonth() - 1)
		if (theDate.getMonth() == 0){
			theDate.setMonth(12)
			theDate.setYear(theDate.getYear() - 1)
		}
	}
	else if (newDir == 1){
		theDate.setMonth(theDate.getMonth() + 1)
		if (theDate.getMonth() == 13){
			theDate.setMonth(1)
			theDate.setYear(theDate.getYear() + 1)
		}
	}
	CalWin.document.clear();
	buildCal(theDate, frmName, frmTarget, concat);
}

function placeDate(monthNum, dayNum, yearNum, frmName, frmTarget, concat)
{
	var dateString = (monthNum + 1) + '/' + dayNum + '/' + yearNum;
	if(concat && document[frmName][frmTarget].value.length != 0)
		document[frmName][frmTarget].value += ',' + dateString;
	else
		document[frmName][frmTarget].value = dateString;
	if(!concat)
		CalWin.close();
}