
if (!blnExist){ 

// --- user configuration block ---
var ARR_MONTHS
var blnExist = true
var CalBgColor="white";
var TempColor=null;

var VisibleNameDay = true; //Ridi jsetli maji byt videt dny

if (VisibleNameDay)
{
	var BgColorNameDay ="white"; //barva pozadi nazvu dnu
	var AlignNameDay = "Center" //zarovnani nazvu dnu Center ,Left, Right
	var BoldNameDay = true // Jestli maji byt tun nzvy dn
}

var BoldDays = true


	// months as they appear in the selection list
 ARR_MONTHS = ["January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];

var ARR_WEEKDAYS

// day week starts from (normally 0-Mo or 1-Su)
var NUM_WEEKSTART ;
var language = "cz";
var calThisMonth ="background-color:#CCCCFF;"
var calMonthWidth=15;
var calOtherMonth ="background-color:#CC9966;"
var calDayCurrent ="background-color:#FFFFCC;"
var calMonthBgColor="#CC9966"
var calMonthBgColorSelecDay = "#ffff66"

var calDaysTable ="background-color:white;"

var blnSelectedDay = false 
 
var calendars = [];

function calendar(strOutputControl,strHeightDays,str_date,str_form_name,str_min_date,str_max_date,strWidth,strHeight,strBgColor,strStyleDays,strBgColorSelectCombo,strStyleTitleDays,strAlignSelDay,strFontSizeSelectedDay,strStyleSelDay,strStyleSatDay,strStyleSunDay,strForeColorMinDays,strFontSizeMinDays,str_ctrl_name)
{

if(strOutputControl=="")
{
alert('Nezadaly jste jmeno controlu do ktereho se ma datum vloyit pred odeslanim stranky aby bylo mzne ho ziskat na strane serveru')
return false;
}
this.OutputControl = strOutputControl;
this.set_min_date = cal_set_min_date;
this.set_max_date = cal_set_max_date;
this.update_month_select = cal_update_month_select; //Pokud se zmeni rok zjistime jestli neni potreba upravit mesice
this.set_min_date (str_min_date);
this.set_max_date (str_max_date);
this.get_html=cal_get_html;
this.get_body=cal_get_body;
this.set_year=cal_set_year;
this.set_month=cal_set_month;
this.set_day=cal_set_day;


//nastaveni calendare
this.set_Width = cal_set_width;
this.set_Width (strWidth)
this.set_Height = cal_set_height;
this.set_Height (strHeight)
this.set_BgColor = cal_set_BgColor;
this.set_BgColor (strBgColor)

//nastaveni tabulky s combox
this.set_BgColorSelectCombo = cal_set_BgColorSelectCombo;
this.set_BgColorSelectCombo(strBgColorSelectCombo);


this.StyleTitleDays = strStyleTitleDays;

this.StyleDays = strStyleDays;


this.FontSizeSelectedDay = (strFontSizeSelectedDay); 
this.StyleSelectedDay = strStyleSelDay;
this.set_AlignSelDay = cal_AlignSelDay;
this.set_AlignSelDay(strAlignSelDay);

//Nastaveni soboty
this.StyleSatDay = strStyleSatDay;

//nastaveni nedele
this.StyleSunDay = strStyleSunDay;

//Nastaveni vlastnosti dnu ktere nelze vybrat
this.set_bgColorDaysCanNotSelect = cal_bgColorDaysCanNotSelect; //nastavuje barvu pozadi dnu
this.set_bgColorDaysCanNotSelect("red");
this.set_FontNameDaysCanNotSelect = cal_FontNameDaysCanNotSelect; // nastavuje font dnu
this.set_BoldNameDaysCanNotSelect = cal_BoldNameDaysCanNotSelect; // nastavuje jstli ma byt font tucne
//-------------------------------------------
//Nastaveni Vlastnosti dnu ktere lze vybrat
this.set_bgColorDaysCanSelect = cal_bgColorDaysCanSelect; 
this.set_bgColorDaysCanSelect("white");
//------------------------------------------
this.HeightDays=strHeightDays;

//nastaveni minimalnich dnu
this.set_ForeColorMinDay = cal_ForeColorMinDay; 
this.set_ForeColorMinDay(strForeColorMinDays);
this.set_FontSizeMinDay = cal_FontSizeMinDay;
this.set_FontSizeMinDay(strFontSizeMinDays);
//-----------------------------------

this.update=(document.body&&document.body.innerHTML?cal_css_update:cal_rel_update);
this.id=calendars.length;calendars[this.id]=this;
var re_url=new RegExp('cal'+this.id+'_val=(\\d+)');
this.dt_current=(re_url.exec(String(window.location))?new Date(new Number(RegExp.$1)):(str_date?cal_parse_date(str_date):cal_date_only()));

if(!str_form_name)return alert('Form name is required parameter of draw method.');
if(!document.forms[str_form_name])return alert("Form with name '"+this.form_name+"' can't be found in the document.");
this.form_name=str_form_name;
this.control_name=(str_ctrl_name?str_ctrl_name:'datetime_'+this.id);

document.write(this.get_html(this.dt_current));
this.mon_ctrl=document.forms[this.form_name].elements['dt_mon_'+this.id];
this.year_ctrl=document.forms[this.form_name].elements['dt_year_'+this.id];
}


function cal_css_update(dt_datetime)
{
this.dt_current=dt_datetime;

var obj_container=(document.all?document.all['cal_body_'+this.id]:document.getElementById('cal_body_'+this.id));
obj_container.innerHTML=this.get_body(dt_datetime);

//zajisti aby byl vzbranej spravny mesic podle value
for (var i=0;i<this.mon_ctrl.length;i++)
{
if (this.mon_ctrl.options[i].value==dt_datetime.getMonth())
this.mon_ctrl.selectedIndex=i;
}

this.year_ctrl.selectedIndex=dt_datetime.getFullYear()-Number(this.year_ctrl.options[1].text)+1;
if (this.year_ctrl.selectedIndex==-1)this.year_ctrl.selectedIndex=1
}


function cal_rel_update(dt_datetime)
{
var arr_location=String(window.location).split('?');
var arr_params=String(arr_location[1]).split('&');
var num_found=-1;
for(var i=0;i<arr_params.length;i++)
if((arr_params[i].split('='))[0]=='cal'+this.id+'_val')
{
	num_found=i;
	break;
}
arr_params[(num_found==-1?(arr_location[1]?arr_params.length:0):num_found)]='cal'+this.id+'_val='+dt_datetime.valueOf();window.location=arr_location[0]+'?'+arr_params.join('&');
}


function cal_set_min_date(str_min_Date)
{
var minDate = new Date(str_min_Date);

this.min_date=minDate
}


function cal_set_max_date(str_max_Date)
{
var maxDate = new Date(str_max_Date);
this.max_date=maxDate
}

function cal_set_day(num_datetime)
{
var oldDate = this.dt_current
var dt_newdate=new Date(num_datetime);


if ( oldDate.getFullYear() != dt_newdate.getFullYear())
this.update_month_select(dt_newdate)

this.update(cal_validate(dt_newdate)?dt_newdate:this.dt_current);

}


function cal_set_month()
{
var dt_newdate=new Date(this.dt_current);
var num_month=this.mon_ctrl.options[this.mon_ctrl.selectedIndex].value;
dt_newdate.setMonth(num_month);

if(num_month!=dt_newdate.getMonth())dt_newdate.setDate(0);

if(cal_validate(dt_newdate))
{
this.update(dt_newdate);
}
else
this.mon_ctrl.selectedIndex=this.dt_current.getMonth();

}



function cal_set_year()
{
var dt_newdate = new Date(this.dt_current);
var str_year=this.year_ctrl.options[this.year_ctrl.selectedIndex].text;
var str_scroll=this.year_ctrl.options[this.year_ctrl.selectedIndex].value;
var num_year;

if(str_scroll)
{	
 num_year=(str_scroll=='+'?Number(this.year_ctrl.options[this.year_ctrl.length - 2].text) + 1:Number(this.year_ctrl.options[1].text) - 1);
}
else num_year=new Number(str_year);

dt_newdate.setFullYear(num_year);
//if (dt_newdate < this.min_date)
//dt_newdate = this.min_date

var num_month=this.mon_ctrl.options[this.mon_ctrl.selectedIndex].value;
if(num_month!=dt_newdate.getMonth())dt_newdate.setDate(0);

if(!cal_validate(dt_newdate))
 {
    this.year_ctrl.selectedIndex=this.dt_current.getFullYear()-Number(this.year_ctrl.options[1].text)+1;
	return;
 }

if(str_scroll)
{
	this.year_ctrl.length=0; //pokud bylo yvoleno predchozi ,nebo nasleujici roky vymaze se combo
	
	if (num_year-4 >  this.min_date.getFullYear())
		this.year_ctrl.options[0]=new Option('<<'+(num_year-4),'-');
	else
		{//ten nejmensi bude rovnej nejmensimu povolenimu
		while (num_year-4 !== this.min_date.getFullYear())
			{
				num_year= num_year + 1			
			}
	
		if (num_year-4 == this.min_date.getFullYear())
			this.year_ctrl.options[0]=new Option((num_year-4));
		}
	
		//naplni combo 8 rokama
		for(var i=1;i<8;i++)
		{	
		this.year_ctrl.options[i]=new Option(num_year + i - 4 );
		//this.year_ctrl.options[i].selected=!(i-4);
		if (this.max_date.getFullYear() == (num_year + i- 4))
			break;
		}
		
		if (num_year+4 < this.max_date.getFullYear()  )	
 			this.year_ctrl.options[8]=new Option((num_year+4)+'>>','+');
	

}

dt_newdate = this.update_month_select(dt_newdate)

this.update(dt_newdate);

}


function cal_update_month_select(dt_newdate)
{
if(this.max_date.getMonth()< dt_newdate.getMonth())
dt_newdate = this.max_date

if (this.min_date.getFullYear()== dt_newdate.getFullYear())
	{
	this.mon_ctrl.length = 0;
	for (var i=(this.min_date.getMonth());i<12;i++)
		{
			this.mon_ctrl.options[i-(this.min_date.getMonth())]= new Option(ARR_MONTHS[i],i,true,true);
		}
		if (dt_newdate.getMonth() < this.min_date.getMonth())
			{
				dt_newdate.setMonth(this.min_date.getMonth())
									
			}
	}
else
	{
			
if 	(this.mon_ctrl.length < 12)
	{
	this.mon_ctrl.length = 0;
	for (var i=0;i<12;i++)
		{
		this.mon_ctrl.options[i]= new Option(ARR_MONTHS[i],i,true,true);
			if (this.max_date.getFullYear()== dt_newdate.getFullYear() && this.max_date.getMonth()==i)break ;
		}
	}
	
	}
if (dt_newdate< this.min_date)
	dt_newdate = this.min_date;
	
return dt_newdate;
}


function cal_limit_min(str_min_date,b_absolute)
{
this.min_date=(b_absolute?this.parse_date(str_min_date):new Date(this.date.valueOf()-new Number(str_min_date*864e5)));
}


function dts_limit_max(str_max_date,b_absolute)
{
this.cal_date=(b_absolute?this.parse_date(str_max_date):new Date(this.date.valueOf-new Number(str_max_date*864e5)));
}


function cal_get_html(dt_datetime)
{


var i,str_buffer=new String('<table width="'+this.width+'" height="'+this.height+'" cellspacing="0" bgColor="'+ this.BgColor + '" class="calOuterTable" border="3" Align="left" ><tr>'+'<td>'+'<table cellspacing="0" border="0"  class="calSelectTable" Align="Center" width="100%"><tr><td bgcolor="'+this.BgColorSelectCombo+'" valign="Center" align="left">'+'<select name="dt_mon_'+this.id+'" class="calMonCtrl" onchange="return calendars['+this.id+'].set_month();">');

var counter = 0

if (this.min_date.getMonth() < 12   && this.min_date.getFullYear() ==  dt_datetime.getFullYear() ) counter = this.min_date.getMonth()



for(i=counter;i<12;i++)
	{
	str_buffer+='<option value="'+i+'"'+(i==dt_datetime.getMonth()?' selected':'')+'>'+ARR_MONTHS[i]+"</option>\n";
	}
	str_buffer+='</select></td>'+'<td align="right"  bgcolor="'+this.BgColorSelectCombo+'" ><select name="dt_year_'+this.id+'" class="calYearCtrl" onchange="return calendars['+this.id+'].set_year();">';
	 

//tady se plni roky do combo
var tempYear = dt_datetime.getFullYear();
var blnNexYear = true;
while ( (tempYear - 4) < this.min_date.getFullYear())
		tempYear += 1		
		
    if ( (tempYear - 4) > this.min_date.getFullYear())
		str_buffer+='<option value="-">&lt;&lt;'+(tempYear-4)+"</option>\n";
	else
		str_buffer+='<option >'+(tempYear-4) +"</option>\n";

for(i=-3;i<4;i++)
{
	str_buffer+='<option'+(tempYear+i==dt_datetime.getFullYear()?' selected':'')+'>'+(tempYear+i)+"</option>\n";
	if (tempYear+i == this.max_date.getFullYear() ) 
	{
	blnNexYear=false;
	break;
	
	}
}

if(blnNexYear)str_buffer+='<option value="+">'+(tempYear+4)+"&gt;&gt;</option>\n";

// Tady konci plneni roku do comba

str_buffer+='</select></td></tr></table></td></tr>'+'<tr><td><div id="cal_body_'+this.id+'">'+this.get_body(dt_datetime)+'</div>'+'</td>'+'</tr></table>';


return(str_buffer);
}


function cal_get_body(dt_datetime)
{
var dt_prev_year=new Date(dt_datetime);
dt_prev_year.setFullYear(dt_prev_year.getFullYear()-1);
if(dt_prev_year.getDate()!=dt_datetime.getDate())dt_prev_year.setDate(0);
var dt_next_year=new Date(dt_datetime);
dt_next_year.setFullYear(dt_next_year.getFullYear()+1);
if(dt_next_year.getDate()!=dt_datetime.getDate())dt_next_year.setDate(0);
var dt_firstday=new Date(dt_datetime);
dt_firstday.setDate(1);
dt_firstday.setDate(1-(7+dt_firstday.getDay()-NUM_WEEKSTART)%7);

var str_Style_SelDays= this.StyleSelectedDay ;
var str_Style_Font_Size = 'Style="font-size:'+ this.FontSizeSelectedDay+'";';
var strStyleSatDay = this.StyleSatDay;
var strStyleSunDay = this.StyleSunDay
//-----------------------
document.getElementById(this.OutputControl).value =  dt_datetime.getDate()+" "+ (dt_datetime.getMonth() + 1) + " " + dt_datetime.getFullYear()

//document.getElementById(this.OutputControl).value = (dt_datetime.getMonth() + 1) + " " +  dt_datetime.getDate()+  " " + dt_datetime.getFullYear()


var str_buffer=new String('<table cellspacing="0" Align="Center" cellpadding="0" height="'+this.HeightDays+'"  width="100%" border="0">');

str_buffer+='<tr>';

if (VisibleNameDay ) //pokud maji byt videt nazvy dnu
{
	for(var n=0;n<7;n++)
	{
		str_buffer+='<td '+this.StyleTitleDays+' >'+ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7]+'</td>';
	}
}

str_buffer+="</tr>\n";

var dt_current_day = new Date(dt_firstday);

var _style;
var _blnNotSelect = false
var _tyden = 0

while(dt_current_day.getMonth()==dt_datetime.getMonth()||dt_current_day.getMonth()==dt_firstday.getMonth())
{
	_tyden +=1
	str_buffer+='<tr>';

	for(var n_current_wday=0;n_current_wday<7;n_current_wday++)
		{
			//	 this.bgColorDaysCanNotSelect
			if(dt_current_day < this.min_date )
				{
				 _blnNotSelect = true
				 _style = this.bgColorDaysCanNotSelect
				 }
			else
				{
				 _blnNotSelect = false
				 _style = this.bgColorDaysCanSelect
				}
					
				
			if(dt_current_day.getDate()==dt_datetime.getDate()&&dt_current_day.getMonth()==dt_datetime.getMonth())
				//poku se jedna o vybranej den
				{
				str_buffer+='<td align="'+this.AlignSelDay+'" valign="middle" align="'+this.AlignDays+'" '+str_Style_SelDays+'>';
				}
			else 
					
				if(dt_current_day.getDay()==0||dt_current_day.getDay()==6)
					if(dt_current_day.getDay()==6)
						str_buffer+='<td class="tdDayS" align="'+this.AlignDays+'" '+ strStyleSatDay +'>';
					else
						str_buffer+='<td class="tdDayM" align="'+this.AlignDays+'" '+strStyleSunDay +' >';
				else
				{	
						str_buffer+= '<TD class="tdDay" '+this.StyleDays+'  >';
					
				}
				
			if(dt_current_day.getDate()==dt_datetime.getDate()&&dt_current_day.getMonth()==dt_datetime.getMonth())
				//poku se jedna o vybranej den
		{
		
				str_buffer+='<a title="'+dt_current_day.getDate()+'" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');" '+str_Style_SelDays+' >';
				
		}	
		
		else
			
				if(dt_current_day.getMonth()==dt_datetime.getMonth() && (!blnSelectedDay) )
				{
				
				if (_blnNotSelect )		
				    {}
				else
				   
				   if(dt_current_day.getDay()==0||dt_current_day.getDay()==6)
					if(dt_current_day.getDay()==6)
					str_buffer+='<a title="'+dt_current_day.getDate()+'" onmouseover="ChangeBgColorOverDay(this)" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');"  '+strStyleSatDay+' class="OverDay">';
					else
					str_buffer+='<a title="'+dt_current_day.getDate()+'" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');"  '+strStyleSunDay+' class="OverDay">';
				else
				    {
					   str_buffer+='<a title="'+dt_current_day.getDate()+'" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');"  '+this.StyleDays+' class="OverDay">';
					}
				}
				else
				
				
				if (_blnNotSelect )
					{
					}
				else
			
				if(dt_current_day.getDay()==0||dt_current_day.getDay()==6)
					if(dt_current_day.getDay()==6) // pro dny z dalsiho mesice
					{
						str_buffer+='<a title="'+dt_current_day.getDate()+'" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');" '+strStyleSatDay+' class="OverDay">';
					}
					else
						str_buffer+='<a title="'+dt_current_day.getDate()+'" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');" '+strStyleSunDay+' class="OverDay">';
					else
						{
						str_buffer+='<a title="'+dt_current_day.getDate()+'" href="javascript:calendars['+this.id+'].set_day('+dt_current_day.valueOf()+');" '+this.StyleDays+' class="OverDay">';
						}
				
					
			
					if (_blnNotSelect  )
					{ 
					 str_buffer+='<font color="'+this.ForeColorMinDay+'" Style="font-size:'+this.FontSizeMinDay+';">'+ dt_current_day.getDate()+'</font></td>';
					}
					else 
					{
					str_buffer+=dt_current_day.getDate()+'</a></td>';
					}
			
		
			
				dt_current_day.setDate(dt_current_day.getDate()+1);
			}
	
	
	str_buffer+="</tr>\n";
	

}
	if (_tyden < 6 )
	{
	 str_buffer+="<tr><td colspan='5'>&nbsp;</td></tr>"; 		
	} 	

 str_buffer+='</table>';

return(str_buffer);
}


function cal_parse_date(strDate)
{
var dt_datetime = new Date(strDate) 



return dt_datetime;

}


function cal_date_only(dt_datetime)
{
if(!dt_datetime)dt_datetime=new Date();
dt_datetime.setHours(0);
dt_datetime.setMinutes(0);
dt_datetime.setSeconds(0);
dt_datetime.setMilliseconds(0);
return dt_datetime;
}


//Calendar 
function cal_set_width(width)
{
	this.width = width;
}
function cal_set_height(height)
{
	this.height= height;
}
function cal_set_BgColor(Color)
{
	this.BgColor = Color;
}

//tabulka s combo
function cal_set_BgColorSelectCombo(Color)
{
	this.BgColorSelectCombo = Color; 
}




function cal_FontSizeTitleDays (FontSize)
{   
	this.FontSizeTitleDays = FontSize;
}
//------------------------
function cal_FontUnderlineTitleDays (strFontUnderline)
{   if (strFontUnderline =='True')
	{
		this.FontUnderlineTitleDays = "text-decoration:underline;";
	}
	else this.FontUnderlineTitleDays = ""
}


//nastaveni vybraneho dne

function cal_FontSizeSelectedDay(Size)
{
this.FontSizeSelectedDay=Size;
}

function cal_AlignSelDay (Align)
{
this.AlignSelDay=Align;
}

//-------------------------


// nastaveni minimalniho dne
function cal_ForeColorMinDay (Color)
{
this.ForeColorMinDay = Color;
}
function cal_FontSizeMinDay(Size)
{
this.FontSizeMinDay = Size;
}

//funkce pro nastaveni vlastosti dnu ktere nelze vybrat
function cal_bgColorDaysCanNotSelect(Color)
{
 this.bgColorDaysCanNotSelect = ' bgColor="'+Color+'" ' ;
}

function cal_FontNameDaysCanNotSelect(Font)
{
	cal_FontNameDaysCanNotSelect;
}

function cal_BoldNameDaysCanNotSelect(Bold)
{
	this.BoldNameDaysCanNotSelect = Bold
}

function cal_ForeColorDays(Color)
{
 this.ForeColorDays = Color ;
}
function cal_FontSizeDays(Size)
{
 this.FontSizeDays = Size ;
}

function cal_BorderDays(Size)
{
	this.BorderDays=Size;
}



//------------------------------------------------------

//Ktere JE MOZNO VYBRAT
function cal_bgColorDaysCanSelect(Color)
{
this.bgColorDaysCanSelect = 'bgColor="'+Color+'"'
}
//----------------------------------------------


function cal_validate(dt_datetime)
{

return true;
}

	function ChangeBgColorOverDay(obj)
	{	
	//TempColor = obj.style.backgroundColor
	//	obj.style.backgroundColor = "#CCCCCC"
	}
	
	function ChangeBgColorOutDay(obj)
	{	
	//	obj.style.backgroundColor = TempColor
	}
	
}