<!--

function callendar(o)
{

	this.show = callendar_show;
	this.hide = callendar_hide;
	this.getDiv = callendar_get_div;
	this.setPos = callendar_set_pos;
	this.put = callendar_put;
	this.getEmpty = callendar_get_empty_td;
	this.getMpos = callendar_get_mouse_pos;
	this.getCell = callendar_get_cell;
	this.getCntD = callendar_get_count_days;
	this.getCss = callendar_get_css;
	this.setD = callendar_set_data;
	this.setAcD = callendar_set_act_data;
	this.chBg = callendar_ch_background;
	this.clk = callendar_on_click;
	this.days = ["pn", "wt", "śr", "czw", "pt", "sb", "nd"];
	this.months = ["styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrześień", "październik", "listopad", "grdzień"];
	this.ident = "ahf4gHda78xG";
	this.format = "y-m-d";
	this.formObj = null;
	this.OBJNAME = o;
	
	this.css = {
	"main" : {"border" : "1px solid #999999", "background" : "#eeeeee"},
	"size" : 25, "table_color" : "#ffffff", "day_color" : "#ff0000", 
	"bg" : "#eeeeee", "bg_wn" : "#ccccdd", "bg_onm" : "#99cc99", "bg_set" : "#0099ff", "bg_sn" : "#ffdad5", 
	"text" : {"font" : "verdana,tahoma,arial", "color" : "#333333", "size" : "11", "bold" : 700, "on_color" : "#ff0000"}
	};
	
	var dIdn = new Date();
	this.dt = [dIdn.getFullYear(), dIdn.getMonth()+1, dIdn.getDate()]; //aktualna data
	this.dtAc = [0, 0, 0]; //ustawiana z formularza
	this.currentMonth = this.dt[1];
	this.currentYear = this.dt[0];

	
	document.write('<div id="'+this.ident+'" style="position:absolute; left:0; top:0; visibility:visible;"></div>');
	document.write('<style type="text/css" rel="stylesheet">');
	document.write('.'+this.ident+'_call{'+this.getCss()+'}.'+this.ident+'_call:hover{'+this.getCss(this.css.text.on_color)+'}');
	document.write('</style>');

}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_set_data(t)
{
	if(t == 1)
	{
		this.currentMonth ++;
		if(this.currentMonth == 13)
		{
			this.currentYear ++;
			this.currentMonth = 1;
		}
	}
	else if(t == 2)
	{
		this.currentYear ++;
		//this.currentMonth = 1;
	}
	else if(t == -1)
	{
		this.currentMonth --;
		if(this.currentMonth == 0)
		{
			this.currentYear --;
			this.currentMonth = 12;
		}
	}
	else if(t == -2)
	{
		this.currentYear --;
		//this.currentMonth  = 1;
	}

	this.put(this.formObj);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_get_div()
{
	return (document.all)? document.all[this.ident].style : document.getElementById(this.ident).style;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_get_mouse_pos(t)
{
	if(t == "x")
		return (typeof(XmousePosition) == "undefined")? 0 : XmousePosition ;
	else
		return (typeof(YmousePosition) == "undefined")? 0 : YmousePosition ;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_set_pos()
{
	this.getDiv().left = this.getMpos("x");
	this.getDiv().top = this.getMpos("y");
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_show(f)
{
	this.formObj = f;
	this.setPos();
	this.setAcD(this.formObj.value);
	this.put();
	
	this.getDiv().visibility = "visible";
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_hide()
{
	this.getDiv().visibility = "hidden";
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_put()
{
	var i, j, tid, prf, month, css, str="", bg;

	css = this.getCss();

	str = '<div style="border:'+this.css.main.border+'; background-color:'+this.css.main.background+';"><table border=0><tr>';

	str += '<td align="left" style="'+css+'">';
	str += '<a href="javascript:'+this.OBJNAME+'.setD(-2)" class="'+this.ident+'_call">&laquo;&laquo;</a>';
	str += '&nbsp;&nbsp;&nbsp;<a href="javascript:'+this.OBJNAME+'.setD(-1)" class="'+this.ident+'_call">&laquo;</a>';
	str += '</td><td align="right" style="'+css+'">';
	str += '<a href="javascript:'+this.OBJNAME+'.setD(1)" class="'+this.ident+'_call">&raquo;</a>&nbsp;&nbsp;&nbsp;';
	str += '<a href="javascript:'+this.OBJNAME+'.setD(2)" class="'+this.ident+'_call">&raquo;&raquo;</a>';
	str += '</td>';

	str += '</tr><tr>';

	str += '<td colspan="2" align="center" style="'+css+'"><p style="font-weight:100;">'+this.months[this.currentMonth-1]+' - '+this.currentYear+'</p></td>';

	str += '</tr><tr><td colspan="2"><table border="0" cellpadding="0" cellspacing="1" bgcolor="'+this.css.table_color+'"><tr>';

	for(i=0; i<=6; i++)
	{
		bg = (i == 6)? this.css.bg_sn : this.css.bg_wn ;
		str += '<td bgcolor="'+bg+'"><div style="padding:2px; text-align:center;'+this.getCss()+'">'+this.days[i]+'</div></td>';
	}

	str += '</tr><tr>';

	tid = new Date(this.currentYear, this.currentMonth-1, 1);
	prf = tid.getDay();

	prf = (prf >= 1)? prf-1 : 6 ;

	j=1;
	to = this.getCntD(this.currentMonth, this.currentYear);

	for(i=1; i<=to; i++)
	{
		if(i==1)
		{
			str += this.getEmpty(prf);
			j = j + prf;
		}

		str += this.getCell(i, j);

		if(j%7 == 0)
			str += (i == to)? "" : '</tr><tr>';
		else
			str += (i == to)? this.getEmpty(7-(j%7)) : "" ;

		j++;
	}

	str += '</tr></table></td></tr><tr><td colspan="2" align="right" style="'+css+'">';
	str += '<a href="javascript:'+this.OBJNAME+'.hide();" class="'+this.ident+'_call">zamknij</a></td></tr></table></div>';
	
	document.getElementById(this.ident).innerHTML = str;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_get_count_days(m, y)
{
	var arr;
	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];
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_get_empty_td(x)
{
	var i, s="";
	for(i=1; i<=x; i++)
		s += '<td bgcolor="'+this.css.bg+'">&nbsp;</td>';

	return s;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_get_cell(x, y)
{
	var str, bg, onm, cl, i, sn;
	var css = this.getCss();
	i = x;
	sn = (y%7 == 0)? true : false;

	if(this.dt[0] == this.currentYear && this.dt[1] == this.currentMonth && this.dt[2] == i)
		x = '<span style="color:'+this.css.day_color+';">'+i+'</style>';
	
	if(this.dtAc[0] == this.currentYear && this.dtAc[1] == this.currentMonth && this.dtAc[2] == i)
		bg = this.css.bg_set ;
	else
		bg = (sn)? this.css.bg_sn : this.css.bg ;

	onm = 'onmouseover="'+this.OBJNAME+'.chBg(this, \''+this.css.bg_onm+'\')" ';
	onm += 'onmouseout="'+this.OBJNAME+'.chBg(this, \''+bg+'\')"';
	
	cl = 'onclick="'+this.OBJNAME+'.clk('+i+')"';
	
	str = '<td style="background-color:'+bg+'; cursor:hand; '+css+'" width="'+this.css.size+'" height="'+this.css.size+'" ';
	str += 'align="center" valign="middle" '+onm+' '+cl+'>'+x+'</td>';

	return str;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_ch_background(o, c)
{
	o.style.background = c;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_on_click(i)
{
	var m, d, dt;
	this.dtAc[0] = this.currentYear;
	this.dtAc[1] = this.currentMonth;
	this.dtAc[2] = i;

	m = (this.currentMonth < 10)? "0"+this.currentMonth : this.currentMonth ;
	d = (i < 10)? "0"+i : i ;

	dt = this.format;

	dt = dt.replace("y", this.currentYear);
	dt = dt.replace("m", m);
	dt = dt.replace("d", d);

	this.formObj.value = dt;
	this.hide();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function callendar_set_act_data(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.dtAc = [0, 0, 0];
	else
	{
		this.dtAc = [y, m, d];
		this.currentYear = this.dtAc[0];
		this.currentMonth = this.dtAc[1];
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function callendar_get_css(x)
{
	var color;
	color = (callendar_get_css.arguments.length == 0)? this.css.text.color : x ;
	return "font-family:"+this.css.text.font+"; color:"+color+"; font-size:"+this.css.text.size+"; font-weight:"+this.css.text.bold+"; text-decoration:none;";
}


//-->

