window.debugMode = false; 
/*@@@Section Global@@@*/

var b, __pop, IE = (!window.opera && document.all ? true : false);
var debug = (window.debugMode == undefined || window.debugMode == null) ? true : window.debugMode;

var Classes = new Object();
window.Classes = Classes;

var Class = function() {
	return function() {
		this.extend = function(classObj) {
			var tmp = _r(arguments,1);
			if(classObj instanceof Object) {
					if(classObj.prototype) {
						for (var property in classObj.prototype)
							if(!this[property]) this[property] = classObj.prototype[property];
						if(classObj.prototype['__construct']) classObj.prototype['__construct'].apply(this,tmp);
					}
					else {
						for (var property in classObj)
							this[property] = classObj[property];
						if(classObj['__construct']) classObj['__construct'].apply(this,tmp);
					}
			}
		};
		this.copy = function(classObj) {
			if(classObj && classObj instanceof Object)
				if(classObj.prototype) {
					for (var property in classObj.prototype)
						this[property] = classObj.prototype[property];
				}
				else {
					for (var property in classObj)
						this[property] = classObj[property];
				}
		};
		this.clone = function() {
			var obj = new Class();
			for (var property in this)
				obj[property] = this[property];
			return obj;
		};
		this.info = function() {
			var str = '';
			for (var property in this)
				if(this[property] instanceof Object)
					str+=property+'=[Object]\r\n';
				else str+=property+'='+this[property]+'\r\n';
			return str;
		};
		this.infoAbout = function(obj) {
			var str = '';
			for (var property in obj)
				if(this[property] instanceof Object)
					str+=property+'=[Object]\r\n';
				else str+=property+'='+this[property]+'\r\n';
			return str;
		};
		this.inherited = function(classObject,method) {
			if(!classObject) return;

			var tmp = _r(arguments,2);
			if(classObject.prototype && classObject.prototype[method])
				return classObject.prototype[method].apply(this, tmp);
			else if(classObject && classObject[method])
				return classObject[method].apply(this, tmp);
		}
		//---------------------------------
		if(this.__construct) this.__construct.apply(this, arguments);
	}
};

Classes.Browser = new Class()
Classes.Browser.prototype = {
	isIE: false,
	isIE6: false,
	isIE7: false,
	isIE8: false,
	isOpera: false,
	isFireFox: false,
	isSafari: false,
	__construct: function() {
		reg = new RegExp("(MSIE|FIREFOX|OPERA|SAFARI)[^0-9]*(\\d)+","g");
		matches = reg.exec(navigator.userAgent.toUpperCase());
		if(matches!=null) {
			switch(matches[1]) {
			case 'MSIE':
				this.isIE = true;
				if(matches[2] && parseInt(matches[2]) == 6) this.isIE6 = true;
				if(matches[2] && parseInt(matches[2]) == 7) this.isIE7 = true;
				if(matches[2] && parseInt(matches[2]) == 8) this.isIE8 = true;
				break;
			case 'FIREFOX':
				this.isFirefox = true;
				break;
			case 'OPERA':
				this.isOpera = true;
				break;
			case 'SAFARI':
				this.isSafari = true;
				break;
			}
			if(this.isIE && window.opera) {
				this.isIE = false;
				this.isOpera = true;
			}
		}
	},
	displayInfo: function() {
			var str = '';
			for (var property in this)
				if(property.substr(0,2) == 'is') str+=property+' = '+this[property]+'\r\n';
			alert(str);
	}
}

var browser = new Classes.Browser();

Classes.ElementList = Class();
Classes.ElementList.prototype = {
	elementArray: null,
	selector:		null,
	tagName:		null,
	tagId:			null,
	className:	null,
	rootElement:  null,
	__construct: function(selector) {
		this.elementArray = new Array();
		if(arguments.length>=2)
			this.rootElement = arguments[1];
		reg = new RegExp("^(\\w*\\s*)?(\\#\\w+\\s*)?(\\s*\\.(?:\\w*\\s*)+){0,1}","g");
		matches = reg.exec(selector);
		if(matches != null && matches.length<=4) {
			this.selector = matches[0];
			this.tagName = matches[1];
			if(this.tagName)
				this.tagName = this.tagName.toUpperCase().replace(' ','');
			this.tagId = matches[2];
			if(this.tagId)
				this.tagId = this.tagId.substr(1);
			this.className = matches[3];
			if(this.className)
				this.className = this.className.substr(1);
			this.harvestElements(this.rootElement);
		}
	},
	checkNodeList: function(nodeList) {
		var classRule = new RegExp("^"+this.className+"\\s*|\\s+"+this.className+"\\s+|\\s*"+this.className+"\\s*$","g");
		for(var i=0;i<nodeList.length;i++) {
			e = nodeList[i];
			if(this.tagName && this.tagName != e.nodeName) continue;
			if(this.tagId && this.tagId != e.id) continue;
			if(this.className && !(e.className && e.className.match(classRule))) continue;
			this.elementArray.push(e);
		}
	},
	harvestElements: function() {
		var tab = arguments.length>=1 ? arguments[0] : null;
		if(this.tagId) {
			tab = new Array;
			tab.push(_e(this.tagId));
			this.checkNodeList(tab);
		}
		else
		if(this.tagName) {
			tab = (!tab ? document.body : tab).getElementsByTagName(this.tagName.toUpperCase());
			this.checkNodeList(tab);
			return;
		}
		else {
			tab = (!tab ? document.body : tab);
			this.checkNodeList(tab.childNodes);
			if(!tab.childNodes) return;
			for(var i=0;i<tab.childNodes.length;i++)
				this.harvestElements(tab.childNodes[i]);
		}
	},
	forEach: function(callback) {
		this.elementArray.forEach(callback,this);
	}
};

function wylaczEnter(e)
{
	var key;
	key = (window.event)? window.event.keyCode : e.which; //IE : FF

	return (key != 13);
}



function _join(obj1,obj2) {
	var newObj = {};
	for(var a in obj1) {
		newObj[a] = obj1[a];
	}
	for(var a in obj2) {
		newObj[a] = newObj[a]!==undefined ? newObj[a] : obj2[a];
	}
	return newObj;
}

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 _string(value,defaultValue) {
	var v = !value ? defaultValue : value;
	return v;
}

function _int(value,defaultValue) {
	value = parseInt(value, 10);
	return isNaN(value) ? defaultValue : value;
}

function _float(value,defaultValue) {
	value = parseFloat(value.replace(/,/g, '.0'));
	return isNaN(value)? defaultValue : value;
}

function _floatIn(value,defaultValue) {
	var pattern = /[0-9,.]/;
	var patternDot = /[,.]/;
	if(pattern.test(value)) {
		if(patternDot.test(value))
			value = value.replace(/,/g, '.');
		else
			value = parseInt(value);
	}

	return isNaN(value)? defaultValue : value;
}

function _offset(e) {
	var a = [0,0];
	var e = _e(e);
	while(e && e.parentNode!=undefined) {
		a[1] += e.offsetTop;
		a[0] += e.offsetLeft;
		e = e.offsetParent;
	}
	return a;
}

function show(e) { e = _e(e);	if(e) e.style.display = ''; }

function hide(e) { e = _e(e); if(e) e.style.display = 'none'; }

function centerElement(element)
{
		element = _e(element);
		var hasElement = document.documentElement && document.documentElement.clientWidth;
		var w = browser.isIE ? (hasElement ? document.documentElement.clientWidth : document.body.clientWidth) : window.innerWidth;
		var h = browser.isIE ? (hasElement ? document.documentElement.clientHeight : document.body.clientHeight) : window.innerHeight;
		var offsetTop = _int((browser.isIE || browser.isOpera ? (hasElement ? document.documentElement.scrollTop : document.body.scrollTop) : window.scrollY),0);
		var offsetLeft = _int((browser.isIE || browser.isOpera ? (hasElement ? document.documentElement.scrollLeft : document.body.scrollLeft) : window.scrollX),0);

		element.style.position = 'absolute';
		element.style.left = '0px';
		element.style.top = '0px';

		var eo = _offset(element);
		offsetLeft -= eo[0];
		offsetTop -= eo[1];

		var x = offsetLeft+(w - element.offsetWidth)/2;
		var y = offsetTop+(h - element.offsetHeight)/2;

		element.style.left = _int(x,0)+'px';
		element.style.top = _int(y,0)+'px';
}

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 _r(x) {
	var y = _a(x);
	switch(arguments.length) {
	case 1:	break;
	case 2:
		return y.slice(arguments[1],y.length);
		break;
	case 3:
		return y.slice(arguments[1],arguments[2]);
		break;
	}
	return y;
}

Function.prototype.bind = function() {
  var method = this, object = arguments[0];
  return function() {
	var args = _a(arguments);
	return method.apply(object, args);
  }
}

Function.prototype.bindEvent = function() {
  var method = this, object = arguments[0], args = _a(arguments);
  return function(e) {
	args[0] = e;
	return method.apply(object, args);
  }
}

Function.prototype.bindArgs = function() {
  var method = this, object = arguments[0], args = _r(arguments,1);
  return function() {
	return method.apply(object, args);
  }
}

Function.prototype.bindFuncArgs = function() {
  var method = this, args = _a(arguments);
  return function() {
	return method.apply(method, args);
  }
}

if (!Array.prototype.forEach) {
	Array.prototype.forEach = function(fun/*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") throw new TypeError();
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this) fun.call(thisp, this[i], i, this);
		}
	};
}

function formGetData(formId)
{
	var formNode = _e(formId);
	var formLen = formNode.length;
	var requestData = '';

	if(formNode && formNode.length > 0) {
		for(var j=0;j<formNode.length;j++) {
			var node = formNode.elements[j];
			if(j==0)
				requestData = node.name + '=' + encodeURIComponent(node.value);
			else
				requestData += '&' + node.name + '=' + encodeURIComponent(node.value);
		}
	}
	return requestData;
}

function addEvent(element,event,func) {
	if(!element) return;
	if(browser.isIE) element.attachEvent("on"+event, func);
	else element.addEventListener(event,func,false);
}

function removeEvent(element,event,func) {
	if(!element) return;
	if(browser.isIE) element.detachEvent("on"+event, func);
	else element.removeEventListener(event,func,false);
}

function eventTarget(x) {
	x = x ? x : window.event;
	return x.target ? x.target : x.srcElement;
}

function fixEvent(x) {
	return x ? x : window.event;
}

function preventDefault(e) {
	if(!e) return;
	if(e.preventDefault) e.preventDefault();
	e.returnValue = false;
}

function stopPropagation(e) {
	if(!e) return;
	if(e.stopPropagation) e.stopPropagation();
	e.cancelBubble = true;
}

function objectInfo(object) {
	if(!object) return '';

	var str = '<table>';
	for(var e in object) {
		str += '<tr><td style="vertical-align: top">'+e+':</td><td>';
		if(object[e]) {
			if(typeof (object[e]) == "object") str += "{<br />"+objectInfo(object[e])+"}";
			else str += object[e];
		}
		str += '</td></tr>';
	}
	str += '</table>';
	return str;
}

/* http://www.openjs.com/scripts/dom/class_manipulation.php */
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function redirectTo(url) {
	document.location = url;
}

/*@@@Section Dymek@@@*/


if(!IE)
{
	if (document.captureEvents) {
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove=mousePos;
	var netX, netY;
}


function init()
{
	if(__pop) return;
	addEvent(window,'load',function() {
		__pop = document.getElementById("pop");
		if (browser.isIE6) {
			__popIframe = document.getElementById("popIframe");
		} else {
			__popIframe = null;
		}
		b = document.body;
	});
}

function mousePos(e) {
	netX=e.pageX;
	netY=e.pageY;
}

function popPrzesun(pX, pY) {
	if(__pop.style.visibility!='visible') return;
	var offsetTop = _int((browser.isIE || browser.isOpera ? (document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop) : window.scrollY),0);

	if(IE) {myszX=event.clientX; myszY=event.clientY+offsetTop;}
		else {myszX=netX-b.scrollLeft; myszY=netY-b.scrollTop;}

	tempX=myszX+pX;
	if(tempX<0) tempX=0;
	tmp=b.clientWidth-myszX-pX-__pop.offsetWidth-20;
	if(tmp<0) {tempX+=tmp; if(tempX<0) tempX=0;}
	__pop.style.left=b.scrollLeft+tempX+"px";

	tempY=myszY+pY;
	if(tempY<0) tempY=0;
	tmp=b.clientHeight-myszY-pY-__pop.offsetHeight-15;
	if(tmp<0) {
		tmp=myszY-15-__pop.offsetHeight;
		if(tmp>=0) tempY=tmp;
	}
	__pop.style.top=b.scrollTop+tempY+"px";

	if (__popIframe) {
		__popIframe.style.left = __pop.style.left;
		__popIframe.style.top = __pop.style.top;
		__popIframe.style.width = __pop.offsetWidth;
		__popIframe.style.height = __pop.offsetHeight;
	}
}


function popPokaz(pX, pY, src)
{
	__pop.style.visibility='visible';
	if (__popIframe) {
		__popIframe.style.visibility='visible';
	}
	__pop.innerHTML=src;
	popPrzesun(pX,pY);
}


function popZamknij()
{
	if (__popIframe) {
		__popIframe.style.visibility='hidden';
	}
	__pop.style.visibility='hidden';
	__pop.innerHTML='';
	__pop.style.left=0;
	__pop.style.top=0;
}

function popKom(tresc) {
	text='<div class="dymek">'+tresc+'</div>';
	popPokaz(10,10,text);
}


function popLinkPrzesun() {
	popPrzesun(10,10);
}


function popSrodekPrzesun() {
	popPrzesun(-90,20);
}

init();

/*@@@Section Ajax@@@*/

var ajax = new AJAX("");

function caller()
{
	if(!ajax) return;
	try {
		for(i=0;i<ajax.callerArray.length;i++)
		{
			var callerObj = ajax.callerArray[i];
			if(callerObj.responseReceived())
			{
				ajax.callerArray.splice(i,1);
				callerObj.responseHandler(callerObj.data);
				return;
			}
		}
	}
	catch(e) {
		if(debug) alert('status: '+e.message);
	}
}


function HttpRequest(url,data,requestData,responseHandler,async,method) {
	try {
		this.http = false;
		if (window.XMLHttpRequest) {
			this.http = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
			try {
				this.http  = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				this.http = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	catch(e) {
		throw "Błąd podczas inicjacji obiektu XmlHTTPRequest";
	}
	this.url = url;
	this.method = method;
	this.responseHandler = responseHandler;
	this.data = data;
	this.requestData = requestData.replace(/&amp;/g,'&');
	this.savedContent = '';
	this.error = false;
	this.responseReceived = function() {
		if (this.http.readyState == 4)
		{
			if (this.http.status == 200)
			{
				return true;
			} else
			{
				if(debug) alert("Wystąpił błąd podczas transmisji danych:\n" +
				this.http.statusText);
				this.error = true;
				return true;
			}
		}
		return false;
	};
	this.getResponseText = function() {
		return this.error ? '' : this.http.responseText;
	}
	this.getResponseXML = function() {
		root = this.http.responseXML ? (this.http.responseXML.documentElement ? this.http.responseXML.documentElement : this.http.responseXML.firstChild) : null;
		if(debug && !root) {
			if(arguments.length == 1)
				arguments[0]('Niepoprawny XML');
			else
				showMessage('Niepoprawny XML');
		}
		else {
			if(root.nodeName.toUpperCase() == 'ERROR' && root.childNodes[0] && root.childNodes[0].firstChild.nodeValue == 1) {
				var errorMessage = root.childNodes[1] && root.childNodes[1].firstChild && root.childNodes[1].firstChild.nodeValue ? root.childNodes[1].firstChild.nodeValue : '';
				errorMessage = errorMessage.replace(/^W#/, '');
				var errorCode = parseInt(root.childNodes[2] && root.childNodes[2].firstChild && root.childNodes[2].firstChild.nodeValue ? root.childNodes[2].firstChild.nodeValue : 0);
				if(arguments.length == 1)
					arguments[0](errorMessage, errorCode);
				else
					showMessage(errorMessage, errorCode);
				return null;
			}
		}
		return root;
	}
	this.http.open(this.method, this.url,async);
	this.http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	this.http.onreadystatechange = caller;
	this.http.send(this.requestData);
	if(!async && this.responseHandler) this.responseHandler(this.data);
}

function defaultResponseHandler(id) {
	var element = document.getElementById(id);
	if(element != null) {
		element.innerHTML = this.getResponseText();
		runScriptsInsideElement(element);
	}
	else showMessage(this.getResponseText());
}

function AJAX(url) {
	this.url	= url;
	this.callerArray = new Array();
	this.setURL = function(newURL) {
		this.url = newURL;
	}

	// metoda domyślnie obsługująca odpowiedź z serwera
	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;
			var 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('?');
		var pos2 = uri.indexOf('#');
		if(pos2>0)
			if(!pos || pos==-1||(pos>0 && pos2<pos))
				pos = pos2;
		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() {};
			var 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() {};
			var 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;
	}
	this.xhtmlConvert = function(x) {
		return x.replace('&lt;![CDATA[','<![CDATA[').replace(']]&gt;',']]>');
	}
	this.jsonConvert = function(x) {
		return eval('('+x+')');
	}
}

function harvestData(element)
{
	var div = _e(element);
	var requestData = '';
	var x = 0;

	e = div.getElementsByTagName('input');
	for(var j=0;j<e.length;j++) {
		if(!((e[j].type=="checkbox" && e[j].checked==false) || (e[j].type=="radio" && e[j].checked==false) || e[j].disabled == true)) {
			if(x==0) requestData = e[j].name + '=' + encodeURIComponent(e[j].value);
			else requestData += '&' + e[j].name + '=' + encodeURIComponent(e[j].value);
			x++;
		}
	}
	e = div.getElementsByTagName('select');
	for(var j=0;j<e.length;j++) {
		if(x==0) requestData = e[j].name + '=' + encodeURIComponent(e[j].value);
		else requestData += '&' + e[j].name + '=' + encodeURIComponent(e[j].value);
		x++;
	}
	e = div.getElementsByTagName('textarea');
	for(var j=0;j<e.length;j++) {
		if(x==0) requestData = e[j].name + '=' + encodeURIComponent(e[j].value);
		else requestData += '&' + e[j].name + '=' + encodeURIComponent(e[j].value);
		x++;
	}
	return requestData;
}

/*@@@Section XMLToJSON@@@*/

Classes.XMLToJSON = {
	convert: function(xmlDocument) {
		var root  = null;
		if(!xmlDocument) throw "Nieprawid-owy XML";
		if(!xmlDocument.childNodes && !xmlDocument.nodeName) {
			root = xmlDocument.documentElement ? xmlDocument.documentElement : xmlDocument.firstChild;
		} else root = xmlDocument;		
		return this.convertNode(root);
	},	
	convertNode: function(node) {
		var retObj = {};
		if(!node) return retObj;		
		for(var i=0;i<node.childNodes.length;i++) {
			if(!node.childNodes[i]) continue;
			
			if(!node.childNodes[i].childNodes.length) 
				retObj[node.childNodes[i].nodeName] = null;
			else {
				if(node.childNodes[i].firstChild.nodeType == 3 || node.childNodes[i].firstChild.nodeType == 4)
					retObj[node.childNodes[i].nodeName] = node.childNodes[i].firstChild.nodeValue;
				else 
					retObj[node.childNodes[i].nodeName] = this.convertNode(node.childNodes[i]);							
			}
		}
		return retObj;
	}
}
/*@@@Section MenuKategorie@@@*/

Classes.MenuKategorie = Class();
Classes.MenuKategorie.prototype = {
	id: null,
	categoriesId: null,	
	handle: null,
	state: 0,
	
	__construct: function(params) {
		this.copy(params);
		this.categoriesId = 0;
		this.handle = setInterval(this.handleInterval.bind(this),1200);
		this.uaktywnij();
	},
	handleInterval: function() {
		if(!this.hideMenu) return;
		this.hideMenu.style.display = 'none';
		this.hideMenu = false;
	},	
	uaktywnij: function() {		
		if(!browser.isIE /*|| browser.isIE7 */|| browser.isIE8) return;		
		e = _e(this.id);		
		//e.style.marginLeft = '-10px';		
		var li,list = e.getElementsByTagName('li');
		for(var i=0;i<list.length;i++) {
			li = list[i];
			//alert(li.className);
			if(li && (li.className+'').lastIndexOf('categorySub')!=-1) {
				//alert('o binf');
				var div = li.getElementsByTagName('div');
				div = div[0];				
				//alert(div);
				var f1 = this.pokaz.bindEvent(this,div);
				var f2 = this.zamknij.bindEvent(this,div);				
				addEvent(li,'mouseover',f1);
				addEvent(li,'mouseout',f2);
				//addEvent(li,'click',this.gotoUrl.bindArgs(this,a.href));
			}			
		}		
	},
	pokaz: function(event,e) {
		if(this.hideMenu) {
			this.hideMenu.style.display = 'none';		
			this.hideMenu = false;
		}
		e.style.display = 'block';		
	},
	zamknij: function(event,e) {
		//e.style.display = 'none';		
		this.hideMenu = e;
	},

	/* do kategorii na stronach kategorii */
	onHideClick: function(id) {
		show(_e(id+'roff'));
		hide(_e(id+'ron'));
		hide(_e(id+'block'));
	},
	onShowClick: function(id) {
		show(_e(id+'ron'));
		show(_e(id+'block'));
		hide(_e(id+'roff'));
	},
	showAll: function() {
		var list = _e('filtrowanie').getElementsByTagName('div');		
		if(this.state == 0) {		
			for(var i=0;i<list.length;i++) {
				if(list[i].id && list[i].id.substr(list[i].id.length-5)=='block') this.onShowClick(list[i].id.substr(0,list[i].id.length-5));			
			}
			this.state = 1;
			show('hide-all-button');
			hide('show-all-button');
		} else {
			for(var i=0;i<list.length;i++) {
				//alert(list[i].className);
				if(list[i].id && list[i].id.substr(list[i].id.length-5)=='block' && list[i].className.indexOf('tree_block1')==-1) this.onHideClick(list[i].id.substr(0,list[i].id.length-5));			
			}
			this.state = 0;
			hide('hide-all-button');
			show('show-all-button');
		}		
	}	
}

/*@@@Section Include@@@*/

function poleUstaw(pozycja, nieaktywny)
{
	var e = _e(pozycja);
	e.disabled = nieaktywny;
	if(!nieaktywny)
		e.style.background = '#FFFFFF';
	else
		e.style.background = '#eeeeee';
}

function odbiorcaUstaw(typ)
{
	switch(typ)
	{
		case 0:
			poleUstaw('r_faktura_imie',false);
			poleUstaw('r_faktura_nazwisko',false);
			show('starImie');
			show('starNazwisko');

			poleUstaw('r_faktura_firma',true);
			poleUstaw('r_faktura_nip',true);
			hide('starFirma');
			hide('starNip');
		break;
		case 1:
			poleUstaw('r_faktura_imie',true);
			poleUstaw('r_faktura_nazwisko',true);
			hide('starImie');
			hide('starNazwisko');

			poleUstaw('r_faktura_firma',false);
			poleUstaw('r_faktura_nip',false);
			show('starFirma');
			show('starNip');
		break;
	}
}

function newsletterUstaw()
{
	var bp = _e('blok-przelacz-news');

	if(bp)
	{
		var label = bp.getElementsByTagName('label');
		var licznik = 0;

		if(label)
		{
			for(var i=0; i<label.length; i++)
			{
				var kat = _e('k_'+i);
				if(kat && kat.checked)
				{
					licznik++;
				}
			}

			_e('newsletter_wszystko').checked = (i>0 && (i-1) == licznik)? 'checked' : '';
		}
	}
}

function newsletterZaznaczWszystko()
{
	var e, bp = _e('blok-przelacz-news');
	var label = bp.getElementsByTagName('label');
	if(label) {
		for(var i=0; i<label.length; i++) {
			if(e = _e('k_'+i))
				e.checked = (_e('newsletter_wszystko').checked)? 'checked' : '';
		}
	}
}

function blokPrzelacz(id)
{
	var bpp  = _e('bpp'+id);
	var bpu  = _e('bpu'+id);
	var bp  = _e('blok-przelacz-'+id);

	if((bpp == null) || (bpu == null))
		return;

	if(bpu.style.display == "none") //ukryj(bpu) - pokazany, pokaz(bpp) - ukryty
	{
		bpu.style.display = "";
		bpp.style.display = "none";
		bp.style.display = "";
	}
	else
	{
		bpu.style.display = "none";
		bpp.style.display = "";
		bp.style.display = "none";
	}
}

/* Wykorzystane przy przekierowaniu do platnosci.pl */
var aktywuj = false;
var gotowy = false;

function odliczaj()
{
	var button = _e('butt');

	if(aktywuj)
	{
		setTimeout('odliczaj()', 5000);
		aktywuj = true;
	}
	else
	{
		button.style.display = '';
		if(button.style.display != 'none')
		{
			if(gotowy)
			{
				_e('platnosci').submit();
			}
			else
			{
				setTimeout('odliczaj()', 3000);
				gotowy = true;
			}
		}
	}
}
var newsKindPopup;
function newsletter_zapisz()
{
        newsKindPopup = 4;
	ajax.callMethod('NewsletterZapiszKomponent','zapisz', null, harvestData('newsletter_form'), null, function(data) {
		var root = this.getResponseXML(showMessage);
		if(!root) return;
		var e =_e('newsletter_lista_zapis');
		e.innerHTML = root.childNodes[0].firstChild.nodeValue;
	});
}

function showErrorMessage(msg,type) {
	var typeErrorMessage;
	if (type == 1) {typeErrorMessage = 'popup-grey';}
	else if (type == 2) {typeErrorMessage = 'popup-green';}
	else if (type == 3) {typeErrorMessage = 'popup-yellow';}
	else if (type == 4) {typeErrorMessage = 'popup-red';}
        else if (type == 0) {typeErrorMessage = 'popup-green';}
        else {typeErrorMessage = 'popup-red';}
	showMessage(msg,typeErrorMessage);
}

function showMessage(msg,type) {
	var box = _e('showMessageBox'), content = _e('showMessageContent');
	var typeMessage;
        
        if (typeof newsKindPopup != 'undefined' && newsKindPopup == 4 && type == 0) {typeMessage = 'popup-red';}
	else if (type == 1) {typeMessage = 'popup-grey';}
	else if (type == 2) {typeMessage = 'popup-green';}
	else if (type == 3) {typeMessage = 'popup-yellow';}
	else if (type == 4) {typeMessage = 'popup-red';}
        else if (type == 0) {typeMessage = 'popup-green';}
        else {typeMessage = 'popup-red';}
	if(box && content) {
		show("msg-ok-btn");
		hide("msg-confirm-btn");
		show(box);
		box.className = typeMessage;
		content.innerHTML = msg;
		var wynik = centerElement('showMessageBox');
		if (browser.isIE6) {
			var showframe = _e('showMessageIframe');
			showframe.style.left = box.style.left;
			showframe.style.top = box.style.top;
			showframe.style.width = box.offsetWidth;
			showframe.style.height = box.offsetHeight;
			show(showframe);
			showframe.style.zIndex = '1';
			}


		box.style.zIndex = '50';
	} else {
		alert(msg);
	}
}

function showConfirmMessage(msg,yeshandler,nohandler,nthhandler,type) {
	var box = _e('showMessageBox'), content = _e('showMessageContent');
	var typeMessageConfirm;
	if (type == 1) {typeMessageConfirm = 'popup-grey';}
	else if (type == 2) {typeMessageConfirm = 'popup-green';}
	else if (type == 3) {typeMessageConfirm = 'popup-yellow';}
	else if (type == 4) {typeMessageConfirm = 'popup-red';}
        else if (type == 0) {typeMessageConfirm = 'popup-green';}
	else {typeMessageConfirm = 'popup-red';}
	
	if(box && content) {
		hide("msg-ok-btn");
		show("msg-confirm-btn");
		show(box);
		
		box.className = typeMessageConfirm;
		centerElement('showMessageBox');
		box.style.zIndex = '50';
		content.innerHTML = msg;
		_e('cm-tak-btn').onclick = function() {
			if(yeshandler) yeshandler();
			hide(_e('showMessageBox'));
		};
		_e('cm-nie-btn').onclick = function() {
			if(nohandler) nohandler();
			hide(_e('showMessageBox'));
		};
		_e('cm-nth-btn').onclick = function() {
			hide(_e('showMessageBox'));
		};
	} else {
		alert(msg);
	}
}

function idz(url) {
	window.location = url;
}


//podmiana obrazków dla odpowiednich przycisków
function ustawPrzyciskiOver() {
	this.src = this.src.replace('.jpg', '_zap.jpg');
	this.src = this.src.replace('.gif', '_zap.gif');
}
function ustawPrzyciskiOut() {
	this.src = this.src.replace('_zap.jpg', '.jpg');
	this.src = this.src.replace('_zap.gif', '.gif');
}
function ustawPrzyciski(root) {
	var a, i, n, regexp = /\?zap$/;
	if (!root) {
		root = document;
	}
	a = root.getElementsByTagName('input');
	for (i = 0, n = a.length; i < n; i += 1) {
		if (a[i].src.match(regexp)) {
			addEvent(a[i], 'mouseover', ustawPrzyciskiOver.bind(a[i]));
			addEvent(a[i], 'mouseout', ustawPrzyciskiOut.bind(a[i]));
			a[i].src = a[i].src.replace(regexp, '');
		}
	}
	a = root.getElementsByTagName('img');
	for (i = 0, n = a.length; i < n; i += 1) {
		if (a[i].src.match(regexp)) {
			addEvent(a[i], 'mouseover', ustawPrzyciskiOver.bind(a[i]));
			addEvent(a[i], 'mouseout', ustawPrzyciskiOut.bind(a[i]));
			a[i].src = a[i].src.replace(regexp, '');
		}
	}
}


function wyszukiwarkaFocusHandler(event) {
	var e = eventTarget(event);
	if (e.value == e.getAttribute('placeholder')) {
		e.value = '';
	}
}

function wyszukiwarkaBlurHandler(event) {
	var e = eventTarget(event);
	if (!e.value) {
		e.value = e.getAttribute('placeholder');
	}
}

function wyszukiwarkaSubmitHandler(event) {
	var form, e, errors = [], delta;
	form = eventTarget(event);
	e = form.fraza;
	//wyczyść zabłąkany placeholder
	if (e.value == e.getAttribute('placeholder')) {
		e.value = '';
	}
	//sprawdź długość frazy
	if (e.value.length < form.szukajMinLength) {
		errors.push('Podana fraza wyszukiwania <b>' + e.value + '</b> jest za krótka.');
		errors.push('Wpisz minimum <b>' + form.szukajMinLength + '</b> znaki.');
		errors.push('Wyszukuj ponownie  za kilka sekund.');
	}
	//sprawdź częstość wyszukiwania
	delta = form.szukajDelta + ((new Date()).getTime() - form.szukajDateStart.getTime()) / 1000;
	if (delta < form.szukajMinDelta) {
		errors.push('Zbyt częste próby wyszukiwania. Spróbuj ponownie za kilka sekund.');
	}
	//pokaż komunikaty
	if (errors.length > 0) {
		showErrorMessage(errors.join('<br/>\n'));
		preventDefault(event);
		return false;
	}
	return true;
}

function wyszukiwarkaPlaceholder() {
	var e, form = document.getElementById('searchForm');
	if (form && form.fraza && !form.forum) {
		e = form.fraza;
		//najpierw sprawdź wsparcie atrybutu w przeglądarce
		if (!("placeholder" in document.createElement("input"))) {
			addEvent(e, 'focus', wyszukiwarkaFocusHandler);
			addEvent(e, 'blur', wyszukiwarkaBlurHandler);
			if (!e.value) {
				e.value = e.getAttribute('placeholder');
			}
		}
		//dodaj sprawdzenia przy wysyłaniu formularza
		form.szukajDateStart = new Date();
		form.szukajDelta = parseInt(e.getAttribute('data-delta'), 10);
		form.szukajMinDelta = parseInt(e.getAttribute('data-min-delta'), 10);
		form.szukajMinLength = parseInt(e.getAttribute('data-min-length'), 10);
		addEvent(form, 'submit', wyszukiwarkaSubmitHandler);
	}
}

function GAtrackSendForm(name) {
	if (GATrack)
		GATrack.trackSendForm(name);
}

function GAtrackEvent(category,act,label) {
	if (GATrack)
		GATrack.trackEvent(category,act,label);
}
/*@@@Section AC_RunActiveContent@@@*/

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

/*@@@Section Mouse@@@*/

Classes.Mouse = Class();
Classes.Mouse.prototype = {
	dx:		0,
	dy:		0,
	x:			0,
	y:			0,
	
	targetElement:		null, 
	button:					false,
	mouseEvents:	{
		onMouseMove:		new Array(),
		onMouseDown:		new Array(),
		onMouseUp:		new Array()
	},
	
	__construct: function() {
		//document.onmousemove = this.findCoords.bind(this);
		document.onmousedown = this.mouseButtonPressed.bind(this);
		document.onmouseup     = this.mouseButtonReleased.bind(this);
	},
	findCoords: function(e) {
		if( !e ) { e = window.event; } 
			if( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) { 
				this.x = 0;
				this.y = 0;
				return; 
			}
		if( typeof( e.pageX ) == 'number' ) { 
			var posX = e.pageX; var posY = e.pageY; 
		} else {
			var posX = e.clientX; var posY = e.clientY;
			if( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || window.navigator.vendor == 'KDE' ) ) {
			if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
				posX += document.documentElement.scrollLeft; posY += document.documentElement.scrollTop;
			} else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
				posX += document.body.scrollLeft; posY += document.body.scrollTop;
				}
			}
		}
		this.dx = posX - this.x;
		this.dy = posY - this.y;
		this.x = posX;
		this.y = posY;		
		if(this.mouseEvents && this.mouseEvents.onMouseMove) {
			var e = this.mouseEvents.onMouseMove;
			for(var i = 0;i<e.length;i++) e[i](this);
		}
	},
	mouseButtonPressed:  function(e) {
		var targ;
		this.button = true;		
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;		
		this.targetElement = targ;		
		if(this.mouseEvents && this.mouseEvents.onMouseDown) {
			var e = this.mouseEvents.onMouseDown;
			for(var i = 0;i<e.length;i++) e[i](this);	
		}		
	},
	mouseButtonReleased: function(e) {
		this.button = false;
		if(this.mouseEvents && this.mouseEvents.onMouseUp) {
			var e = this.mouseEvents.onMouseUp;
			for(var i = 0;i<e.length;i++) e[i](this);			
		}
	},
	addEvent: function(event,func) {
		if(!this.mouseEvents) return;
		var ea = this.mouseEvents[event];
		ea.push(func);
	},
	removeEvent: function(event,func) {
		if(!this.mouseEvents) return;
		var ea = this.mouseEvents[event];
		for(var i = 0;i < ea.length;i++)
			if(ea[i].toString() == func.toString()) {
				ea.splice(i,1);
				return;
			}
	}
}

var mouse = new Classes.Mouse();
/*@@@Section Koszyk@@@*/

/*global Class, Classes, _e, _v, _xn, _xv, addClass, addEvent, ajax, hasClass, hide, preventDefault, removeClass, show, showMessage, window*/

Classes.Koszyk = new Class();
Classes.Koszyk.prototype = {
	activeTabSchowek: false,
	flashCountKoszyk: 0,
	flashCountSchowek: 0,
	flashIntervalId: null,
	schowekUsunId: null,
	slide: null,
	slideTimeout: 2000,

	__construct: function (params) {
		this.copy(params);
		addEvent(window, 'load', function () {
			this.slide = new Classes.SlideFx({
				containerClassName: 'koszykSlideContainer',
				contentClassName: 'koszykSlide',
				onFinish: this.onSlideFinish.bind(this),
				animationSpeed: 10,
				animationStep: 0.03
			});
		}.bind(this));
	},

	onSlideFinish: function () {
		if (this.slide.direction > 0) {
			setTimeout(function () {
				this.slide.start(-1);
			}.bind(this), this.slideTimeout);
		}
		else {
			this.slide.hide();
		}
	},

	dodajKoszyk: function (pid, amount_unit) {
		var paramsPost = 'productID=' + pid;

		if (amount_unit) {
			paramsPost = paramsPost + '&amount=' + Math.abs(_floatIn(amount_unit, 1));
		}
		ajax.callMethod('KoszykKomponent', 'addProduct', null, paramsPost, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
				if (root) {
					obj.callbackDodaj(root,'addBasket');
				}
			}
		);
		if (GATrack)
			GATrack.trackEvent('Product', 'Addtobasket', pid);
	},
	zmienKoszyk: function (pid, amount, amount_unit,type) {
		var paramsPost = 'productID=' + pid;
                if (amount_unit) {
                    if (type == 'up') {
                       amount = amount + amount_unit;
                    } else if(type == 'down') {
                       amount = amount - amount_unit;
                    }
                    paramsPost = paramsPost + '&amount=' + amount;
		}
		ajax.callMethod('KoszykKomponent', 'updateProductX', null, paramsPost, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
				if (root) {
					obj.callbackDodaj(root,'addBasket');
				}
			}
		);
	},	
	usunKoszyk: function (pid) {
		var paramsPost = 'productID=' + pid;
		ajax.callMethod('KoszykKomponent', 'removeProductX', null, paramsPost, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
				if (root) {
					obj.callbackDodaj(root, 'removeBasket');
				}
			}
		);
	},
	dodajSchowek: function (pid) {
		var paramsPost = 'productID=' + pid;
		ajax.callMethod('KoszykKomponent', 'addProductCloset', null, paramsPost, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
				if (root) {
					obj.callbackDodaj(root, 'addStore');
				}
			}
		);
		if (GATrack)
			GATrack.trackEvent('Product', 'Addtoclipboard', pid);
	},
	usunSchowek: function (pid) {
		var paramsPost = 'productID=' + pid;
		ajax.callMethod('KoszykKomponent', 'removeProductY', null, paramsPost, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
				if (root) {
					obj.callbackDodaj(root, 'removeStore');
				}
			}
		);
	},	
	usunPorown: function (pid) {
		var paramsPost = 'productID=' + pid;
		ajax.callMethod('KoszykKomponent', 'removeProductZ', null, paramsPost, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
				if (root) {
					obj.callbackDodaj(root, 'removeCompare');
				}
			}
		);
	},		
	callbackDodaj: function (root, koszyk) {
		var div = _e('koszykZawartosc');
		if ('error' === _xn(root.firstChild)) {
			showMessage(_xv(root.firstChild));
			
		} else if (koszyk == 'addBasket') { 
                        if (div) {//na stronie jest komponent
                        div.innerHTML = '<div id="koszykTools"><div>'+ajax.xhtmlConvert(_xv(root.firstChild));
                        $("#top-contact-basket-scroll .arroww-up").data('direction', 'rozwiń');
                        showBasketForAMoment(koszyk == 'addBasket');
                        howManyPercentInBasket();
                        }
			//showMessage('Produkt został dodany do koszyka. Odśwież zawartość koszyka aby zobaczyć opis towarów.',2);
		} else if (koszyk == 'koszykTools') {
                        div.innerHTML = '<div id="koszykTools"><div>'+ajax.xhtmlConvert(_xv(root.firstChild));
                        $("#top-contact-basket-scroll .arroww-up").data('direction', 'rozwiń');
			showMessage('Produkt został usunięty z koszyka.',2);
                        howManyPercentInBasket();
		} else if (koszyk == 'addStore') {
                        div.innerHTML = '<div id="koszykTools"><div>'+ajax.xhtmlConvert(_xv(root.firstChild));
                        $("#top-contact-basket-scroll .arroww-up").data('direction', 'rozwiń');
			showMessage('Produkt został dodany do schowka.',2);
                        $('#msg-ok-btn').bind('click',function(){
                           window.location.reload();
                        })
		} else if (koszyk == 'removeStore') {
                        div.innerHTML = '<div id="koszykTools"><div>'+ajax.xhtmlConvert(_xv(root.firstChild));
                        $("#top-contact-basket-scroll .arroww-up").data('direction', 'rozwiń');
			showMessage('Produkt został usunięty ze schowka.',2); 
                        $('#msg-ok-btn').bind('click',function(){
                           window.location.reload();
                        })
		} else if (koszyk == 'removeCompare'){
                    div.innerHTML = '<div id="koszykTools"><div>'+ajax.xhtmlConvert(_xv(root.firstChild));
                    $("#top-contact-basket-scroll .arroww-up").data('direction', 'rozwiń');
                    showMessage('Produkt został usunięty z porównania.',2);
                    $('#msg-ok-btn').bind('click',function(){
                           window.location.reload();
                    })
		} else if (koszyk == 'removeBasket'){
                    div.innerHTML = '<div id="koszykTools"><div>'+ajax.xhtmlConvert(_xv(root.firstChild));
                    $("#top-contact-basket-scroll .arroww-up").data('direction', 'rozwiń');
                    showBasketForAMoment(koszyk == 'removeBasket');
                    howManyPercentInBasket();
		} 
	},

	addProductSubmit: function (pid, amount_unit) {
		_e('powiazaneProduktId').value = pid;
		_e('powiazaneAmount').value = Math.abs(parseFloat(amount_unit));
		_e('form-powiazane').submit();
	},

	basketSubmit: function () {
		var formKoszyk = _e('formKoszyk');
		if (formKoszyk) {
			formKoszyk.submit();
		}
	},
        saveNote: function(){
            showMessage('Notatki zostały zapisane.',2);
        },
	aflijacja: function (id, bId) {
		var element = _e(id).checked, blok = _e(bId);
		var komun = _e('afiliacyjny_komunikat');
		if (komun) {
			komun.style.display = "none";
		}

		if (element) {
			blok.style.display = "";
		} else {
			this.basketSubmit();
		}
	},

	amountProduct: function (pid, amount_unit, changeValue) {
		var amount, formKoszyk = _e('formKoszyk');
		if (formKoszyk) {
			if (isNaN(Math.abs(parseFloat(changeValue))) == true) {
				formKoszyk.submit();
			} else {
				amount = Math.abs(parseFloat(_e('koszyk_ilosc_' + pid).value));	
				amount_unit = Math.abs(parseFloat(amount_unit));
				
				if (amount_unit == 1) {
					changeValue = Math.abs(parseFloat(changeValue));
					amount = changeValue;
				} else {
					isTail = changeValue.search(',');
					if (isTail != -1 ){changeValue = changeValue.replace(',','.');}
					
					changeValue = Math.abs(parseFloat(changeValue));
					isCorrect = changeValue % amount_unit;
					
					if (isCorrect == 0){
						amount = changeValue;
					} else {
						countUnit = changeValue/amount_unit;
						countUnit = Math.ceil(countUnit);
						amount = amount_unit*countUnit;
					}
				}
				 
				
				_e('koszykIlosc').value = amount;
				if (0 < amount) {
					_e('modeK').value = 'koszyk_ilosc';
					_e('productId').value = pid;
					formKoszyk.submit();
				}
			}
		}
	},
        
        amountProductWithCount: function (pid, amount_unit, changeValue) {
		var amount, formKoszyk = _e('formKoszyk');
                var countValue = _e('jednostka_miary_dodatkowa_'+pid).value;
		if (formKoszyk) {
                        
			if (isNaN(Math.abs(parseFloat(changeValue))) == true) {
				formKoszyk.submit();
			} else {
				amount = Math.abs(parseFloat(_e('koszyk_ilosc_' + pid).value));	
				amount_unit = Math.abs(parseFloat(amount_unit));
				
                                amount = parseInt(changeValue) * amount_unit;
				_e('koszykIlosc').value = amount;
				if (0 < amount) {
					_e('modeK').value = 'koszyk_ilosc';
					_e('productId').value = pid;
					formKoszyk.submit();
                                        
				}
			}
		}
	},
        unitMeasurePrimaryBasket: function(id_unit_primary, id_unit_secondary, conv_unit) {
                
		var idPrimary = _e(id_unit_primary);
                var idSecondary = _e(id_unit_secondary);
		_e(id_unit_primary).value = parseInt(idSecondary.value / conv_unit);
	},
        
        amountProductBasketBlock: function (indexBlock, pid, amount_unit, changeValue) {
		var amount, formKoszyk = _e('handBasket'+indexBlock);
                var paramsPost = 'productID=' + pid;
		if (formKoszyk) {
			if (isNaN(Math.abs(parseFloat(changeValue))) == true) {
				formKoszyk.submit();
			} else {
				amount = Math.abs(parseFloat(_e('koszyk_podr_ilosc_' + pid).value));	
				amount_unit = Math.abs(parseFloat(amount_unit));
				
				if (amount_unit == 1) {
					changeValue = Math.abs(parseFloat(changeValue));
					amount = changeValue;
				} else {
					isTail = changeValue.search(',');
					if (isTail != -1 ){changeValue = changeValue.replace(',','.');}
					
					changeValue = Math.abs(parseFloat(changeValue));
					isCorrect = changeValue % amount_unit;
					
					if (isCorrect == 0){
						amount = changeValue;
					} else {
						countUnit = changeValue/amount_unit;
						countUnit = Math.ceil(countUnit);
						amount = amount_unit*countUnit;
					}
				}
                                
                                if (amount_unit) {
                                    paramsPost = paramsPost + '&amount=' + amount;
                                }
                                ajax.callMethod('KoszykKomponent', 'updateProductX', null, paramsPost, this,
                                        function (obj) {
                                                var root = this.getResponseXML(showMessage);
                                                if (root) {
                                                        obj.callbackDodaj(root,'addBasket');
                                                }
                                        }
                                );
			}
		}
	},

	removeProduct: function (pid) {
		var formKoszyk = _e('formKoszyk');
		if (formKoszyk) {
			_e('modeK').value = 'koszyk_usun';
			_e('productId').value = pid;
			formKoszyk.submit();
		}
	},

	removeProductAll: function () {
		var formKoszyk = _e('formKoszyk');
		if (formKoszyk) {
			_e('modeK').value = 'koszyk_usun_all';
			formKoszyk.submit();
		}
	},

	flashContent: function () {
		var k = _e('contentKSkoszyk'), s = _e('contentKSschowek');
		if (k && this.flashCountKoszyk) {
			if (hasClass(k, 'flashK')) {
				removeClass(k, 'flashK');
				--this.flashCountKoszyk;
			} else {
				addClass(k, 'flashK');
			}
		}
		if (s && this.flashCountSchowek) {
			if (hasClass(s, 'flashS')) {
				removeClass(s, 'flashS');
				--this.flashCountSchowek;
			} else {
				addClass(s, 'flashS');
			}
		}
		if (this.flashIntervalId && !this.flashCountKoszyk && !this.flashCountSchowek) {
			clearInterval(this.flashIntervalId);
			this.flashIntervalId = null;
		}
	},

	showKoszyk: function () {
		this.activeTabSchowek = false;
		show('contentKSkoszyk');
		hide('contentKSschowek');
		return false;
	},

	showSchowek: function () {
		this.activeTabSchowek = true;
		show('contentKSschowek');
		hide('contentKSkoszyk');
		return false;
	},

	schowekUsun: function (pid) {
		var formUsun = _e('formUsun');
		if (formUsun) {
			formUsun.productId.value = pid;
			formUsun.submit();
		}
	},
	
	schowekUsunAll: function () {
		var formUsun = _e('formUsun');
		if (formUsun) {
			_e('modeS').value = 'schowek_usun_all';
			formUsun.submit();
		}
	},

	checkProduct: function (pid) {
		ajax.callMethod('KoszykKomponent', 'checkProduct', null, 'pid=' + pid, this,
			function (obj) {
				var root = this.getResponseXML(showMessage);
			}
		);
	},

	msgPodzielKoszyk: function (e) {
		if (e && e.checked) {
			showMessage('Złożone zamówienie obejmie tylko produkty o najkrótszym i jednakowym czasie realizacji.\n' +
				'Pozostałe produkty nadal pozostaną w koszyku, tak aby można było złożyć kolejne zamówienie.',3);
		}
	}
};

/*@@@Section Porownywarka@@@*/


Classes.Porownywarka = new Class();
Classes.Porownywarka.prototype = {

	__construct: function () {
		var e, i, n, elements, tbodies, browser = new Classes.Browser();
		//emuluj klasę ":hover" dla IE6
		if (browser.isIE && !browser.isIE7) {
			tbodies = document.getElementsByTagName('tbody');
			for (i = 0, n = tbodies.length; i < n; ++i) {
				if (hasClass(tbodies[i], 'autoselect')) {
					elements = tbodies[i].getElementsByTagName('tr');
					for (i = 0, n = elements.length; i < n; ++i) {
						e = elements[i];
						addEvent(e, 'mouseover', this.selectRow.bind(e));
						addEvent(e, 'mouseout', this.deselectRow.bind(e));
					}
				}
			}
		}
	},

	selectRow: function () {
		addClass(this, 'selected');
	},

	deselectRow: function (e) {
		removeClass(this, 'selected');
	},

	onTakClick: function(pid) {
		this.addProduct(pid,1,1);
	},
	onNieClick: function(pid) {
		this.addProduct(pid,1,0);
	},
	onNthClick: function(pid) {
	},	
	addProduct: function (pid) {
		var nocheck = arguments[1] ? 1 : 0;
		var clear = arguments[2] ? 1 : 0;
                //var div = _e('koszykZawartosc');
		ajax.callMethod('PorownywarkaKomponent', 'addProduct', null, 'productID=' + pid+'&clear='+clear+'&nocheck='+nocheck, this,
			function (obj) {
                                var tagId = _e('porownProdukty');
				var root = this.getResponseXML(showMessage);
                                
				if (root) {
					if ('error' === _xn(root.firstChild)) {
						showMessage(_xv(root.firstChild),4);
					} else {
					if ('confirm' === _xn(root.firstChild)) {
						var v = _int(_xv(root.firstChild),0);
						var c = 0;
						if(v>1)
							c = showConfirmMessage('Do porównywarki dodawany jest produkt z innej kategorii niż umieszczone do porównania, czy usunąć zawartość porównywarki, pozostawiając produkty z jednej kategorii',
							obj.onTakClick.bindArgs(obj,pid),
							obj.onNieClick.bindArgs(obj,pid),
							obj.onNthClick.bindArgs(obj,pid),
							4);
						else
							c = showConfirmMessage('Do porównywarki dodawany jest produkt z innej kategorii, czy usunąć zawartość porównywarki',
							obj.onTakClick.bindArgs(obj,pid),
							obj.onNieClick.bindArgs(obj,pid),
							obj.onNthClick.bindArgs(obj,pid),
							4);
					} else {
                                            tagId.innerHTML = ajax.xhtmlConvert(_xv(root.firstChild));
                                            showMessage('Produkt został dodany do porównania.',2);
                                            $('#msg-ok-btn').bind('click',function(){
                                               window.location.reload();
                                            })
					}
				}
                            }
                        }
		);
	},

	porownUsun: function (productID) {
		var data = {
			productID: productID,
			handler: this
		};
		ajax.callMethod('PorownywarkaKomponent', 'removeProduct', null, 'productID=' + data.productID, data, this.callbackPorownUsun);
	},

	callbackPorownUsun: function (params) {
		var root = this.getResponseXML(), e = _e('porownProdukty');
		if (root && params && params.handler) {
			if ('error' === _xn(root.firstChild)) {
				showMessage(_xv(root.firstChild));
			} else if (e) {
				e.innerHTML = ajax.xhtmlConvert(_xv(root.firstChild));
				if (!e.innerHTML) {
					hide(e);
				} else {
					show(e);
				}
			} else {
				showMessage('Produkt został usunięty z porównania.',2);
			}
		}
	},

	formPorownUsun: function (productID) {
		var form = _e('formPorownUsun');
		if (form) {
			form.productID.value = productID;
			form.submit();
		}
	}
};

var porown = new Classes.Porownywarka();
/*@@@Section ZamowienieSzybkie@@@*/

/*global Class, Classes, _e, addEvent, window*/

Classes.ZamowienieSzybkie = new Class();
Classes.ZamowienieSzybkie.prototype = {
	szukarkaWin: null,

	__construct: function () {
		var i, n, e, form = _e('szukarka');
		if (form) {
			for (i = 0, n = form.elements.length; i < n; i += 1) {
				e = form.elements[i];
				if ('text' === e.type) {
					addEvent(e, 'focus', e.select.bind(e));
				}
			}
		}
	},

	show: function () {
		/*var opt = 'dependent=yes,toolbar=no,resizable=yes,width=640,height=480';*/
		try
		{
			if (this.szukarkaWin && this.szukarkaWin.close && !this.szukarkaWin.closed) {
				this.szukarkaWin.close();
				this.szukarkaWin = null;
			}
		} catch (e1) {}
		try {
			this.szukarkaWin = window.open('zamowienie_szybkie.php', '_blank'/*, opt*/);
			if (this.szukarkaWin && this.szukarkaWin.opener) {
				this.szukarkaWin.focus();
				if (this.szukarkaWin.sizeToContent) {
					this.szukarkaWin.sizeToContent();
				}
			}
		} catch (e2) {}
	},

	hide: function () {
		if (window.opener) {
			window.opener.focus();
			if (window.opener.szukarka) {
				window.opener.szukarka.szukarkaWin = null;
			}
			window.close();
		} else {
			window.history.back();
		}
		return false;
	}

};

/*@@@Section SlideFx@@@*/

Classes.SlideFx = Class();
Classes.SlideFx.prototype = {
	animationSpeed:	20,
	animationStep: 		0.05,

	width:		null,
	content:	null,
	container:	null,

	containerClassName: null,
	contentClassName: null,

	progress:	0,
	direction:  -1,     // 1 lub -1
	handle: 	null,
	visible:		false,

	// zdarzenia
	onFinish: 	null,

	__construct: function(params) {
		this.copy(params);
		var p = document.body;
		this.content = document.createElement('div');
		if(this.contentClassName)
			this.content.className = this.contentClassName;

		this.container = document.createElement('div');
		if(this.containerClassName)
			this.container.className = this.containerClassName;

		this.container.style.overflow = 'hidden';
		this.container.appendChild(this.content);
		p.appendChild(this.container);
		this.width = this.content.offsetWidth;
		this.hide();
	},
	hide: function() {
		this.visible = false;
		this.content.style.marginLeft = this.width+'px';
		hide(this.container);
	},
	show: function(direction) {
		this.visible = true;

		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 = _int((IE || browser.isOpera ? (has_element ? document.documentElement.scrollTop : document.body.scrollTop) : window.scrollY),0);
		var offsetLeft = _int((IE || browser.isOpera ? (has_element ? document.documentElement.scrollLeft : document.body.scrollLeft) : 0),0);

		this.container.style.marginTop = offsetTop+'px';

		show(this.container);
		this.start(direction);
	},
	updateAnimation: function() {
		this.content.style.marginLeft = (this.width-Math.round(this.width*this.progress))+'px';
		if((this.progress >= 1.0 && this.direction > 0) || (this.progress <= 0.0 && this.direction < 0)) {
			window.clearInterval(this.handle);
			this.handle = null;
			if(this.onFinish)	this.onFinish();
		}
		this.progress += this.direction*this.animationStep;
		if(this.progress >= 1.0 && this.direction > 0) {
			this.progress = 1.0;
		}
		if(this.progress <= 0.0 && this.direction < 0) {
			this.progress = 0.0;
		}
	},
	start: function(direction) {
		this.direction = direction;
		this.progress = direction > 0 ? 0 : 1;
		if(this.handle) {
			window.clearInterval(this.handle);
			this.handle = null;
		}
		this.handle = window.setInterval(this.updateAnimation.bindArgs(this),this.animationSpeed);
	},
	setContent: function(html) {
		this.content.innerHTML = html;
	}
}

/*@@@Section GATrackingCode@@@*/

Classes.GATrackingCode = Class();
Classes.GATrackingCode.prototype = {
	pageTracker1: null,
	pageTracker2: null,
	
	__construct: function(params) {
		this.copy(params);
	},
/**
	* Dodawanie lisnków dla GA Tracking Code
	*/
	gaEvents: function() {
		var links = document.getElementsByTagName('a');
		var myDomain = document.location.hostname;
		
		for (i = 0; i < links.length; i++) {
			if (!links[i].href)
				continue;
			
			var onclick = links[i].getAttribute('onclick');
			
			/* GATrack jest już przypisany */
			if (String(onclick).indexOf('GATrack', 0)>-1)
				continue;
			
			/* strona produktu, label: ID produktu */
			var matches = String(links[i].href).match(/\/([\d]+),[^,\.]+.html/i);
			if (matches!==null){
				this.addOnclickEvent(links[i],'Product','Open',matches[1],onclick);
				continue;
			} 
			
			/* pdf, label: adres bez domeny i protokołu */
			if (String(links[i].href).indexOf('.pdf')>-1) {
				this.addOnclickEvent(links[i],'Download','Get',String(links[i]).replace(/^http[s]*:\/\/[^\/]*/, ''),onclick);
				continue;
			}
			
			/* mailto:, label: adres e-mail; wykluczenie dodatkowych atrybutów opcji mailto: */
			matches = String(links[i].href).match(/mailto:[\s]*([\?]*)/);
			if (matches!==null) {
				this.addOnclickEvent(links[i],'Mai','SendMail',matches[1],onclick);
				continue;
			}
			
			/* link zew , label: adres url bez protokołu*/
			var reg = new RegExp('^http[s]*:\/\/'+ myDomain, 'i');
			matches = String(links[i].href).match(reg);			
			if (matches==null) {
				matches = String(links[i].href).match(/http[s]*:\/\/(.+)/);
				if (matches!==null) {
					this.addOnclickEvent(links[i],'Outgoing','goto',matches[1],onclick);
					continue;
				}
			}
			
		}
    		
	},
/**
* Dodaje kod śledzenia do atrybutu onclick elementu
*/
	addOnclickEvent: function(el,category,act,label,onclick) {
		if (!el)
			return;
		el.setAttribute('onclick', "GATrack.trackEvent(\'" + category + "','" + act + "','" + label + "')" + (onclick?'; '+ onclick:''));
	},
/**
 * Śledzenie wysłania zapytania z formularza kontaktowego
 */
	trackSendForm: function(name) {
		var type_1 = _e(name+'-request_type_is');
		var label = '';
		if (type_1 && type_1.selectedIndex!==null) {
			label = type_1.options[type_1.selectedIndex].label;
		}
		var type_2 = _e(name+'-request_type_id');
		if (type_2 && type_2.selectedIndex!==null) {
			label += '-' + type_2.options[type_2.selectedIndex].label;
		}
		this.trackEvent('Mail','SendForm',label);
	},
/**
 * Wyslanie informacji do GA
 */
	trackEvent: function(category,act,label) {
		if (this.pageTracker1)
			_gaq.push(['pageTracker1._trackEvent', "'"+category+"'","'"+act+"'","'"+label+"'"]);
// 			_gaq.push(['pageTracker1._trackEvent', category, act, label]);
		if (this.pageTracker2)
			_gaq.push(['pageTracker2._trackEvent', "'"+category+"'","'"+act+"'","'"+label+"'"]);
// 			_gaq.push(['pageTracker1._trackEvent', category, act, label]);			
	},
/**
 * ustawia pageTracker1 i pageTracker2
 */
	setTracker: function(gaCode1, gaCode2) {
		this.pageTracker1 = gaCode1?true:false;
		this.pageTracker2 = gaCode2?true:false;
	}
	
	
}
var GATrack = new Classes.GATrackingCode();
addEvent(window,'load',function(){GATrack.gaEvents();});
/*@@@Section Licznik@@@*/

/*globals Classes, Class, window, _v */

Classes.Licznik = new Class();
Classes.Licznik.prototype = {
	dateElement: null,
	dateEnd: null,
	endMsg: null,
	intervalId: null,

	__construct: function (dateId, endMsg) {
		var interval, h, m, s;
		this.endMsg = endMsg;
		this.dateEnd = new Date();
		this.dateElement = document.getElementById(dateId);
		if ((interval = _v(this.dateElement))) {
			interval = interval.split(':');
			if (interval.length >= 3) {
				this.dateEnd.setSeconds(this.dateEnd.getSeconds() + parseInt(interval[2], 10));
				this.dateEnd.setMinutes(this.dateEnd.getMinutes() + parseInt(interval[1], 10));
				this.dateEnd.setHours(this.dateEnd.getHours() + parseInt(interval[0], 10));
			}
			this.update();
			this.intervalId = window.setInterval(this.update.bind(this), 1000);
		}
	},

	update: function () {
		var delta, n, days, interval = [0, 0, 0], dateNow = new Date();
		delta = this.dateEnd.getTime() - dateNow.getTime(); //ilość milisekund
		if (delta > 0) {
			delta /= 1000;
			n = Math.floor(delta) % 60;
			interval[2] = (n > 9 ? String(n) : '0' + n); //ilość sekund
			delta /= 60;
			n = Math.floor(delta) % 60;
			interval[1] = (n > 9 ? String(n) : '0' + n); //ilość minut
			delta /= 60;
			interval[0] = Math.floor(delta); //ilość godzin
			days = Math.floor(interval[0] / 24); //ilość dni
			/*
			if (interval[0] > 0) {
				this.dateElement.firstChild.nodeValue = interval[0] + 'g ' + interval[1] + 'm ' + interval[2] + 's';
			} else if (interval[1] > 0) {
				this.dateElement.firstChild.nodeValue = interval[1] + 'm ' + interval[2] + 's';
			} else {
				this.dateElement.firstChild.nodeValue = interval[2] + 's';
			}
			*/
			if (days > 1) {
				this.dateElement.firstChild.nodeValue = days + ' dni';
			} else if (days > 0) {
				this.dateElement.firstChild.nodeValue = '1 dzień';
			} else {
				this.dateElement.firstChild.nodeValue = interval.join(':');
			}
		} else {
			this.dateElement.firstChild.nodeValue = this.endMsg;
			clearInterval(this.intervalId);
		}
		this.dateElement.style.display = 'block';
	}
};

/*@@@Section Kontakt@@@*/

Classes.Kontakt = new Class();
Classes.Kontakt.prototype = {
	name: null,
	windowConstStatus: null,
	site: null,
	type: null,
	productsId: null,
	requestTypeId: null,
	param1: null,
	param2: null,

	__construct: function (params) {
		this.copy(params);
	},

	show: function () {	

		for (var i = 0; i < arguments.length; i++) {
			if (i==0)		
				this.param1 = arguments[i];	
			if	(i==1)	
				this.param2 = arguments[i];
		}				
				
		ajax.callMethod('KontaktKomponent', 'fetch', null, 'window_const_status=' + this.windowConstStatus + '&type=' + this.type + '&name=' + this.name + '&request_type_id=' + this.requestTypeId, this, function (obj) {
			var e, kod, root = this.getResponseXML(obj.errorHandler.bind(obj));
			if (obj && root) {
				e = _e(obj.name);
				e.innerHTML = ajax.xhtmlConvert(root.childNodes[0].firstChild.nodeValue);
				ustawPrzyciski(e);
				show(e);
				if (1==obj.windowConstStatus || 2==obj.windowConstStatus) {
					centerElement(e);
				}

				kod = root.childNodes[1].firstChild.nodeValue;
				var date = new Date();
				_e(obj.name + '-obrazek').src = obj.site + '?classID=KontaktKomponent&method=generujObrazek&window_const_status=' + obj.windowConstStatus + '&type=' + obj.type + '&name=' + obj.name + '&t=' + date.getTime();

				addEvent(_e(obj.name + '-wyslij'), 'click', obj.onSendClick.bind(obj));
				addEvent(_e(obj.name + '-request_type_is'), 'change', obj.onChangeType.bind(obj));
				addEvent(_e(obj.name + '-odswiez'), 'click', obj.onImgReloadClick.bind(obj));

				if (1==obj.windowConstStatus || 2==obj.windowConstStatus) {
					addEvent(_e(obj.name + '-anuluj'), 'click', obj.onCancelClick.bind(obj));
					addEvent(_e(obj.name + '-zamknij'), 'click', obj.onCancelClick.bind(obj));
				}
			}
		});
	},

	onSendClick: function () {
		$('.error').remove();
                $('.error-input').removeClass('error-input');
                var mail = $('#'+this.name+'-nadawca_email');
                var mail2 = $('#'+this.name+'-adresat_email');
		var telephone = $('#'+this.name+'-nadawca_telephone');
		var captcha = $('#'+this.name+'-kod_email');
                var name = $('#'+this.name+'-nadawca_imie_nazwisko');
                var text = $('#'+this.name+'-tresc_email');
                var textLabelSpan = $('label[for='+this.name+'-tresc_email] span');
                var nrFaktury = $('#'+this.name+'-numer_zamowienia');
                var nrFakturyLabelSpan = $('label[for='+this.name+'-numer_zamowienia] span');
                var nazwaProduktu = $('#'+this.name+'-nazwa_produktu');
		var nazwaProduktuLabelSpan = $('label[for='+this.name+'-nazwa_produktu] span');
                
		var mailVal = mail.val();
                var mail2Val = mail2.val();
		var telephoneVal = telephone.val();
		var captchaVal = captcha.val();
                var error = false;
                
                if(mail.length > 0 && (mailVal || telephoneVal)) {
                    if(mailVal && !validateEmail(mailVal)) {
                        telephone.removeClass('error-input');
                        mail.addClass('error-input');
                        mail.closest('tr').after('<tr class="error"><td></td><td>Podany e-mail ma nieprawidłowy format!</td></tr>')
                        error = true;
                    }
                    if(telephoneVal && !validateTel(telephoneVal)) {
                        mail.removeClass('error-input');
                        telephone.addClass('error-input');
                        telephone.closest('tr').after('<tr class="error"><td></td><td>Podany telefon ma nieprawidłowy format! <br />Wymagany format telefonu: xxxxxxxxx</td></tr>')
                        error = true;
                    }
                }
                else if (mail.length > 0 && !mailVal && !telephoneVal) {
                    mail.addClass('error-input');
                    telephone.addClass('error-input');
                    mail.closest('tr').after('<tr class="error"><td></td><td>Wynagane jest podanie adresu e-mail lub numeru telefonu!</td></tr>');
                    telephone.closest('tr').after('<tr class="error"><td></td><td>Wynagane jest podanie adresu e-mail lub numeru telefonu!</td></tr>');
                    error = true;
                }
                if(captcha.length > 0 && !captchaVal) {
                    captcha.addClass('error-input');
                    captcha.closest('tr').after('<tr class="error"><td></td><td>Nie podano kodu z obrazka!</td></tr>');
                    error = true;
                }
                if(name.length > 0 && name.val()=='') {
                    name.addClass('error-input');
                    name.closest('tr').after('<tr class="error"><td></td><td>Nie podano imienia i nazwiska!</td></tr>');
                    error = true;
                }
                if(text.length > 0 && textLabelSpan.length > 0 && text.val()=='') {
                    text.addClass('error-input');
                    text.closest('tr').after('<tr class="error"><td></td><td>Nie podano treści zapytania!</td></tr>');
                    error = true;
                }
                if(mail2.length > 0 && mail2Val && !validateEmail(mail2Val)) {
                    mail2.addClass('error-input');
                    mail2.closest('tr').after('<tr class="error"><td></td><td>Podany e-mail ma nieprawidłowy format!</td></tr>');
                    error = true;
                    
                }
                else if (mail2.length > 0 && !mail2Val) {
                    mail2.addClass('error-input');
                    mail2.closest('tr').after('<tr class="error"><td></td><td>Nie podanu adresu e-mail!</td></tr>');
                    error = true;
                }
                if (nrFaktury.length > 0 && nrFakturyLabelSpan.length > 0 && nrFaktury.val()=='') {
                    nrFaktury.addClass('error-input');
                    nrFaktury.closest('tr').after('<tr class="error"><td></td><td>Nie podano numeru zamówienia lub faktury!</td></tr>');
                    error = true;
                }
                if (nazwaProduktu.length > 0 && nazwaProduktuLabelSpan.length > 0 && nazwaProduktu.val()=='') {
                    nazwaProduktu.addClass('error-input');
                    nazwaProduktu.closest('tr').after('<tr class="error"><td></td><td>Nie podano nazwy produktu!</td></tr>');
                    error = true;
                }
                
                if(error) {
                    return;
                }
                
                ajax.callMethod('KontaktKomponent', 'send', null, harvestData(_e(this.name + '-form'))  + '&window_const_status=' + this.windowConstStatus + '&productsId=' + this.productsId + '&type=' + this.type + '&name=' + this.name + (this.param1!=null?'&param1='+this.param1:'') + (this.param2!=null?'&param2='+this.param2:''), this, function (obj) {
			var e, root = this.getResponseXML(obj.errorHandler.bind(obj));
			if (obj && root) {
				showMessage(root.childNodes[0].firstChild.nodeValue,2);

				if (1==obj.windowConstStatus || 2==obj.windowConstStatus) {
					e = _e(obj.name);
					e.innerHTML = '';
					hide(e);
				} else {
					obj.onChangeType();
				}
			}
		});
                
                
                
//		ajax.callMethod('KontaktKomponent', 'send', null, harvestData(_e(this.name + '-form'))  + '&window_const_status=' + this.windowConstStatus + '&productsId=' + this.productsId + '&type=' + this.type + '&name=' + this.name + (this.param1!=null?'&param1='+this.param1:'') + (this.param2!=null?'&param2='+this.param2:''), this, function (obj) {
//			var e, root = this.getResponseXML(obj.errorHandler.bind(obj));
//			if (obj && root) {
//				//showMessage(root.childNodes[0].firstChild.nodeValue);
//
//				if (1==obj.windowConstStatus) {
//					e = _e(obj.name);
//					e.innerHTML = '';
//					hide(e);
//				} else {
//					obj.onChangeType();
//				}
//			}
//		});
	},

	onChangeType: function () {
		ajax.callMethod('KontaktKomponent', 'change', null, harvestData(_e(this.name + '-form')) + '&window_const_status=' + this.windowConstStatus + '&productsId=' + this.productsId + '&type=' + this.type + '&name=' + this.name, this, function (obj) {
			var e, root = this.getResponseXML(obj.errorHandler.bind(obj));
			if (obj && root) {
				e = _e(obj.name);
				e.innerHTML = ajax.xhtmlConvert(root.childNodes[0].firstChild.nodeValue);
				show(e);
				kod = root.childNodes[1].firstChild.nodeValue;
				var date = new Date();
				_e(obj.name + '-obrazek').src = obj.site + '?classID=KontaktKomponent&method=generujObrazek&window_const_status=' + obj.windowConstStatus + '&type=' + obj.type + '&name=' + obj.name + '&t=' + date.getTime();

				addEvent(_e(obj.name + '-wyslij'), 'click', obj.onSendClick.bind(obj));
				addEvent(_e(obj.name + '-request_type_is'), 'change', obj.onChangeType.bind(obj));
				addEvent(_e(obj.name + '-odswiez'), 'click', obj.onImgReloadClick.bind(obj));

				if (1==obj.windowConstStatus || 2==obj.windowConstStatus) {
					addEvent(_e(obj.name + '-anuluj'), 'click', obj.onCancelClick.bind(obj));
					addEvent(_e(obj.name + '-zamknij'), 'click', obj.onCancelClick.bind(obj));
				}
			}
		});
	},

	onCancelClick: function () {
		var e = _e(this.name);
		e.innerHTML = '';
		hide(e);
	},

	onImgReloadClick: function () {
		var date = new Date();
		_e(this.name + '-obrazek').src = this.site + '?classID=KontaktKomponent&method=generujObrazek&window_const_status=' + this.windowConstStatus + '&type=' + this.type + '&name=' + this.name + '&new=1&t=' + date.getTime();
	},

	errorHandler: function (msg) {
		var date = new Date();
		_e(this.name + '-obrazek').src = this.site + '?classID=KontaktKomponent&method=generujObrazek&window_const_status=' + this.windowConstStatus + '&type=' + this.type + '&name=' + this.name + '&t=' + date.getTime();
		$('#kontakt_zgloszenie').prepend('<div class="error">'+msg+'</div>');
	}
};

