//<?php
/**
*	Vygeneruje tabulku s kalendářem
*
*	@package    JavaScript
*	@author     Josef Doležal <josef.dolezal@abeo.cz>
*	@author     Jan Mazánek <jan.mazanek@abeo.cz>
*	@copyright  1997-2005 Abeo s.r.o.
*	@since      20050222, version 1.22.123
*	@todo       20050313, jamaz;To:Dolo: ošetření chybových stavů
*	@internal   charset: UTF-8
*	@version    SVN: $Id: calendar.js 7330 2007-08-11 19:25:57Z jan-mazanek $
*/

/**
*/

var calendar_now = new Date();			//	Dnešní datum
var calendar_show_date = new Date();	//	Datum, které má být zobrazeno (vybrané datum)
var calendar_year_min=2005;				//	Minimální dostupný rok
var calendar_year_max=2020;				//	Maximální dostupný rok

//	Definice stylu neaktivních datumů
var	onmouseout_backgroundColor='#eee';
var	onmouseout_color='#000';
var	onmouseout_fontWeight ='normal';
var	onmouseout_border='1px outset';
//	Definice stylu onmouseover datumu
var	onmouseover_backgroundColor='#f00';
//	Definice stylu aktivního datumu
var	now_backgroundColor='#eee';
var	now_color='#00f';
var	now_fontWeight ='bold';
var	now_border='1px inset';

var calendar_output='';					//	HTML element, do jehož .value je zapisován datum vybraný v kalendáři
										//	Nastavit vždy před zobrazením kalendáře

function calendar_write()
{	//	Vygeneruje HTML kód s kalendářem
	var month_array = new Array('Leden','Únor','Březen','Duben','Květen','Červen','Červenec','Srpen','Září','Říjen','Listopad','Prosinec');
	document.write('<form name="form_calendar" id="form_calendar">\r\n');
	document.write('<table>\r\n');
	document.write('<tr>\r\n');
	document.write('	<td><select name="calendar_month" id="calendar_month" onchange="change_month(this.options.selectedIndex);">\r\n');
	for(i=0;i<month_array.length;i++) {
		if(calendar_now.getMonth()!=i) {
			document.write('		<option value="'+i+'">'+month_array[i]+'</option>\r\n');
		}else{
			document.write('		<option value="'+i+'" selected="selected">'+month_array[i]+'</option>\r\n');
		}
	}
	document.write('	</select></td>\r\n');
	document.write('	<td><select name="calendar_year" id="calendar_year" onchange="change_year(this.options[this.options.selectedIndex]);">\r\n');
	for(i=calendar_year_min;i<=calendar_year_max;i++) {
		if(calendar_now.getFullYear()!=i) {
			document.write('		<option value="'+i+'">'+i+'</option>\r\n');
		}else{
			document.write('		<option value="'+i+'" selected="selected">'+i+'</option>\r\n');
		}
	}
	document.write('	</select></td>\r\n');
	document.write('	<td><input type="button" value="X" title="Zavřít kalendář" onclick="calendar_hide();"></td>\r\n');
	document.write('</tr><tr>\r\n');
	document.write('	<td colspan="3"><table cellspacing="0" width="100%">\r\n');
	document.write('		<tr>\r\n');
	document.write('			<td>Po</td><td>Út</td><td>St</td><td>Čt</td><td>Pá</td><td>So</td><td>Ne</td>\r\n');
	document.write('		</tr><tr>\r\n');
	for(j=0;j<6;j++) {
		for(i=0;i<7;i++) {
			document.write('			<td id="d'+i+'r'+j+'" onclick="calendar_output_date(this);" onmouseover="calendar_td_onmouseover(\'d'+i+'r'+j+'\');" onmouseout="calendar_td_onmouseout(\'d'+i+'r'+j+'\');"> </td>\r\n');
		}
		document.write('		</tr>\r\n');
	}
	document.write('	</table></td>\r\n');
	document.write('</tr></table></form>');
	calendar_set(calendar_show_date);
}


function calendar_set(calendar_show_date)
{	begin_date = new Date(calendar_show_date.getFullYear(),calendar_show_date.getMonth(),1);
	day_of_week = begin_date.getDay();
	begin_date_year = begin_date.getFullYear();
	end_date = new Date (calendar_show_date.getFullYear(),calendar_show_date.getMonth()+1,1);
	day_count = (end_date - begin_date)/1000/60/60/24;
	input_table(day_of_week,day_count);
}


function input_table(day_of_week,day_count)
{
	calendar_init();
	var td_name;
	var td=document;
	j=0;
	if(day_of_week!=0) {
		i=day_of_week-1;
	}else{
		i=6
	}
	if(	(calendar_show_date.getMonth()==calendar_now.getMonth()) &&
		(calendar_show_date.getFullYear()==calendar_now.getFullYear())
	) {	var month_match=1;
	}else{
		var month_match=0;
	}
	for(c=1;c<day_count+1;++c) {
		td_name='d'+i+'r'+j;
		td=document.getElementById(td_name);
		if(	(calendar_now.getDate()==c)	&& month_match) {
			td.style.fontWeight=now_fontWeight;
			td.style.backgroundColor=now_backgroundColor;
			td.style.color=now_color;
			td.style.border=now_border;
		}else{
			td.style.backgroundColor=onmouseout_backgroundColor;
			td.style.color=onmouseout_color;
			td.style.fontWeight=onmouseout_fontWeight;
			td.style.border=onmouseout_border;
		};
		td.innerHTML=c;
		++i;
		if(i==7) {
			i=0;j++;
		}
	}
}

function calendar_init()
{	//	Vyprázdní dny v buňkách kalendáře
	var td_name;
	var td=document;
	for(j=0;j<6;j++) {
		for(i=0;i<7;i++) {
			td_name='d'+i+'r'+j;
			td=document.getElementById(td_name);
			td.innerHTML='&nbsp;';
			td.style.backgroundColor='transparent';//onmouseout_backgroundColor;
			td.style.color='transparent';//onmouseout_color;
			td.style.fontWeight=onmouseout_fontWeight;
			td.style.border='0px none transparent';
		}
	}
}

function change_month(sel_month)
{	calendar_show_date = new Date(calendar_show_date.getFullYear(),sel_month,1);
	calendar_set(calendar_show_date);
}

function change_year(sel_year)
{	sel_year = sel_year.value;
	calendar_show_date = new Date(sel_year,calendar_show_date.getMonth(),1);
	calendar_set(calendar_show_date);
}

function calendar_display(obj)
{	var left=findPosX(obj);
	var top=findPosY(obj);
	var calendar=document.getElementById('form_calendar');

	calendar_output=obj;
	calendar_set(calendar_show_date);
	calendar.style.left=left;
	calendar.style.top=top+20;
	calendar.style.display='block';
	
	//	Skrytí HTML Selectů (obejití chyby IE - http://www.codetoad.com/forum/20_22736.asp)
	var tmp='';
	if(tmp=document.getElementById('pobyt_doba_min')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('pobyt_doba_max')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('let_v_hodinach_min')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('let_v_hodinach_max')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('odjezd_misto')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('stat')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('stravovani_min')) {
		tmp.style.display='none';
	}
	if(tmp=document.getElementById('ubytovani_kategorie_min')) {
		tmp.style.display='none';
	}
}
function calendar_hide()
{
	document.getElementById('form_calendar').style.display='none';
	//	Zobrazení HTML Selectů skrytých v calendar_display()
	var tmp='';
	if(tmp=document.getElementById('pobyt_doba_min')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('pobyt_doba_max')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('let_v_hodinach_min')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('let_v_hodinach_max')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('odjezd_misto')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('stat')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('stravovani_min')) {
		tmp.style.display='inline';
	}
	if(tmp=document.getElementById('ubytovani_kategorie_min')) {
		tmp.style.display='inline';
	}
}
function calendar_output_date(date_day)
{	//	Nastaví datum do calendar_output.value
	var mesic=parseInt(document.getElementById('calendar_month').options.selectedIndex,10)+1;
	var rok=document.getElementById('calendar_year');
	rok=parseInt(rok.options[rok.options.selectedIndex].value,10);
	if(calendar_output && (date_day.innerHTML!='&nbsp;')) {
		calendar_output.value=date_day.innerHTML+'. '+mesic+'. '+rok;
		calendar_hide();
	}
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function calendar_td_onmouseover(element_id)
{	var td=document.getElementById(element_id);
	if(td && (td.innerHTML!='&nbsp;')) {
		td.style.backgroundColor=onmouseover_backgroundColor;
		td.style.cursor='hand';
		return true;
	}
	return false;
}

function calendar_td_onmouseout(element_id)
{	var td=document.getElementById(element_id);
	if(td && (td.innerHTML!='&nbsp;')) {
		td.style.backgroundColor=onmouseout_backgroundColor;
		return true;
	}
	return false;
}
//?>