	var loading_img = document.createElement('img');
	loading_img.src = 'images/progress.gif';
	loading_img.width = '50';
	loading_img.height = '27';
	
	var pnn=(document.layers) ? true : false;
	var pn6=(navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
	var pie=false;
	var pop=false;
	if (document.all){ if (navigator.userAgent.search('Opera')>=0){ pie=false; pop=true;} else {pie=true; pop=false;}}
	
	function Cover(del, func) {
		if (del == true) {
			var a = document.getElementById('cover');
			if (a) {a.parentNode.removeChild(a);}
			var a = document.getElementById(func);
			if (a) {a.parentNode.removeChild(a);}
			$A(document.getElementsByTagName('select')).each(function(s) {s.style.display=''});
		} else {
			$A(document.getElementsByTagName('select')).each(function(s) {s.style.display='none'});
			var a = document.createElement('div');
			a.id = 'cover';
			a.style.height = (pie == false && pop == false) ? document.height + 'px' : document.body.scrollHeight + 'px';
			a.style.width = document.documentElement.scrollWidth + 'px';
			var cov = document.getElementById('body').appendChild(a);
			if (func != null ) eval(func);
		}
	}
	
	function Cancel() {
		window.location.reload();
	}

	function getScrollXY() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}

	function PrintAlertBox(msg) {
		var sc = getScrollXY();
		var box = document.createElement('div');
		var title = document.createElement('div');
		with (title) {
			className = 'box_title';
			innerHTML = msg;
		}
		box.id = 'alert_box';		
		var box = document.body.appendChild(box);
		var title = box.appendChild(title);
		var canc_btn = document.createElement('a');
		with (canc_btn) {
			canc_btn.onclick = function () { Cover(true, 'alert_box');  return false;}
			canc_btn.href = '';
			canc_btn.innerHTML = 'OK';
			canc_btn.className = 'cancel';
		}
		box.appendChild(canc_btn);
		var left = (sc[0] + Math.floor(document.documentElement.clientWidth / 2) - Math.floor(box.offsetWidth / 2)) + 'px';
		var top = (sc[1] + Math.floor(document.documentElement.clientHeight / 2) - Math.floor(box.offsetHeight / 2)) + 'px';
		with (box) {
			style.left = left;
			style.top = top;
		}
	}

	function PrintFormErrorBox(element, msg) {
		var sc = getScrollXY();
		var box = document.createElement('div');
		var title = document.createElement('div');
		with (title) {
			className = 'box_title';
			innerHTML = msg;
		}
		box.id = 'error_box';		
		var box = document.body.appendChild(box);
		var title = box.appendChild(title);
		var canc_btn = document.createElement('a');
		with (canc_btn) {
			canc_btn.onclick = function () { Cover(true, 'error_box'); element.focus(); return false;}
			canc_btn.href = '';
			canc_btn.innerHTML = 'OK';
			canc_btn.className = 'cancel';
		}
		box.appendChild(canc_btn);
		var left = (sc[0] + Math.floor(document.documentElement.clientWidth / 2) - Math.floor(box.offsetWidth / 2)) + 'px';
		var top = (sc[1] + Math.floor(document.documentElement.clientHeight / 2) - Math.floor(box.offsetHeight / 2)) + 'px';
		with (box) {
			style.left = left;
			style.top = top;
		}
	}

	function PrintErrorBox(msg) {
		var sc = getScrollXY();
		var box = document.createElement('div');
		var title = document.createElement('div');
		with (title) {
			className = 'box_title';
			innerHTML = msg;
		}
		box.id = 'error_box';		
		var box = document.body.appendChild(box);
		var title = box.appendChild(title);
		var canc_btn = document.createElement('a');
		with (canc_btn) {
			canc_btn.onclick = function () { Cover(true, 'error_box');  return false;}
			canc_btn.href = '';
			canc_btn.innerHTML = 'OK';
			canc_btn.className = 'cancel';
		}
		box.appendChild(canc_btn);
		var left = (sc[0] + Math.floor(document.documentElement.clientWidth / 2) - Math.floor(box.offsetWidth / 2)) + 'px';
		var top = (sc[1] + Math.floor(document.documentElement.clientHeight / 2) - Math.floor(box.offsetHeight / 2)) + 'px';
		with (box) {
			style.left = left;
			style.top = top;
		}
	}

	function PrintProgressBox(msg, cancelbtn) {
		var sc = getScrollXY();
		var box = document.createElement('div');
		var title = document.createElement('div');
		box.id = 'progress_box';
		with (title) {
			className = 'box_title';
			innerHTML = msg;
		}
		var box = document.body.appendChild(box);
		box.appendChild(loading_img);
		var title = box.appendChild(title);
		if (!cancelbtn) {
			var canc_btn = document.createElement('a');
			with (canc_btn) {
				canc_btn.onclick = function () { Cancel(); return false;}
				canc_btn.href = '';
				canc_btn.innerHTML = 'Anuluj';
				canc_btn.className = 'cancel';
			}	
			box.appendChild(canc_btn);
		}		
		var left = (sc[0] + Math.floor(document.documentElement.clientWidth / 2) - Math.floor(box.offsetWidth / 2)) + 'px';
		var top = (sc[1] + Math.floor(document.documentElement.clientHeight / 2) - Math.floor(box.offsetHeight / 2)) + 'px';
		with (box) {
			style.left = left;
			style.top = top;
		}
	}	
	
	function changePanel(id) {
		if (id == 1) {
			$('f_btn_epoch').className = 'btn1_act';
			$('f_btn_issue').className = 'btn2_inact';
			$('f_epoch').style.display = '';
			$('f_issue').style.display = 'none';			
		} else {
			$('f_btn_epoch').className = 'btn1_inact';
			$('f_btn_issue').className = 'btn2_act';
			$('f_epoch').style.display = 'none';
			$('f_issue').style.display = '';
		}
	}

	function changeProfilePanel(id) {
		if (id==3){
			$('panel_btn1').className = 'panel_btn1_inact';
			$('panel_btn2').className = 'panel_btn2_inact';
			$('panel_btn3').className = 'panel_btn3_act';
			$('my_orders').className = 'panel_inactive';
			$('my_profil').className = 'panel_inactive';
			$('my_products').className = 'panel_active';		
		} else if (id==2) {
			$('panel_btn1').className = 'panel_btn1_inact';
			$('panel_btn2').className = 'panel_btn2_act';
			$('panel_btn3').className = 'panel_btn3_inact';
			$('my_orders').className = 'panel_inactive';
			$('my_profil').className = 'panel_active';
			$('my_products').className = 'panel_inactive';		
		} else {
			$('panel_btn1').className = 'panel_btn1_act';
			$('panel_btn2').className = 'panel_btn2_inact';
			$('panel_btn3').className = 'panel_btn3_inact';
			$('my_orders').className = 'panel_active';
			$('my_profil').className = 'panel_inactive';
			$('my_products').className = 'panel_inactive';		
		}
	}
	
	function showCont(id) {
		var btn = $('cont_btn_' + id);
		if (btn != null){
			if (btn.className == 'cont_btn_show') {
				btn.className = 'cont_btn_hide';
				$('cont_' + id).className = 'cont_visible';
			} else {
				btn.className = 'cont_btn_show';
				$('cont_' + id).className = 'cont_hidden';
			}
		}
	}
	
	function manageOrderCont(id) {
		if ($('order_cont_'+id).className == 'order_cont_hidden') {
			$('order_cont_'+id).className = 'order_cont_shown';
			$('order_cont_btn_'+id).innerHTML = 'ukryj';
		} else {
			$('order_cont_'+id).className = 'order_cont_hidden';
			$('order_cont_btn_'+id).innerHTML = 'pokaż';
		}
	}
	
	function catchError(response) {
		switch (response) {
			case '-2': {
				Cover(true, 'progress_box');
				Cover(false, "PrintAlertBox('Aby dodawać materiały do koszyka,<br> musisz się zalogować.')");
				return false;
			}
			case '-3': {
				Cover(true, 'progress_box');
				Cover(false, "PrintAlertBox('Ten plik już jest w koszyku.')");
				return false;
			}
			case '-4': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Brak wymaganego parametru.')");
				return false;
			}
			case '-5': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Wersja produktu jest niepoprawna.')");
				return false;
			}
			case '-6': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Nie ma takiego pliku w bazie danych.')");
				return false;
			}
			case '-7': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Wystąpił nieoczekiwany błąd.')");
				return false;
			}
			case '-8': {
				Cover(true, 'progress_box');
				Cover(false, "PrintAlertBox('Ten plik jest elementem zestawu znajdującego się już w koszyku.')");
				return false;
			}
			case '-10': {
				Cover(true, 'progress_box');
				Cover(false, "PrintAlertBox('Ten plik nie został dodany do koszyka.')");
				return false;
			}
			case '-11': {
				Cover(true, 'progress_box');
				Cover(false, "PrintAlertBox('Ten zestaw nie został dodany do koszyka.')");
				return false;
			}
			case '-12': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Błąd w poście.')");
				return false;
			}
			case '-13': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Błąd zapisu do bazy danych SQL.')");
				return false;
			}
			case '-14': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Błąd w zapytaniu do bazy danych SQL.')");
				return false;
			}
			case '-15': {
				Cover(true, 'progress_box');
				Cover(false, "PrintFormErrorBox($('form_login'), 'Podany login jest zajęty przez innego użytkownika.')");
				return false;
			}
			case '-16': {
				Cover(true, 'progress_box');
				Cover(false, "PrintFormErrorBox($('form_old_password'), 'Podane hasło jest niepoprawne.')");
				return false;
			}
			case '-17': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Nie jesteś zalogowany.')");
				return false;
			}
			case '-18': {
				Cover(true, 'progress_box');
				Cover(false, "PrintErrorBox('Twój koszyk jest pusty.')");
				return false;
			}
			case'-19':{Cover(true,'progress_box');Cover(false,"PrintErrorBox('Nie ma takiego loginu w bazie danych.')");return false;}
			case '-666': {
				Cover(true, 'progress_box');
				Cover(false, "PrintAlertBox('Trwają jeszcze prace nad systemem płatności online. Teraz możliwe jest korzystanie tylko z materiałów demonstracyjnych. Są one dostępne po kliknięciu w wybrany dział w lewym menu.')");
				return false;
			}		
			default: {
				return true;
			}	
		}
	}
	
	function repaintBoxes() {
		Cover(false, "PrintProgressBox('Trwa odświeżanie strony...')");
		loadSmallCart();
		loadLargeCart();
		loadAccount(); //w ostatniej funkcji musi byc Cover(true,...);
	}

	function repaintBoxes2() {
		Cover(false, "PrintProgressBox('Trwa odświeżanie strony...')");
		loadLogonBox();
		loadAccount(); //w ostatniej funkcji musi byc Cover(true,...);		
	}	
