function showPopup(url) {
    var wx;
	var wy;
    wx = (window.screen.width/2) - (200 + 10);
    wy = (window.screen.height/2) - (130 + 30);

    var w = window.open(url,"popup","status=no,height=320,width=400,resizable=no,left=" + wx + ",top=" + wy + ",screenX=" + wx + ",screenY=" + wy + ",scrollbars=yes");
    w.focus();
}

// function $(id) {
// 	if (typeof id != "object") 
// 		id = document.getElementById(id);
// 	return id;
// }

function getX(o) {
	o = $(o);
	if (o.offsetParent) return o.offsetLeft+getX(o.offsetParent);
	return o.offsetLeft;
}

function getY(o) {
	o = $(o);
	if (o.offsetParent) return o.offsetTop+getY(o.offsetParent);
	return o.offsetTop;
}

function Ajax() {
	this.request = null;

	this.initialize = function() {
		this.response = null;
		
		if (this.request == null) {
			if (typeof window.ActiveXObject != 'undefined' )
				this.request = new ActiveXObject("Microsoft.XMLHTTP");
			else 
				this.request = new XMLHttpRequest();
		}
		return this.request;
	}
	
	this.get = function(url,funkcja_wynikowa) {
		if (this.initialize() == null) return false;
		this.request.onreadystatechange = this.wynik(this,funkcja_wynikowa);
		this.request.open('GET',url,true);
		this.request.send(null);	
	}
	
	this.post = function(url,funkcja_wynikowa,tresc) {
		if (this.initialize() == null) return false;
		this.request.onreadystatechange = this.wynik(this,funkcja_wynikowa);
		this.request.open('POST',url,true);
		this.request.send(tresc);	
	}
	
	this.wynik = function(obAjax, funkcja_wynikowa) {
		return function() {
			if (obAjax.request.readyState == 4 && obAjax.request.status == 200) {
				funkcja_wynikowa(obAjax.request.responseText);
			}
		}
	}
}

function attachImg() {
	return function(wynik) {
		window.opener.location.reload();
	}
}

function wybierzObrazek(aktu,plik) {
	a = new Ajax();
	a.get('/adm/pzdj.php?aktu='+aktu+'&plik='+plik,attachImg());
}

function ml(usr,dmn) {
    document.write(
        '<a href="mailto:'+usr+'@'+dmn+'">'+usr+'@'+dmn+'</a>'
    );
}

function markdownEditResult(b) {
	return function(wynik) {
		document.getElementById(b).innerHTML = wynik;
	}
}

var _stara_wartosc_md = '';
function markdownEditEventTimeoutGen(a,b) {
	return function() {
		t = document.getElementById(a);
		if (t.value != _stara_wartosc_md) {
			_stara_wartosc_md = t.value;
			req = new Ajax();
			req.post('/mkdn.php',markdownEditResult(b),document.getElementById(a).value);
		}
	}
}

var _markdown_ta_id;
function markdownEditEventGen(a,b) {
	return function(evt) {
		window.clearTimeout(_markdown_ta_id);
		_markdown_ta_id = window.setTimeout(markdownEditEventTimeoutGen(a,b),500);
	}
}

function markdownEdit(a,b) {
	ta = document.getElementById(a);
	_markdown_ta_id = window.setTimeout(markdownEditEventTimeoutGen(a,b),1000);
	ta.onkeyup = markdownEditEventGen(a,b);
}

function dateUpdateDays(id) {
	var dni=new Array;
	dni=[[31,28,31,30,31,30,31,31,30,31,30,31],[31,29,31,30,31,30,31,31,30,31,30,31]];
	
	var rok=document.getElementById(id+'_y').value;
	var miesiac=document.getElementById(id+'_m').value;

	var p;
	if (rok % 400 == 0 || (rok % 4==0 && rok % 100 != 0)) p=1; else p=0;
	var d=dni[p][miesiac-1];

	var l=document.getElementById(id+'_d');
	var s = l.selectedIndex;
	l.options.length=0;
	var j=0;
	var i;
	for (i=1;i<=d;i++) l.options[j++]=new Option(i,i);
	if (s < l.options.length) l.selectedIndex = s; else l.selectedIndex = l.options.length-1;
}

function dateUpdateChange(id) {
	dateUpdateDays(id)
	return true;
}

function fillYear(id,rod,rdo) {
	var l=document.getElementById(id+'_y');
	l.options.length=0;
	var j=0;
	var i;
	for (i=rdo;i>=rod;i--) l.options[j++]=new Option(i,i);
	l.selectedIndex=0;
}

function fillDate(id,rod,rdo) {
	fillYear(id,rod,rdo);
	var l=document.getElementById(id+'_m');	
	var n;
	l.options.length=0;
	var j=0;
	var i;
	for (i=1;i<=12;i++) {
		n=i+''
		if (i < 10) n='0'+n;
		l.options[j++]=new Option(n,i);
	}
	l.selectedIndex=0;
	dateUpdateDays(id);
}
//z defaultami
function fillDate2(id) {
	var d = new Date();
	fillDate(id, d.getFullYear()-100, d.getFullYear());
}

function dateSet(id,r,m,d) {
	document.getElementById(id+'_y').value=r
	document.getElementById(id+'_m').value=m
	dateUpdateDays(id)
	document.getElementById(id+'_d').value=d
}

function pokaz_menu(l,m) {
	ukryj_menu();
	var x = getX(l);
	var y = getY(l);
	$(m).style.display = 'block';
	$(m).style.left = (x+5)+'px';
	$(m).style.top = (y+35)+'px';
}

function ukryj_menu() {
	anuluj_czas_menu();
	schowaj('menu_studio');
	schowaj('menu_statysta');
	schowaj('menu_klient');
}

var czas_mnu = false;
function czas_menu() {
	czas_mnu = window.setTimeout(ukryj_menu,100);
}

function anuluj_czas_menu() {
	if (czas_mnu) {
		window.clearTimeout(czas_mnu);
		czas_mnu = false;
	}
}

function pokaz(id) {
	var el = $(id);
	if (el == undefined) return;
	if (el.style == undefined) return;
	el.style.display = '';
}

function schowaj(id) {
	var el = $(id);
	if (el == undefined) return;
	if (el.style == undefined) return;
	el.style.display = 'none';
}

function showArray(a) {
	if (a.constructor != Array) return;
	for (var ob in a)
		pokaz(a[ob]);
}

function hideArray(a) {
	if (a.constructor != Array) return;
	for (var ob in a)
		schowaj(a[ob]);
}

function pokaz_poziomy(id) {
	var el = $('umiejetnosc_'+id);
	if (el == undefined) return;
	if (el.checked)
		pokaz('poziomy_'+id);
	else
		schowaj('poziomy_'+id);
}

//z defaultami
function dateSet2(id) {
	var d = new Date();
	dateSet(id, d.getFullYear(), d.getMonth()+1, d.getDate());
}

function zmien_status(pole, klient, status) {
	if (status == undefined) return;
	var req = new Ajax();
	req.get('/adm/status.php?pole='+pole+'&klient='+klient+'&status='+status, function() {});
}

function selectDay(id) {
	var h = $('hidden_'+id);
	if (h == undefined) return;
	var req = new Ajax();
	if (h.value == '1') {
		h.value = '0';
		removeClass('td_'+id, 'wybrany');
		req.get('ustaw_dzien.php?dzien='+id+'&wybrany=0');
	} else {
		h.value = '1';
		addClass('td_'+id, 'wybrany');
		req.get('ustaw_dzien.php?dzien='+id+'&wybrany=1');
	}
}

function removeClass(pole, klasa) {
	if ($(pole) != undefined) {
		var regboki = new RegExp("^"+klasa+"$|^"+klasa+" | "+klasa+"$");
		var regsrodek = new RegExp(" "+klasa+" ");
		var k = $(pole).className;
		k = k.replace(regboki, '');
		k = k.replace(regsrodek, ' ');
		$(pole).setAttribute('class', k);
		$(pole).setAttribute('className', k);
	}
}

function addClass(pole, klasa) {
	var p = $(pole);
	if (p == undefined) return;
	var k = p.className+' '+klasa;
	p.setAttribute('class', k);
	p.setAttribute('className', k);
}

function setCursor(co, curs) {
	var c = $(co);
	if (c == undefined) return;
	c.style.cursor = curs;
}

var _i = new Image(1,1);
_i.src = '/img/v2/menu/main/hover/m.png';
_i.src = '/img/v2/menu/main/hover/l.png';
_i.src = '/img/v2/menu/main/hover/r.png';



function hideFlowPlayer(div, fp) {
	if (!flowplayer(fp).isHidden()) {
		flowplayer(fp).stop(); 
		flowplayer(fp).hide();
		$(div).style.display='none';
	}
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function Hint(id,content) {
	this.hint = null;
	this.ofsX = 10;
	this.ofsY = 10;
	var o = this;
	document.getElementById(id).onmousemove = function (e) {
		if (!e) var e = window.event;
		if (o.hint == null) {
			o.hint = document.createElement("div");
			o.hint.innerHTML = content;
			o.hint.setAttribute("className","hintClassic");
			o.hint.setAttribute("class","hintClassic");
			o.hint.style.display = 'none';
			document.getElementById('main').appendChild(o.hint);		
		}
		xy = getScrollXY();
		o.hint.style.left=(e.clientX+xy[0]+o.ofsX)+'px';
		o.hint.style.top=(e.clientY+xy[1]+o.ofsY)+'px';
		o.hint.style.display = '';
	}
	document.getElementById(id).onmouseout = function (e) {
		o.hint.style.display = 'none';
		o.hint = null;
	}
}

