function iDocumentOpen(url,options) {
	if (!url)
		return;
	if (!options)
		options={};
	if ((typeof(options.id)!='undefined')&&(!options.id))
		return;
	if (typeof(options.table)!='undefined')
		url=url.replace(/__TABLE__/,options.table);
	if (typeof(options.agent)!='undefined')
		url=url.replace(/__AGENT__/,options.agent);
	if (typeof(options.id)!='undefined') {
		var p=options.id.indexOf('.');
		var table=false;
		var rid=options.id;
		if (p>0) {
			table=options.id.substr(0,p);
			rid=options.id.substr(p+1);
		}
		url=url.replace(/__RID__/,rid);
		if (table)
		  url=url.replace(/__TABLE__/,table);
	}
	if (typeof(options.parameters)!='undefined')
		url+='&'+options.parameters;
	var w=options.width;
	if (!w) w=900;
	var h=options.height;
	if (!h) h=700;
	window.open(url,'','width='+w+',height='+h+',left='+(screen.width-w)/2+',top='+(screen.height-h)/2+',resizable=yes,scrollbars=yes,status=yes'+(options.menubar?',menubar=1':''));
}

window.iReload=function(reference,action) {
	if (action=='Delete') {
		var links=$$('A.NaviListLink');
		if (links.length) {
			document.location.href=links[0].href;
			return;
		}
	}
	document.location.reload();
}

function iFlashHtml(src,width,height,id,bgcolor,flashvars) {
	/*var vars=[];
	for(e in flashvars) {
		vars.push(e+'='+iFlashEscape(flashvars[e]));
	}
	vars=vars.join('&');*/

	var html='';
	/*if (id) {
		html+='<SCRIPT LANGUAGE=VBScript\> \n';
		html+='on error resume next \n';
		html+='Sub '+id+'_FSCommand(ByVal command, ByVal args)\n';
		html+='  call '+id+'_DoFSCommand(command, args)\n';
		html+='end sub\n';
		html+='</SCRIPT\> \n';
	}*/
	html+='<object type="application/x-shockwave-flash"';
	html+='   width="'+width+'px"';
	html+='   height="'+height+'px"';
	if (id) {
		html+='   id="'+id+'"';
		html+='   name="'+id+'"';
	}
	html+='   data="'+src+'">';
	html+='<param name=movie value="'+src+'">';
	html+='<param name=flashvars value="'+flashvars+'">';
	html+='<param name=quality value=high>';
	html+='<param name=menu value=false>';
	if (bgcolor=='transparent')
		html+='<param name=wmode value=transparent>';
	else if (bgcolor)
		html+='<param name=bgcolor value='+bgcolor+'>';
	html+='</object>';
	//alert(html);
	return(html);
}

function iFlashGenerate(src,width,height,id,bgcolor,flashvars,install) {
	var html='';
	if ((!install)||(iFlashVersion()>=6)) {
		html+=iFlashHtml(src,width,height,id,bgcolor,flashvars);
	} else if (install) {
		html+='<p>Do prawidłowego działania serwisu wymagany jest plugin Macromedia Flash 6 lub nowszy.</p><p>';
		html+=iFlashHtml('layout/flash.swf',70,70,'href=index.php');
		html+='</p><p>Nie widzisz animacji? Zainstaluj plugin:</p><p>';
		html+='<a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" target=_blank><img src="layout/flash.gif" width=75 height=75></a>';
		html+='</p>';
	}
	document.write(html);
}

function iFlashVersion() {
	var i,v=0;
	if (navigator.plugins.length) {
		var p=navigator.plugins;
		if ((p)&&(p.length>0)&&(p['Shockwave Flash']))	{
			var w=p['Shockwave Flash'].description.split(' ');
				for(i=0;i<w.length;i++) {
					var j=parseInt(w[i]);
					if (!isNaN(j))
						v=Math.max(v,j);
				}
		}
		return(v);
  	} else {
		for(v=10;v>0;v--) {
			var x=null;
			try {
				x=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+v);
			} catch(e) {}
			if (x) return(v);
		}
		return(0);
	}
}

function iBannerHomeAnt(banners) {
	var container=$('BannerHome');
	var glass=$('BannerHomeGlass');
	glass.fade('hide');
	var template='<div style="position:absolute;height:290px;"><img src="{src}" style="top:0;"><div class="Opaque">&nbsp;</div><div class="Content"><h3><a href="{url}" class="more">{name}</a></h3>'+/* <p>{body}&nbsp;'<a href="{url}" class="more">(więcej)</a></p> */ '</div></div>';
	var i=0;
	document.iBannerHomeSelected=Math.floor(Math.random()*banners.length);
	var divs=[];
	banners.each(function(banner) {
		var html=template.substitute(banner);
		var div=Elements.from(html)[0];
		divs[i]=div;
		if (i!=document.iBannerHomeSelected)
			div.setStyle('display','none');
		i++;
		div.id='banner_'+i;
		container.adopt(div);
	});
	
	if (banners.length>1) {
		var fx=new Fx.Tween(glass, {property: 'opacity'});
		window.setInterval(function() {
			fx.start(0,1).chain(
			    function(){
			    	divs[document.iBannerHomeSelected].setStyle('display','none');
			    	document.iBannerHomeSelected++;
					if (document.iBannerHomeSelected>=banners.length)
						document.iBannerHomeSelected=0;
					divs[document.iBannerHomeSelected].setStyle('display','block');
					this.start(1,0); 
				}
			);
		},5000);
	}
}

function iBannerSkyscrapper(banners) {
	var r=Math.floor(Math.random()*banners.length);
	banner=banners[r];
	dx=160;
	dy=600;
	if(banner.avatar) {
		dy=775;
		document.getElementById('sky').style.top='0px';
	}
	if (banner.src.indexOf('?')>=0)
	   banner.src+='&';
	else
	   banner.src+='?';
	banner.src+='random='+Math.random();
	if(banner.format=='swf') {
		iFlashGenerate(banner.src,dx,dy,false,'transparent','click='+escape(banner.url)+'&clicktag='+escape(banner.url)+'&gdaclick='+escape(banner.url),false);
	} else {
		var t='';
		if (banner.url)
			t+='<a href="'+banner.url+'">';
		t+='<img src="'+banner.src+'" alt="" style="width:'+dx+'px;height:'+dy+'px;">';
		if (banner.url)
			t+='</a>';
		document.write(t);
	}
	if (banner.flying) {
		//$('sky').setStyle('position','relative');
		var fx=new Fx.Tween($('sky'),{transition:'cubic:out',property:'top',link:'cancel'});
		if (Browser.Engine.trident)
			$('sky').setStyle('left',5);
		window.setInterval(function() {
			var sy;
			if (Browser.Engine.trident)
				sy=document.body.scrollTop;
			else
				sy=window.scrollY;
			if (sy>150-50)
				sy+=50;
			else
				sy=150;
			fx.start(sy);
		},100);
	}
}

function iBannerGenerate(banners)
{
	var r=Math.floor(Math.random()*banners.length);
	banner_width=iLeft(banners[r]['banner_size'],'x');
	banner_height=iRight(banners[r]['banner_size'],'x');
	if(iRightBack(banners[r]['banner_source'],'.')=='swf') {
		iFlashGenerate(banners[r]['banner_source'],banner_width,banner_height,false,'transparent','click='+escape(banners[r]['banner_target'])+'&clicktag='+escape(banners[r]['banner_target'])+'&gdaclick='+escape(banners[r]['banner_target'])+'&banner_language='+banners[r]['banner_language']+'&home='+banners[r]['banner_home'],false);
	} else {
		var t='';
		if (banners[r]['banner_target'])
			t+='<a href="'+banners[r]['banner_target']+'">';
		t+='<img src="'+banners[r]['banner_source']+'" alt="" style="width:'+banner_width+'px;height:'+banner_height+'px;">';
		if (banners[r]['banner_target'])
			t+='</a>';
		document.write(t);
	}
}

function iBookOpen(pages,propotions,unique) {
	var s='';
	for(var i=0;i<pages.length;i++) {
		if (i>0)
			s+=',';
		s+=pages[i];
	}

    if (!$chk(propotions))
    	propotions=141;
    pagedx=400/propotions*100;
    pagedy=400;
    if (pagedx>400) {
    	pagedy=400*400/pagedx;
    	pagedx=400;
	}
	//var dx=(pagedx<300?640:2*pagedx+40);
	var dx=2*pagedx+40;
	var dy=pagedy+40;
	if (dx<640) dx=640;
	if (dy<440) dy=440;	
	var sx=(window.screen.width-dx)/2;
	var sy=(window.screen.height-dy)/2;
	dx+=20;
	dy+=20;
	var w=window.open(iBase()+'book.php?propotions='+escape(propotions)+(unique?'&unique='+escape(unique):'&pages='+escape(pages)),'Book','width='+dx+',height='+dy+',innerWidth='+dx+',innerHeight='+dy+',left='+sx+',top='+sy+',resizable');
}

function iBookRegister2(pages,propotions) {
	var unique=iGenerateID();
	if (!document.iBooks)
		document.iBooks={};
	document.iBooks[unique]=[pages,propotions];
	return(unique);
}

function iBookOpen2(unique) {
	var b=document.iBooks[unique];
	iBookOpen(b[0],b[1],unique);
}

var iGeoMap=new Class({
	initialize: function(container,points,icons) {
		this.Map=new GMap2(container,{maptypes: [G_NORMAL_MAP]});

		var size=container.getSize();
		this.MapUI=new GMapUIOptions(new GSize(size.X,size.Y));
		this.MapUI.maptypes.normal=true,
		this.MapUI.maptypes.satellite=false,
		this.MapUI.maptypes.hybrid=false,
		this.MapUI.maptypes.physical=false,
		this.Map.setUI(this.MapUI);
		this.Map.disableScrollWheelZoom();
		this.Bounds=new GLatLngBounds();
		this.Gdir=new GDirections(this.Map);
		this.WarehouseUrl=points.WarehouseUrl;
		this.StoreUrl=points.StoreUrl;
		if (points.WwwShopEnabled) this.WwwShopEnabled=true;
		else this.WwwShopEnabled=false;
			
		//Normal Icon
		this.IconWarehouse=new GIcon(G_DEFAULT_ICON);
		this.IconWarehouse.imageMap=false;
		this.IconWarehouse.image=icons.Warehouse.Normal.Url;
		this.IconWarehouse.shadow='';
		this.IconWarehouse.iconSize=new GSize(icons.Warehouse.Normal.Size.x,icons.Warehouse.Normal.Size.y);
		this.IconWarehouse.iconAnchor=new GPoint(0,icons.Warehouse.Normal.Size.y);
		//SmallIcon Icon 
		this.IconWarehouseSmall=new GIcon(G_DEFAULT_ICON);
		this.IconWarehouseSmall.imageMap=false;
		this.IconWarehouseSmall.image=icons.Warehouse.Small.Url;
		this.IconWarehouseSmall.shadow='';
		this.IconWarehouseSmall.iconSize=new GSize(icons.Warehouse.Small.Size.x,icons.Warehouse.Small.Size.y);
		//Normal Icon
		this.IconStore=new GIcon(G_DEFAULT_ICON);
		this.IconStore.imageMap=false;
		this.IconStore.image=icons.Store.Normal.Url;
		this.IconStore.shadow='';
		this.IconStore.iconSize=new GSize(icons.Store.Normal.Size.x,icons.Store.Normal.Size.y);
		this.IconStore.iconAnchor=new GPoint(0,icons.Store.Normal.Size.y);
		//SmallIcon Icon 
		this.IconStoreSmall=new GIcon(G_DEFAULT_ICON);
		this.IconStoreSmall.imageMap=false;
		this.IconStoreSmall.image=icons.Store.Small.Url;
		this.IconStoreSmall.shadow='';
		this.IconStoreSmall.iconSize=new GSize(icons.Store.Small.Size.x,icons.Store.Small.Size.y);
		
		this.Markers=[];//{Normal:[],Small:[],Private:[]};
		var xmin,xmax,ymin,ymax,count=0;
		[
			{Points:points.Warehouse,Icon:this.IconWarehouse,IconSmall:this.IconWarehouseSmall,ShopType:'Warehouse'},
			{Points:points.Store,Icon:this.IconStore,IconSmall:this.IconStoreSmall,ShopType:'Store'}
		].each(function(v) {
			for(var i=0;i<v.Points.length;i++) {
				var p=v.Points[i];
				if ((p.X<=0)||(p.Y<=0)) continue;
				if (!$chk(xmin) || (xmin>p.X)) xmin=p.X;
				if (!$chk(xmax) || (xmax<p.X)) xmax=p.X;
				if (!$chk(ymin) || (ymin>p.Y)) ymin=p.Y;
				if (!$chk(ymax) || (ymax<p.Y)) ymax=p.Y;
				var point=new GLatLng(p.Y,p.X);
				var point_small=new GLatLng(p.Y,p.X);
				//walkaround => add custom icon URL
				if(p.CustomIcon){
					v.IconCustom=new GIcon(G_DEFAULT_ICON);
					v.IconCustom.imageMap=false;
					v.IconCustom.image=p.CustomIcon;
					v.IconCustom.shadow='';
					v.IconCustom.iconSize=new GSize(90,20);
					//v.IconCustom.iconAnchor=new GPoint(0,20);
				}else
					v.IconCustom=v.Icon;
				if(p.OverlayPosition!=0){
					point_small=new GLatLng(p.Y-p.OverlayPosition*0.01,p.X)
				}
				
				this.Markers.push({
					Normal:new GMarker(point,{icon:v.Icon}),
					Small:new GMarker(point_small,{icon:v.IconSmall}),
					Custom:new GMarker(point,{icon:v.IconCustom}),
					Rid:p.Rid,
					ShopType:v.ShopType,
					Name:p.Name,
					Address1:p.Address1,
					Address2:p.Address2,
					Phone:p.Phone,
					WwwShop:this.WwwShopEnabled?p.WwwShop:''
				});
				this.Bounds.extend(point);
				count++;
			}
		}.bind(this));
		if (count) {
			var zoom=this.Map.getBoundsZoomLevel(this.Bounds);
			this.Map.setCenter(this.Bounds.getCenter(),count==1?zoom-4:zoom);
		} else {
			this.Map.setCenter(new GLatLng(52.0409,19.2850),6);
		}
		for(var i=0;i<this.Markers.length;i++) {
			if(this.Map.getZoom() > 9) {
				this.Map.addOverlay(this.Markers[i].Custom);
			}else if(this.Map.getZoom() > 7) {
				this.Map.addOverlay(this.Markers[i].Normal);
			}else{
				this.Map.addOverlay(this.Markers[i].Small);
			}
			if (this[this.Markers[i].ShopType+'Url']) {
				/*Add Markers URLS*/
				this.Markers[i].Custom.Url=this[this.Markers[i].ShopType+'Url'].replace(/__Shop__/,this.Markers[i].Rid);
				this.Markers[i].Normal.Url=this[this.Markers[i].ShopType+'Url'].replace(/__Shop__/,this.Markers[i].Rid);
				this.Markers[i].Small.Url=this[this.Markers[i].ShopType+'Url'].replace(/__Shop__/,this.Markers[i].Rid);
				/*Add additional data*/
				this.Markers[i].Custom.Name='<a class="gMapHref" href="'+this.Markers[i].Custom.Url+'">'+this.Markers[i].Name+'&nbsp;&raquo;</a>';
				this.Markers[i].Normal.Name='<a class="gMapHref" href="'+this.Markers[i].Normal.Url+'">'+this.Markers[i].Name+'&nbsp;&raquo;</a>';
				this.Markers[i].Small.Name='<a class="gMapHref" href="'+this.Markers[i].Small.Url+'">'+this.Markers[i].Name+'&nbsp;&raquo;</a>';
				this.Markers[i].Custom.Address=this.Markers[i].Address1+' '+this.Markers[i].Address2;
				this.Markers[i].Normal.Address=this.Markers[i].Address1+' '+this.Markers[i].Address2;
				this.Markers[i].Small.Address=this.Markers[i].Address1+' '+this.Markers[i].Address2;
				/*Add Markers URLS WwwShops*/
				if (this.Markers[i].WwwShop) {
					PhoneOrUrl='<a class="gMapHref" href="'+this.Markers[i].WwwShop+'" target=_blank>'+this.Markers[i].WwwShop+'&nbsp;&raquo;</a>';
					this.Markers[i].Custom.WwwShop=this.Markers[i].WwwShop;
					this.Markers[i].Normal.WwwShop=this.Markers[i].WwwShop;
					this.Markers[i].Small.WwwShop=this.Markers[i].WwwShop;
				}else {
					PhoneOrUrl=this.Markers[i].Phone;
				}
				this.Markers[i].Custom.PhoneOrUrl=PhoneOrUrl;
				this.Markers[i].Normal.PhoneOrUrl=PhoneOrUrl;
				this.Markers[i].Small.PhoneOrUrl=PhoneOrUrl;
				
				if (this.Markers[i].WwwShop) {
					GEvent.addListener(this.Markers[i].Custom, "click", function(marker){window.open(this.WwwShop,"PSB");/*window.location.href=this.WwwShop;*/});
					GEvent.addListener(this.Markers[i].Normal, "click", function(marker){window.open(this.WwwShop,"PSB");/*window.location.href=this.WwwShop;*/});
					GEvent.addListener(this.Markers[i].Small, "click", function(marker){window.open(this.WwwShop,"PSB");/*window.location.href=this.WwwShop;*/});
				} else {
					GEvent.addListener(this.Markers[i].Custom, "click", function(marker){window.location.href=iBase()+this.Url;});
					GEvent.addListener(this.Markers[i].Normal, "click", function(marker){window.location.href=iBase()+this.Url;});
					GEvent.addListener(this.Markers[i].Small, "click", function(marker){window.location.href=iBase()+this.Url;});
				}
				
				
				GEvent.addListener(this.Markers[i].Custom, "mouseover", function(marker){this.openInfoWindowHtml(this.Name+'<p>'+this.Address+'<br>'+this.PhoneOrUrl+'</p>');});
				GEvent.addListener(this.Markers[i].Normal, "mouseover", function(marker){this.openInfoWindowHtml(this.Name+'<p>'+this.Address+'<br>'+this.PhoneOrUrl+'</p>');});
				GEvent.addListener(this.Markers[i].Small, "mouseover", function(marker){this.openInfoWindowHtml(this.Name+'<p>'+this.Address+'<br>'+this.PhoneOrUrl+'</p>');});
				//GEvent.addListener(this.Markers[i].Small, "mouseout", function(marker){this.closeInfoWindow();});
			}
		}
		//this.Map.setCenter(new GLatLng((ymax+ymin)/2,(xmax+xmin)/2), 8);
		//var field=this;
		GEvent.addListener(this.Map, "zoomend",function(oldzoom,newzoom){this.mapZoomChanged(oldzoom,newzoom)}.bind(this));
		GEvent.addListener(this.Gdir, "load", function(){this.onGDirectionsLoad()}.bind(this));
		GEvent.addListener(this.Gdir, "error", function(){this.onGDirectionsError()}.bind(this));
	},
	mapZoomChanged:function(oldzoom,newzoom){
		this.Map.clearOverlays();
		for(var i=0;i<this.Markers.length;i++) {
			if(this.Map.getZoom() > 9) {
				this.Map.addOverlay(this.Markers[i].Custom);
			}else if(this.Map.getZoom() > 7) {
				this.Map.addOverlay(this.Markers[i].Normal);
			}else{
				this.Map.addOverlay(this.Markers[i].Small);
			}
		}
		/*
		if(this.Gdir.fromAddress){
			setGDirections(this.Gdir.fromAddress,this.Gdir.toAddress);
		}
		*/
	},
	onMarkerClick:function(self){
		alert('marker: '+self.Rid);
	},
	setGDirections:function(fromAddress, toAddressCity, toAddressStreet){
		this.Gdir.fromAddress=fromAddress;
		this.Gdir.toAddressCity=toAddressCity;
		this.Gdir.toAddressStreet=toAddressStreet;
		this.Gdir.toAddress=toAddressStreet+', '+toAddressCity;
		this.Gdir.ParseAddressType=1;
		this.Gdir.load("from: " + fromAddress + " to: " + this.Gdir.toAddress, { "locale": 'pl', "travelMode": G_TRAVEL_MODE_DRIVING, "getSteps":true } );
	},
	onGDirectionsError:function(){
		var code=this.Gdir.getStatus().code;
		var infoMsg='';
		switch(code){
			case 601: infoMsg='Nie odnaleziono <b>'+this.Gdir.fromAddress+'</b>. Sprobuj ponownie. ('+code+')'; break;
			case 602: infoMsg='Nie odnaleziono <b>'+this.Gdir.fromAddress+'</b>. Sprobuj ponownie. ('+code+')'; break;
			case 603: infoMsg='Nie odnaleziono <b>'+this.Gdir.fromAddress+'</b>. Sprobuj ponownie. ('+code+')'; break;
			case 604: infoMsg='Nie można wyświetlić trasy z <b>'+this.Gdir.fromAddress+'</b>. Sprobuj ponownie. ('+code+')'; break;
		}
		if(infoMsg=='')
			return;
		if(!(this.Gdir.ParseAddressType>2)){
			this.Gdir.toAddressStreet=iParseGDirectionAddress(this.Gdir.toAddressStreet,this.Gdir.ParseAddressType++);
			this.setGDirections(this.Gdir.fromAddress,this.Gdir.toAddressCity,this.Gdir.toAddressStreet);
		}else{
			$('GeoMapRoute-Desc').innerHTML='<p class="DocStatus DocRejected">'+infoMsg+'</p>';
			$('GeoMapRoute-Desc').style.display='block';
		}
	},
	onGDirectionsLoad:function(){
		routes=this.Gdir.getNumRoutes();
		if(routes==0)
			return; 
		route=this.Gdir.getRoute(0);
		html='<h4>Opis trasy</h4><table cellspacing=0 class=routelist><thead><td class=c2 colspan=2><div>Z miejscowości <b>'+this.Gdir.fromAddress+'</b> do <b>'+this.Gdir.toAddressStreet+', '+this.Gdir.toAddressCity+'</b><small>'+route.getDuration().html+'</small></div></td><td class=c3><div>'+route.getDistance().html+'</div></td></thead><tbody>';
		steps=route.getNumSteps();
		for(i=0;i<steps-2;i++){
			step=route.getStep(i);
			html+='<tr><td class=c1><div>'+(i+1)+'.</div></td><td class=c2><div>'+step.getDescriptionHtml()+'</div></td><td class=c3><div>'+step.getDistance().html+'</div></td></tr>';
		}
		html+='</tbody><tfoot><tr><td class=c1><div>'+(++i)+'</div></td><td class=c2><div>Dotarłeś na miejsce. <b>'+this.Gdir.toAddress+'</b></div></td><td class=c3><div>0 m</div></td></tr></tfoot></table>';
		$('GeoMapRoute-Desc').innerHTML=html;
		$('GeoMapRoute-Desc').style.display='block';
	}
});

function iParseGDirectionAddress(oStreet,oType){
	var street=oStreet;
	if (oType==1) {
		rm=street.match(/[A-Za-z]+$/);
		if(rm){
			if(rm.length>0) {
				street=street.substr(0,street.length-rm.length);
			}else
				oType=2;
		}else
			oType=2;
	}
	if (oType==2) {
		rm=street.match(/[0-9]+$/);
		if(rm)
			if(rm.length>0)
				street=street.substr(0,street.length-rm.length);
	}
	return street;
}

function iSelectorSwitch(){
	sl=$('SelectorList');
	ss=$('SelectorSearch');
	s=$('Selector');
	if (s.hasClass('expanded')) {
		s.removeClass('expanded');
		sl.setStyle('display','none');
		if (ss) ss.setStyle('display','none');
	} else {
		s.addClass('expanded');
		sl.setStyle('display','block');
		if (ss) ss.setStyle('display','block');
	}
}

function iTabSwitch(i){
	for(var m=1;m<=9;m++){
		if (!$('TabList'+m)) continue;
		if (i==m) {
			$('TabList'+m)
				.setStyle('display','block')
				.fireEvent('TabShow');
			$('Tab'+m)
				.addClass('active');
		} else {
			$('TabList'+m)
				.setStyle('display','none')
				.fireEvent('TabHide');
			$('Tab'+m)
				.removeClass('active');
		}
	}
}

/*function iSelectorSwitch2(i){
	// FUNCTION HAS IE PROBLEM ...!!!
	for(var m=1;m<=2;m++){
		if(m==i){
			if($('SelectorList'+m).getStyle('display')=='none'){
				$('SelectorList'+m).setStyle('display','block');
				$('Selector'+m).set('class','expanded');
			}	else {
				$('SelectorList'+m).setStyle('display','none');
				$('Selector'+m).set('class','');
			}
		} else {
			$('SelectorList'+m).setStyle('display','none');
			$('Selector'+m).set('class','rolled');
		}
	}
	if (($('SelectorList1').getStyle('display')=='none')&&($('SelectorList2').getStyle('display')=='none')){
		$('Selector1').set('class','');
		$('Selector2').set('class','');
	}
}*/

// ------------------- File Begin

function iFileUploadButton() {
	var field=this;
	var index=(this.FieldClass=='iFieldFile'?'Upload':iGenerateID());
	var item=new Element('div',{
		id:this.Name+(index?'_'+index:''),
		'class':'GetFile'
	});
	var form=new Element('form',{
		action:iBase()+this.options.BoxUrl,
		target:this.Name+(index?'_'+index:'')+'_Frame',
		method:'post',
		enctype:'multipart/form-data',
		encoding:'multipart/form-data',
		id:this.Name+(index?'_'+index:'')+'_Form'
	});
	if (index)
		var input_index=new Element('input',{
			type:'hidden',
			name:this.Name+'_FileId',
			value:index
		})
	var input_fieldindex=new Element('input',{
		type:'hidden',
		name:this.Name+'_FieldIndex',
		value:this.FieldIndex
	});
	var input_button=new Element('div',{
		'class':"B BfloatL BiRight BiAdd BFile",
		href:'javascript:',
		html:'<span><span>Załącz plik</span></span>'
	});
	var input=new Element('input',{
		type:'file',
		'class':'file hand',
		name:this.Name+'_FileUpload',
		events:{
			change:function() {
				// zaczyna upload pliku
				field.fireEvent('uploadstart',item);
				form.submit();
				form.setStyle('display','none');
				
				var progress=new Element('span',{
					html:'Wysyłanie pliku ...'
				});
				item.adopt(progress);
				field.naviButtons(item,true);
			}
		}
	});
	var iframe=new Element('iframe',{
		name:this.Name+(index?'_'+index:'')+'_Frame',
		id:this.Name+(index?'_'+index:'')+'_Frame',
		styles:{display:'none'}
	});
	//item.adopt(form.adopt(input_index,input_button.adopt(input)),iframe);
	//item.adopt();
	item.adopt(input_button,form.adopt(input,input_fieldindex,input_index),iframe);
	item.inject(this.Items,'after');
	
	//<div class="GetFile">
	//	<a id="btn3" class="B BfloatL BiRight BiAdd BFile" href="javascript:"><span><span>Załącz plik</span></span></a>
	//	<input id="fileGet3" type="file" class="file hand" 
	//		onMouseOver="document.getElementById('btn3').style.background='#FFF864';"
	//		onMouseOut="document.getElementById('btn3').style.background='#FFEC58';">
	//</div>
}
function iFileNaviButtons(item,upload_cancel) {
	// podlaczanie przyciskow do pliku
	var field=this;
	// usuwanie
	item.adopt(
		new Element('span',{'class':'actions'}).adopt(
			new Element('a',{
				'class':'B BsizeXS BiRight BiRem BbgGrayRed',
				events:{
					'click':function() {
						field.fileDelete(item,upload_cancel);
					}
				},
				html:'<span><span>Usuń</span></span>'
			})
		)
	);
	/*if (this.fieldClass()!='iFieldFile') {
		var s=item.getElement('SPAN.actions');
		new Element('a',{
			'class':'B BsizeXS BiRight BiMoveUp BbgGrayYellow',
			events:{
				'click':function() {
					
				}
			},
			html:'<span><span>Przesuń</span></span>'
		}).inject(s,'top');
		new Element('a',{
			'class':'B BsizeXS BiRight BiMoveUp BbgGrayYellow',
			events:{
				'click':function() {
					
				}
			},
			html:'<span><span>Przesuń</span></span>'
		}).inject(s,'top');
	}*/
	//<a class="B BsizeXS BiRight BiMoveUp BbgGrayYellow" href="javascript:alert('Button A zawsze ma HREF!')"><span><span>Przesuń</span></span></a>
	//<a class="B BsizeXS BiRight BiMoveUp BbgGrayYellow" href="javascript:alert('Button A zawsze ma HREF!')"><span><span>Przesuń</span></span></a>
	//<a class="B BsizeXS BiRight BiMoveDown BbgGrayYellow" href="javascript:alert('Button A zawsze ma HREF!')"><span><span>Przesuń</span></span></a>
}
iFieldFile.implement({
    uploadButton: iFileUploadButton,
    naviButtons:  iFileNaviButtons
});
iFieldFileList.implement({
    uploadButton: iFileUploadButton,
    naviButtons:  iFileNaviButtons
});

// ------------------- File End

window.addEvent('domready', function() {
	// przewijanie do 1 bledu
	var scroll=function() {
		var f=$$('.field-failure');
		if (f.length>0) {
			f=f[0];
			// przewiniecie
			var p=f.getPosition();
			window.scrollTo(0,p.y-350);
			if (q=f.getElement('INPUT[type=text],INPUT[type=password],TEXTAREA,SELECT'))
				$try(function() {
					q.focus();
				});
		}
	}.delay(10);
	
});