// powered by ROTFL & LOL
var jso={
	gI:function(a,b){
		// get Element by ID
		b=b||document;
		return b.getElementById(a)
	},
	gT:function(a,b,i){
		// get Elements by Tag Name
		b=b||document;
		b=b.getElementsByTagName(a)
		a=[]
		for(i=0;i<b.length;i++)a[a.length]=b[i];
		return a
	},
	gAV:function(a,b,c,d,i){
		// get Elements by Atribute [+ Value]
		a=a||"*";
		b=b||document;
		if(!c)return false;
		b=b.getElementsByTagName(a)
		a=[]
		for(i=0;i<b.length;i++)if(b[i][c]&&(!d||(b[i][c].match(new RegExp('(^| )'+d+'($| )','gi'))!=null)))a[a.length]=b[i];;
		return a
	},
	cE:function(a,b,c,d,e,i){
		// create Element
		a=document.createElement(a)
		if(b)for(i in b)a[i]=b[i];;
		if(c)for(i in c)a.appendChild(c[i].nodeType?c[i]:document.createTextNode(c[i]));;
		if(e)for(i in e)jso.aE(a,i,e[i]);;
		if(d)d.appendChild(a);
		return a
	},
	gE:function(x){
		// get Element from Event
		x=x||window.event;
		x=x.target||x.srcElement;
		if(x.nodeType==3)x=x.parentNode;
		return x
	},
	aE:function(O,E,F){
		// add Event to Element
		return(O.x=O.addEventListener)?O.x(E,F,0):(O.x=O.attachEvent)?O.x('on'+E,F):!1;
	},
	rE:function(O,E,F){
		// remove  Event from Element
		return(O.x=O.removeEventListener)?O.x(E,F,0):(O.x=O.detachEvent)?O.x('on'+E,F):!1;
	},
	sE:function(e){
		e = e||event
		if(e.preventDefault)
			e.preventDefault();
		e.returnValue=false
		return false
	},
	sO:function(a,b){
		// set Opacity
		if(jso.ie)
			a.style.filter='alpha(opacity='+(100*b)+')';
		else
			a.style.opacity = b;
	},
	cooC:function(name,value,days){
		if(days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	cooR:function(name){
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ')
				c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0)
				return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	cooE:function(name)
	{
		createCookie(name,"",-1);
	},
	ie:false
}
/*@cc_on @if(@_jscript) jso.ie=true @end @*/
// srajax
jso.ajax = function(params)
{
	var T = this
	for(var i in params)
		this[i]=params[i];
	this.ajax = false
	if (window.XMLHttpRequest)
		this.ajax = new XMLHttpRequest();
	else
		this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
	if (this.ajax)
	{
		if(this.onend)
			this.ajax.onreadystatechange=function(){if(T.ajax.readyState==4)T.onend(T.ajax);};
		this.method=this.method?this.method.toUpperCase():'GET';
		this.uri=this.uri||'';
		this.postData=this.postData?this.postData:null;
		this.ajax.open(this.method,this.uri, true);
		if (this.method == 'POST')
			this.ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajax.send(this.postData)
		this.ok = true
	}
	else
	{
		this.ok = false
	}
}
// inputy
jso.inputEdit = function(string)
{
	var T = this
	this.domInput = jso.gI(string)
	if(!this.domInput)
		return;
	this.defaultText = jso.gAV('label',0,'htmlFor',this.domInput.id)[0]
	if(!this.defaultText)
		return;
	this.defaultText = this.defaultText.firstChild;
	if(!this.defaultText)
		return;
	this.defaultText = this.defaultText.nodeValue.replace(/^[ 	\n]*(.*)[ 	\n]*$/gi,'$1');
	if(!this.defaultText)
		return;
	this.inputType = this.domInput.type.toLowerCase();
	this.domInput.onfocus = function(){T.eventAction.call(T,1)}
	this.domInput.onblur = function(){T.eventAction.call(T,0)}
	this.domInput.form.inputsToClean[this.domInput.form.inputsToClean.length] = this;
	this.domInput.title = this.defaultText
	this.eventAction(0)
}
jso.inputEdit.prototype.eventAction = function(plus)
{
	if(plus && this.domInput.value == this.defaultText)
	{
		this.domInput.value = '';
	if(this.inputType == 'password' && !jso.ie)
			this.domInput.type = 'password';
	}
	else if(!plus && !this.domInput.value)
	{
		this.domInput.value = this.defaultText;
	if(this.inputType == 'password' && !jso.ie)
			this.domInput.type = 'text';
	}
}
// inputsToClean
jso.submitForm = function()
{
	var forms = jso.gT('form')
	for(var i in forms)
	{
		if(!forms[i].inputsToClean)
		{
			forms[i].inputsToClean = []
			forms[i].onsubmit = function()
			{
				if(this.inputsToClean)
				{
					for(var j in this.inputsToClean)
					{
						this.inputsToClean[j].eventAction.call(this.inputsToClean[j],1);
					}
				}
			}
  	}
	}
}
// kalendarz
jso.calendar = function(params)
{
	var T = this
	var tmp,i;
	for(var i in params)
		this[i]=params[i];
	this.active = false;
	this.domInput.readOnly = true;
	this.domInput.onclick = function(e){T.showCalendar.call(T,e||event)}
}

jso.calendar.prototype.showCalendar = function(e)
{
	var tmp
	if(this.active)
		return;
	this.active = true;
	this.domInput.disabled = true;
	if(this.domInput.value=='')
	{
		tmp=new Date()
		this.day=tmp.getUTCDate()
		this.month=tmp.getMonth()
		this.year=tmp.getFullYear()
	}
	else
	{
		tmp=this.domInput.value.split('-')
		this.day=parseFloat(tmp[2])
		this.month=parseFloat(tmp[1])-1
		this.year=parseFloat(tmp[0])
	}
	if(!this.domCalendar)
		this.createCalendar.call(this);
	this.domCalendar.style.left=( e.pageX == undefined ? e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft : e.pageX )-15+'px'
	this.domCalendar.style.top=( e.pageY == undefined ? e.clientY + document.body.scrollTop + document.documentElement.scrollTop :  e.pageY )-15+'px'
	this.setDate.call(this)
	jso.gT('body')[0].appendChild(this.domCalendar)
}

jso.calendar.prototype.createCalendar = function()
{
	var T = this;
	var thead=jso.cE('tr',0,
		[
			jso.cE('th',0,['pn']),
			jso.cE('th',0,['wt']),
			jso.cE('th',0,['śr']),
			jso.cE('th',0,['czw']),
			jso.cE('th',0,['pt']),
			jso.cE('th',{className:'jso_calendar_weekend'},['sob']),
			jso.cE('th',{className:'jso_calendar_weekend'},['ndz'])
		]);
	var tfoot=thead.cloneNode(1)
	this.domCalendar = jso.cE('div',{className:'jso_calendar'});
	this.domYear = jso.cE('input',{
		type:'text',
		onkeypress:function(e){e=e||event;if(e.keyCode==13)T.setYear.call(T,T.domYear.value);},
		onblur:function(){T.setYear.call(T,T.domYear.value)}
	})
	this.domMonth = jso.cE('select',{onchange:function(){T.setMonth.call(T,T.domMonth.value)}},
		[
			jso.cE('option',{value:0},['styczeń']),
			jso.cE('option',{value:1},['luty']),
			jso.cE('option',{value:2},['marzec']),
			jso.cE('option',{value:3},['kwiecień']),
			jso.cE('option',{value:4},['maj']),
			jso.cE('option',{value:5},['czerwiec']),
			jso.cE('option',{value:6},['lipiec']),
			jso.cE('option',{value:7},['sierpień']),
			jso.cE('option',{value:8},['wrzesień']),
			jso.cE('option',{value:9},['październik']),
			jso.cE('option',{value:10},['listopad']),
			jso.cE('option',{value:11},['grudzień'])
		]
	)
	this.domTable = jso.cE('table',0,
		[
		jso.cE('thead',0,
			[
				jso.cE('tr',0,
					[
						jso.cE('th',{className:'jso_calendar_icon'}),
						jso.cE('th',{colSpan:3,className:'jso_calendar_clickable',onclick:function(){T.clean.call(T)}},['usuń datę']),
						jso.cE('th',{colSpan:3,className:'jso_calendar_clickable',onclick:function(){T.close.call(T)}},['zamknij'])
					]),
				jso.cE('tr',0,
					[
						jso.cE('th',{className:'navigation_preview',title:'poprzedni miesiąc',onclick:function(){T.setMonth.call(T,T.month-1)}}),
						jso.cE('th',{colSpan:2,className:'jso_calendar_clickable',title:'rok'},[this.domYear]),
						jso.cE('th',{colSpan:3,className:'jso_calendar_clickable',title:'miesiąc'},[this.domMonth]),
						jso.cE('th',{className:'navigation_next',title:'następny miesiąc',onclick:function(){T.setMonth.call(T,T.month+1)}})
					]),
				thead
			]),
			jso.cE('tfoot',0,[tfoot])
		],this.domCalendar);
	if(jso.ie)
		jso.cE('iframe',0,0,this.domCalendar);
}

jso.calendar.prototype.setYear=function(value, set)
{
	var ok = false
	value = parseFloat(value)
	if(!isNaN(value) && value > 0)
	{
		this.year = value
		ok = true
	}
	if(set !== false)
		this.setDate.call(this);
	return ok;
}

jso.calendar.prototype.setMonth = function(value, set)
{
	var ok = false;
	value = parseFloat(value);
	if(!isNaN(value))
	{
		if(value < 0)
		{
			if((ok = this.setYear.call(this,this.year+Math.floor(value/11), false)))
				this.month = 12 + value % 11;
		}
		else if(value > 11)
		{
			if((ok = this.setYear.call(this,this.year+Math.floor(value/11), false)))
				this.month = value % 12;
		}
		else
		{
			this.month = value
			ok = true
		}
	}
	if(set !== false)
		this.setDate.call(this);
	return ok
}

jso.calendar.prototype.setDate=function()
{
	var T = this
	this.domMonth.value = this.month
	this.domYear.value = this.year
	var date,year,month,day,weekDay,i;
	var tbody = jso.cE('tbody')
	var monthStart = Date.UTC(this.year,this.month,1);
	var monthEnd = Date.UTC(this.year,this.month+1,1) - 86400000;
	date = new Date(monthStart)
	weekDay = date.getUTCDay()
	var startDate = (weekDay != 1) ? (monthStart - (weekDay == 0 ? 6 : weekDay - 1) * 86400000) : monthStart;
	date = new Date(monthEnd)
	weekDay = date.getUTCDay()
	var endDate = (weekDay != 0) ? (monthEnd + (7 - weekDay) * 86400000) : monthEnd;
	for(i=startDate; i <= endDate; i+=86400000)
	{
		date = new Date(i)
		year = date.getUTCFullYear()
		month = date.getUTCMonth()
		day = date.getUTCDate()
		weekDay = date.getUTCDay()
		if(weekDay==1)
			tr = jso.cE('tr',0,0,tbody);
		if(month == this.month)
			jso.cE('td',{
				calendar:{year:year,month:month,day:day},
				className:(day==this.day?'jso_calendar_active':(weekDay==0||weekDay==6?'jso_calendar_weekend':'')),
				onclick:function(){
					T.setYear.call(T,this.calendar.year,false);
					T.setMonth.call(T,this.calendar.month,false);
					T.day = this.calendar.day;
					T.sendValue.call(T)
				}
			},[day],tr)
		else
			jso.cE('td',{
				calendar:{year:year,month:month,day:day},
				className:'jso_calendar_other',
				onclick:function(){
					T.setYear.call(T,this.calendar.year,false);
					T.setMonth.call(T,this.calendar.month,false);
					T.day = this.calendar.day;
					T.sendValue.call(T)
				}
			},[day],tr)
	}
	var old_tbody = jso.gT('tbody',this.domTable)[0]
	if(old_tbody)
		this.domTable.replaceChild(tbody,old_tbody)
	else
		this.domTable.appendChild(tbody)
}

jso.calendar.prototype.sendValue=function()
{
	this.domInput.value = this.year + '-' + (this.month>8?'':'0') + (this.month+1) + '-' + ((this.day>9?'':'0')+this.day);
	this.close.call(this)
}

jso.calendar.prototype.clean=function()
{
	this.domInput.value = '';
	this.close.call(this)
}

jso.calendar.prototype.close=function()
{
	this.domCalendar.parentNode.removeChild(this.domCalendar)
	this.active = false
	this.domInput.disabled = false
}