/*********************************************************************************************************************

                              Date picker written by Mark Wilton-Jones 5-8/10/2002

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

This was heavily modified by Pickatime.

*/

var monthList = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var curDate = new Date(2007,0,1);
curDate.getTheYear = curDate.getFullYear ? curDate.getFullYear : curDate.getYear;
//Opera 7, Opera 6 Mac/Linux, Konqueror and Safari's security means that you cannot write to about:blank as it is counted as a different domain
//Escape does not recognise about:blank (it uses its own, but it occasionally makes the popup go blank) but it does understand ''
var opOrEscape = window.opera || ( document.layers && !navigator.mimeTypes['*'] ) || navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ) || ( window.ScriptEngine && ScriptEngine() == 'JScript' && navigator.platform == 'Win32' && window.ActiveXObject && !navigator.__ice_version );

function MWJ_dropYear() { curDate.setYear( curDate.getTheYear() - 1 ); doReDraw(); }
function MWJ_raiseYear() { curDate.setYear( curDate.getTheYear() + 1 ); doReDraw(); }
function MWJ_dropMonth() { if( curDate.getMonth() ) { curDate.setMonth( curDate.getMonth() - 1 ); } else { curDate.setMonth(11); curDate.setYear( curDate.getTheYear() - 1 ); } doReDraw(); }
function MWJ_raiseMonth() { if( curDate.getMonth() < 11 ) { curDate.setMonth( curDate.getMonth() + 1 ); } else { curDate.setMonth(0); curDate.setYear( curDate.getTheYear() + 1 ); } doReDraw(); }
function resetDate() { curDate.setTime((new Date()).getTime()); }
var CalDivElement;
var DateArr=new Array();

function setDateArr(ind,d) {
	DateArr[ind] = d;
}
function hideShowCal() {
	if (CalDivElement == null) return;
	if (CalDivElement.style.display == "none")
		CalDivElement.style.display = "";
	else CalDivElement.style.display = "none";
}

function getYearRow() {
	var lst = DateArr.length-1;
	var ret = '<tr><td colspan=7 bgcolor="#cccccc"><center> ';
	if (DateArr[0].getFullYear() < curDate.getFullYear()) {
		ret += '<a href="javascript:MWJ_dropYear()">&lt;&lt;</a>';
	}
	ret += ' <b>'+curDate.getTheYear()+'</b> ';
	if (DateArr[lst].getFullYear() > curDate.getFullYear()) {
		ret += '<a href="javascript:MWJ_raiseYear();">&gt;&gt;</a>';
	}
	return ret+'</center></td></tr>';
}
function getMonthRow() {
	var lst = DateArr.length-1;
	var ret = '<tr><td colspan=7 bgcolor="#cccccc"><center> ';
	if (DateArr[0].getFullYear() < curDate.getFullYear() || DateArr[0].getMonth() < curDate.getMonth()) {
		ret += '<a href="javascript:MWJ_dropMonth()">&lt;&lt;</a>';
	}
	ret += ' <b>'+monthList[curDate.getMonth()]+'</b> ';
	if (DateArr[lst].getFullYear() > curDate.getFullYear() || DateArr[lst].getMonth() > curDate.getMonth()) {
		ret += '<a href="javascript:MWJ_raiseMonth();">&gt;&gt;</a>';
	}
	return ret+'</center></td></tr>';
}
function setCalDivElement(dest) {
	CalDivElement = document.getElementById(dest);
	curDate.setFullYear(DateArr[0].getFullYear());
	curDate.setMonth(DateArr[0].getMonth());
	doReDraw();
}
function doReDraw() {
	var theContent = 
		'<table border="1" cellpadding="2" cellspacing="1" width="233">'+
		getYearRow()+
		getMonthRow()+
		'<tr><th bgcolor="#cccccc">Sun</th><th bgcolor="#cccccc">Mon</th><th bgcolor="#cccccc">Tue</th><th bgcolor="#cccccc">Wed</th>'+
		'<th bgcolor="#cccccc">Thu</th><th bgcolor="#cccccc">Fri</th><th bgcolor="#cccccc">Sat</th></tr>'
	;
	var y=0;
	for( var x = 1; x <= [31,((!( curDate.getTheYear() % 4 ) && ( ( curDate.getTheYear() % 100 ) || !( curDate.getTheYear() % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][curDate.getMonth()]; x++ ) {
		curDate.setDate(x);
		while (y < DateArr.length && curDate.getTime() > DateArr[y].getTime())
			y++;
		if( x == 1 && curDate.getDay() ) { theContent += '<tr><td colspan="'+curDate.getDay()+'"></td>'; }
		theContent += ( ( !curDate.getDay() ) ? '<tr>' : '' ) + '<td align="center" bgcolor="#'+
			((curDate.getMonth()==(new Date()).getMonth()&&curDate.getYear()==(new Date()).getYear()&&x==(new Date()).getDate())?'ffbbdd':((!curDate.getDay()||curDate.getDay()==6)?'ffffbb':'ffffff'))+'">';
		if (y < DateArr.length && curDate.getTime() == DateArr[y].getTime())
			theContent += '<a href="?date='+(curDate.getMonth()+1)+'/'+x+'/'+curDate.getTheYear()+'">'+x+'</a>';
		else
			theContent += x;
		theContent += '</td>';
	}
	curDate.setDate(1);
	theContent += '</table>';
	if (CalDivElement != null)
		CalDivElement.innerHTML = theContent;
}
