function ankieta(a)
{
	x = (screen.width-500)/2;
	y = (screen.height-500)/2;
	window.open("ankieta.php?id="+a,"Ankieta","left="+x+",top="+y+",width=600,height=500,scrollbars=yes,toolbar=no,menubar=no,fullScreen=no,resizable=yes");
}

function ScrollText(text,seed)
{
	var msg = text;
	var out = " ";
	var c   = 1;
	if (seed > 100)
	{
		seed--;
		var cmd="ScrollText(\"" + msg + "\"," + seed + ")";
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 100 && seed > 0)
	{
		for (c=0 ; c < seed ; c++)
		{
			out+=" ";
		}
		out+=msg;
		seed--;
		var cmd="ScrollText(\"" + msg + "\"," + seed + ")";
		window.status=out;
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 0)
	{
		if (-seed < msg.length)
		{
			out+=msg.substring(-seed,msg.length);
			seed--;
			var cmd="ScrollText(\"" + msg + "\"," + seed + ")";
			window.status=out;
			timerTwo=window.setTimeout(cmd,100);
		}
		else
		{
			var cmd="ScrollText(\"" + msg + "\",100)";
			window.status=" ";
			timerTwo=window.setTimeout(cmd,75);
		}
	}
}

function obetnij_spacje(Str)
{
	dlugosc=Str.length;
	while (Str.slice(0,1) == " ")
	{
		 Str = Str.substr(1,dlugosc-1);
	 	 dlugosc = Str.length
	}
	while (Str.slice(dlugosc-1,dlugosc)== " ")
	{
	 	 Str = Str.substr(0,dlugosc-1);
	 	 dlugosc = postcodeStr.length
 	}
	return Str;
}

function blank(pole)
{
	return (pole=="");
}

function search()
{
	if (blank(obetnij_spacje(sz.search_txt.value)))
	{
		sz.search_txt.value='szukaj...';
		sz.op.value='';
	}
	else
		sz.op.value='o';
}

function test()
{
	ok = true;
	if ((!sz.op.value.length)||blank(obetnij_spacje(sz.search_txt.value)))
		ok=false; //szukana nazwa
	(ok==true)?sz.submit():alert("Wprowadzono niepoprawne dane!");
}

function zmien(obiekt,numer,link_nr)
{
	aid=document.getElementById(link_nr)
	if(numer>0) {
		obiekt.bgColor = '#FFFFFF';
		aid.style.color='#004185';
	}
	else {
		obiekt.bgColor = '#004185';
		aid.style.color='#FFFFFF';
	}
	return true;
}

function showimg(imgPath,imgFile,imgWidth,imgHeight,imgDescription,imgScale)
{
//Pami�ta� o tym, aby wszystkie flash na stronie mia�y ustawione
//<param name="wmode" value="transparent" />
//oraz wszystkie inne warstwy ni� "wyskakuj�cego" obrazka mia�y z-index<50
//Style z ustawieniami do warstwy obrazka znajduj? si� w style.css
//Je?li opis podamy jaki tekst, to poka�e si� on bezpo?rednio
//Je?li opis b�dzie mia� wpisane 0 (zero), to b�dzie poszukiwany w tre?ci
//Je?li opis b�dzie mia� warto?� >0, to b�dzie warto?ci opisu z pola imgDesc{imgID} np. imgDesc1234
	
	imgDescription = "&nbsp;"+imgDescription+"&nbsp;";
	
	document.images.imgImg.width=137;
	document.images.imgImg.height=12;
	document.images.imgImg.src='/edytorek/edytorimg/loading.gif';
	var MAX_MIN_WIDTH=640;
	var MAX_MIN_HEIGHT=480;
	var imgW=imgWidth;
	var imgH=imgHeight;
	var imgS=imgScale;
	var scrollX=0;
	var scrollY=0;
	
	/*
	if(document.body)
		scrollX=document.body.scrollLeft;//IE6, Opera
	else if (window.scrollX)
		scrollX=window.scrollX;//FF
	else if(document.documentElement)
		scrollX=document.documentElement.scrollLeft;//IE7, FF, Opera
	else
		scrollX=0;

	if(document.body)
		scrollY=document.body.scrollTop;//IE6, Opera
	else if(document.documentElement)
		scrollY=document.documentElement.scrollTop;//IE7, FF, Opera
	else if (window.scrollY)
		scrollY=window.scrollY;//FF
	else
		scrollY=0;
	*/
	
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	
	scrollX=document.all? iebody.scrollLeft : pageXOffset
	scrollY=document.all? iebody.scrollTop : pageYOffset
	

	if ((imgS>0) && (parseInt(imgWidth)>MAX_MIN_WIDTH || parseInt(imgHeight)>MAX_MIN_HEIGHT)) {
		dXY = Math.min(MAX_MIN_WIDTH/imgWidth,MAX_MIN_HEIGHT/imgHeight);
		imgW = parseInt(imgWidth*dXY);
		imgH = parseInt(imgHeight*dXY);
		//alert ("imgWidth="+imgWidth+", imgHeight="+imgHeight+"\nimgW="+imgW+", imgH="+imgH);
	}
	else
		imgS=0;

	//Odleg�o?� od lewej kraw�dzi
	if (imgW<iebody.clientWidth)
		document.getElementById("imgTable").style.left=(scrollX+((iebody.clientWidth)/2)-(imgW/2)-5)+"px";
	else
		document.getElementById("imgTable").style.left=(scrollX+5)+"px";

	//Odleg�o?� od g�ry
	if (imgH<iebody.clientHeight){
		document.getElementById("imgTable").style.top=(scrollY+((iebody.clientHeight)/2)-(imgH/2)-15)+"px";
	}
	else
		document.getElementById("imgTable").style.top=(scrollY+15)+"px";

	document.images.imgImg.width=imgW;
	document.images.imgImg.height=imgH;
	document.images.imgImg.src=imgPath+imgFile;
	document.getElementById("imgFooter").width=imgW+"px";
	document.getElementById("imgTable").style.visibility='visible';

	if (document.getElementById("imgMax")){
	//Nowa wersja
		if (imgS>0) {
			addEvent(document.getElementById("imgMax"), 'click', function(){showimg(imgPath,imgFile,imgWidth,imgHeight,imgDescription,0);});
			document.getElementById("imgMax").style.display="block";
		}
		else{
			document.getElementById("imgMax").style.display="none";
		}
		//document.getElementById("imgTitle").innerHTML='Ilustracja';
	}
	else{
	//Stara wersja
		document.getElementById("imgHeader").innerHTML='<img hspace=\"1\" vspace=\"1\" align=\"right\" src="/edytorek/edytorimg/close.gif" alt="zamknij" style="cursor:pointer" onclick="document.getElementById(\'imgTable\').style.visibility=\'hidden\';document.getElementById(\'imgTable2\').style.visibility=\'hidden\';document.images.imgImg.src=\'/edytorek/edytorimg/empty.gif\';hideIMG();" />';	
		if (imgS>0) {
			document.getElementById("imgHeader").innerHTML+='<img hspace=\"1\" vspace=\"1\" align=\"right\" src="/edytorek/edytorimg/max.gif" alt="Maksymalizuj" style="cursor:pointer" onclick="showimg(\''+imgPath+'\',\''+imgFile+'\',\''+imgWidth+'\',\''+imgHeight+'\',\''+imgDescription+'\',0);" />';
		}
		document.getElementById("imgHeader").innerHTML+='Ilustracja';
	}
	if (isNaN(imgDescription)){
		document.getElementById("imgFooter").innerHTML=imgDescription;
	}
	else if (imgDescription>0){
		document.getElementById("imgFooter").innerHTML=eval('imgDesc'+imgDescription+'.innerHTML');
	}
	else {
		//Komentarz z tre?ci dokumentu
		var str = document.body.innerHTML;
		var re1 = new RegExp('title=["?](.*?)["?](.*)'+imgFile+'(.*)', 'gi');//Je?li wielowyrazowe, to w cudzys�owach
		var re2 = new RegExp('title=([^ ]+)(.*)'+imgFile+'(.*)', 'gi');//Je?li jednowyrazowe, to bez cudzys�ow�w
		var a;
		if (!(a=re1.exec(str)))
			a=re2.exec(str);
		if (a) {
			document.getElementById("imgFooter").innerHTML=""+a[1].replace("powi�ksz zdj�cie ", "")+"";
		}
		else if (document.getElementById("txtGaleria").innerHTML){
			document.getElementById("imgFooter").innerHTML=document.getElementById("txtGaleria").innerHTML;
		}
		else {
			document.getElementById("imgFooter").innerHTML="";
		}
	}
	
	document.getElementById("imgTable2").style.left=(parseInt(document.getElementById("imgTable").style.left)-1)+"px";
	document.getElementById("imgTable2").style.top=(parseInt(document.getElementById("imgTable").style.top)-1)+"px";
	document.getElementById("imgTable2").style.width=(document.getElementById("imgTable").clientWidth+5)+"px";
	document.getElementById("imgTable2").style.height=(document.getElementById("imgTable").clientHeight+5)+"px";
	document.getElementById("imgTable2").style.visibility='visible';
}

function showimg__(imgPath,imgFile,imgWidth,imgHeight,imgDescription,imgScale)
{
	//document.images.imgImg.src='/edytorimg_new/empty.gif';
	document.images.imgImg.src='pimg/loading.gif';
	var MAX_MIN_WIDTH=640;
	var MAX_MIN_HEIGHT=480;
	imgW=imgWidth;
	imgH=imgHeight;
	imgS=imgScale;
	if ((imgS>0) && (parseInt(imgWidth)>MAX_MIN_WIDTH || parseInt(imgHeight)>MAX_MIN_HEIGHT)) {
		dXY = Math.min(MAX_MIN_WIDTH/imgWidth,MAX_MIN_HEIGHT/imgHeight);
		imgW = parseInt(imgWidth*dXY);
		imgH = parseInt(imgHeight*dXY);
		//alert ("imgWidth="+imgWidth+", imgHeight="+imgHeight+"\nimgW="+imgW+", imgH="+imgH);
	}
	else
		imgS=0;

	if (imgW<document.documentElement.clientWidth)
		document.getElementById('imgTable').style.left=document.documentElement.scrollLeft+((document.documentElement.clientWidth)/2)-(imgW/2)-5;
	else
		document.getElementById('imgTable').style.left=document.documentElement.scrollLeft+5;

	//Odleg�o�� od g�ry
	if (imgH<document.documentElement.clientHeight)
		document.getElementById('imgTable').style.top=document.documentElement.scrollTop+((document.documentElement.clientHeight)/2)-(imgH/2);
	else
		document.getElementById('imgTable').style.top=document.documentElement.scrollTop+15;

	document.images.imgImg.width=imgW;
	document.images.imgImg.height=imgH;
	document.images.imgImg.src=imgPath+imgFile;
	document.getElementById('imgFooter').width=imgW;
	document.getElementById('imgTable').style.visibility='visible';
//	document.all.imgTable.style.visibility='visible';

	imgHeader = document.getElementById('imgHeader');

	imgHeader.innerHTML='<img hspace=1 vspace=1 align=right src="edytorimg_new/close.gif" alt="zamknij" style="cursor:pointer" onclick="document.getElementById(\'imgTable\').style.visibility=\'hidden\';document.getElementById(\'imgTable2\').style.visibility=\'hidden\';document.images.imgImg.src=\'/edytorimg_new/empty.gif\';hideIMG();">';
	//imgHeader.innerHTML='<img hspace=1 vspace=1 align=right src=/edytorimg_new/close.gif alt="zamknij" style="cursor:pointer" onclick="imgTable.style.visibility=\'hidden\';imgTable2.style.visibility=\'hidden\';document.images.imgImg.src=\'/pimg/loading.gif\';">';
	if (imgS>0) {
		imgHeader.innerHTML+='<img hspace=1 vspace=1 align=right src="edytorimg_new/max.gif" alt="Maksymalizuj" style="cursor:pointer" onclick="showimg(\''+imgPath+'\',\''+imgFile+'\','+imgWidth+','+imgHeight+','+imgDescription+',0);">';
	}
	//imgHeader.innerHTML+='<img src=/edytorimg_new/empty.gif height=13>Ilustracja&nbsp;<b>'+imgFile+'</b>';
//	imgHeader.innerHTML+='Ilustracja';
	imgHeader.innerHTML+=imgDescription=='' ? 'Ilustracja': imgDescription;

	if (imgDescription>0) {
		//imgHeader.innerHTML+=imgDescription;
		//imgFooter.innerHTML=eval('imgDesc'+imgDescription+'.innerHTML');
	}
	else {
		//Komentarz z tre�ci dokumentu
		var str = document.body.innerHTML;
		var re1 = new RegExp('title=["?](.*?)["?](.*)'+imgFile+'(.*)', 'gi');//Je�li wielowyrazowe, to w cudzys�owach
		var re2 = new RegExp('title=([^ ]+)(.*)'+imgFile+'(.*)', 'gi');//Je�li jednowyrazowe, to bez cudzys�ow�w
		var a;
		if (!(a=re1.exec(str)))
			a=re2.exec(str);
		if (a) {
			imgFooter.innerHTML=""+a[1]+"";
		}
		else
			imgFooter.innerHTML="";
	}
	document.getElementById('imgTable2').style.left=parseInt(document.getElementById('imgTable').style.left)-1;
	document.getElementById('imgTable2').style.top=parseInt(document.getElementById('imgTable').style.top)-1;
	document.getElementById('imgTable2').style.width=document.getElementById('imgTable').clientWidth+5;
	document.getElementById('imgTable2').style.height=document.getElementById('imgTable').clientHeight+5;
	document.getElementById('imgTable2').style.visibility='visible';
}
function hideIMG()
{
	document.all.imgTable2.style.left=0;
	document.all.imgTable2.style.width=0;
	document.all.imgTable.style.left=0;
	document.images.imgImg.width=0;
}
function checkEmailForm(f)
{
	if (f.nadawca.value=="" || f.tresc.value=="") {
		alert("Pole nadawca oraz tre�� wiadomo�ci musz� by� wype�nione.");
		return false;
	}
	return true;
}
function chat()
{
	x = (screen.width-500)/2;
	y = (screen.height-400)/2;
	window.open("chat/login.php","","left="+x+",top="+y+",width=500,height=400,scrollbars=no,menubar=no,statusbar=no");
}
// sprawdzanie poprawnosci emaila
function emailCheck (emailStr) {
	var checkTLD=1; // sprawdzanie końcówki
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Niepoprawny adres email (sprawdź położenie @ oraz .)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Nazwa użytkownika zawiera niedozwolone znaki.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Nazwa domeny zawiera niedozwolone znaki.");
			return false;
	   }
	}
	if (user.match(userPat)==null) {
		alert("Niepoprawna nazwa użytkownika.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Docelowy adres IP jest niepoprawny!");
				return false;
		   }
		}
	return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("Niepoprwana nazwa domeny.");
			return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("Adres musi kończyć się nazwą domeny lub dwuliterową nazwą " + "kraju.");
		return false;
	}
	if (len<2) {
		alert("W adresie brakuje nazwy hosta!");
		return false;
	}
	return true;
}

function checkForm1()
{
	var f = document.getElementById("frm");
	if (f.od.value=="" || f.dw.value=="") {
		alert("Nie podałeś adresu odbiorcy i/lub swoich danych.");
		return false;
	}
//	else{
//	if (!emailCheck(f.od.value) || !emailCheck(f.dw.value)){
//		alert("Jeden z adresów email jest niepoprawny.");
//		return false;
//	} 
	if (f.msg.innerText=="") {
		alert("Nie podałeś treści wiadomości.");
		return false;
	}
	return true;
}
function checkForm2()
{
	var f = document.getElementById("frm");
	if (f.msg.innerText=="") {
		alert("Nie podałeś treści wiadomości.");
		return false;
	}
	return true;
}

