var IE6, IE7, IE, FF, O;

with(window.navigator.userAgent) {
	if(indexOf('MSIE') != -1) {
		IE = true;
		if(indexOf('MSIE 7') != -1) IE7 = true;
		else IE6 = true;
	}
	else if(indexOf('Gecko') != -1) FF = true;
	else if(indexOf('Opera') != -1) O = true;
};

function hexdec(n) { return parseInt(n, 16); };

var email = /(^([a-z0-9\-\+\._]+)+@([a-z0-9\-]+\.)+(com|net|edu|mil|gov|org|int|info|name|([a-z]{2}))$)/i;

function s_fl(o) {
	if(o.id=="s_fm" && o.checked==true) { e('s_l').checked=false; return true; };
	if(o.id=="s_l" && o.checked==true) { e('s_fm').checked=false; return true; };
};

function swf() {
	var url, w, h, id;
	this.draw = draw;
	function draw(url, w, h, id) {
		this.url = url;
		this.w = w;
		this.h = h;
		this.id = id;
		document.write('<'+'script type="text/javascript" src="http://static-old.easygo.pl/js/f.js"><'+'/script>');
	};
};
swf = new swf;

function scrollDiv(o, d) { var t = e(o).getElementsByTagName('div'), j = 0, u = new Array(), scrollCache = new Array(), i; for(i in t) if(t[i].id) { u[j] = t[i]; scrollCache[j] = t[i].innerHTML; j++; } for(i = 0; i < j; i++) u[i].innerHTML = scrollCache[d == 'rew'? (i? i - 1: j - 1): (i == j - 1? 0: i + 1)]; };

var mRI = 0;
var mRB;

function mRU(o, b) {

	var i, m, t;

	if(!mRI) {
		o = e(o);
		if(!o) return false;

		o.style.visibility='hidden';
		o.style.display='inline';

		t = o.getElementsByTagName('A');
		for(i in t) t[i].onmouseover = mRU;

		o.onmouseover = mRU;
		o.onmouseout = mRD;
		b.onmouseout = mRD;

		m = new Object();
		m.x1 = getX(b); m.x2 = getX(o); m.w1 = getW(b); m.w2 = getW(o); m.y1 = getY(b); m.y2 = getY(o); m.h1 = getH(b); m.h2 = getH(o);

		m.object = o;
		m.speed = 10;
		m.frames = 10;
		m.count = 0;
		m.shadow = true;
		mRI = m;
		mRDraw(1);
	};
	mRI.count++;
};

function mRDraw(a) {

	var m, o, x1, x2, w1, w2, y1, y2, h1, h2, w, h;

	m = mRI;
	o = m.object;

	x1 = m.x1; x2 = m.x2; w1 = m.w1; w2 = m.w2; y1 = m.y1; y2 = m.y2; h1 = m.h1; h2 = m.h2;

	if(typeof(mRB) != 'object') {
		mRB = document.createElement('div');
		with(mRB.style) {
			border = '1px solid #cde4ed';
			background = '#ffffff';
			width = (a? w1: w2) + 'px';
			height = (a? h1: h2) + 'px';
			position = 'absolute';
			zIndex = 50;
			left = (a? x1: x2) + 'px';
			top = (a? y1: y2) + 'px';
		};
		m.i = m.frames;
		if(m.shadow) e(o.id+'Shadow').style.display = 'none';
		o.style.visibility='visible';
		o.style.display = 'none';
		w = (a? w1: w2);
		h = (a? h1: h2);
		document.body.appendChild(mRB);
	};

	if(h > 0 && w > 0 && --m.i) {
	w = w - (a? -1: 1) * w2 / m.frames + (a? -1: 1) * w1 / m.frames;
	h = h - (a? -1: 1) * h2 / m.frames + (a? -1: 1) * h1 / m.frames;

		with(mRB.style) {
			left = Math.floor(x2 - (x1 > x2? -1: 1) * (a? m.i: m.frames - m.i) * Math.abs(x1 - x2) / m.frames) + 'px';
			top = Math.floor(y2 - (y1 > y2? -1: 1) * (a? m.i: m.frames - m.i) * Math.abs(y1 - y2) / m.frames) + 'px';

			width = w + 'px';
			height = h + 'px';
		};
		setTimeout('mRDraw('+a+')', m.speed);
	} else {
		document.body.removeChild(mRB);
		mRB = void(0);
		if(a) {
			o.style.display = 'inline';
			if(m.shadow) e(o.id+'Shadow').style.display = 'block';
		} else {
			if(m.shadow) e(o.id+'Shadow').style.display = 'none';
			mRI = void(0);
		};
	};
};

Number.prototype.numberFormat = function() {return Math.ceil(parseFloat(this)*100).toString().split('').reverse().join('').replace(/([0-9]{0,2})([0-9]{3})?([0-9]{3})?([0-9]{3})?([0-9]{1,3})/g, '$1,$2 $3 $4 $5').toString().split('').reverse().join('').replace(/\s+/, ' ');}
String.prototype.numberFormat = function() {return parseFloat(this).numberFormat();}
function mRD() { setTimeout('mRDrawWait('+mRI.count+')', 333); };
function mRDrawWait(p) { if(mRI.count == p) mRDraw(0); };

function getInt(n) { return n == 'auto'? 0: parseInt(n.replace('px', '')); };
function getStyle(o, s) { if(o.currentStyle) return o.currentStyle[s]; else if(window.getComputedStyle) return document.defaultView.getComputedStyle(o, null).getPropertyValue(s.replace(/([A-Z]+)/g, '-$1').toLowerCase()); };
function getX(o) { return getXY(o, 1); };
function getY(o) { return getXY(o, 0); };
function getW(o) { return getInt(getStyle(o, 'width')) + getInt(getStyle(o, 'paddingLeft')) + getInt(getStyle(o, 'paddingRight')); };
function getH(o) { return getInt(getStyle(o, 'height')) + getInt(getStyle(o, 'paddingTop')) + getInt(getStyle(o, 'paddingBottom')); };
function getXY(o, xy) { var p = 0; if(o.offsetParent) while(1) { p += (xy? o.offsetLeft: o.offsetTop); if(!o.offsetParent) break; o = o.offsetParent; } else if(o.x || o.y) p += (xy? o.x: o.y); return p; };
var e_cache = new Array();
function e(o, c) { if(!e_cache[o] || c) e_cache[o] = document.getElementById(o); return e_cache[o]; };
function l(u) { var s = document.createElement('script'); s.type = 'text/javascript'; s.defer = true; s.src = u; document.body.appendChild(s); };
function c(a) { var t = new Date(); new Image().src='/js/statystyki.js?'+a+','+t.getTime(); return true; }
function in_nodes(needle, haystack) { var i; if(haystack === needle) return true; if(haystack.childNodes) with(haystack) { for(i in childNodes) if(childNodes[i] === needle || in_nodes(needle, childNodes[i])) return true; } else return false; }
function in_array(needle, haystack) { var i; if(haystack === needle) return true; for(i in haystack) if(haystack[i]===needle) return true; return false; }

// Przełączanie widoczności

function adv() {
	if(e('search_adv').style.display=='none') {
		e('search_adv').style.display='inline';
		e('search_adv_link').innerHTML = (document.location.href.indexOf('samoloty/en') >= 0 ? 'Standard<br/>search' : 'wyszukiwanie<br/>standardowe');
	} else {
		e('search_adv').style.display='none';
		e('search_adv_link').innerHTML = (document.location.href.indexOf('samoloty/en') >= 0 ? 'Advanced<br/>search' : 'wyszukiwanie<br/>zaawansowane');
	}
}


var link = {
	install: function() {
		var t = document.getElementsByTagName('form'), i, j;
		for(i = 0; i < t.length; i++) {
			var u = t[i].getElementsByTagName('select');
			for(j = 0; j < u.length; j++) u[j].onkeydown = function() { if(window.event.keyCode == 13) {this.form.submit(); void(0); return false;}; };
		};
		return true;
	}
};



// Lista wyników szukania - przełączanie połączeń

var f = {
	check: function(el) {

//		for(i = 0; i < 1; i++) {

			els = el.getElementsByTagName('INPUT');
			for(j in els) if(els[j].type == 'radio' && !els[j].checked) {
				els[j].checked = true;
				return true;
			}
//			el = el.parentNode;
//		}
	},
	o: function(id, v) {
		var d = 0, i;

		t = document.getElementsByName('in' + id);
		if(t.length) {
			for(i = 0; i < t.length; i++) {
				if(!f.d[id][v][t[i].value]) {
					t[i].disabled = true;
					t[i].style.visibility = 'hidden';
				} else {
					if(!d++) {
						t[i].checked = true;
						e('flight' + id).value = f.d[id][v][t[i].value];
					}
					t[i].disabled = false;
					t[i].style.visibility = 'visible';
				}
			}
		} else {
			e('flight' + id).value = f.d[id][v][''];
		}
	},
	i: function(id, v) {
		var t = document.getElementsByName('out' + id), i;
		for(i = 0; i < t.length; i++) if(t[i].checked == true) {
			e('flight' + id).value = f.d[id][t[i].value][v];
			return true;
		}
		return false;
	},
	d: new Array()
}



var web20 = {
	go: function(title,text) {
		if(title) e('coverTitle').innerHTML = title;
		if(text) e('coverText').innerHTML = text;
		e('body').style.display='none';
		e('cover').style.display='block';
		document.body.style.background='#ffffff';
		return true;
	},
	run: function(title,text) {
		web20.go(title,text);
	}
}



var dates = {
	wd: null, wm: null, pd: null, pm: null, mc: new Date().getMonth() + 1, dz: new Date().getDate(),
	pi: function(i) { return parseInt(i.value); },
	dc: function(mt) { with(this) { mt = pi(mt); switch(true){
			case mt == 1 || mt == 3 || mt == 5 || mt == 7 || mt == 8 || mt == 10 || mt == 12: return 31; break;
			case mt == 2: return (mt < mc ? d + 1 : d) % 4 ? 28 : 29; break;
			default: return 30;
	}}},
	install: function(wdid, wmid, pdid, pmid) { with(this) {
		with(wd = e(wdid)) { onchange = function() { dates.check('wd'); }};
		with(wm = e(wmid)) { onchange = function() { dates.check('wm'); }};
		with(pd = e(pdid)) { onchange = function() { dates.check('pd'); }};
		with(pm = e(pmid)) { onchange = function() { dates.check('pm'); }};
	}},
	check: function(o) { with(this) { switch(o) {
		case 'wd':
			if(wm.selectedIndex == 0 && pi(wd) < dz) wm.selectedIndex++;
			if(pi(wd) > dc(wm)) wd.value = dc(wm);
			if(wm.selectedIndex > pm.selectedIndex) pm.selectedIndex = wm.selectedIndex;
			if(wm.selectedIndex == pm.selectedIndex && pi(wd) > pi(pd)) pd.value = pi(wd);
			break;
		case 'wm':
			if(wm.selectedIndex == 0 && pi(wd) < dz) wd.value = dz;
			if(pi(wd) > dc(wm)) wd.value = dc(wm);
			if(wm.selectedIndex > pm.selectedIndex) pm.selectedIndex = wm.selectedIndex;
			if(wm.selectedIndex == pm.selectedIndex) {
				if(pi(wd) > pi(pd)) pd.value = pi(wd);
				if(pi(pd) > dc(pm)) pd.value = dc(pm);
			}
			break;
		case 'pd':
			if(pi(pd) < pi(wd) && pm.selectedIndex == wm.selectedIndex) {
				if(pm.selectedIndex < pm.options.length + 1) pm.selectedIndex++;
				else pd.value = wd.value;
			}
			if(pi(pd) > dc(pm)) {
				if(pm.selectedIndex < pm.options.length + 1) pm.selectedIndex++; else pd.value = dc(pm);
			}
			break;
		case 'pm':
			if(pm.selectedIndex < wm.selectedIndex) pm.selectedIndex = wm.selectedIndex;
			if(pm.selectedIndex == wm.selectedIndex) {
				if(pi(pd) < pi(wd)) pd.value = pi(wd);
			}
			if(pi(pd) > dc(pm) && pm.selectedIndex < pm.options.length + 1) pm.selectedIndex++;
			break;
	}}}
};



var ifr = {
	iframe: false,
	install: function() { if(IE6) { with(this) {

		remove();
		if(!iframe) {
			with(iframe = document.createElement('iframe')) {
				frameBorder = 0; display = 'none'; visibility = 'visible'; src = '/blank.html'; position = 'absolute'; textAlign = 'left'; margin = '0px'; padding = '0px';
			};
			with(document.getElementsByTagName('body')[0]) {
				insertBefore(this.iframe, childNodes[0]);
			}
		}
		return iframe;
	} } return false; },
	remove: function() { with(this) {

		if(iframe) with(iframe.style) {
			display = 'none'; margin = '0px'; padding = '0px'; className = '';
		}
	} return false; }
};



var pop = {
	debug: false,
	si: [],
	fr: false,
	obj: false,
	div: false,
	max: 250,
	posX: 0,
	posY: 0,
	offY: 0,
	bgcolor: '#ffffff',
	brstyle: '1px solid #999999',
	visible: false,
	timeout: 2000,
	timeleft: 0,
	interval: 100,
	pop: function(_evt, _txt, _width) { with(this) {

		if(!_txt || _txt.length == 0) return;
		obj = _evt[IE ? 'srcElement' : 'target'] || obj;
		if(obj) {
			with(obj) {
				if(tagName == 'SELECT') onclick = hide;
			}
			posX = getX(obj);
			posY = getY(obj);
			offY = obj.offsetHeight;
			onmouseover = function(event) { onover(event); }
			onmouseout = function(event) { onout(event); }
		}
		if(typeof(selector) != 'undefined') selector.hide();
		if(typeof(acp) != 'undefined') acp.hide();
		if(visible) hide();
		if(!div) {
			div = document.createElement('div');
			with(document.getElementsByTagName('body')[0]) {
				if(typeof(ifr) != 'undefined') {
					this.fr = ifr.install();
					if(this.fr) insertBefore(this.fr, childNodes[0]);
				}
				insertBefore(div, childNodes[0]);
			}
		}
		with(div) {
			style.display = 'block';
			innerHTML = '<div>' + _txt + '</div>';
			with(style) {
				display = 'block'; zIndex = '99999998'; visibility = 'visible'; position = 'absolute'; textAlign = 'left'; left = posX + 'px'; top = posY + offY + 'px'; backgroundImage = "url('/img/_geoicons/top.gif')"; backgroundPosition = '-15px 0px'; backgroundRepeat = 'no-repeat'; margin = '0px'; padding = '0px'; paddingTop = '5px';
			}
			with(childNodes[0].style) {
				backgroundColor = bgcolor; borderLeft = borderBottom = borderRight = !debug ? brstyle : '1px solid red'; padding = '5px';
			}
			childNodes[0].style.width = typeof(_width) == 'number' ? _width + 'px' : (childNodes[0].scrollWidth > max && _width != 'auto' ? max + 'px' : 'auto');
			onmouseover = function(event) { onover(event); }
			onmouseout = function(event) { onout(event); }
		}
		if(fr) with(fr.style) {
			zIndex = '99999997'; position = 'absolute'; textAlign = 'left'; margin = '0px'; padding = '0px'; left = posX + 'px'; top = posY + offY + 5 + 'px'; height = div.childNodes[0].scrollHeight + 'px'; width = div.clientWidth + 'px'; display = 'block';
		}
		visible = true;
		tic();
		return false;
	}},
	tic: function() { with(this) {

		if(visible) {
			timeleft = timeout;
			si.push(setInterval('pop.tac();', interval));
		}
	}},
	tac: function() { with(this) {

		if(timeleft - interval > 0) timeleft -= interval;
		else hide();
	}},
	hide: function() { with(this) {

		var i;

		visible = false;
		timeleft = 0;
		for(i in si) clearInterval(si[i]);
		if(div) with(div.style) {
			display = 'none'; top = '0px'; left = '0px'; visibility = 'hidden';
		}
		if(typeof(ifr) != 'undefined') ifr.remove();
		return false;
	}},
	onout: function(_evt) { with(pop) {

		if(visible) tic();
	}},
	onover: function(_evt) { with(pop) {

		var _check = IE ? (_evt ? _evt.srcElement : (window.event || {srcElement:false}).srcElement) : _evt[IE ? 'srcElement' : 'target'], i;

		if(typeof(_check) == 'object' && (in_nodes(_check, obj) || in_nodes(_check, div))) {
			for(i in si) clearInterval(si[i]);
			timeleft = timeout;
		}
	}}
};



var acp = {
	debug: false,
	si: false,
	qid: 0,
	obj: false,
	chr: false,
	url: false,
	offY: 0,
	posX: 0,
	posY: 0,
	list: false,
	qurl: false,
	submit: false,
	where: false,
	bufor: [],
	sleep: 300,
	width: 0,
	where: 'nazwisko',
	needle: '',
	strlen: 4,
	options: [],
	visible: false,
	idtarget: { value: false },
	selectedIndex: -1,
	replaceQueryChars: false,
	replaceBrackets: false,
	show: function() { with(this) {

		width = obj.offsetWidth;
		visible = true;
		with(list) {
			style.display = 'block'; style.overflowY = 'auto'; style.overflowX = 'hidden'; style.width = Math.max(width, scrollWidth) + 'px';
		}
		if(fr) with(fr.style) {
			display = 'block'; width = list.offsetWidth + 'px'; height = list.offsetHeight + 'px';
		}
	}},
	query: function() { with(this) {

		var scr;

		if(needle.length >= strlen) {
			if(typeof(bufor[decodeURI(needle)]) != 'object') {
				with(scr = document.createElement('script')) {
					src = qurl + decodeURI(needle) + (where ? ','+this.where : '');
				}
				document.body.appendChild(scr);
			} else fill(bufor[decodeURI(needle)]);
		}
	}},
	fill: function(_bufor) { with(this) {

		var li, i, c;

		if(_bufor.length) {
			bufor[decodeURI(needle)] = _bufor; selectedIndex = -1; options = [];
			if(!list) {
				list = document.createElement('ul');
				with(document.getElementsByTagName('body')[0]) {
					if(typeof(ifr) != 'undefined') {
						this.fr = ifr.install(); if(this.fr) insertBefore(this.fr, childNodes[0]);
					}
					insertBefore(list, childNodes[0]);
				}
				with(list) {
					className = 'ac';
					with(style) {
						if(debug) border = '1px solid red';
						zIndex = '99999998'; left = posX + 'px'; top = posY + offY + 'px';
					}
				}
				if(fr) with(fr) {
					className = 'ac';
					with(style) {
						zIndex = '99999997'; left = posX + 'px'; top = posY + offY + 'px' ;
					}
				}
			}
			with(list) {
				while(lastChild) removeChild(lastChild);
				for(i in _bufor) if(typeof(_bufor[i]) == 'object') {
					options[parseInt(i)] = _bufor[i];
					with(li = document.createElement('li')) {
						innerHTML = '<a href="javascript:void(0);" onclick="acp.selectedIndex=0;acp.take(this);">'+ _bufor[i].n + (_bufor[i].c ? '<span>, '+_bufor[i].c+'</span>' : '') +'</a>';
						if(_bufor[i].c) if(c = getElementsByTagName('span')) c[0].style.fontWeight = 'normal';
					}
					appendChild(li);
				}
			}
			show();
		}
	}},
	take: function(_obj, _hide) { with(this) {

		var sibling = _obj.parentNode.previousSibling, i;


		_hide = typeof(_hide) == 'undefined' ? true : _hide;
		if(_hide) {
			if(sibling) while(sibling) {
				selectedIndex++;
				sibling = sibling.previousSibling;
			} else selectedIndex = 0;
		}
		if(list) for(i in list.childNodes) list.childNodes[i].className = '';
		_obj.parentNode.className = 'sel';
		if(selectedIndex > -1 && options[selectedIndex]) with(options[selectedIndex]) {
			obj.value = n;
			if(replaceQueryChars) obj.value = obj.value.replace('_', '').replace('%', '');
			if(replaceBrackets) obj.value = obj.value.replace(/\s*\[.*\]/, '').replace(/\..*/,'');
			idtarget.value = id || idtarget.value;
		}
		if(_hide && visible) {
			hide();
			obj.select();
		}
	}},
	navigate: function(_updown) { if(this.list) with(this) {

		selectedIndex += _updown;

		var selectedNode = list.childNodes[selectedIndex = selectedIndex > -1 && selectedIndex < list.childNodes.length ? selectedIndex : (selectedIndex == list.childNodes.length ? list.childNodes.length - 1 : 0)];

		take(selectedNode.childNodes[0], false);
		list.scrollTop = Math.max(selectedNode.offsetTop - list.clientHeight / 2, 0);
	}},
	hide: function(from) { if(this.visible) with(this) {

		if(typeof(ifr) != 'undefined') ifr.remove();
		if(list) list.parentNode.removeChild(list);
		list = false;
		visible = false;
		return false;
	}},
	acp: function(_evt, _idtarget, _where, _url) { with(this) {

		url = _url || false;
		where = _where || where;
		idtarget = _idtarget || { value: false };
		var _obj = obj;
		obj = _evt[IE ? 'srcElement' : 'target'] || obj;
		if(obj) {
			posX = getX(obj);
			posY = getY(obj);
			offY = obj.offsetHeight;
			width = obj.offsetWidth;
			with(obj) {
				onblur = function(event) { check(event); };
				onfocus = function(event) { check(event); };
				onkeydown = function(event) { return block(event); };
			}
		}
		if(_obj != obj && visible) hide();
		var _chr = _evt.keyCode || 0;
		if(in_array(_chr, [38, 40])) navigate(_chr == 38 ? -1 : 1);
		if(!in_array(_chr, [9, 13, 16, 27, 38, 40])) {
			needle = obj.value.toLowerCase();
			if(replaceQueryChars) needle = needle.replace('_', '').replace('%', '');
			if(replaceQueryChars) needle = needle.replace(/\s*\[.*\]/, '').replace(/\..*/,'');
			if(needle.length >= strlen) setTimeout('if(acp.qid=='+(++qid)+')acp.query();', sleep);
			else if(visible) hide();
		}
	}},
	check: function(_evt) { with(this) {

		var _check = [_evt || window.event][IE ? 'srcElement' : 'target'], _hide = true, c;

		if(typeof(_check) == 'object' && visible) {
			if(_check == obj || _check == list || _check.parentNode == list || _check.parentNode.parentNode == list) _hide = false;
			if(list) with(list) {
				for(c in childNodes) if(_check == childNodes[c].firstChild) _hide = false;
			}
			if(_hide) hide(); else _check.select();
		}
	}},
	block: function(_evt) { with(this) {

		var _chr = (_evt || window.event).keyCode || 0;

		if(_chr == 13 && submit && url && selectedIndex > -1) location.href = url + obj.value;
		if(visible) {
			if(in_array(_chr, [9, 13]) && selectedIndex == -1 && !submit) navigate(1);
			if(in_array(_chr, [9, 13, 16, 27])) hide();
		}
		return !submit ? _chr != 13  : true;
	}}
};
acp.f = acp.acp;
acp.h = acp.hide;
acp.b = acp.block;
acp.ap = acp.fill;
acp.ch = acp.sa = function() { return false; };

if(!document.all) { window.captureEvents(Event.CLICK); window.onclick = function(event) { if(typeof(acp.check) == 'function') acp.check(event); } } else document.onclick = function(event) { if(typeof(acp.check) == 'function') acp.check(event); };

var ad = {
	iframe: function(param){
		var odp = '';
		try {
			odp = '<iframe frameborder="0" allowtransparency="yes" scrolling="no"';
			odp += ' src="/ad/' + param.site + '/' + param.ad + '.html?' + (document.referrer && !document.referrer.match('/' + document.domain + '/')? 'referer=' + escape(document.referrer) + '&': '') + 'url=' + escape(document.URL);
			if(param.site == 'main' || param.site.indexOf('_main') > 0) odp += 'strona-glowna.html';
			odp += '" style="border:0 none;height:0;' + param.style + ' "';
			odp += ' id="' + param.id + '"';
			if(typeof(param.cssClass) != 'undefined') {
				odp+= ' class='+param.cssClass;
			}
			odp += '></iframe>';
			document.write(odp);
		} catch(err) {}
}}

