// JavaScript Document
var wr = /^[a-zA-Z0-9_\-\.!]+@[a-zA-Z0-9_\-\.!]+\.[a-zA-Z0-9_\-\.!]{2,}/g;
KOM = new Array();
KOM['pol'] = new Array();

KOM['pol']['POLEOBOWIAZKOWE'] = 'Pole obowiązkowe';
KOM['pol']['BLEDNYMAIL'] = 'Niepoprawny format maila';
KOM['pol']['POLEKROTKIE'] = 'Pole za krótkie';

var idBH;
czywyslanie = true;
function pozaladowaniu() {
	c= readCookie('textSize');
	if (c=='1.3em') ustaw_zmiana_();
	
		if (document.getElementById('strefa-baner-home')) {
		if (idBH) {
			clearTimeout(idBH);
		 	zamien_nastepny('baner-home');
		} else {
			idBH = setTimeout("pozaladowaniu()", 7000);
		}
	}

}


function zmienObr(ob, skad) {
	nwsrc = pobierzsrc(skad);
	wymien(ob, nwsrc);
}

function mpodmenu(i,stan) {
	//alert (i); 
	if (stan) {
		//pokaz menu i
		wyswietl('podmenu_'+i,'block');
			//clearTimeout(id);
			//id = setTimeout(ustawReset,5000);

	} else {
		wyswietl('podmenu_'+i,'none');
		//ukryj menu i
	}
}

function zamien_przenikanie (gdzie,nw) {
	// obM - obrazek ukrywany
	// obP - obrazek pokazywany
	var s = (document.getElementById('bO')) ? document.getElementById('bO').value : 0;
	var n = nw;
	var obM = document.getElementById(gdzie+''+s);
	var obP = document.getElementById(gdzie+''+n);
	var startP = 100;
	var startM = 0;

	if (!obM || !obP || s==n) return false;
	var idP = setInterval(function() {
		startP-=10;
		var uP = startP/100;
	obM.style.opacity = uP; // Opera
	obM.style.MozOpacity = uP; // FF
	obM.style.filter = 'alpha(opacity='+startP+')'; // IE	   
		if (startP<=0)
		{
			clearInterval(idP);
			obM.className = 'off';
			document.getElementById('ba'+s).className = 'off';
			Cufon.replace('a', {hover: true});
			Cufon.now();
		}
	}, 30);
		var idM = setInterval(function() {
		startM+=10;
		var uM = startM/100;
	obP.style.opacity = uM; // Opera
	obP.style.MozOpacity = uM; // FF
	obP.style.filter = 'alpha(opacity='+startM+')'; // IE	   
		if (startM>=100)
		{
			clearInterval(idM);
			obP.className = '';
			document.getElementById('bO').value = n;
			document.getElementById('ba'+n).className = 'on';
			 clearTimeout(idBH);
			idBH = setTimeout("pozaladowaniu()", 7000);
			 Cufon.replace('a', {hover: true});
			 Cufon.now();
		}
	}, 30);

}

function zamien_nastepny (gdzie) {
	if (!document.getElementById('bO') || !document.getElementById('iO')) return false;
	ilr = parseInt(document.getElementById('iO').value);
	nn = (document.getElementById('bO').value==ilr) ? 0 : parseInt(document.getElementById('bO').value)+1;
	zamien_przenikanie (gdzie,nn);
}
function zamien_poprzedni (gdzie) {
	if (!document.getElementById('bO') || !document.getElementById('iO')) return false;
	ilr = document.getElementById('iO').value;
	nn = (document.getElementById('bO').value==0) ? ilr : parseInt(document.getElementById('bO').value)-1;
	zamien_przenikanie (gdzie,nn);
}

function f_logowanie(f) {
	if (!document.getElementById('KomunikatLogowanieSK')) return false;
	document.getElementById('KomunikatLogowanieSK').innerHTML = 'Logowanie...';
	document.getElementById('KomunikatLogowanieSK').className = 'ramkaUwaga';
}
function f_grunty(f) {
if (!document.getElementById('ilw')) return false;
p=true;
if (document.getElementById('ilw').value>0) p = confirm ('Twoja wiadomosc byla juz wyslana, czy wyslac ja powtórnie?');
if (p || document.getElementById('ilw').value==0){ 
il = 0;
	if (document.getElementById('in')) {
		if (document.getElementById('in').value=='') {
			il++;
			if (document.getElementById('k-in')) document.getElementById('k-in').innerHTML=KOM['pol']['POLEOBOWIAZKOWE'];
		} else {
			if (document.getElementById('k-in')) document.getElementById('k-in').innerHTML='';
		}
	}
	
	if (document.getElementById('tel')) {
		if (document.getElementById('tel').value=='') {
			il++;
			if (document.getElementById('k-tel')) document.getElementById('k-tel').innerHTML=KOM['pol']['POLEOBOWIAZKOWE'];
		} else {
			if (document.getElementById('k-tel')) document.getElementById('k-tel').innerHTML='';
		}
	}
	
	if (document.getElementById('mail')) {
		if (document.getElementById('mail').value=='') {
			il++;
			if (document.getElementById('k-mail')) document.getElementById('k-mail').innerHTML=KOM['pol']['POLEOBOWIAZKOWE'];
		} else if (!document.getElementById('mail').value.match(wr)) {
			il++
			if (document.getElementById('k-mail')) document.getElementById('k-mail').innerHTML=KOM['pol']['BLEDNYMAIL'];
		} else {
			if (document.getElementById('k-mail')) document.getElementById('k-mail').innerHTML='';
		}
	}

	if (document.getElementById('miasto')) {
		if (document.getElementById('miasto').value=='') {
			il++;
			if (document.getElementById('k-miasto')) document.getElementById('k-miasto').innerHTML=KOM['pol']['POLEOBOWIAZKOWE'];
		} else {
			if (document.getElementById('k-miasto')) document.getElementById('k-miasto').innerHTML='';
		}
	}
} else return false;
if (il>0) return false;

	document.getElementById('KomunikatGSK').innerHTML = 'Prosze czekac, trwa wysylanie...';
	document.getElementById('KomunikatGSK').className = 'ramkaUwaga';
}

function ustaw_akt(i,il) {
	if (!document.getElementById('At'+i)) return;
	for (j=0;j<il;j++) {
		if (document.getElementById('At'+j)) document.getElementById('At'+j).className='off';
		if (document.getElementById('Aw'+j)) wyswietl('Aw'+j,'inline');
	}
	if (document.getElementById('At'+i)) document.getElementById('At'+i).className='on';
	if (document.getElementById('Aw'+i)) wyswietl('Aw'+i,'none');
}


function przycisk(inp,co) {
if (!inp) return;
if (co) {
		if (inp.className.indexOf('btn')>=0) inp.className = 'btn on';
		else inp.className = 'on';
	} else {
		if (inp.className.indexOf('btn')>=0) inp.className = 'btn';
		else inp.className = '';
	}
}

function w_m(i) {
	if (document.getElementById('a')) document.getElementById('a').value = i;
	if (document.getElementById('ftmieszkan')) document.getElementById('ftmieszkan').submit();
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

var zmiana;
function ustaw_zmiana_() {
	if (zmiana) {
		change_size('1em'); zmiana=false;
		if (document.getElementById('zmianaAa')) {
			document.getElementById('zmianaAa').src = '/img/ico-css.jpg';
			document.getElementById('opisAa').title = 'powiększ czcionkę';
		}
	}
	else {
		change_size('1.3em'); zmiana=true;
		if (document.getElementById('zmianaAa')) {
			document.getElementById('zmianaAa').src = '/img/ico-cssAa.jpg';
			document.getElementById('opisAa').title = 'pomniejsz czcionkę';
		}
	}
	
}
	
function change_size(punkt) {
	if (document.getElementById('zawartosc')) document.getElementById('zawartosc').style.fontSize=punkt;
	if (document.getElementById('srodekC')) document.getElementById('srodekC').style.fontSize=punkt;
createCookie("textSize", punkt, 90);
}

function ustaw_wyszukiwarke(lokal,nzinw,nzurl) {
	document.getElementById('lokalzlisty').value = lokal;
	document.getElementById('ftmieszkan').action = nzinw+'/'+nzurl+','+lokal+'.html';
	document.getElementById('ftmieszkan').submit();
	
	
}

function ustaw_wyszukiwarke_lista(co,jak) {
	document.getElementById('wgSORT').value = co;
	document.getElementById('jakSORT').value = jak
	document.getElementById('ftmieszkan').submit();
}


function asortuj(k,co) {
  posortowane=false;
 // alert (k);
  tr = document.getElementById(co).childNodes[0].childNodes;
  while (!posortowane) {
    posortowane=true;
    for (i=1;i<tr.length-1;i++) {
      if (tr[i].childNodes[k].childNodes[0].nodeValue>
        tr[i+1].childNodes[k].childNodes[0].nodeValue) {
        posortowane=false;
        for (j=0;j<tr[i].childNodes.length;j++) {
          tmp = tr[i].childNodes[j].firstChild.nodeValue;
          tr[i].childNodes[j].firstChild.nodeValue
            = tr[i+1].childNodes[j].firstChild.nodeValue;
          tr[i+1].childNodes[j].firstChild.nodeValue = tmp;
        }
      }
    }
  }
}

function asortujl(k,co) {
  posortowane=false;
  tr = document.getElementById(co).childNodes[0].childNodes;
  while (!posortowane) {
    posortowane=true;
    for (i=1;i<tr.length-1;i++) {
      if (parseFloat(tr[i].childNodes[k].childNodes[0].nodeValue)>
        parseFloat(tr[i+1].childNodes[k].childNodes[0].nodeValue)) {
        posortowane=false;
        for (j=0;j<tr[i].childNodes.length;j++) {
          tmp = tr[i].childNodes[j].firstChild.nodeValue;
          tr[i].childNodes[j].firstChild.nodeValue
            = tr[i+1].childNodes[j].firstChild.nodeValue;
          tr[i+1].childNodes[j].firstChild.nodeValue = tmp;
        }
      }
    }
  }
}

