///* auto image sizer */

function ELIB_init_images()
{
	var ELIB_request;
	var ELIB_image_sizes;
	var ELIB_popup_window;
	
	function xmlh()
	{
		var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}


	
	function ELIB_remake_images()
	{
		try {
			if (ELIB_request.readyState != 4) return;
			eval(ELIB_request.responseText);
			var lista=document.body.getElementsByTagName('a');
			for (i=0;i<lista.length;i++) {
				if (!lista[i].onclick && lista[i].href.match(/\.(jpe?g|png|gif)$/i)) {
					if (ELIB_image_sizes[lista[i].href]) lista[i].onclick=ELIB_click;
				}
			}
			lista=document.body.getElementsByTagName('area');
			for (i=0;i<lista.length;i++) {
				if (!lista[i].onclick && lista[i].href.match(/\.(jpe?g|png|gif)$/i)) {
					if (ELIB_image_sizes[lista[i].href]) lista[i].onclick=ELIB_click;
				}
			}
		}
		catch(e) { 
		}
	}
	
	function ELIB_click()
	{
		try {
			var w=0,h=0;
			var s=ELIB_image_sizes[this.href];
			if (s) {
				w=s.w+30;
				h=s.h+30;
			}
			if (ELIB_popup_window && ELIB_popup_window.close && !ELIB_popup_window.closed) {
				ELIB_popup_window.close();
			}
			
			var misio=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	misio=true;
@end @*/
			var str="dependent=yes,toolbar=no,resizable=yes";
			if (w && h) {
				var sb=0;
				if (w>screen.availWidth) {w=screen.availWidth;sb=1;}
				if (h>screen.availHeight) {h=screen.availHeight;sb=1;}
				str+=",width="+w+",height="+h;
				if (sb) str+=",scrollbars=yes";
				var x,y;
				x=Math.floor((screen.availWidth-w)/2);
				y=Math.floor((screen.availHeight-h)/2);
				if (x>20) {
					str+=(misio?',left=':',screenX=')+x;
				}
				if (y>20) {
					str+=(misio?',top=':',screenY=')+y;
				}
			}
			ELIB_popup_window=window.open(this.href,"_blank",str);
			if (!ELIB_popup_window) return true;
			var doc=ELIB_popup_window.document;
			doc.open();
			var alt="",title="";
			if (this.alt) alt=this.alt;
			if (this.title) alt=this.title;
			doc.write(
	  			'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' +
				'<html id="popup">' +
				'<head><head><title>' + title + '</title>' +
				'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' +
				'<style type="text/css">' +
				'body,html {margin:0px;padding:0px}\n'+
				'p {text-align:center;margin:0px;padding:15px 0 0 0}\n'+
				'img {display:inline}\n'+
				'</style>'+
				'</head><body><p><img src="'+this.href+'" alt="'+alt+'"></p>' +
				'<script type="text/javascript"> document.body.onmouseup = function(e) {var ev = e||event; if ((ev.button||ev.which) < 2) self.close();} ' +
				'</script></body></html>'
				);
			doc.close();
			if (misio) event.returnValue=false;
			return false;
		}
		catch(e) {
			return true;
		}
	}
	try {
		var arr=new Array();
		var i,j,str;
		if (!document.body.getElementsByTagName) return;
		var lista=document.body.getElementsByTagName('a');
		for (i=0;i<lista.length;i++) {
			if (!lista[i].onclick && lista[i].href.match(/\.(jpe?g|png|gif)/i)) {
				for (j=0;j<arr.length;j++) if (arr[j]==lista[i].href) break;
				if (j>=arr.length) arr[j]=lista[i].href;
			}
		}
		lista=document.body.getElementsByTagName('area');
		for (i=0;i<lista.length;i++) {
			if (!lista[i].onclick && lista[i].href.match(/\.(jpe?g|png|gif)/i)) {
				for (j=0;j<arr.length;j++) if (arr[j]==lista[i].href) break;
				if (j>=arr.length) arr[j]=lista[i].href;
			}
		}
		if (!arr.length) return;
		if (!(ELIB_request=xmlh())) return;
		for (i=0;i<arr.length;i++) {
			if (i) str+='&url=';else str='url=';
			try {
				str+=encodeURIComponent(arr[i]);
			}
			catch(e) {
				str+=escape(arr[i]);
			}
		}
		ELIB_request.open("POST","/imgsizer");
		ELIB_request.onreadystatechange=ELIB_remake_images;
		ELIB_request.send(str);
	}
	catch(e) {
	}
}


/*jsl:import /var/httpd/common/imgsize.js*/
/*jsl:import /var/httpd/common/flash.js*/

var delay_flash=false;

function make_flash()
{
	insert_flash('logo','/gfx/logo.swf',700,85);
	if (delay_flash) return;
	var diva=document.getElementById('topholder');
	if (!diva) return;
	var divb=document.createElement('div');
	divb.id='flasholder';
	if(navigator.userAgent.toLowerCase().indexOf('linux')>=0) divb.style.bottom='9px';
	diva.appendChild(divb);
	insert_flash('flasholder','/gfx/top6.swf',918,145);
}

		
function pager_remake()
{
	if (delay_flash) make_flash();
	ELIB_init_images();
	remake_links('dolek');
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 	var el=document.getElementById('skiper');
	if (el) {
		el.onfocus=function() {
			this.className='fokus';
		};
		el.onblur=function() {
			this.className='';
		};
		
	}
@end @*/
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return decodeURIComponent(dc.substring(begin + prefix.length, end));
}

function init()
{
    
    if (!document.getElementById) return;
      pager_remake();
      add_poleca();
      return;
}

function remake_link(el)
{
	el.onmousedown=function() {
		this.className+=' mouser';
	};
	el.onblur=function() {
		this.className=this.className.replace(/mouser/g,'');
	};
}


function remake_links(div)
{
	div=document.getElementById(div);
	if (!div) return;
	var i;
	var li=div.getElementsByTagName('a');
	for (i=0;i<li.length;i++) remake_link(li[i]);
}

function add_poleca()
{
	var i,poleca;
	poleca=getCookie('poleca');
	if (!poleca) return;
	for (i=0;i<document.forms.length;i++) {
		var xl=document.forms[i]['polecajacy'];
		if (xl) xl.value=poleca;
		else {
			var xl=document.createElement('input');
			xl.setAttribute('type','hidden');
			xl.setAttribute('name','polecajacy');
			xl.setAttribute('value',poleca);
			document.forms[i].appendChild(xl);
		}
	}
}

function nleter(forma)
{
	var nazwisko,email,doit;
	var el,i;
	function xmlh()
	{
		var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}
	if (typeof (forma) == "string") forma=document.getElementById(forma);
	for (i=0;i<forma.length;i++) {
		el=forma[i];
		if (!el || el.nodeName.toLowerCase() != 'input' || !el.name) continue;
		if (el.name == "nazwisko") nazwisko=el.value;
		if (el.name == "email") email=el.value;
		if (el.name == "newsletter") doit=el.checked;
	}
	try {
	if (!doit) return;
	var str="nazwisko="+encodeURIComponent(nazwisko)+
		"&email="+encodeURIComponent(email)+
		"&onsend=empty.html&onfail=emfail.html&duplicat=emdupa.html&utf8=1";
	//alert("Test 1: "+str);
	var req=xmlh();
	//alert(req);
	if (!req) return;
	req.open("POST","/cgi-bin/userbase.cgi",false);
	//alert("Test 2:open");
	req.send(str);
	//alert("Test 3:sent");
	//if (nazwisko && nazwisko.indexOf('Koziepad')>=0) {
	//	alert(req.responseText);
	//}
	} catch(e) {
		//if (nazwisko && nazwisko.indexOf('Koziepad')>=0) alert(e);
	}
}

(function()
{
	var wonlo=window.onload;
	window.onload=function() {
		init();
		if (wonlo) wonlo();
	};
})();

function create_flash_banner()
{
    
    if(navigator.userAgent.toLowerCase().indexOf('linux')>=0) {
    	/* problem z linuxowa wtyczka - wyglada ochidnie */
	delay_flash=true;
    }
    else make_flash();
}
