// <!--
var scope = 0;
var state = {scope:0,id:-1};
var today;
function doHighlight(obj)
{
	obj.style.border = '1px solid #999999';
}
function doSelect(obj)
{
	var refresh = 1;
	if ( arguments.length == 2 ) refresh = arguments[1];
	if ( state.id != -1 ) {
		if ( state.scope == 0 ) doClearDay();
		else if ( state.scope == 1 ) doClearWeek();
		else if ( state.scope == 2 ) doClearMonth();		
	}
	document.forms.state.scope.value = state.scope = scope;
	document.forms.state.id.value = state.id = obj.id;
	
	if ( scope == 0 ) doSelectDay();
	else if ( scope == 1 ) doSelectWeek();
	else if ( scope == 2 ) doSelectMonth();
	
	// set the hidden form value
	var d = state.id.split('_');
	// get 1, 2, and 4
	if ( d[2] < 10 ) d[2] = '0'+d[2];
	if ( d[4] < 10 ) d[4] = '0'+d[4];
	window.parent.setDate("" + d[1] + d[2] + d[4], refresh);	
}
function doSelectDay()
{
	var obj;
	if ( arguments.length == 0 ) obj = document.getElementById(state.id);
	else obj = document.getElementById(arguments[0]);
	if ( obj.id.substr(obj.id.lastIndexOf('_')+1,1)=='z' ) obj.style.color = '#CCCCCC';
	else obj.style.color = '#FFFFFF';
	if ( obj.id != today )
	//	obj.style.borderColor = obj.style.backgroundColor = '#C0C0C0';	
	//else 
		obj.style.borderColor = obj.style.backgroundColor = '#AFAFAF';	
}
function doSelectWeek()
{
	var week, all = 1;
	if ( arguments.length == 0 ) week = state.id.substr(0,state.id.lastIndexOf('_'));
	else week = arguments[0];
	if ( arguments.length > 1 ) all = arguments[1];
	var obj = document.getElementById(week);
	var days = obj.childNodes;
	for ( var i = 0; i < days.length; i++ ) {
		if ( days[i].id != '' ) {
			if ( all || days[i].id.indexOf('z') < 0 ) doSelectDay(days[i].id);
		}		
	}	
}
function doSelectMonth()
{
	var week = state.id.substr(0,state.id.lastIndexOf('_'));
	var mon = week.substr(0,week.lastIndexOf('_'));
	var obj = document.getElementById(mon);
	var weeks = obj.childNodes[0].childNodes;
	var msg = "";
	for ( var i = 0; i < weeks.length; i++ )
		if ( weeks[i].id != '' ) doSelectWeek(weeks[i].id,0);
}
function doClearDay()
{
	var obj;
	if ( arguments.length == 0 ) obj = document.getElementById(state.id);
	else obj = document.getElementById(arguments[0]);
	if ( obj.id.substr(obj.id.lastIndexOf('_')+1,1)=='z' ) obj.style.color = '#AAAAAA';
	else obj.style.color = '#000000';
	if ( obj.id != today )
	//	obj.className = "today";
	//	obj.style.borderColor = obj.style.backgroundColor = '#CFCFCF';	
	//else
	//	obj.className = "day";
		obj.style.borderColor = obj.style.backgroundColor = '#FFFFFF';
}
function doClearWeek()
{
	var week, all = 1;
	if ( arguments.length == 0 ) week = state.id.substr(0,state.id.lastIndexOf('_'));
	else week = arguments[0];
	if ( arguments.length > 1 ) all = arguments[1];
	var obj = document.getElementById(week);
	var days = obj.childNodes;
	for ( var i = 0; i < days.length; i++ ) {
		if ( days[i].id != '' ) {
			if ( all || days[i].id.indexOf('z') < 0 ) doClearDay(days[i].id);
		}		
	}
}
function doClearMonth()
{
	var week = state.id.substr(0,state.id.lastIndexOf('_'));
	var mon = week.substr(0,week.lastIndexOf('_'));
	var obj = document.getElementById(mon);
	var weeks = obj.childNodes[0].childNodes;
	for ( var i = 0; i < weeks.length; i++ )
		if ( weeks[i].id != '' ) doClearWeek(weeks[i].id);
}
function doPrevious()
{
	var val = document.forms.state.month.value;
	document.forms.state.month.value = parseInt(val)-1;
	document.forms.state.submit();
}
function doNext()
{
	var val = document.forms.state.month.value;
	document.forms.state.month.value = parseInt(val)+1;
	document.forms.state.submit();	
}
function doScope(val)
{
	scope = val;
	var refresh = 1;
	if ( arguments.length == 2 ) refresh = arguments[1];
	// update the UI
	if ( document.getElementById(state.id) ) doSelect(document.getElementById(state.id),refresh);
}
// -->