<!--

var callendar = {
	
	divName : null, 
	ident : "callendar",
	format : "y-m-d",
	cssClassName : {table:"callendar", name1:"miesiac", name2:"nazwy_dni", day:"dzien", sunday:"niedziela", day_set:"dzien_ustawiony", day_act:"dzien_aktualny", empty:"empty", arrow:"arrow"},
		
	days : ["pn", "wt", "Å›r", "czw", "pt", "sb", "nd"],
	months : ["styczeÅ„", "luty", "marzec", "kwiecieÅ„", "maj", "czerwiec", "lipiec", "sierpieÅ„", "wrzeÅ›ieÅ„", "paÅºdziernik", "listopad", "grdzieÅ„"],

	dateAct : {y:new Date().getFullYear(), m:new Date().getMonth()+1, d:new Date().getDate()}, //aktualna data
	dateSet : {y:0, m:0, d:0}, //ustawiana
	dateCall : {y:0, m:0}, //aktualny rok i mieci¹c na kalendarzu
	
	arrows : {LL:"&laquo;&laquo;", L:"&laquo;", R:"&raquo;", RR:"&raquo;&raquo;", odst:"&nbsp;&nbsp;&nbsp;"},
	
	onDayClick : null,
	onArrowClick : null,
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	write : function(dv, date)
	{
		this.divName = dv;
	
		if(date)
			this.setDate(date);
		
		this.dateCall = {y:this.dateAct.y, m:this.dateAct.m};

		var str = this.getStr();
		
		document.getElementById(this.divName).innerHTML = str;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	go2 : function(date)
	{
		if(date)
			this.setDate(date);
		
		document.getElementById(this.divName).innerHTML = this.getStr();
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	dClick : function(obj, i)	//po kliknieciu na dzien
	{
		if(typeof this.onDayClick == "function")
			this.onDayClick(this.dateCall.y, this.dateCall.m, i);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	aClick : function()		//po kliknieciu na strzalke
	{
		if(typeof this.onArrowClick == "function")
			this.onArrowClick(this.dateCall.y, this.dateCall.m);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		
	getStr : function()
	{
		var i, j, to;
	
		var str = '<table class="'+this.cssClassName.table+'" cellpadding="0" cellspacing="0"><tr>';
		
		str += '<td class="'+this.cssClassName.arrow+'"><a href="javascript:'+this.ident+'.clickArr(-2)">'+this.arrows.LL+'</a></td>';
		str += '<td class="'+this.cssClassName.arrow+'"><a href="javascript:'+this.ident+'.clickArr(-1)" class="'+this.cssClassName.link+'">'+this.arrows.L+'</a></td>';
		str += '<td colspan="3" class="'+this.cssClassName.empty+'">&nbsp;</td>';
		str += '<td class="'+this.cssClassName.arrow+'"><a href="javascript:'+this.ident+'.clickArr(1)" class="'+this.cssClassName.link+'">'+this.arrows.R+'</a></td>';
		str += '<td class="'+this.cssClassName.arrow+'"><a href="javascript:'+this.ident+'.clickArr(2)" class="'+this.cssClassName.link+'">'+this.arrows.RR+'</a></td>';
		

		str += '</tr><tr>';

		str += '<td valign="middle" colspan="7" class="'+this.cssClassName.name1+'">'+this.months[this.dateCall.m-1]+' - '+this.dateCall.y+'</td>';

		str += '</tr><tr>';
		
		for(i=0; i<=6; i++)
		{
			str += '<td class="'+this.cssClassName.name2+'">'+this.days[i]+'</td>';
		}
	
		str += '</tr><tr>';
	
		var tid = new Date(this.dateCall.y, this.dateCall.m-1, 1);
		var prf = tid.getDay();
	
		prf = (prf >= 1)? prf-1 : 6 ;
	
		j=1;
		to = this.getCountDays(this.dateCall.m, this.dateCall.y);
	
		for(i=1; i<=to; i++)
		{
			if(i==1)
			{
				str += this.getEmptyTd(prf);
				j = j + prf;
			}
	
			str += this.getTd(i, j);
	
			if(j%7 == 0)
				str += (i == to)? "" : '</tr><tr>';
			else
				str += (i == to)? this.getEmptyTd(7-(j%7)) : "" ;
	
			j++;
		}
	
		str += '</tr>';
		str += '</table>';
		
		return str;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getTd : function(x, y)
	{
		var i = x;
		var sn = (y%7 == 0)? true : false;
		var cssClass = "";
	
		if(this.dateSet.y == this.dateCall.y && this.dateSet.m == this.dateCall.m && this.dateSet.d == i)
			cssClass = this.cssClassName.day_set;
		else if(this.dateAct.y == this.dateCall.y && this.dateAct.m == this.dateCall.m && this.dateAct.d == i)
			cssClass = this.cssClassName.day_act;
		else if(sn)
			cssClass = this.cssClassName.sunday;
		else
			cssClass = this.cssClassName.day;
		
		var onm="";
		
		var clck = 'onclick="'+this.ident+'.dClick(this, '+i+')"';
		
		return '<td class="'+cssClass+'" valign="middle" '+onm+' '+clck+'>'+x+'</td>';
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getEmptyTd : function(x)
	{
		var i, s="";
		for(i=1; i<=x; i++)
			s += '<td class="'+this.cssClassName.empty+'">&nbsp;</td>';

		return s;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getCountDays : function(m, y)
	{
		var arr = [null, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		
		if(m == 2)
		{
			return (y%4==0)? ((y%100 == 0)? ((y%400 == 0)? 29 : 28 ) : 29) : 28 ;
		}
		else
			return arr[m];
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	setDate : function(val)
	{
		var y, m, d, i, j, reg;
	
		j = 0;
	
		for(var i=0; i<this.format.length; i++)
		{
			tmp = this.format.substr(i, 1);
			if(tmp == "y")
			{
				y = parseFloat(val.substr(j, 4));
				j+=3;
			}
			if(tmp == "m")
			{
				m = parseFloat(val.substr(j, 2));
				j+=1;
			}
			if(tmp == "d")
			{
				d = parseFloat(val.substr(j, 2));
				j+=1;
			}
			j++;
		}

		if(val.length < 6 || y+'' == "NaN" || m+'' == "NaN" || d+'' == "NaN")
			this.dateSet = {y:0, m:0, d:0};
		else
		{
			this.dateSet = {y:y, m:m, d:d};
			//this.currentYear = this.dtAc[0];
			//this.currentMonth = this.dtAc[1];
		}
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	clickArr : function(t)
	{
		if(t == 1)
		{
			this.dateCall.m ++;
			if(this.dateCall.m == 13)
			{
				this.dateCall.y ++;
				this.dateCall.m = 1;
			}
		}
		else if(t == 2)
		{
			this.dateCall.y ++;
			//this.currentMonth = 1;
		}
		else if(t == -1)
		{
			this.dateCall.m --;
			if(this.dateCall.m == 0)
			{
				this.dateCall.y --;
				this.dateCall.m = 12;
			}
		}
		else if(t == -2)
		{
			this.dateCall.y --;
			//this.currentMonth  = 1;
		}
	
		this.go2();
		this.aClick();
	}

};

//-->
