var _S_CONF="Na pewno chcesz kasować:\n";
var _S_CLOS="OK";
var _S_ZN1="znak";
var _S_ZN2="znaki";
var _S_ZN3="znaków";
var _S_POL="Pole: ";
var _S_MUS1=" - musi zawierać co najmniej";
var _S_MUS2=" - musi być liczbą";
var _S_MUS3=" - musi być zaznaczone";
var _S_HAS="Potwierdzenie hasła jest inne niż hasło";
var _S_MAIL="Błędnie napisany adres e-mailowy!";
var _S_DAT="Błędnie napisana data!";

var preload_loader=new Image(32,32);
preload_loader.src="pix/loader.gif";

function AL$(id) { return document.getElementById(id); }
function wri(par1,par2) { if (par2) par1.innerHTML=par2; else document.write(par1); }
function AL_ChkDel(text,link) { if (confirm(_S_CONF+text+"?")) location.href=link; }

function AL_SendMail(sDom, sUser) { location.href="mail"+"to:"+sUser+"@"+sDom; }

function AL_AddTag(form,tag) {
	lista=form.value;
	pre=(lista)? ", " : "";
	form.value=lista+pre+tag;
}


function AL_TinyToggle(id) { tinyMCE.execCommand('mceToggleEditor', false, id); }


function AL_InputNum(form,min,max,nullfl) {
	licz=form.value;
	licz=licz.replace(/,/, '.')
	if (isNaN(licz)) licz="0";
	if (nullfl && licz=="") licz="0";
	if (licz!="") {
		if (licz<min) licz=min;
		if (licz>max && max!=0) licz=max;
	}
	form.value=licz;
}


function AL_WinPop(fname,sz,wy) {
	wid=(sz)? "width="+sz : "";
	hei=(wy)? "height="+wy : "";
	cfg='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'+wid+','+hei;
	win=window.open("winpop.php?"+fname,"win",cfg);
	win.focus(); 
}


function AL_GetFlashVer() {
	return flash=function(x,y,i) {
		if((x=navigator.mimeTypes)&&(x=x["application/x-shockwave-flash"])&&(x=x.enabledPlugin) && (y=navigator.plugins)&&(y=y['Shockwave Flash']))i=/\d+/.exec(y.description)
		else if(y=window.ActiveXObject) eval("for(i=2;;i++)try{x=new y('ShockwaveFlash.ShockwaveFlash.'+(i+1))}catch(e){break}")
		return x?i||x:0
	}()
}

function AL_GetFlash(idName,movie,wdth,hght,fVars) {
	fVars=fVars.replace(/&amp;/, '&');
	objTag1="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+wdth+"' height='"+hght+"' id='"+idName+"'>";
	objTag2="<object data='"+movie+"' type='application/x-shockwave-flash' width='"+wdth+"' height='"+hght+"' id='"+idName+"'>";
	paramTag="<param name='movie' value='"+movie+"'>"
	+"<param name='wmode' value='transparent'>"
	+"<param name='quality' value='high'>"
	+"<param name='scale' value='auto'>"
	+"<param name='menu' value='false'>"
	+"<param name='allowScriptAccess' value='sameDomain'>"
	+"<param name='allowFullScreen' value='false'>"
	+"<param name='swliveconnect' value='true'>"
	+"<param name='FlashVars' value='"+fVars+"'>"
	+"</object>";

	if (document.all && !window.opera) sFlash=objTag1+paramTag;
	else sFlash=objTag2+paramTag;
	
	obj=document.getElementById(idName);
	if (obj) obj.innerHTML=sFlash;
	else wri(sFlash);
}


function AL_ZoomLayer(name,dtyp) {
	var sName=name;
	wri("<div id='AL_Bkg' onclick='"+sName+".Close();'></div><div id='AL_Lay'><table height='100%' align='center' border='0'><tr><td align='center' valign='middle'><table><tr><td><div id='AL_Txt'></div></td></tr></table></td></tr></table></div>");
	var pLay=AL$("AL_Lay");
	var pBkg=AL$("AL_Bkg");
	var pTxt=AL$("AL_Txt");
	var bGalFl=0;
	var pImgNew=new Image();
	var sLoader="<a href='JavaScript:"+sName+".Close();'><img src='pix/loader.gif' border='0' /></a>";
	var sClose="<div id='AL_CloT'><a href='JavaScript:"+sName+".Close();'>"+_S_CLOS+"</a></div>";
	var sCloseX="<div id='AL_CloX' onclick='"+sName+".Close();'></div>";
	var sTitle;
	var sOpis;
	var aTab;
	var iGalNr;
	var sPath;
	var pdTyp=dtyp;
	var isIE=document.all? 1 : 0;

	document.onmousedown = function(e) {
		e = (e || event);
		var target = e.target || e.srcElement;
		if (target.id!="AL_Tyt") return;

		var ox = pTxt.offsetLeft-e.clientX;
		var oy = pTxt.offsetTop-e.clientY;
		ox+= isIE? ((pTxt.scrollWidth-pLay.scrollWidth)/2) : ((pTxt.clientWidth-pLay.clientWidth)/2);
		oy+= isIE? ((pTxt.scrollHeight-pLay.scrollHeight)/2) : ((pTxt.clientHeight-pLay.clientHeight)/2);

		document.onmousemove = function(e) {
			e = (e || event);
   			pTxt.style.left = (ox+e.clientX) + "px";
			pTxt.style.top  = (oy+e.clientY) + "px";
			return false;
		}
	}

	document.onmouseup = function(e) { document.onmousemove = null; }

	this.getXMLHttpRequest = function() {
		var request = false;

		if(window.XMLHttpRequest) {
			request=new XMLHttpRequest();
			if (request.overrideMimeType) request.overrideMimeType('text/html');
		} else if(window.ActiveXObject) {
			try { request=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e) { request=new ActiveXObject("Microsoft.XMLHTTP"); }
		}
		return request;
	}

	this.GetParam = function(form) {
		input=form.elements;
		param="";
		for(i=0;i<input.length;i++) {
			switch(input[i].type) {
				case "radio":
				case "checkbox": if(input[i].checked) param+=input[i].name+"="+input[i].value; break;
				case "select-one":
					sel=input[i].options[input[i].selectedIndex];
					war=(sel.value.length>0)? sel.value : sel.innerHTML;
					param+=input[i].name+"="+war;
					break;
				case "select-multiple":
					for(j=0;j<input[i].options.length;j++) if(input[i].options[j].selected) param+=input[i].name+"="+input[i].options[j].value;
					break;
				default: param+=input[i].name+"="+input[i].value;
			}
			if (i<input.length-1) param+="&";
		}
		return param;
	}

	this.GetData = function(url,div,func) {
		var lnk="ajaxget.php?"+url;
		var pReq=this.getXMLHttpRequest();
		pReq.open('GET',lnk,true);
		pReq.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');
		pReq.onreadystatechange = function() {
			if ((pReq.readyState == 4) && (pReq.status == 200)) {
				if (func) eval(func);
				else wri(div,pReq.responseText);
				delete pReq;
				pReq=false;
			}
		}
		pReq.send(null);
	}

	this.PostData = function(url,div,form,func) {
		var param=this.GetParam(form);
		var lnk="ajaxget.php?"+url;
		var pReq=this.getXMLHttpRequest();
		pReq.open('POST',lnk);
		pReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		pReq.onreadystatechange = function() {
			if ((pReq.readyState == 4) && (pReq.status == 200)) {
				if (func) eval(func);
				else wri(div,pReq.responseText);
				delete pReq;
				pReq=false;
			}
		}
		pReq.send(param);
	}

	this.ChngBkg = function(name,grf,pos) { AL$(name).style.background="url('"+grf+"') no-repeat "+pos; }

	this.Visible = function(vis) {
		var viewsel=(vis==1)? "hidden" : "visible";
		var viewzom=(vis==1)? "block" : "none";
		var viewzom2=(vis==1)? "visible" : "hidden";
		var x=document.getElementsByTagName("select");
		for(i=0;i<x.length;i++) x[i].style.visibility=viewsel;
		pBkg.style.display=viewzom;
		pBkg.style.visibility=viewzom2;
		pLay.style.display=viewzom;
		pLay.style.visibility=viewzom2;
	}

	this.Close = function() {
		this.Visible(0);
		pLay.style.height="0px";
		pBkg.style.height="0px";
		pTxt.style.height="0px";
 		wri(pTxt,_S_CLOS);
		document.onkeydown=false;
	}

	this.ImgLoaded = function() {
		var sImg="<a href='#' onclick='"+sName+".Close(); return false;'><img src='"+pImgNew.src+"' border=0></a>";
		var sClo="<div id='AL_Clo' onclick='"+sName+".Close();'></div>";
		var sPre=""; sFor=""; sPodp="";
		if (bGalFl) {
			if (iGalNr>0) sPre="<div id='AL_GalPrev' onclick='"+sName+".Next(-1);''></div>";
			if (iGalNr<aTab.length-1) sFor="<div id='AL_GalForv' onclick='"+sName+".Next(1);'></div>";
			var sPodp="<div id='AL_GalPodp'>("+(iGalNr+1)+"/"+aTab.length+")<br /><b>"+aTab[iGalNr][1]+"</b>";
			if (aTab[iGalNr][2]) sPodp+="<br />"+aTab[iGalNr][2];
			sPodp+="</div>";
		} else {
			var sPodp="<div id='AL_GalPodp'>";
			if (sTitle) sPodp+="<b>"+sTitle+"</b>";
			if (sOpis) sPodp+="<b>"+sOpis+"</b>";
			sPodp+="</div>";
		}

		wri(pTxt,"<div style='position:relative;'>"+sImg+sPre+sFor+sClo+sPodp+"</div>");

		var szer=(pImgNew.width/3)+"px";
		var wyso=pImgNew.height+"px";

		if (sPre) {
			var z=AL$("AL_GalPrev");
			z.style.width=szer;
			z.style.height=wyso;
		}

		if (sFor) {
			var z=AL$("AL_GalForv");
			z.style.width=szer;
			z.style.height=wyso;
		}
		if (sPodp) AL$("AL_GalPodp").style.width=pImgNew.width+"px";
	}

	this.Resize = function() {
		var ZoomPx=isIE? document.body.scrollLeft : window.pageXOffset;
		var ZoomPy=isIE? document.body.scrollTop : window.pageYOffset;
		var ZoomPw=isIE? document.body.clientWidth+"px" : "100%";
		var ZoomPh=isIE? document.body.clientHeight+"px" : "100%";

		if (isIE) {
			if (pdTyp=="strict") {
				var ZoomPx=document.documentElement.scrollLeft;
				var ZoomPy=document.documentElement.scrollTop;
				ZoomPy=document.documentElement.scrollTop;
				ZoomPw="100%";
				ZoomPh="100%";
			} else {
				pBkg.style.position="absolute";
				pBkg.style.height=document.body.scrollHeight+"px";
			}
		}

		pLay.style.left="0px";
		pLay.style.top=ZoomPy+"px";
		pLay.style.width=ZoomPw;
		pLay.style.height=ZoomPh;
	}

	this.Init = function() {
		pTxt.style.height="auto";
		pBkg.style.left="0px";
		pBkg.style.top="0px";
		pBkg.style.width="";
		pBkg.style.height="";
		this.Resize();
		this.Visible(1);
		window.onresize = this.Resize;
	}

	this.checkKey = function (event) {
		var isIE=document.all? 1 : 0;
		var code=(isIE)? window.event.keyCode : event.keyCode;

		switch (code) {
			case 27: eval(sName+".Close();"); break;
			case 13: if (!bGalFl) eval(sName+".Close();"); break;
			case 37: if (bGalFl && iGalNr>0) eval(sName+".Next(-1);"); return false; break;
			case 39: if (bGalFl && iGalNr<aTab.length-1) eval(sName+".Next(1);"); return false; break;
		}
	}

	this.Alert = function(title,txt) {
		this.Init();
		wri(pTxt,"<div class='zzz' id='AL_Tyt'>"+title+sCloseX+"</div><div id='AL_Tre'>"+txt+sClose+"</div>");
		document.onkeydown=this.checkKey;
	}

	this.Flash = function(title,name,src,sz,wy,param) {
		this.Init();
		wri(pTxt,"<div id='AL_Tyt'>"+title+sCloseX+"</div><div id='AL_Tre'><div id='klipv'></div>"+sClose+"</div>");
		AL_GetFlash('klipv',src,sz,wy,param,1);
	}

	this.Ajax = function(url) {
		this.Init();
		wri(pTxt,sLoader);
		this.GetData(url,pTxt);
		document.onkeydown=this.checkKey;
	}

	this.AjaxPost = function(url,form) {
		this.Init();
		wri(pTxt,sLoader);
		this.PostData(url,pTxt,form);
	}

	this.Image = function(fname,title,opis) {
		sTitle=title;
		sOpis=opis;
		bGalFl=0;
		this.Init();
		wri(pTxt,sLoader);
		pImgNew.src=fname;
		pImgNew.onload=this.ImgLoaded;
		document.onkeydown=this.checkKey;
	}

	this.Next = function(dx) {
		iGalNr+=dx;
		wri(pTxt,sLoader);
		pImgNew.src=sPath+aTab[iGalNr][0];
		pImgNew.onload=this.ImgLoaded;
	}

	this.Gallery = function(path,tab,nr) {
		bGalFl=1;
		this.Init();
		aTab=tab;
		iGalNr=nr;
		sPath=path;
		if (sPath) sPath+="/";
		this.Next(0);
		document.onkeydown=this.checkKey;
	}
}
