//Dodaje zdarzenie do obiektu (w IE, FF, Opera)
//Przykład zastosowania w funkcji showimg
function addEvent(obj, type, fn) { 
	//obj.attachEvent("on"+type, fn); 
	//return false;
	if (obj.addEventListener) { 
		obj.addEventListener(type, fn, false); 
	} else if (obj.attachEvent) { 
		obj["e"+type+fn] = fn; 
		obj[type+fn] = function() {obj["e"+type+fn](window.event); } 
		obj.attachEvent("on"+type, obj[type+fn]); 
	} 
}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }

//	Funkcje do rozwi?zywania problemu z wy?wietlaniem ramki wokół obiektów Flash (pocz?tek)

window.onload = function()
{
	
	var objects = document.getElementsByTagName('noscript');
	for (var i = objects.length - 1; i >= 0 ; i--)
	{
		var html = objects[i].innerHTML;
		html = html.substring(12, html.length-12);
		objects[i].outerHTML = html;
	}
}

/*
window.onload = function(){
	var o,n,j,i,p,t,ob = new Array(),objs = document.getElementsByTagName('object');	
	for(i=0;i<objs.length;i++) if (!objs[i].className.match(/(^|\s)noninteractive($|\s)/)) ob.push(objs[i]);
	objs=null;
	for(i=0;i<ob.length;i++)
	{
		t='';
		for(j=0;j<ob[i].childNodes.length;j++)
		{
			if (ob[i].childNodes[j].tagName != 'OBJECT')
			t += ob[i].childNodes[j].outerHTML;
		}
		t = ob[i].outerHTML.replace("</OBJECT>",t + "</OBJECT>");
		
		n = ob[i].nextSibling;
		p = ob[i].parentNode;
		
		p.removeChild(ob[i]);
		ob[i] = null;
	
		o = document.createElement('span');
		o.innerHTML = t;
		o = o.firstChild;
	
		p.insertBefore(o,n);
	}
}
*/

/*
window.onload = function(){
	o=document.getElementsByTagName('object');l=o.length
	for(j=0;j<l;j++){
        a=p=A=P=''
		A=o[j].attributes; 
		P=o[j].parentNode.getElementsByTagName('param'); 
		for(i=0;i<A.length;i++){a+=A[i].name+'="'+A[i].value+'" '+"\n";}
		for(i=0;i<P.length;i++){p+='<param name="'+P[i].name+'" value="'+P[i].value+'"/>'+"\n"}
		o[j].outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+a+'>'+p+'</object>';
	}
}
*/
//	Funkcje do rozwi?zywania problemu z wy?wietlaniem ramki wokół obiektów Flash (koniec)


var nn4 = (document.layers) ? true:false; 
var ie4 = (document.all) ? true:false; 
var ie6nn6 = (document.getElementById) ? true:false; 

	//Utworzenie obiektu, który będzie zbierał zdarzenia od kliknięć myszki
	//Element ten będzie poza bubble, więc będzie go można wykorzystać w otwieraj?cym się okienku
	//aby można było dowiedzieć się, z jakiego elementu pochodzi zdarzenie
	//np. window.opener.elementClicked.title
	window.elementClicked = null;
	function mDown(){
	  window.elementClicked = event.srcElement;
	}
	document.onmousedown = new Function("mDown()");
	//



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 = Str.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("WprowadĽ tekst, który chcesz wyszukać.");
	return false;
}

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

	document.images.imgImg.width=137;
	document.images.imgImg.height=12;
	document.images.imgImg.src='/edytorimg_new/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 (window.scrollX)
		scrollX=window.scrollX;//FF
	else
		scrollX=document.body.scrollLeft;//IE, Opera

	if (window.scrollY)
		scrollY=window.scrollY;
	else
		scrollY=document.body.scrollTop;

		
	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<document.body.clientWidth)
		document.getElementById("imgTable").style.left=(scrollX+((document.body.clientWidth)/2)-(imgW/2)-5)+"px";
	else
		document.getElementById("imgTable").style.left=(scrollX+5)+"px";

	//Odległo?ć od góry
	if (imgH<document.body.clientHeight){
		document.getElementById("imgTable").style.top=(scrollY+((document.body.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="/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();" />';	
		if (imgS>0) {
			document.getElementById("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);" />';
		}
		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") && 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 hideIMG()
{
	document.getElementById("imgTable2").style.left="0px";
	document.getElementById("imgTable2").style.width="0px";
	document.getElementById("imgTable").style.left="0px";
	document.images.imgImg.width="0px";
}

function rekom()
{
	var r_w = '';
	r_w = window.open("linki.php","linki","width=400,height=400,toolbar=no,menubar=no,scrollbars=yes");
	r_w.location.reload();
	r_w.focus();
//	window.open("/linki.php","linki","width=400,height=400,toolbar=no,menubar=no,scrollbars=yes");
}

function PokazUkryj(idObj, pokaz) 
{ 
nn6 = (document.getElementById) ? true:false; 
nn4 = (document.layers) ? true:false; 
ie4 = (document.all) ? true:false; 
//if ((nn6) && (ie4)) {nn6=null;} 
 
var attribV;
var attribD;
 if (nn6) {
  attribV = (pokaz) ? 'visible' : 'hidden';
  attribD = (pokaz) ? '' : 'none';
  document.getElementById(idObj).style.visibility=attribV; 
  document.getElementById(idObj).style.display=attribD;	
 } 
 else if (ie4){ 
    attribV = (pokaz) ? 'visible' : 'hidden';
	attribD = (pokaz) ? '' : 'none';
	document.all[idObj].style.visibility=attribV;
    document.all[idObj].style.display=attribD;	
 } 
 else if (nn4){ 
     attribV = (pokaz) ? 'show' : 'hide';
     document.layers[idObj].visibility = attribV;
 } 
} 

function popFrameLoad(plik, stan, opis, w, h){
//Funkcja służ?ca do ładowania do "wyskakuj?cego okienka" (ramki) dowolny plik, np. ankietę.

//document.all.iFrameTable.style.left=50;
//document.getElementById("iFrameTable").style.top=150;
//document.getElementById("iFrameTable").style.left=150;
//document.getElementById("popIF").style.width=300;
//alert(document.body.scrollHeight);
//alert(document.body.clientHeight);
	var IFW=640;//Szeroko?ć wyskakuj?cego "okienka"
	var IFH=480;//Wysoko?ć wyskakuj?cego "okienka"
	if(w>0)	IFW=w;
	if(h>0)	IFW=h;
	var scrollX=0;
	var scrollY=0;
	
	if (window.scrollX)
		scrollX=window.scrollX;//FF
	else
		scrollX=document.body.scrollLeft;//IE, Opera

	if (window.scrollY)
		scrollY=window.scrollY;
	else
		scrollY=document.body.scrollTop;

if (plik){
		//if (ie6nn6 && ie4 || ie4)//Tylko IE
		/*
		if (ie4)//Tylko IE
			popIF.location.href=plik;
		else if (ie6nn6)//Tylko FF
		*/
			document.getElementById("popIF").contentWindow.location.href=plik;
	}
//		window.frames['popIF'].location.href=plik;

	if (opis)
		document.getElementById("tdIFhead").innerHTML="&nbsp;"+opis;


	//Odległo?ć od lewej krawędzi
	if (IFW<document.body.clientWidth)
		document.getElementById("iFrameTable").style.left=(document.body.scrollLeft+((document.body.clientWidth)/2)-(IFW/2)-5)+"px";
	else
		document.getElementById("iFrameTable").left=(document.body.scrollLeft+5)+"px";

	//Odległo?ć od góry
	if (IFH<document.body.clientHeight)
		document.getElementById("iFrameTable").style.top=(document.body.scrollTop+((document.body.clientHeight)/2)-(IFH/2)-15)+"px";
	else
		document.getElementById("iFrameTable").style.top=(document.body.scrollTop+15)+"px";

		document.getElementById("popIF").style.width="638px";
		document.getElementById("popIF").style.height="460px";

//document.getElementById("iFrameTable").style.top=150;
//document.getElementById("iFrameTable").style.left=150;

	if (stan>0){
		document.getElementById("iFrameTable").style.display="block";
		document.getElementById("iFrameTable").style.zIndex=254;
	}
	else{
		document.getElementById("iFrameTable").style.display="none";
		document.getElementById("iFrameTable").style.zIndex=100;
	}
}


function obj_visible(obj) {
	
//	var pozycje = Array('kategor','images','tables','references','links','sondy','ankiety');
	var pozycje = Array('kategor','images','tables','links','sondy','ankiety');
	for (x=0; x<pozycje.length; x++) 
	{ 
		if(obj==pozycje[x]){ // selected element
	if (ie6nn6){
		var actual = eval("document.getElementById('"+pozycje[x]+"').style.display");
		if(actual=='none') eval("document.getElementById('"+pozycje[x]+"').style.display='';");
		else eval("document.getElementById('"+pozycje[x]+"').style.display='none';");
		var actual = eval("document.getElementById('"+pozycje[x]+"_roll').className");
		if(actual=='ed_roll') eval("document.getElementById('"+pozycje[x]+"_roll').className='ed_roll2'");
		else eval("document.getElementById('"+pozycje[x]+"_roll').className='ed_roll'");
	}
	else if (ie4) { // IE
		var actual = eval("document.all."+pozycje[x]+".style.display");
		if(actual=='none') eval("document.all."+pozycje[x]+".style.display='';");
		else eval("document.all."+pozycje[x]+".style.display='none';");
		var actual = eval("document.all."+pozycje[x]+"_roll.className");
		if(actual=='ed_roll') eval("document.all."+pozycje[x]+"_roll.className='ed_roll2'");
		else eval("document.all."+pozycje[x]+"_roll.className='ed_roll'");
	} 
	else if (nn4){ // NS
		var actual = eval("document.layers['"+pozycje[x]+"'].display");
		if(actual=='none') eval("document.layers['"+pozycje[x]+"'].display='';");
		else eval("document.layers['"+pozycje[x]+"'].display='none';");
	}
		}
		else{ // other elements
			if (ie6nn6){
				eval("document.getElementById('"+pozycje[x]+"').style.display='none';");
				eval("document.getElementById('"+pozycje[x]+"_roll').className='ed_roll'");
			}
			else if (ie4) { // IE
				eval("document.all."+pozycje[x]+".style.display='none';");
				eval("document.all."+pozycje[x]+"_roll.className='ed_roll'");
			} 
			else if (nn4){ // NS
				eval("document.layers['"+pozycje[x]+"'].display='none';");
			}
		}		
	} 
}

//Funkcje do efektownego wyszarzania obrazków
function high(which2)
{ theobject=which2
highlighting=setInterval("highlightit(theobject)",30)}
function low(which2)
{clearInterval(highlighting)
if (which2.style.MozOpacity)
which2.style.MozOpacity=0.3
else if (which2.filters)
which2.filters.alpha.opacity=50
}

function highlightit(cur2){
if (cur2.style.MozOpacity<1)
cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1
else if (cur2.filters&&cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}
/**
Obrazka dodać kod:
style="FILTER: alpha(opacity = 50); moz-opacity: 0.3; "
onmouseover="high(this)" 
onmouseout="low(this)"

czyli np:
<IMG SRC="adres_pliku" onmouseover="high(this)" style="FILTER: alpha(opacity = 50); moz-opacity: 0.3" onmouseout="low(this)">
*/
// sprawdzanie poprawnoťci 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 się kończyć nazwą domeny lub dwuliterowej nazwy " + "kraju.");
return false;
}
if (len<2) {
alert("W adresie brakuje nazwy hosta!");
return false;
}
return true;
}

//Sprawdzenie księgi gości
function test_ks_g(forma){
ok=true;

if(ok&&blank(obetnij_spacje(forma.elements['ks_g_imie'].value))) 
	{	forma.elements['ks_g_imie'].style.background = "#ff0000";	ok=false;} //nazwa firmy

if(!blank(forma.elements['ks_g_email'].value)){	
	if(ok&&!emailCheck(forma.elements['ks_g_email'].value))
		{	forma.elements['ks_g_email'].style.background = "#ff0000";	ok=false;} 			//email
}

if(ok&&blank(obetnij_spacje(forma.elements['ks_g_tresc'].value))) 
	{	forma.elements['ks_g_tresc'].style.background = "#ff0000";	ok=false;} //nazwa firmy


(ok==true)?forma.submit():alert("Wprowadzono niepoprawne dane!");
}

//Pokazanie okna z wpisem do księgi gości
function kg_show_add() {
	menu = 'ksiega_dodaj';
	if (document.getElementById) { // IE NS6
		obj = document.getElementById(menu);
		actual = obj.style.display ;
		if(actual=='none') obj.style.display='';
		else obj.style.display='none';
	} 
	else { // NS4
		var actual = eval("document.layers['"+menu+"'].display");
		if(actual=='none') eval("document.layers['"+menu+"'].display='';");
		else eval("document.layers['"+menu+"'].display='none';");
	}
}