
//var menus = [
//new ypSlideOutMenu("menuSzkolenia", "down", 0,0,160,240),
//new ypSlideOutMenu("menuPublikacje", "down", 0, 0, 160, 240),
//new ypSlideOutMenu("menuKontakt", "down", 0, 0, 120, 240),
//new ypSlideOutMenu("menuONas", "down", 0, 0, 160, 240),
//]

function getWindowWidth() {
	return window.innerWidth ? window.innerWidth : document.body.offsetWidth;
}

//Written by Bogdan Blaszczak/BlaTek
//blatek@25.pl
//function Calendar(E,T){
//	if(!document.getElementById||!document.body.appendChild)return
//	var i,j,tBody,Row,od,Do,d,dt
//	function cEl(t,p,h,w){
//		p.appendChild(t=document.createElement(t))
//		if(h)t.innerHTML=h;if(w)t.style.width='27px'
//		return t}
//		function cB(x){with(cld_BlaTek){
//			B=0;x==0?R--:x==1?R++:x==2?(!M?(M=11,R--):M--):(M==11?(M=0,R++):M++)}
//		}
//		with(cld_BlaTek){
//			od=Date.UTC(R,M,1);Do=Date.UTC(R,M+1,1)}
//			E=document.getElementById(E)
//			while(E.childNodes.length)E.removeChild(E.firstChild)
//			tBody=cEl('tbody',cEl('table',E))
//			tBody.onmouseup=function(){T.focus()}
//			tBody.onmousemove=function(){
//				if(window.getSelection)window.getSelection().removeAllRanges()}
//				Row=cEl('tr',tBody)
//				cEl('td',Row,'&laquo;',1).onmousedown=function(){cB(0)}
//				cEl('th',Row,cld_BlaTek.R)
//				cEl('td',Row,'&raquo;',1).onmousedown=function(){cB(1)}
//				Row=cEl('tr',tBody)
//				cEl('td',Row,'&laquo;',1).onmousedown=function(){cB(2)}
//				cEl('th',Row,cld_BlaTek.month[cld_BlaTek.M])
//				cEl('td',Row,'&raquo;',1).onmousedown=function(){cB(3)}
//
//				tBody=cEl('tbody',cEl('table',E))
//				Row=cEl('tr',tBody)
//				for(i=0;i<7;i++)
//				with(cEl('th',Row,cld_BlaTek.day[i]))
//				if(i==6)style.backgroundColor='#f88'
//
//				for(i=od;i<Do;i+=86400000){
//					with(new Date(i)){d=getUTCDate();dt=getUTCDay()}
//					if(dt==1||i==od)Row=cEl('tr',tBody)
//					if(dt!=1&&d==1)for(j=1;j<(dt?dt:7);j++)cEl('th',Row)
//					dt=cEl('td',Row,d);dt.onmousedown=function(x){
//						x=+this.innerHTML
//						with(cld_BlaTek)
//						T.value=(x<10?'0'+x:x)+'-'+((x=M+1)<10?'0'+x:x)+'-'+R
//					}
//					with(cld_BlaTek)
//					if(d==D.getDate()&&M==D.getMonth()&&R==D.getFullYear())
//					dt.style.backgroundColor='#ccffff'
//				}
//				T.onblur=function(){if(cld_BlaTek.B)E.style.display='none'}
//				cld_BlaTek.B=1;E.style.display='block'
//}
//
//
////global object (You can translate month&day names)
//cld_BlaTek={
//		day:['pn','wt','śr','cz','pt','so','n'],
//		month:['styczeń','luty','marzec','kwiecień','maj','czerwiec',
//		'lipiec','sierpień','wrzesień','październik','listopad','grudzień'],
//		D:new Date(),M:new Date().getMonth(),R:new Date().getFullYear()
//}

function WinOpen() {
	var i,e = document.getElementById('StrefaDrukowania');
	msg=open("","Window","toolbar=no,directories=no,menubar=no,width=400,height=300");
	//	msg.document.write("Hello");
	W=e.getElementsByTagName('div');
	for(i=0;i<W.length;i++)
	if (W[i].className=='print')
	msg.document.write(W[i].innerHTML);
}

//function Prnt(x){
// var i,strefa=document.getElementById('strefaDrukowania'),
//  W=strefa.getElementsByTagName('div')
// for(i=0;i<W.length;i++)
//  W[i].className=x.parentNode==W[i]?'noprint':'print';
//  alert(W[0]);
// window.print()
//}

function Prnt(x) {
	w = window.open('','printable');
	document.getElementById('strefaDrukowania').className='print';
	setTimeout("w.document.body.innerHTML=document.getElementById('strefaDrukowania').innerHTML", 1110);

	setTimeout('w.print()', 1200);
	setTimeout('w.close()', 1200);


}

function PrntAll(){
	var i,strefa=document.getElementById('strefaDrukowania'),
	W=strefa.getElementsByTagName('div')
	for(i=0;i<W.length;i++)
	W[i].className='print'
	window.print()
}

function changeType(sekcja)
{
	var fieldTyp=document.f.elements['seltyp'];
	var typ = fieldTyp.options[fieldTyp.selectedIndex].value
	alert(typ);

	document.f.action='pola.php?action=change';
	document.f.method='POST';
	document.f.submit();
}

function makeGrey(id,txt)
{
	if (document.all)
	{
		document.all[id].innerHTML='<span style="color:#000000">'+txt+'</span>';
	}
	else
	{
		x=document.getElementById(id); x.style.color="#000000";
	}
}

function makeRed(id,txt)
{
	if (document.all)
	{
		document.all[id].innerHTML='<span style="color:#ff0000">'+txt+'</span>';
	}
	else
	{
		x=document.getElementById(id); x.style.color="#ff0000";
	}
}

function makeGrey(id)
{
	x=document.getElementById(id);
	x.style.color="#000000";
}

function makeRed(id)
{
	x=document.getElementById(id);
	x.style.color="#ff0000";
}
/* Walidacja komentarzy ******************************************************/
function commentFormSubmit() {
	if (commentForm.komentarz.value.length>0) {
		commentForm.submit();
	}
	else {
		alert('Tekst komentarza nie może być pusty.');
		commentForm.komentarz.focus();
	}
};
function commentHistoryBack(p_location) {
	document.location = p_location;
}

/* Zarządzanie gridem ********************************************************/
var markRowNumber = -1;

function markingRow(p_markRow) {
	if (markRowNumber != -1) {
		eval('idRow_'+markRowNumber+'.className="aaa";');
	}
	markRowNumber = p_markRow;
	eval('idRow_'+markRowNumber+'.className="tr-mark";');
}
function deleteRow(p_url) {
	if (confirm('Czy na pewno chcesz usun?ć te dane?')) {
		document.location = p_url;
	}
}
function editRow(p_url) {
	document.location = p_url;
}
function addRow(p_url) {
	document.location = p_url;
}

// ----------------------------------------------------------------------------
function ListOrOther(p_idList, p_nameText, p_checkbox) {
	var fieldText = document.all(p_nameText);
	if (p_checkbox.checked) {
		fieldText.disabled = "";
		fieldText.focus();
		document.all(p_idList).disabled = "disabled";
	}
	else {
		fieldText.disabled = "disabled";
		document.all(p_idList).disabled = "";
	}
	//		document.all(p_idList).style.display = "";
}
// ----------------------------------------------------------------------------
function CheckboxesOrOther(p_idList, p_nameText, p_checkbox) {
	var field = document.all(p_nameText);
	if (p_checkbox.checked) {
		field.disabled = "";
		field.focus();
	}
	else {
		field.disabled = "disabled";
	}
}
// ----------------------------------------------------------------------------
function ChangeVisible(p_checkbox, p_id) {
	var checked = false;
	if (p_checkbox.checked) {
		document.all(p_id).style.display = "";
	}
	else {
		document.all(p_id).style.display = "none";
	}
}
var popup;
function FindFirm() {
	NewWindowCenter('rec-findFirm.php?clearWhere=true', '', 500, 400);
};
function NewWindowCenter(p_url, p_name, p_width, p_height) {
	if (popup) {
		popup.close();
	}
	gora=(screen.height-p_height)/2 / 2;
	lewo=(screen.width-p_width)/2 / 2 ;
	popup = window.open(p_url, p_name, "toolbar=no,menubar=no,scrollbars=yes, resizable=yes,status=yes,location=no,directories=no,top="+gora+",left="+lewo+",height="+p_height+",width="+p_width);
	popup.focus();
//	ActivFirm('readOnly', '-readonly');
};

function NewFirm() {
	ClearFirm();
	ActivFirm(false, '');
};
function EmptyFirm() {
	ClearFirm();
	ActivFirm('readOnly', '-readonly');
}
function ClearFirm() {
	document.all('firm[nip]').value = '';
	document.all('firm[name]').value = '';
	document.all('firm[street]').value = '';
	document.all('firm[code]').value = '';
	document.all('firm[city]').value = '';
	document.all('firm[employees]').value = '';
	document.all('firm[sales]').value = '';
	document.all('firm[phone]').value = '';
	document.all('firm[fax]').value = '';
	document.all('firm[idFirm]').value = '';
};
function EditFirm() {
	ActivFirm(false, '');
}
// ----------------------------------------------------------------------------
function ActivFirm(p_active, p_className) {
	try {
		classNameTextarea = 'textarea-small'+p_className;
		p_className = 'inred-long'+p_className;

		document.all('firm[nip]').readOnly = p_active;
		document.all('firm[name]').readOnly = p_active;
		document.all('firm[street]').readOnly = p_active;
		document.all('firm[code]').readOnly = p_active;
		document.all('firm[city]').readOnly = p_active;
		document.all('firm[employees]').readOnly = p_active;
		document.all('firm[sales]').readOnly = p_active;
		document.all('firm[phone]').readOnly = p_active;
		document.all('firm[fax]').readOnly = p_active;
		document.all('firm[idFirm]').readOnly = p_active;

		document.all('firm[nip]').className = p_className;
		document.all('firm[name]').className = p_className;
		document.all('firm[street]').className = classNameTextarea;
		document.all('firm[code]').className = p_className;
		document.all('firm[city]').className = p_className;
		document.all('firm[employees]').className = p_className;
		document.all('firm[sales]').className = p_className;
		document.all('firm[phone]').className = p_className;
		document.all('firm[fax]').className = p_className;
		document.all('firm[idFirm]').className = p_className;
	}
	catch (ex) {
		alert('Error in ActiveFirm');
	}
}
// ----------------------------------------------------------------------------
var lastKey;
// ----------------------------------------------------------------------------
function KeyClick(e, codeNumber, functionEval) {
	//alert('start');
	var keynum;

	if (window.event) { // IE
		keynum = e.keyCode;
	}
	else if (e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}
	//alert("key: " + keynum);
	if (keynum==codeNumber) {
		//eval(functionEval);
		functionEval();
	}
	lastKey = keynum;
	return ;
	//keychar = String.fromCharCode(keynum);
	// NS 17 - CTRL
	// NS 78 - N
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Zmienna globalna do przechowywania kwoty płatno?ci za imprezę
var summaryPaymentAmount = 0;
// ----------------------------------------------------------------------------
// Zmiana globalna do przechowywania kwoty za opłatę
var paymentAmount = 0;
// ----------------------------------------------------------------------------
// Zmienna globalna do przechowywania kwoty za pokój
var hotelRoomAmount = 0;
// liczba terminów noclegów
var roomTermCount = 0;
// suma opłaty za noclegi (terminy * opłata)
// ----------------------------------------------------------------------------
// suma opłaty za warsztaty
var practicalAmount = 0;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Zdarzenie podpiane na zmianę warto?ci płatno?ci za imprezę
function CalculatePayment(p_value) {
	paymentAmount = p_value;
	CalculateSummary(); // wyliczenie na nowo warto?ci podpowiadanej kwoty całkowitej
}
// ----------------------------------------------------------------------------
// Uwzględnia w podsumowaniu opłaty za noclegi
function CalculateHotelRoom(p_add, p_amount) {
	if (p_add) {
		hotelRoomAmount = p_amount;
	}
	CalculateSummary();
}
// ----------------------------------------------------------------------------
// zliczanie ilo?ci noclegów
function CalculateRoomTerm(p_add) {
	if (p_add) {
		roomTermCount++;
	}
	else {
		roomTermCount--;
	}
	CalculateSummary();
}
// ----------------------------------------------------------------------------
// Uwzglednia w podsumowaniu opłaty za zajęcia praktyczne
function CalculatePractical(p_add, p_amount) {
	if (p_add) {
		practicalAmount += p_amount;
	}
	else {
		practicalAmount -= p_amount;
	}
	CalculateSummary();
}
// ----------------------------------------------------------------------------
// Metoda do wyliczania i ustawiania całkowietej podpowiadanej kwoty do zapłaty
function CalculateSummary() {
	summaryPaymentAmount = paymentAmount + hotelRoomAmount*roomTermCount + practicalAmount;
//	alert('hotelRoomAmount: ' + hotelRoomAmount + ', roomTermCount: ' + roomTermCount);
	SetPromptSummary();
}
// ----------------------------------------------------------------------------
// ustawia podpowiedĽ
function SetPromptSummary() {
	try {
		document.getElementById('summaryPrompt').innerHTML = summaryPaymentAmount;
	}
	catch (ex) {
		// nic nie wykonujemy - chodzi o sprawdzenie czy jest to pole juz zdefiniowane
	}
}
// ustawia podpowiedĽ
function SetUserSummary() {
	try {
		document.getElementById('summary').value = summaryPaymentAmount;
	}
	catch (ex) {
	}
}

// ----------------------------------------------------------------------------
// tablica z limitami pokoi
var arrayLimit = new Array();
var arraySleepActual = new Array();
// ----------------------------------------------------------------------------
// ustawia limity na noclegi
function SetLimit(p_limit, p_idHotelRoom) {
	var limitInfo;
	for(var i=0; i<arrayLimit.length; i++) {
		// ustawienie domy?lnego tesktu (czyli zero przez liczba pokoi)
		document.getElementById(arrayLimit[i]).innerHTML = '0/' + p_limit;
		try {
			idRoomTerm = arrayLimit[i].substr(6);
//				alert('SetLimit: ' + p_limit + ', length: ' + arrayLimit.length + ' p_idHotelRoom: ' + p_idHotelRoom + ', idRoomTerm: ' + idRoomTerm );

			// liczba osób które dokonały rejestracji
			var actualValue = arraySleepActual[p_idHotelRoom][idRoomTerm]['roomCountPerson'];
			// liczba zajętych miejsc hotelowych
			var actualPlace = arraySleepActual[p_idHotelRoom][idRoomTerm]['roomCountPlace'];
			// dodatkowe osoby
			var extraPerson = arraySleepActual[p_idHotelRoom][idRoomTerm]['sumHotelExtraPerson'];

			actualValue = actualValue>0 ? actualValue : 0;
			actualPlace = actualPlace>0 ? actualPlace : 0;

			// ustawienie tekstów limitów na formularzu
			limitInfo = actualPlace + '/' + p_limit + '&nbsp;&nbsp;&nbsp;';
			limitInfo += '(Liczba rezerwacji: ' + actualValue + ', ';
			limitInfo += 'w tym dodatkowe osoby: ' + extraPerson;
			limitInfo += ')';
			document.getElementById(arrayLimit[i]).innerHTML = limitInfo;
		}
		catch (ex) {
			// bł?d zawsze występuję ponieważ nie sprawdzam czy element jest dostępny
			//alert('Wyst?pił problem z ustawianiem limitów: ' + '\n' + ex.message );
		}
	}
}
// ustawia limity na noclegi (dla otwartej rejestracji)
function SetLimitUser(p_limit, p_idHotelRoom) {

	var limitInfo;
	for(var i=0; i<arrayLimit.length; i++) {
		// ustawienie domy?lnego tesktu (czyli zero przez liczba pokoi)
		//document.getElementById(arrayLimit[i]).innerHTML = '0/' + p_limit;
		try {
			idRoomTerm = arrayLimit[i].substr(6);
//				alert('SetLimit: ' + p_limit + ', length: ' + arrayLimit.length + ' p_idHotelRoom: ' + p_idHotelRoom + ', idRoomTerm: ' + idRoomTerm );

			// liczba osób które dokonały rejestracji
			var actualValue = arraySleepActual[p_idHotelRoom][idRoomTerm]['roomCountPerson'];
			// liczba zajętych miejsc hotelowych
			var actualPlace = arraySleepActual[p_idHotelRoom][idRoomTerm]['roomCountPlace'];
			// dodatkowe osoby
			var extraPerson = arraySleepActual[p_idHotelRoom][idRoomTerm]['sumHotelExtraPerson'];

			actualValue = actualValue>0 ? actualValue : 0;
			actualPlace = actualPlace>0 ? actualPlace : 0;

			// ustawienie tekstów limitów na formularzu
			limitInfo = actualPlace + '/' + p_limit + '&nbsp;&nbsp;&nbsp;';
			limitInfo += '(Liczba rezerwacji: ' + actualValue + ', ';
			limitInfo += 'w tym dodatkowe osoby: ' + extraPerson;
			limitInfo += ')';

			limitInfo = (p_limit-actualPlace)>0 ? 'Brak miejsc' : '';
			document.getElementById(arrayLimit[i]).innerHTML = limitInfo;
		}
		catch (ex) {
			// bł?d zawsze występuję ponieważ nie sprawdzam czy element jest dostępny
			//alert('Wyst?pił problem z ustawianiem limitów: ' + '\n' + ex.message );
		}
	}
}
