var vxr_popup = null;
var vxr_calendar = null;
var vxr_force_off_property = null;

function future_dates(date, year, month, day)
{
	return (date < new Date());
}

function get_calendar()
{
	if( vxr_calendar == null )
	{
		vxr_calendar = new Calendar(null, null, function onSelect(cal) { });
		vxr_calendar.setRange(2005, 2025);
		//vxr_calendar.setDateStatusHandler(future_dates)
	}
	
	return vxr_calendar;
}

function force_off_popup(property)
{
	o = $('force_off_' + property);
	
	if( vxr_popup == o )
	{
		force_off_popup_hide();
		return;
	}

	force_off_popup_hide();
	
	o.innerHTML = '<p>Force off <a href="/properties/force_off/' + property + '">indefinitely</a>, or</p><p>Force off until: <div id="calendar-control"></div></p><p>[<a href="javascript:force_off_popup_hide()">Cancel</a>] [<a href="javascript:force_off_date()">OK</a>]</p>';
	
	cal = get_calendar();
	cal.create(document.getElementById('calendar-control'));
	cal.show();
	
	Element.show(o);
	o.scrollIntoView(false);
	vxr_popup = o;
	vxr_force_off_property = property;
}

function force_off_popup_hide()
{
	if( vxr_popup != null )
	{
		Element.hide(vxr_popup);
		vxr_popup.innerHTML = '';
		vxr_popup = null;
		vxr_force_off_property = null;
	}
}

function force_off_date()
{
	window.location = '/properties/force_off_until/' + vxr_force_off_property + '?year=' + vxr_calendar.date.getFullYear() + '&month=' + (vxr_calendar.date.getMonth() + 1) + '&day=' + vxr_calendar.date.getDate();
	//window.alert('Starting...');
	//new Ajax.Updater({success:'mode_' + vxr_force_off_property}, '/properties/force_off_date/' + vxr_force_off_property + '?year=' + vxr_calendar.date.getFullYear() + '&day=' + (vxr_calendar.date.getMonth() + 1) + '&month=' + vxr_calendar.date.getDate(), {asynchronous:true, evalScripts:true});
	//window.alert('Started.');
	//new Ajax.Request('/properties/force_off_date/302?year=2005&amp;day=12&amp;month=12', {asynchronous:true, evalScripts:true, onSuccess:function(request){force_off_update(302)}}); return false;
	force_off_popup_hide();
}
