
	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

	function basename(sciezka) { return sciezka.replace( /.*\//, "" ); } 
	
	function popup(url, x, y, nazwa) {
		var szer = x;
		var wys = y;
		
		if (nazwa == "") { nazwa = "okno"; }
		nazwa = nazwa.replace(/[^a-zA-Z0-9]/g, '_');

		var okno = window.open(url, nazwa, 'toolbar=0,location=0,directories=0,scrollbars=1,status=0,menubar=0,resizable=yes,width='+szer+',height='+wys);
		okno.moveTo(parseInt((screen.width - szer) / 2),parseInt((screen.height - wys) / 2));
		okno.focus();
	}

	function init() {
		
		var i;
		
		// dodaj animacje dla górnego menu
		var sections = document.getElementById('sections');
		if (sections) {
			var hrefs = sections.getElementsByTagName('a');
			for (i = 0; i < hrefs.length; i++) {
				hrefs.item(i).onmouseover = function() {this.style.background = "url('img/bg3.gif') repeat-x";}
				hrefs.item(i).onmouseout = function() {this.style.background = "";}
			}
		}
		
		// dopracuj animację lewego menu
		var menu = document.getElementById('side-menu');
		var items = menu.getElementsByTagName('li');
		for (i = 0; i < items.length; i++) 
		{
			if (items.item(i).parentNode.id == 'side-menu') // tylko elementy pierwszego poziomu
			{
				items.item(i).onmouseover = function() { this.style.background = "#1d7c31"; }
				items.item(i).onmouseout = function() { this.style.background = ""; }
			}
		}
		
	}
	
	function checkRegisterForm() {
	
		var f = document.forms['register'];
		
		if (!f.elements['email'].value.length) {
			alert("Musisz podać adres e-mail");
			return false;
		}
		
		if (!f.elements['email'].value.match(/^[a-zA-Z0-9-.+]+\@[a-zA-Z0-9-.]+\.[a-zA-Z]+$/)) {
			alert("Nieprawidłowy format adresu e-mail");
			return false;
		}

		if (!f.elements['name'].value.length) {
			alert("Musisz podać imię i nazwisko lub nazwę firmy");
			return false;
		}
		
		if (!f.elements['address'].value.length) {
			alert("Musisz podać adres");
			return false;
		}
		
		if (!f.elements['postal_code'].value.length) {
			alert("Musisz podać kod pocztowy");
			return false;
		}
		
		if (!f.elements['postal_code'].value.match(/^[0-9]{2}-[0-9]{3}$/)) {
			alert("Nieprawidłowy format kodu pocztowego");
			return false;
		}

		if (!f.elements['city'].value.length) {
			alert("Musisz podać miasto");
			return false;
		}
		
		if (!f.elements['nip'].value.length) {
			alert("Musisz podać NIP");
			return false;
		}
		
		if (!f.elements['nip'].value.match(/^[0-9-]+$/)) {
			alert("Nieprawidłowy format NIP");
			return false;
		}

		if (!f.elements['pesel_regon'].value.length) {
			alert("Musisz podać PESEL lub REGON");
			return false;
		}
		
		if (!f.elements['pesel_regon'].value.match(/^\d+$/)) {
			alert("Nieprawidłowy format PESEL lub REGON");
			return false;
		}
		
		return true;
	}
	
	function checkPersonalForm() {
	
		var f = document.forms['personal'];

		if (!f.elements['name'].value.length) {
			alert("Musisz podać imię i nazwisko lub nazwę firmy");
			return false;
		}
		
		if (!f.elements['address'].value.length) {
			alert("Musisz podać adres");
			return false;
		}
		
		if (!f.elements['postal_code'].value.length) {
			alert("Musisz podać kod pocztowy");
			return false;
		}
		
		if (!f.elements['postal_code'].value.match(/^[0-9]{2}-[0-9]{3}$/)) {
			alert("Nieprawidłowy format kodu pocztowego");
			return false;
		}

		if (!f.elements['city'].value.length) {
			alert("Musisz podać miasto");
			return false;
		}
		
		if (!f.elements['nip'].value.length) {
			alert("Musisz podać NIP");
			return false;
		}
		
		if (!f.elements['nip'].value.match(/^[0-9-]+$/)) {
			alert("Nieprawidłowy format NIP");
			return false;
		}

		if (!f.elements['pesel_regon'].value.length) {
			alert("Musisz podać PESEL lub REGON");
			return false;
		}
		
		if (!f.elements['pesel_regon'].value.match(/^\d+$/)) {
			alert("Nieprawidłowy format PESEL lub REGON");
			return false;
		}
		
		return true;
	}