/**
 * Klasa do ukrywania/pokazywania elementow list
 */
function SHList(active){
    this._active = active;
    document.getElementById(active).style.display = 'inline';
}

SHList.prototype._active;

SHList.prototype.setVisible = function(id){

    document.getElementById(this._active).style.display = 'none';
    
    document.getElementById(id).style.display = 'inline';
    
    this._active = id;
	
    return false;
}

function enable(box) {
	if (box.className != 'on') 
	box.className = 'highlight';
}

function disable(box) {
	if (box.className != 'on') 
	box.className = '';
}

/* kalendarz js do wyboru daty w serwisie */
function Calendar(id) {
	
	this._daymonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	this._mon = new Array('Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień');	
	//pobranie aktualnej daty
	this._data = new Date();
	this._data.setDate(1);
	this._id = id;
	this._html = '';
	this._visible = 'none';	
	this.build();
}

Calendar.prototype._data;
Calendar.prototype._mon;
Calendar.prototype._id;
Calendar.prototype._day;
Calendar.prototype._dayweek;
Calendar.prototype._daymonth;
Calendar.prototype._year;
Calendar.prototype._month;
Calendar.prototype._html;
Calendar.prototype._input;
Calendar.prototype._visible;

Calendar.prototype.prev = function(){

	this._month--;
	
	if (this._month == -1) {
		
		this._year--;
		this._month = 11;	
	}
	
	this._data.setMonth(this._month);
	this._data.setFullYear(this._year);
	
	this.build();
	this.refresh();
	
}
Calendar.prototype.setData = function(day) {
	m = this._month+1;
	y = this._year;
	d = day;
	
	if (m < 10) m = '0'+ m;
	if (d < 10) d = '0'+ d;
		
	date = y+'-'+m+'-'+d;
	
	document.getElementById(this._input).value = date;
	this.hide();
}

Calendar.prototype.setInputId = function(input) {
	this._input = input;
}

Calendar.prototype.next = function(){
	this._month++;
	
	if (this._month == 12) {
		this._year++;
		this._month = 0;	
	}
	
	this._data.setMonth(this._month);
	this._data.setFullYear(this._year);
	
	this.build();
	this.refresh();
	
}

Calendar.prototype.refresh = function() {

	tmp = '<a href="" onclick="cal.showHide();return false;"><img src="../images/calendar.jpg" /></a>' + this._html;
		
	document.getElementById('blocker').innerHTML = tmp; 	
}

Calendar.prototype.build = function() {
	
	this._day = this._data.getDate();
	this._month = this._data.getMonth();
	this._year = this._data.getFullYear();
	this._dayweek = this._data.getDay();
	
	//jesli rok przestepny ustawiam ilosc dni w lutym
	if (this._year%4 == 0 && this._year%100 != 0 && this._year%400 == 0) {
		this.daymonth = 29;
	}	
	//naglowek kalendarza
	var head = '<div class="head"><a onclick="javascript:cal.next();return false;" style="float:right;" href="">>></a>'+
		'<a onclick="javascript:cal.prev();return false;" style="float:left;" href=""><<</a> ' + 
		this._mon[this._month] + ' ' + this._year + ' </div>' +
		'<div class="head"><div>Pn</div><div>Wt</div><div>Śr</div>'+
		'<div>Cz</div><div>Pt</div><div>So</div><div>Nd</div></div>';
	
	//pola dni kalendarza
	var fields = '';
	
	for (var i=0; i<this._daymonth[this._month]+this._dayweek-1; i++) {
		if (i < this._dayweek-1) {
			fields += '<div></div>';
		} else {
			fields += '<div><a onclick="cal.setData(' + (i-this._dayweek+2)+ ');return false;" href="">' + (i-this._dayweek+2)+ '</a></div>';
		}
	}
	
	var html = '<div id="cal' + this._id + '" class="calendar" style="display:' + this._visible + ';">' + head +
		'<div class="fields">' + fields + '</div>'+
		'</div>';

	this._html = html;
}
Calendar.prototype.show = function() {
	
	document.getElementById('cal' + this._id).style.display = 'block';
	this._visible = 'block';
}
Calendar.prototype.hide = function() {
	document.getElementById('cal' + this._id).style.display = 'none';
	this._visible = 'none';
}

Calendar.prototype.showHide = function() {
	if (this._visible == 'none') {
		this.show();
	} else {
		this.hide();
	}
}

Calendar.prototype.putHere = function() {
	document.write('<div id="blocker"><a href="" onclick="cal.showHide();return false;"><img src="../images/calendar.jpg" /></a>' + this._html + '</div>');
}










