window.debugMode = false; var b, __pop, IE = (!window.opera && document.all ? true : false);
var debug = (window.debugMode == undefined || window.debugMode == null) ? true : window.debugMode;


function _e(x) { return (typeof x == 'string') ? document.getElementById(x) : x; }


function _n(x) { var y = _e(x); return y ? y.nodeName : null; }


function _v(x) { var y = _e(x); return y ? (y.value ? y.value : y.innerHTML) : (arguments.lenght>=2 ? arguments[1] : null); }


function _root(x) { return root = (x ? (x.documentElement ? x.documentElement : x.firstChild) : null); }


function _xn(x) { return x ? x.nodeName : null; }


function _xv(x) { return x ? (x.nodeValue ? x.nodeValue : (x.firstChild ? x.firstChild.nodeValue : (arguments.lenght>=2 ? arguments[1] : null))) : (arguments.lenght>=2 ? arguments[1] : null); }


function _int(value,defaultValue) {
	var v = parseInt(value);
	if(isNaN(v)) v = defaultValue;
	return v;
}

function show(e) { e = _e(e);	if(e) e.style.display = ''; }

function hide(e) { e = _e(e); if(e) e.style.display = 'none'; }

function _a() {
	var array = new Array();
	if(arguments.length == 1) {
		if(arguments[0] instanceof Array) return arguments[0];
		else if(arguments[0] instanceof Object) {
			if(arguments[0].length)
				for(var i=0;i<arguments[0].length;i++) array.push(arguments[0][i]);
			else
				for(var n in arguments[0]) array.push(arguments[0][n]);
		}
		else array.push(arguments[0]);
	} else
		for(var i=0;i<arguments.length;i++) array.push(arguments[i]);
	return array;
}

Function.prototype.bind = function() {
  var method = this, object = arguments[0];
  return function() {
	return method.apply(object, _a(arguments));
  }
}

var ajax = new AJAX("");

function AJAX(url) {
	this.url	= url;
	this.callerArray = new Array();
	this.setURL = function(newURL) {
		this.url = newURL;
	}

	
	this.defaultResponseHandler = null;

	this.call = function(url,data,responseHandler) {
		this.url = url;
		try {
			if(this.url.length == 0) throw "Ustaw URL";
			if(!responseHandler) responseHandler = defaultResponseHandler;
			x = new HttpRequest(this.url,data,'',responseHandler,true,"GET");
			this.callerArray.push(x);
		}
		catch(e) {
			if(debug) alert('call: '+e.message);
		}
	}
	this.callMethod = function(classID,methodName,getData,postData,data,responseHandler) {
		var uri = ''+(document.location ? document.location : 'index.php');
		var pos = uri.indexOf('?');
		if(!pos || pos==-1) pos = uri.length;
		this.url = uri.substr(0,pos);
		if(this.url.charAt(pos-1) == '/') this.url+='index.php';
		try {
			if(this.url.length == 0) throw "Ustaw URL";
			if(getData && getData.length>0) this.url += '?'+getData;
			if(postData && postData.length>0)
				postData +=  '&classID='+classID+'&method='+methodName;
			else
				postData =	'classID='+classID+'&method='+methodName;
			if(!responseHandler) responseHandler = function() {};
			x = new HttpRequest(this.url,data,postData,responseHandler,true,"POST");
			this.callerArray.push(x);
		}
		catch(e) {
			if(debug) alert('call: '+e.message);
		}
	}
	this.callMethodSync = function(classID,methodName,getData,postData,data,responseHandler) {
		var uri = ''+(document.location ? document.location : 'index.php');
		var pos = uri.indexOf('?');
		if(!pos || pos==-1) pos = uri.length;
		this.url = uri.substr(0,pos);
		if(this.url.charAt(pos-1) == '/') this.url+='index.php';
		try {
			if(this.url.length == 0) throw "Ustaw URL";
			if(getData && getData.length>0) this.url += '?'+getData;
			if(postData && postData.length>0)
				postData +=  '&classID='+classID+'&method='+methodName;
			else
				postData =	'classID='+classID+'&method='+methodName;
			if(!responseHandler) responseHandler = function() {};
			x = new HttpRequest(this.url,data,postData,responseHandler,false,"POST");
			return x;
		}
		catch(e) {
			if(debug) alert('call: '+e.message);
		}
	}
	this.post = function(url,data,requestData,responseHandler) {
		this.url = url;
		try {
			if(this.url.length == 0) throw "Ustaw URL";
			if(!responseHandler) responseHandler = defaultResponseHandler;
			x = new HttpRequest(this.url,data,requestData,responseHandler,true,"POST");
			this.callerArray.push(x);
		}
		catch(e) {
			if(debug) alert('call: '+e.message);
		}
	}
	this.callSync = function(url,data) {
		this.url = url;
		try {
			if(this.url.length == 0) throw "Ustaw URL";
			x = new HttpRequest(this.url,data,'',null,false,"GET");
			return x;
		}
		catch(e) {
			if(debug) alert('call: '+e.message);
		}
		return null;
	}
}




var showHideStatus = 0;
var dodany = 0;
var formRefs = new Array; 
var formVisible = new Array; 
var formModified = new Array; 
var askVisible = false; 
var currentForm = 0; 
var newForm = 0; 

var ImagePreloader = {
	leftToLoad: null,
	errorCnt: null,
	abort:  null,	
	imagesArray: null,
	
	onLoad: null,
	onError: null,
	onAbort: null,
	
	preload: function(imgArray) {
		if(!imgArray) return;
		this.errorCnt = 0;
		this.abort = 0;
		this.leftToLoad = imgArray.length;
		this.imagesArray = new Array();
		
		for(i=0;i<imgArray.length;i++) {
			var img = new Image();
			this.imagesArray.push(img);
			img.onload = this.onImgLoad.bind(this);
			img.onerror = this.onImgError.bind(this);
			img.onabort = this.onImgAbort.bind(this);
			img.src = imgArray[i];
		}
	},
	onImgLoad: function() {
		this.leftToLoad--; 
		if(this.leftToLoad <= 0) {
			if(this.errorCnt <= 0 && this.abort <= 0 && this.onLoad) this.onLoad();
			else 
				if(this.abort > 0 && this.onAbort) this.onAbort();
				else
					if(this.errorCnt > 0 && this.onError) this.onError();
		}
	},
	onImgError: function() {
		this.errorCnt++; 
		this.onImgLoad();
	},
	onImgAbort: function() {
		this.abort++; 
		this.onImgLoad();
	}
}

var Style = {
	assign: function(element,style) {
		element = _e(element);
		if(typeof (style) == 'string') {
			if( typeof( element.style.cssText ) != 'undefined' ) element.style.cssText = style;
			else element.setAttribute('style',style);
		}
		else {
			styleStr = '';
			for(x in style) 
				switch(x) {
				case 'zIndex':
					styleStr += 'z-index: '+style[x]+';';
					break;
				case 'marginTop':
					styleStr += 'margin-top: '+style[x]+';';
					break;
				case 'marginLeft':
					styleStr += 'margin-left: '+style[x]+';';
					break;
				default:
					styleStr += x+': '+style[x]+';';
					break;
				}			
			if( typeof( element.style.cssText ) != 'undefined' ) element.style.cssText = styleStr;
			else element.setAttribute('style',styleStr);
		}
		return element;
	}	
};

function centerElementEx(element,style)
{
	element = _e(element);
	var has_element = document.documentElement && document.documentElement.clientWidth;
	var w = IE ? (has_element ? document.documentElement.clientWidth : document.body.clientWidth) : window.innerWidth;
	var h = IE ? (has_element ? document.documentElement.clientHeight : document.body.clientHeight) : window.innerHeight;
	var offsetTop = (IE ? (has_element ? document.documentElement.scrollTop : document.body.scrollTop) : 0);
	var offsetLeft = (IE ? (has_element ? document.documentElement.scrollLeft : document.body.scrollLeft) : 0);

	style.position = 'absolute';
	var e = element.offsetParent;
	while(e)
	{
		offsetTop -= e.offsetTop;
		offsetLeft -= e.offsetLeft;
		e = e.offsetParent;
	}
	
	style.left = (offsetLeft+Math.floor((w-parseInt(style.width.replace('px','')))/2))+"px";
	style.top = (offsetTop+Math.floor((h-parseInt(style.height.replace('px','')))/2))+"px";
}

var Preview = {
	element: null,
	elementStyle: null,
	imageElement:	null,
	imageStyle: null,
	promoLabelElement:	null,
	promoLabelStyle: null,
	closeButton: null,
	closeButtonStyle: null,
	
	width: null,
	height: null,
	imgWidth: null,
	imgHeight: null,
	opacity: 0,
	speed:  1,
	handle: null,
		
	create: function() {
		this.element = document.createElement('div');
		this.elementStyle = {
			position: 'absolute',
			overflow: "hidden",
			visibility: "hidden",
			background: "url('img/bg.png') repeat",
			width: '300px',
			height: '300px',
			left: '0px',
			top: '0px',
			zIndex: '1300'
		};
		Style.assign(this.element,this.elementStyle);		
		
		
		this.element.onclick = this.close.bind(this);
		
		document.body.appendChild(this.element);		
	},
	fitToWindow: function(scale) {		
		var has_element = document.documentElement && document.documentElement.clientWidth;
		w = IE ? (has_element ? document.documentElement.clientWidth : document.body.clientWidth) : window.innerWidth;
		h = IE ? (has_element ? document.documentElement.clientHeight : document.body.clientHeight) : window.innerHeight;
		
		aw = (Math.round(scale*w));
		ah = (Math.round(scale*h));
		
		if(this.imgWidth-40 > aw-100) {					
			this.imgHeight = Math.round(((aw-100)/(this.imgWidth-40))*(this.imgHeight-40));
			this.imgWidth = (aw-100);
		}
		if(this.imgHeight-40 > ah-100) {			
			this.imgWidth = Math.round(((ah-100)/(this.imgHeight-40))*(this.imgWidth-40));
			this.imgHeight = (ah-100);
		}		
		
		this.elementStyle.width = w+'px'; 				
		this.elementStyle.height = h+'px';
		this.imageStyle.width = this.imgWidth +'px'; 				
		this.imageStyle.height = this.imgHeight +'px';		
		
		centerElementEx(this.element,this.elementStyle);
		centerElementEx(this.imageElement,this.imageStyle);
		this.imageStyle.left = (_int(this.imageStyle.left,0)-25)+'px';
		this.imageStyle.top = (_int(this.imageStyle.top,0)-25)+'px';		
	},
	show: function(img) {		
		if(!this.element) this.create();		
		
		if(!this.imageElement) {
			this.imageElement = document.createElement('img');
			this.element.appendChild(this.imageElement);
			
			var has_element = document.documentElement && document.documentElement.clientWidth;
			var w = IE ? (has_element ? document.documentElement.clientWidth : document.body.clientWidth) : window.innerWidth;
		
			this.closeButton = document.createElement('img')
			this.closeButton.src = 'img/zamknij.gif';
			this.closeButtonStyle = {
				visibility: "hidden",				
				position: 'absolute',
				left: (w-this.closeButton.width-20)+'px',
				top: '5px'
			};
			this.closeButton.onclick = this.close.bind(this);
			Style.assign(this.closeButton,this.closeButtonStyle);
			this.element.appendChild(this.closeButton);
		}		
				
		this.imageStyle = {
			visibility: "hidden",
			border: "#FFFFFF solid 20px",
			overflow: "hidden",
			position: 'absolute'
		};
		Style.assign(this.imageElement,this.imageStyle);
		
		this.imageElement.src = img.src;
		
		this.imgWidth = img.width;
		this.imgHeight = img.height;		
				
		this.fitToWindow(0.98);
		
		this.elementStyle.visibility = 'visible';		
		this.imageStyle.visibility = 'visible';
		this.closeButtonStyle.visibility = 'visible';
		if(IE && (typeof document.body.style.maxHeight == "undefined" )) {
				this.elementStyle.background = "transparent";
				this.elementStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/bg.png', sizingMethod='scale')";
		}
		else this.elementStyle.background = "url('img/bg.png') repeat";
		
		Style.assign(this.element,this.elementStyle);		
		Style.assign(this.imageElement,this.imageStyle);
		Style.assign(this.closeButton,this.closeButtonStyle);
		
	},
	frame: function() {		
		if(IE)
			this.elementStyle.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+this.opacity+")";
		else
			this.elementStyle.opacity = (this.opacity/100);		
		
		if(this.opacity>=100) {
			window.clearInterval(this.handle);
			this.handle = null;
			if(IE) 
				this.elementStyle.filter = '';
			else 
				this.elementStyle.opacity = '1.0';
			
			if(IE && (typeof document.body.style.maxHeight == "undefined" )) {			
				this.elementStyle.background = "transparent";	
				this.elementStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/bg.png', sizingMethod='scale')";
			}			
			
		}
		this.opacity += 30;
		
		Style.assign(this.element,this.elementStyle);		
	},
	close: function() {		
		if(!this.element || !this.imageElement) return;
		
		this.imageStyle.visibility = "hidden";
		this.elementStyle.visibility = "hidden";
		this.closeButtonStyle.visibility = 'hidden';
		
		Style.assign(this.element,this.elementStyle);
		Style.assign(this.imageElement,this.imageStyle);
		Style.assign(this.closeButton,this.closeButtonStyle);
		
		if(this.promoLabelElement) {
			this.promoLabelStyle.visibility = 'hidden';
			Style.assign(this.promoLabelElement,this.promoLabelStyle);
		}
	},
	showLabel: function(link) {
		if(!this.promoLabelElement) {		
			this.promoLabelElement = document.createElement('div');		
			this.element.appendChild(this.promoLabelElement);
			this.promoLabelElement.onclick = this.close.bind(this);
		}
		this.promoLabelStyle = {
			visibility: "hidden",			
			width: "200px",
			height: "200px",
			position: 'absolute'			
		};		
		Style.assign(this.promoLabelElement,this.promoLabelStyle);
		img = new Image();
		img.src = link;		
		this.promoLabelStyle.left = (_int(this.imageStyle.left,0)-10)+'px';
		this.promoLabelStyle.top = (_int(this.imageStyle.top,0)+this.imgHeight-img.height+40)+'px';		
		this.promoLabelStyle.visibility = "visible";
		if(IE && (typeof document.body.style.maxHeight == "undefined" )) {
			this.promoLabelStyle.background = 'transparent';
			this.promoLabelStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+link+"', sizingMethod='noscale')";
		}
		else
			this.promoLabelStyle.background = 'url('+link+') no-repeat 0px 0px';				
				
		Style.assign(this.promoLabelElement,this.promoLabelStyle);	
	}
};

var ImagePreloader = {
	leftToLoad: null,
	errorCnt: null,
	abort:  null,	
	imagesArray: null,
	
	onLoad: null,
	onError: null,
	onAbort: null,
	
	preload: function(imgArray) {
		if(!imgArray) return;
		this.errorCnt = 0;
		this.abort = 0;
		this.leftToLoad = imgArray.length;
		this.imagesArray = new Array();
		
		for(i=0;i<imgArray.length;i++) {
			var img = new Image();
			this.imagesArray.push(img);
			img.onload = this.onImgLoad.bind(this);
			img.onerror = this.onImgError.bind(this);
			img.onabort = this.onImgAbort.bind(this);
			img.src = imgArray[i];
		}
	},
	onImgLoad: function() {
		this.leftToLoad--; 
		if(this.leftToLoad <= 0) {
			if(this.errorCnt <= 0 && this.abort <= 0 && this.onLoad) this.onLoad();
			else 
				if(this.abort > 0 && this.onAbort) this.onAbort();
				else
					if(this.errorCnt > 0 && this.onError) this.onError();
		}
	},
	onImgError: function() {
		this.errorCnt++; 
		this.onImgLoad();
	},
	onImgAbort: function() {
		this.abort++; 
		this.onImgLoad();
	}
}

function openPreview(duzy,maly,promoLabel) {		
	var img = duzy && duzy.length > 0 ? duzy : maly;
	ImagePreloader.onLoad = function() {	
		Preview.image = new Image();	
		Preview.image.src = img;
		Preview.show(Preview.image);			
		if(promoLabel && promoLabel.length >0) Preview.showLabel(promoLabel);
	}
	ImagePreloader.onError = function() {}
	ImagePreloader.onAbort = function() {}
	ImagePreloader.preload([img,'img/bg.png','img/zamknij.gif']);
}
function ScrollFx() {
	this.array = new Object;
	this.moveSpeed = 20;
	this.moveSteps = 100;
	this.itemWidth = 171;


	this.getObject = function(id) {
		if(!this.array[id]) {
			this.array[id] = new Object;
			this.array[id]['buffer'] = 0;
			this.array[id]['content'] = _e(id+(this.array[id].buffer == 0 ? '_A' : '_B'));
			this.array[id]['move'] = 0;
			this.array[id]['data'] = '';
			this.array[id]['offset'] = 0;
			this.array[id]['total'] = 0;
			this.array[id]['handle'] = null;
			this.array[id]['onfinish'] = null;
		}
	}

	this.switchBufferDisplay = function(id) {
		this.getObject(id);
		if(this.array[id]) {
			oldBuffer = _e(id+(this.array[id].buffer == 1 ? '_A' : '_B'));
			this.array[id]['content'].style.display = '';
			oldBuffer.style.display = 'none';
		}
	}

	this.switchBufferContent = function(id) {
		this.getObject(id);
		if(this.array[id]) {
			oldBuffer = _e(id+(this.array[id].buffer == 0 ? '_A' : '_B'));
			this.array[id]['content'] = newBuffer = _e(id+(this.array[id].buffer == 1 ? '_A' : '_B'));
			this.array[id].buffer = this.array[id].buffer ? 0 : 1;
		}
	}

	this.assignBuffer = function(id,value) {
		this.getObject(id);
		if(this.array[id]) this.array[id]['content'].innerHTML = value;
	}

	this.isFinished = function(id) {
		this.getObject(id);
		return (this.array[id]['handle']==null);
	}

	this.moveContent = function(id,p) {
		var content = this.array[id]['content'];
		if(!content) return;
		this.array[id].move += Math.abs(p);
		if(this.array[id].move > this.array[id]['total']) this.array[id]['move'] = this.array[id]['total'];

		if(this.array[id]['handle'] && this.array[id]['move'] == this.array[id]['total']) {
			window.clearInterval(this.array[id]['handle']);
			this.array[id]['handle'] = null;
			
			if(this.array[id]['onfinish'])	this.array[id]['onfinish']();
		}
		content.style.marginLeft = (this.array[id]['offset']+(p<0 ? -this.array[id]['move'] : this.array[id]['move']))+'px';
		if(content.childNodes.length>0 && content.childNodes[0].nodeName!='#text') content.childNodes[0].style.visibility = 'visible';
		
	}

	this.setOffset = function(id,p) {
		this.getObject(id);
		this.array[id]['offset'] = p;
		this.array[id]['total'] = 0;
		this.array[id]['move'] = 0;
		var content = this.array[id]['content'];
		if(!content) return;
		if(this.array[id]['handle']) {
			window.clearInterval(this.array[id]['handle']);
			this.array[id]['handle'] = null;
		}
		content.style.marginLeft = p+'px';
		
	}

	this.assignData = function(id,data) {
		this.getObject(id);
		this.array[id]['data'] = data;
	}

	this.assignOnFinish = function(id,event) {
		this.getObject(id);
		this.array[id]['onfinish'] = event;
	}

	this.getData = function(id) {
		this.getObject(id);
		return !this.array[id]['data'] ? '' : this.array[id]['data'];
	}

	this.left = function(id,length) {
		this.getObject(id);
		this.array[id]['move'] = 0;
		this.array[id]['total'] = length;
		var x = -Math.abs(length/this.moveSteps);
		if(this.array[id]['handle']) {
			window.clearInterval(this.array[id]['handle']);
			this.array[id]['handle'] = null;
		}
		this.array[id]['handle'] = window.setInterval('scrollFx.moveContent(\''+id+'\','+x+')',this.moveSpeed);
	}

	this.right = function(id,length) {
		this.getObject(id);
		this.array[id]['move'] = 0;
		this.array[id]['total'] = length;
		var x = Math.abs(length/this.moveSteps);
		if(this.array[id]['handle']) {
			window.clearInterval(this.array[id]['handle']);
			this.array[id]['handle'] = null;
		}
		this.array[id]['handle'] = window.setInterval('scrollFx.moveContent(\''+id+'\','+x+')',this.moveSpeed);
	}
}

var scrollFx = new ScrollFx();
