//<!--

	var wojewodztwa = new Array();
	wojewodztwa['2'] = 'dolnośląskie';
	wojewodztwa['4'] = 'kujawsko-pomorskie';
	wojewodztwa['6'] = 'lubelskie';
	wojewodztwa['8'] = 'lubuskie';
	wojewodztwa['10'] = 'łódzkie';
	wojewodztwa['12'] = 'małopolskie';
	wojewodztwa['14'] = 'mazowieckie';
	wojewodztwa['16'] = 'opolskie';
	wojewodztwa['18'] = 'podkarpackie';
	wojewodztwa['20'] = 'podlaskie';
	wojewodztwa['22'] = 'pomorskie';
	wojewodztwa['24'] = 'śląskie';
	wojewodztwa['26'] = 'świętokrzyskie';
	wojewodztwa['28'] = 'warmińsko-mazurskie';
	wojewodztwa['30'] = 'wielkopolskie';
	wojewodztwa['32'] = 'zachodniopomorskie';
		
	function go_to(where)
	{
		document.formularz.elements.menu.value = where;
		document.formularz.submit();
	}
	
	function turnOn( co, stan, klasa )
	{
		document.formularz.elements[co].disabled = (1-stan);
		document.formularz.elements[co].className = klasa;
		if(!stan)
		{
			document.formularz.elements[co].value = '';
		}
	}
	
	function turnOnOption( co, numer, stan, klasa )
	{
		document.formularz.elements[co].item(numer).disabled = (1-stan);
		document.formularz.elements[co].item(numer).className = klasa;
		if(!stan)
		{
			document.formularz.elements[co].item(numer).value = '';
		}

		if(numer==0) opcja="t";
		else if(numer==1) opcja="n";
		else if(numer==2) opcja="nd";

		if( document.getElementById("label_"+co+opcja) )
		{
			if( stan )	document.getElementById("label_"+co+opcja).className='black';
			else		document.getElementById("label_"+co+opcja).className='gray';
		}
	}
	
	function invisible( co, stan )
	{
		if(stan)
			document.formularz.elements[co].style.display = 'none';
		else
			document.formularz.elements[co].style.display = ''; 
	}		

	function invisible_id( co, stan )
	{
		if(stan)
		{
			var ni = document.getElementById( co );
			ni.style.display = 'none';
		}
		else
		{
			var ni = document.getElementById( co );
			ni.style.display = ''; 
		}
	}
		
	function open_help( temat, szer, wys, priorytet )
	{
		url = 'pomoc.php?temat=' + temat+'&priorytet='+priorytet;
		w=window.open(url,'help','resizable,scrollbars,height='+wys+',width='+szer);			
	}
		
	function checknip( nipstr, info_id )
	{
		ni = document.getElementById( info_id );
		if( nipstr == '') { ni.style.display = 'none'; return; }
		mnozniki = new Array ( 6, 5, 7, 2, 3, 4, 5, 6, 7 ); //cyfry przez ktre bdziemy mnoy
		nipstr = nipstr.replace ( /-/g, "" ); //usuwanie "-" w numerze
		nip = new Array();
		nip = nipstr.split(""); // zamiana stringa na list cyfr
		suma = 0;
		dlugosc = nip.length;
		
		if(dlugosc!=10) { ni.style.display = ''; return; }
			
		for(p=0; p < dlugosc-1; p++)
			suma += nip[p] * mnozniki[p];
		cyfra_kontrolna = (suma % 11); // liczy: suma mod 11
		cyfra_kontrolna = (cyfra_kontrolna % 10);
		//alert( suma + ' | ' + cyfra_kontrolna + ' | ' + dlugosc + ' | ' + nipstr );
		
		if (cyfra_kontrolna == nip[9])
			ni.style.display = 'none';
			//return( true );
		else
			ni.style.display = ''; 
			//return( false );
	}	

	function checkregon( regonstr, info_id )
	{
		ni = document.getElementById( info_id );
		if( regonstr == '') { ni.style.display = 'none'; return; }
		
		mnozniki9  = new Array ( 8, 9, 2, 3, 4, 5, 6, 7 ); //cyfry przez kt䳥 b륺iemy mno࠹捊		mnozniki14 = new Array ( 2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8 ); //cyfry przez kt䳥 b륺iemy mno࠹捊
		regon = new Array();
		regon = regonstr.split(""); // zamiana stringa na listꡣyfr
		suma = 0;
		dlugosc = regon.length
		
		if( ( dlugosc != 9 ) && ( dlugosc != 14 ) ) { ni.style.display = ''; return; }
		
		for(p=0; p < dlugosc-1; p++)
			if( dlugosc==9 )
				suma += regon[p] * mnozniki9[p];
			else
				suma += regon[p] * mnozniki14[p];
				
		cyfra_kontrolna = (suma % 11); // liczy: suma mod 11
		cyfra_kontrolna = (cyfra_kontrolna % 10);
		//alert( suma + ' | ' + cyfra_kontrolna + ' | ' + dlugosc + ' | ' + regonstr );
		
		if (((dlugosc==9) && (cyfra_kontrolna == regon[8])) || ((dlugosc==14) && (cyfra_kontrolna == regon[13])))
			ni.style.display = 'none';
			//return( true );
		else
			ni.style.display = ''; 
			//return( false );
	}
	
	function checkkodp( kodpocztowy, opis_id )
	{
		ni = document.getElementById( opis_id );
		if( kodpocztowy == '') { ni.style.display = 'none'; return; }
		kod = new Array();
		kod = kodpocztowy.split(""); // zamiana stringa na list cyfr
		dlugosc = kodpocztowy.length;
		if(dlugosc!=6) { ni.style.display = ''; return; }
		
		kod_ok = true;
		for(i=0; i<dlugosc; i++)
		{
			if(i!=2)
			{
				if(isNaN(kod[i]))
				{
					kod_ok=false;
					break;
				}
			}
			else
			{
				if(kod[i]!='-')
				{
					kod_ok=false;
					break;
				}
			}
		}
		
		if ( kod_ok )
			ni.style.display = 'none';
			//return( true );
		else
			ni.style.display = ''; 
			//return( false );
	}
		
	function checkiban( iban_field, info_id )
	{
		ni = document.getElementById( info_id );
		iban = iban_field.value;
		if( iban == '') { ni.style.display = 'none'; return; }
		
		iban = iban.replace ( /\W/g, '' ); //usuwamy wszystko poza literami i cyframi
		iban = iban.toUpperCase();
		dlugosc = iban.length;
		bezkraju = false;
		if(dlugosc==26) { iban = 'PL' + iban; dlugosc = iban.length; bezkraju = true; }	//uzupełniamy o kod kraju		
		if(dlugosc!=28) { ni.style.display = ''; return; }
		
		country = iban.substr(0,2);
		check = iban.substr(2,2);
		account = iban.substr(4, iban.length-4 );
		country_converted = '';
		for(icc=0; icc<country.length; icc++)
		{
			country_converted += (country.charCodeAt(icc) - 55);
		}
		numer_iban = account + country_converted + check;
		
		reszta = 0; dlugosc = numer_iban.length;
		for(ib=0; ib<dlugosc; ib++)
		{
			reszta = parseInt(''+reszta+ numer_iban.substr( ib, 1),10 ) % 97;
		}
		
		//alert( iban + ' | ' + country + ' | ' + check + ' | ' + account + ' | ' + country_converted + ' | ' + numer_iban + ' | ' + reszta );
		if (reszta == 1)	//poprawna cyfra kontrolna
		{
			ni.style.display = 'none';
			//formatowanie z odstępami
			nowy = '';
			if(!bezkraju) nowy = country;
			nowy += check;
			for(iban_i=0; iban_i<account.length; iban_i++)
			{
				if(iban_i%4!=0) continue;
				nowy += ' ';
				nowy += account.slice(iban_i,iban_i+4);
			}
			iban_field.value = nowy;
		}
		else
			ni.style.display = ''; 
	}
	
	function checkpkd( pkd_field, info_id )
	{
		ni = document.getElementById( info_id );
		pkd = pkd_field.value;
		if( pkd == '') { /*ni.style.display = 'none';*/ return; }
		
		pkd = pkd.toUpperCase();
		pkd = pkd.replace(/,/g,'.');
		pkd = trim(pkd, ' ');
		czesci = pkd.split('.',5);
		if(czesci.length!=3) { /*ni.style.display = '';*/ return; }
		if(isNaN(czesci[0]) || isNaN(czesci[1]) || (czesci[0].length>2) || (czesci[1].length>2)) { /*ni.style.display = '';*/ return; }
		if((czesci[2]<'A') || ((czesci[2]>'E') && (czesci[2]!='Z')))  { /*ni.style.display = '';*/ return; }
		
		//w takim razie jest OK
		/*ni.style.display = 'none';*/
		pkd_field.value = pad(czesci[0], 2, 0, STR_PAD_LEFT) + '.' + pad(czesci[1], 2, 0, STR_PAD_LEFT) + '.' + czesci[2]; //pkd;
	}

	
	if (!Array.prototype.indexOf)
	{
		Array.prototype.indexOf = function(elt /*, from*/)
		{
			var len = this.length;
			var from = Number(arguments[1]) || 0;
			from = (from < 0) ? Math.ceil(from) : Math.floor(from);
			if (from < 0) from += len;
			for (; from < len; from++)
			{
				if (from in this && this[from] === elt)
					return from;
			}
			return -1;
		}
	}
	
	
	if (!Array.prototype.forEach)
	{
		Array.prototype.forEach = function(fun /*, thisp*/)
		{
			var len = this.length;
			if (typeof fun != "function")
				throw new TypeError();
			
			var thisp = arguments[1];
			for (var i = 0; i < len; i++)
			{
				if (i in this)
					fun.call(thisp, this[i], i, this);
			}
		};
	}
	
	got_focus = '';
		
	function autocompleteOff( objid )
	{
		if( document.getElementById )
		{
			var obj = document.getElementById( objid );
			if(obj.setAttribute) obj.setAttribute('autocomplete','off');
		}
	}
	
	function replace_separator_field( co )
	{
		str_test = co.value + "";
		co.value =  str_test.replace(/,/g,'.');
	}

	function replace_separator_field2( co )
	{
		str_test = co.value + "";
		co.value =  str_test.replace(/,/g,'.');
		
		if(!isNaN(co.value))
		{
			wartosc = co.value*1;
			co.value = wartosc.toFixed(2);
		}
	}
	
	function replace_separator_user( wczym, gdzie )
	{
		var c = document.getElementById(gdzie);
		str_test = c.value + "";
		c.value =  str_test.replace(/,/g,'.');
	}
	
	function replace_separator_user2( wczym, gdzie )
	{
		var c = document.getElementById(gdzie);
		str_test = c.value + "";
		c.value =  str_test.replace(/,/g,'.');
		
		if(!isNaN(c.value))
		{
			wartosc = c.value*1;
			c.value = wartosc.toFixed(2);
		}
	}
	
	function remove_nondigit( co )
	{
		str_test = co.value + "";
		co.value =  str_test.replace(/\D/g,'');
	}
	
	/**
	*
	*  Javascript trim, ltrim, rtrim
	*  http://www.webtoolkit.info/
	*
	*
	**/

	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}

	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}

	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	var STR_PAD_LEFT = 1;
	var STR_PAD_RIGHT = 2;
	var STR_PAD_BOTH = 3;
	
	function pad(str, len, pad, dir) {
	 
		if (typeof(len) == "undefined") { var len = 0; }
		if (typeof(pad) == "undefined") { var pad = ' '; }
		if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }
	 
		if (len + 1 >= str.length) {
	 
			switch (dir){
	 
				case STR_PAD_LEFT:
					str = Array(len + 1 - str.length).join(pad) + str;
				break;
	 
				case STR_PAD_BOTH:
					var right = Math.ceil((padlen = len - str.length) / 2);
					var left = padlen - right;
					str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
				break;
	 
				default:
					str = str + Array(len + 1 - str.length).join(pad);
				break;
	 
			} // switch
	 
		}
	 
		return str;
	 
	}
	
	
	//do ograniczania długości TEXTAREA
		
	/***********************************************
	* Textarea Maxlength script- ɠDynamic Drive (www.dynamicdrive.com)
	* This notice must stay intact for legal use.
	* Visit http://www.dynamicdrive.com/ for full source code
	***********************************************/
/*
	function ismaxlength(obj)
	{
		var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
		//alert(mlength);
		if (obj.getAttribute && obj.value.length>mlength)
			obj.value=obj.value.substring(0,mlength);
	}
*/

	function ismaxlength( obj, info_id, klasa )
	{
		var tekst = obj ? obj.value : "";
		var dlugosc2 = tekst.length;
		tekst = tekst.replace(/\r/g,'');
		dlugosc = tekst.length;
		is_1013 = ( dlugosc==dlugosc2 ? false : true );
		var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : 0;
		
		if ( dlugosc > mlength )
		{
			tekst = tekst.substring(0,mlength);
			dlugosc = tekst.length;
			if( is_1013 ) tekst = tekst.replace(/\n/g,"\r\n");
			obj.value = tekst;
		}
		
		if(obj.getAttribute)
		{
			if( info_id == undefined ){ alert('Brak pola licznika znaków !'); return; }
			info_box = document.getElementById( info_id );
			if( dlugosc == mlength )
				info_box.className = klasa + ' textinfo_red';
			else
				info_box.className = klasa + ' textinfo';
			info_box.innerHTML = dlugosc + ' / ' + mlength;
		}
	}
// -->
