/** ******************************************************************
* JavaScript per il calendario
*
* Elenco delle funzioni:
* - ct_calendar_go2date		va alla data
* - ct_calendar_go2month	va al mese
* - ct_calendar_choose		sceglie il giorno
* - ct_calendar_date		restituisce la data formattata
*
* @package	ct.base
* @author	ConsulTes info@consultes.it
* ***************************************************************** */

	/** ******************************************************************
	* Va alla data
	* @param	NULL
	* @return	NULL
	* ***************************************************************** */
	function ct_calendar_go2date() {
		$date  = ct_calendar_date(1);
		$field = ct_get_query('id_picker_to');
		document.location = '?id_picker_to='+$field+'&date='+$date;
	}

	/** ******************************************************************
	* Va al mese
	* @param	int		$p_direction	direzione
	* @return	NULL
	* ***************************************************************** */
	function ct_calendar_go2month($p_direction) {
		$month = document.calendar.month.selectedIndex + $p_direction;
		document.calendar.month.selectedIndex = $month;
		document.calendar.month.onchange();
	}

	/** ******************************************************************
	* Sceglie il giorno
	* @param	int		$p_day	giorno
	* @return	NULL
	* ***************************************************************** */
	function ct_calendar_choose($p_day) {
		$date  = ct_calendar_date($p_day);
		$field = ct_get_query('id_picker_to');
		opener.document.getElementById($field).value = $date;
		ct_win_close();
		opener.document.getElementById($field).onchange();
	}

	/** ******************************************************************
	* Restituisce la data formattata
	* @param	int		$p_day	giorno
	* @return	string	data formattata
	* ***************************************************************** */
	function ct_calendar_date($p_day) {
		$year  = document.calendar.year.value;
		$month = document.calendar.month.selectedIndex+1; if ($month<10) $month = '0'+$month;
		$day   = $p_day; if ($day<10) $day = '0'+$day;
		$date  = $day+'/'+$month+'/'+$year;
		return $date;
	}

