<!--

$(document).ready(function(){
	// blokada/ukrycie email
	//
	$("a[class=email]").each(function(){
		var ats, dots, address, i;
		ats = [ '(at)', '[at]' ];
		dots = [ "(dot)", '[dot]' ];
		address = $(this).html();
		for ( k = 0; k < 6; k++ ) {
			for ( i = 0; i < dots.length; i++ ) {
				address = address.replace(dots[i], '.');
			}
		}
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		var iMalpa = address.indexOf("@");
		if (address.length > iMalpa+1)
			$(this).html('<a href="mailto:' + address + '">' + address.substring(0, iMalpa) + '</a>');
		else
			$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
		
	});
	$("a[rel='Lightbox']").colorbox({
		current:"grafika {current} z {total}"
	});
	$("a[rel='ShowCounter']").colorbox({
		current:"Licznik {current} z {total}"
	});
});

function replaceAll(txt, replace, with_this) {
  return txt.replace(new RegExp(replace, 'g'),with_this);
}

function SelectGoUrl() {
	if (document.jump.menu.selectedIndex==0) return false;
	self.location.href=document.jump.menu.options[document.jump.menu.selectedIndex].value;
}

function setBackgroundImage (id, imageURL) 
{
	if (document.layers) 
		document[id].background.src = imageURL == 'none' ? null : imageURL;
	else if (document.all) 
		document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
	else if 
		(document.getElementById) document.getElementById(id).style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
}

// ---------------------------------------------------------------------------------------
// obsługa wyszukiwania danych na stronie
// ---------------------------------------------------------------------------------------
function searchformsend(form) {
	if (form.findtext.value.length < 4) {
		alert("Minimum 4 chars (znaki)!");
		form.findtext.focus();
		return false;
	}
	if(inValidCharSet(form.findtext.value)==false){
		alert("Bad chars (niedozwolone znaki)!");
		form.findtext.focus();
		return false;
	}		
	form.submit();
}

// ---------------------------------------------------------------------------------------
// obsługa okien popup
// ---------------------------------------------------------------------------------------
	function n_window(theurl,W,H,T,L,mT,mL,mD,mSt,mM,mSc,mR) {
		if(!W || W=='') W=550;
		if(!H || H=='') H=300;
		if(!T || T=='') T=100;
		if(!L || L=='') L=100;
		if(!mT || mT=='') mT='no'; //toolbar
		if(!mL || mL=='') mL='no'; //location
		if(!mD || mD=='') mD='no'; //directories
		if(!mSt || mSt=='') mSt='yes'; //status
		if(!mM || mM=='') mM='no'; //menubar
		if(!mSc || mSc=='') mSc='yes'; //scrollbars
		if(!mR || mR=='') mR='no'; //resizable
		var the_atts='width='+W+',height='+H+',top='+T+',screenY='+T+',left='+L+',screenX='+L;
		the_atts+=',toolbar='+mT+',location='+mL+',directories='+mD+',status='+mSt;
		the_atts+=',menubar='+mM+',scrollbars='+mSc+',resizable='+mR;
		window.open(theurl,'',the_atts);
	}

	function view_img(theurl) {
		var W=550;
		var H=300;
		var T=100;
		var L=100;
		var mT='no'; //toolbar
		var mL='no'; //location
		var mD='no'; //directories
		var mSt='yes'; //status
		var mM='no'; //menubar
		var mSc='no'; //scrollbars
		var mR='yes'; //resizable
		
		var the_atts='width='+W+',height='+H+',top='+T+',screenY='+T+',left='+L+',screenX='+L;
		the_atts+=',toolbar='+mT+',location='+mL+',directories='+mD+',status='+mSt;
		the_atts+=',menubar='+mM+',scrollbars='+mSc+',resizable='+mR;
		window.open('./viewimg.php?img='+theurl,'',the_atts);
	}

// ---------------------------------------------------------------------------------------
// komunikaty i zapytania
// ---------------------------------------------------------------------------------------
	function YesNoUrl(url, msg) {
		if (confirm(msg)) {
			location.href = url;
		}else{
			return false;
		}
	}
	function YesNo(msg) {
		if (confirm(msg)) {
			return true;
		}else{
			return false;
		}
	}
	function YesNoSend(msg) // gdzieś jeszcze to sie przewija
	{
		return YesNo(msg);
	}
	
	function alert_lang(langs) {
		if(langs='en') {
			alert ("I\'m sorry. \nNot ready english lang");
			return false;
		}
		if(langs='de') {
			alert ("I\'m sorry. \nNot ready germany lang");
			return false;
		}
	}
// ---------------------------------------------------------------------------------------
// antyspazm
// ---------------------------------------------------------------------------------------
	function antispam(a,d,n,w){
		var domena = d;
		var konto = a;
		var nazwa = n;
		var caly_email = w;
		if(!w) {
			link_mail = konto+"@"+domena;
		}else{
			link_mail = caly_email;
		}
		if(!n) {
			wyswietl = link_mail;
		}else{
			wyswietl = nazwa;
		}
		document.write("<a href="+"mailto:"+link_mail+">"+wyswietl+"</a>");
	}
	
// ---------------------------------------------------------------------------------------
// obsługa pokaż/ukryj blok
// ---------------------------------------------------------------------------------------
	/*
		pokaż ukryk blok
	*/
	var shown = new Array();
	for (var i=0;i<1;i++) {
		info = i //+ '\n' + shown[i];
		shown[i] = false;
	}
	function blocking(i)
	{
		if (!supported)	{
			alert('This link does not work in your browser.');
			return;
		}
		shown[i] = (shown[i]) ? false : true;
		current = (shown[i]) ? 'block' : 'none';
		//DEBUG		
		//info = current + '\n' + shown[i];		
		//alert(info);
		if (document.getElementById && document) {
			document.getElementById('number'+i).style.display = current;
		}else if (document.all && document)	{
			document.all['number'+i].style.display = current;
		}
	}

	/*
		pokaż ukryk blok włącznie z grafiką plus/minus
	*/
	function menushow(rowID) {		
		var objDiv = 'tr'+rowID;
		var objImgPlus = 'img'+rowID;
		var bImgPlus = false;
		if (typeof (document.getElementById(objImgPlus))=='object' && document.getElementById(objImgPlus) !== null){
			bImgPlus = true;
		}
		if (document.getElementById(objDiv).className=="hide") {
			document.getElementById(objDiv).className="show";
			if (bImgPlus = true){
				document.getElementById(objImgPlus).src="./images/show_minus.jpg";	
			}
		}else{
			document.getElementById(objDiv).className="hide";
			if (bImgPlus = true){
				document.getElementById(objImgPlus).src="./images/show_plus.jpg";
			}
		}
	}
	
	function menushowmini(rowID) {		
		var objDiv = 'tr_'+rowID;
		if (document.getElementById(objDiv).className=="hide") 
			document.getElementById(objDiv).className="show";
		else
			document.getElementById(objDiv).className="hide";
	}
	
	
// ---------------------------------------------------------------------------------------
// funkcje danych plikow
// ---------------------------------------------------------------------------------------	
	// pobierz rozszezenie z nazwy pliku
	//
	function getFileExtension(sNameFile) {
		var iLastIndex = sNameFile.lastIndexOf('.', sNameFile.length - 1);
		var sFileExtension = sNameFile.substr(iLastIndex + 1);
		return sFileExtension;
	}
	// test rozszerzenie pliku
	//
	function testFileExtension(sFileExt, sShowExt) {
		
		var arrExt = sShowExt.split(",");
		var lenExt = arrExt.length;
		var x=0;
		for (x=0; x<lenExt; x++)
		{
			if (sFileExt.toUpperCase() == trim(arrExt[x].toUpperCase()))
			{
				return true;
			}
		}
		return false;
	}
// ---------------------------------------------------------------------------------------
// funkcje obiektowe typu danych
// ---------------------------------------------------------------------------------------

	// dozwolone tylko z listy - z podaniem zakreau znaów
	//
	function inValidCharSetWithChars(str,charset_dozwolone) {
		var result = true;
		for (var i=0;i<str.length;i++)
			if(charset_dozwolone.indexOf(str.substr(i,1))<0) {
				result = false;
				break;
			}
		return result;
	}
	// sprawdz czy wszystkie znaki są dozwolone - tylko dozwolone tylko z listy
	//
	function inValidCharSet(strA, strB) {
		var result = true;
		var teststr = false;
		var charset_dozwolone = "/@*.-,_ 1234567890aąbcćdeęfghijklłnńmoóqprsśtuwvyzżźxAĄBCĆDEĘFGHIJKLŁMNŃOÓQPRSŚTUWVYZŻŹX";
		if (strB != null)
			charset_dozwolone = charset_dozwolone+strB;
			
		for (var i=0;i<strA.length;i++)
		{
			if(charset_dozwolone.indexOf(strA.substr(i,1))<0)
			{
				alert(strA.substr(i,1));
				return false;
			}
		}
		return true;
	}
	// sprawdz czy są niedozwolone znaki
	//
	function inValidBadCharSet(str) {
		var result = true;
		var charset_dozwolone = "\"";
		for (var i=0;i<str.length;i++) {
			if(charset_dozwolone.indexOf(str.substr(i,1))>=0) {
				result = false;
				break;
			}
		}
		return result;
	}
	
// ---------------------------------------------------------------------------------------
// funkcje podstawowe typu danych
// ---------------------------------------------------------------------------------------
	//
	// znajdz obiekt
	//
	function getIdObject(name) {
		if (document.getElementById || document.all)
			return document.getElementById ? document.getElementById(name) : document.all[name]; // - zwraca obiekt
		return null;
	}
	
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	function isTelefon(strA, strB) {
		var result = true;
		var teststr = false;
		var charset_dozwolone = "-+()1234567890 ";
			
		for (var i=0;i<strA.length;i++)
		{
			if(charset_dozwolone.indexOf(strA.substr(i,1))<0)
			{
				return false;
			}
		}
		return true;
	}
	function IsEmpty(aTextValue) {
		if(typeof(aTextValue) == "undefined") { 
			return true;
		}
		if (aTextValue.length==0) {
			return true;
		}
		if (aTextValue==null) {
			return true;
		}
		if (aTextValue==0) {
			return true;
		}
		if(typeof(aTextValue)=="undefined"){
			return true;
		} 
		else { return false; }
	}

	//
	// funkcje obsługi daty
	//
	var dtCh= "-";
	var minYear=1998;
	var maxYear=2020;
	
	function isDate(dtStr){
		var daysInMonth = DaysArray(12);
		var pos1=dtStr.indexOf(dtCh);
		var pos2=dtStr.indexOf(dtCh,pos1+1);
		var strYear=dtStr.substring(0,pos1);
		var strMonth=dtStr.substring(pos1+1,pos2);
		var strDay=dtStr.substring(pos2+1);

		strYr=strYear;
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			alert("Format daty powinien by: yyyy-mm-dd (np. ''2007-06-30'')");
			return false;
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Błędnie podany miesiąc");
			return false;
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Błędnie podany dzień  miesiaca");
			return false;
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Rok musi być w przedziale od: "+minYear+" do: "+maxYear);
			return false;
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Data nie jest OK - sprawdź datę, może wkradła się godzina to ją usuń.");
			return false;
		}
		return true
	}
	
	function stripCharsInBag(s, bag){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++){   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   } 
	   return this
	}
	
	

//-->
