var is_ie = false;
if (navigator.appVersion.indexOf('MSIE') >= 0) {is_ie = true;}

function retNumber(value) {	var n = parseInt(value); return n == null || isNaN(n) ? 0 : n; };
function $(id) { return document.getElementById(id); };
function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true;	} else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r;	} else { elm['on' + evType] = fn; } };
function removeEvent(elm, evType, fn, useCapture) { if (elm.removeEventListener){ elm.removeEventListener(evType, fn, useCapture); return true; } else if (elm.detachEvent){ var r = elm.detachEvent("on"+evType, fn); return r; } else { return false;	} };
function getStyle(el,styleProp) { var x = document.getElementById(el); if (x.currentStyle) var y = x.currentStyle[styleProp]; else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); return y; };
function findPos(obj){ var curleft = curtop = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); } return [curleft, curtop]; }; // zwraca tablice zawierajaca pozycje elementu w px
function bodyScrollXY(scrOfX, scrOfY) { if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { document.body.scrollTop = scrOfY;	document.body.scrollLeft = scrOfX; } else { document.documentElement.scrollTop = scrOfY; document.documentElement.scrollLeft = scrOfX; } }; // przewija całe okno
Array.prototype.findIndex = function(value){ var ctr = ""; for (var i=0; i < this.length; i++) { if (this[i] == value) { return i; } } return ctr; }; // zwraca pozycje w tablicy dla podanego elementu

function animate(obj_id, size1, size2, atrybut){
	var start;
	var end;
	var grow;
	obj = document.getElementById(obj_id);
	var act_size = parseInt(getStyle(obj_id, atrybut).replace('px', ''));
	if (act_size > size2) {
		start = act_size;
		end = size1;
		grow = false;
	}
	else
		if (act_size == size2) {
			start = size2;
			end = size1;
			grow = false;
		}
		else {
			start = size1;
			end = size2;
			grow = true;
		}
	var steps = 50;
	var timer = 10;
	var temp = start;
	var progress = (Math.max(act_size, size1, size2) - Math.min(size1, size2)) / steps;
	for (var n = 0; n < steps; n++) {
		if (grow)
			temp += progress;
		else
			temp -= progress;
		var x = setTimeout("obj.style." + atrybut + "='" + temp + "px'", timer * n);
	}
};

function show_curtain(expand_element_id) {
	$(expand_element_id).style.display = 'block';
};

// ---------------- END ogolne funkcje

var mini_gallery_tab;
var last_obj;
var fotoIndex;
var start_txt = 'np. Sopot, Tatry, U Bacy';
var suggestTimeout;
var old_first_value, old_second_value;

function set_miejsce_onload(obj) {
	if(obj.value == start_txt) {
		obj.className = 'empty_input';
	}
	else {
		obj.className = '';
	}
};


function clear_miejsce(obj) {
	if(obj.value == start_txt) {
		obj.value = '';
	}
	obj.className = '';
};

function clear_miejsca() {
	if($('miejsceWczasy').value == start_txt) {
		$('miejsceWczasy').value = '';
	}
	if($('miejsceNoclegi').value == start_txt) {
		$('miejsceNoclegi').value = '';
	}
};

function nextFoto(obj, foto_array, foto_id){

	var parent = obj.parentNode;

	if(is_ie)
		obj = parent.childNodes[2];
	else
		obj = parent.childNodes[3];

	if(obj.counter == undefined) obj.counter = 0;

	if( obj.counter >= (foto_array.length -1)) {
		obj.counter = 0;
	}
	else obj.counter = obj.counter + 1;

	$(foto_id).style.background = 'url(' + foto_array[obj.counter] + ') no-repeat center center';
};


function prevFoto(obj, foto_array, foto_id){
	var parent = obj.parentNode;

	if(is_ie)
		obj = parent.childNodes[2];
	else
		obj = parent.childNodes[3];

	if(obj.counter == undefined) obj.counter = 0;

	if( obj.counter <= 0) {
		obj.counter = (foto_array.length-1);
	}
	else obj.counter = obj.counter - 1;

	$(foto_id).style.background = 'url(' + foto_array[obj.counter] + ') no-repeat center center';
};


if (!is_ie) {
	HTMLElement.prototype.click = function(){
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}



var mainPromoArray = [ 'mainPromoStart', 'mainPromoItem2', 'mainPromoItem3', 'mainPromoItem4', ];
var mainPromoTimer;
var mainPromoCounter = 0;

function mainPromoClick(i, n, c) {
	if(n) els = i.parentNode.getElementsByTagName('li');
	else {
		els = i.getElementsByTagName('li');
		n = 1;
	}

	r = 0;
	var heightArray=new Array(0,60,121,182); // wysokosc elementow: 60, 61, 61, 58

	for(el in els) if(typeof(els[el]) == 'object') {
		if(els[el].className!='current' || c) {
			els[el].style.backgroundPosition = '0 -' + heightArray[r] + 'px';
			els[el].className = '';
		}
		else els[el].style.backgroundPosition = '-270px -' + heightArray[r] + 'px';
		r++;
	}

	//i.style.backgroundPosition = '-540px -' + ((n - 1) * 60) + 'px';

	if(c) {
		i.style.backgroundPosition = '-270px -' + heightArray[n - 1] + 'px';
		i.className = 'current';
		if(is_ie) opacity('photo' + n, 80, 100, 1000);
		else opacity('photo' + n, 60, 100, 300);
	}


	if (c) {
		mainPromoCounter = n - 1;
		clearInterval(mainPromoTimer);
		setMainPromoInterval();
		//console.log('xxx: ' + mainPromoCounter);
	}
};


function setMainPromoInterval() {
	(function(){
		mainPromoTimer = setInterval(function(){
			//console.log('-------------- setinterval ---------------');
			mainPromoCounter++;
			if (mainPromoCounter >= 4)
				mainPromoCounter = 0;
			//console.debug($(mainPromoArray[mainPromoCounter]));
			$(mainPromoArray[mainPromoCounter]).click();
		}, 7000);
	})();
}


function wczasy_on() {  // pokazuje wyszukiwarke wczasow
	$('search_noclegi').style.display='none';
	$('search_wczasy').style.display='inline';
	//ustawienie zmiennych dla podpowiedzi do wyszukiwarki
		//$(sugProp.hiddenInput).value='';
		sugProp.writing_timeout=null;
		sugProp.selectedItem=-1,
		sugProp.arrow_active=false;
		sugProp.itemChoosen=false;
		sugProp.search_type='w';
		sugProp.sugBoxName='sugWczasy';
		sugProp.typpingInput='miejsceWczasy';
		sugProp.hiddenInput='textWczasy';
		type_search_val = 'w'; // ustawianie zmiennej dla funkcji after_history_back - nie kasowac!
		$('type_search').value='w';

	$('box_popular_wczasy').style.visibility = 'hidden';
	$('box_popular_noclegi').style.visibility = 'hidden';
	new CALENDAR('','','','').closeCalendar();
};


function noclegi_on() { // pokazuje wyszukiwarke noclegow
	$('search_noclegi').style.display='inline';
	$('search_wczasy').style.display='none';
	//ustawienie zmiennych dla podpowiedzi do wyszukiwarki
		//$(sugProp.hiddenInput).value='';
		sugProp.writing_timeout=null;
		sugProp.selectedItem=-1,
		sugProp.arrow_active=false;
		sugProp.itemChoosen=false;
		sugProp.search_type='n';
		sugProp.sugBoxName='sugNoclegi';
		sugProp.typpingInput='miejsceNoclegi';
		sugProp.hiddenInput='textNoclegi';
		type_search_val = 'n'; // ustawianie zmiennej dla funkcji after_history_back - nie kasowac!
		$('type_search').value='n';

	$('box_popular_wczasy').style.visibility = 'hidden';
	$('box_popular_noclegi').style.visibility = 'hidden';
	new CALENDAR('','','','').closeCalendar();

};


function clear_noclegi() {
	$('miejsceNoclegi').value='';
	$('typyNoclegi').value='';
};


function clear_wczasy() {
	$('miejsceWczasy').value='';
	$('typyWczasy').value='';
	$('od').value='';
	$('do').value='';
};


function toogle_popular_box (obj_id) { // pokazuje/ukrywa box popularne dla wczasow lub noclegow
	obj=$(obj_id)
	if(obj.style.visibility == 'visible')
		obj.style.visibility = 'hidden';
	else
		obj.style.visibility = 'visible';

	return false;
};


function hide_photo() {
	var children = document.getElementById('photo_container').getElementsByTagName('div');
	for (var i=0; i < children.length; i++)
	 {
	 	children[i].style.zIndex=0;
		children[i].style.visibility='hidden';
	 }

	children = document.getElementById('photo_container').getElementsByTagName('span');
	for (var i=0; i < children.length; i++) {
	 	children[i].style.visibility = 'hidden';
	 }
};


function changeOpac(opacity, id) {
	var obj = $(id).style;
	obj.zIndex++;

	if(opacity == 100) {
		obj.opacity = '';
	    obj.MozOpacity = '';
	    obj.KhtmlOpacity = '';
	    obj.filter = '';
		return false;
	}

    obj.opacity = (opacity / 100);
    obj.MozOpacity = (opacity / 100);
    obj.KhtmlOpacity = (opacity / 100);
    obj.filter = "alpha(opacity=" + opacity + ")";


	children = document.getElementById(id).getElementsByTagName('span');
	for (var i=0; i < children.length; i++) {
	 	children[i].style.visibility = 'visible';
	 }

	children = document.getElementById(id).getElementsByTagName('div');
	for (var i=0; i < children.length; i++) {
	 	children[i].style.visibility = 'visible';
	 }
};


function opacity(id, opacStart, opacEnd, millisec) {
	hide_photo();
    var speed = Math.round(millisec / 85);
    var timer = 0;

    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }

	document.getElementById(id).style.visibility = 'visible';
	var children = document.getElementById(id).getElementsByTagName('a');
	children[0].style.visibility = 'visible';
	//setTimeout(hide_photo(),500);
	//changeOpac(70, children[0].id);
};



/* --------------  DRAG START --------------  */

function setProperties(tablica){ //ustawienie zmiennych z odpowiedniej tablicy - w zaleznosci od suwaka
	min_val = tablica[0];
	max_val = tablica[1];
	precision = tablica[2];
	pboxWidth = tablica[3]; // szerokosc kontenera
	img_width = tablica[4]; // szerokosc obrazka - znacznika
	first = tablica[5]; // id pierwszego przesuwanego znacznika
	second = tablica[6]; //id drugiego przesuwanego znacznika
	background = tablica[7]; // id tla dla aktywnego przedzialu
	jump = ((max_val - min_val) / precision);  // ilosc skokow
	jump_px = pboxWidth / jump; // skok w pixelach
	first_input = tablica[8];
	second_input = tablica[9];
	first_span = tablica[10];
	second_span = tablica[11];
	span_suffix = tablica[12];
	values_tab = tablica[13];
	first_start_value = tablica[14];
	second_start_value = tablica[15];
	type = tablica[16];
	noLimitInput = tablica[17];
	scale_id = tablica[18];
};

function adjust_slider_bg(background, first_left, second_left, img_width) {
	var bg = $(background);
	bg.style.width = (Math.max(first_left, second_left) - Math.min(first_left, second_left)) + 'px';
	bg.style.left = (Math.min(first_left, second_left) + Math.floor(img_width / 2)) + 'px';
};

function set_position_on_start(tab) {
	setProperties(tab);

	var showPlus = ''; //jesli wartosc na start == max wartosc lub jesli nie podano startowej wartosci, to plus ma sie pojawic w drugim spanie
	var nolimit = false;
	if ( type == 'max_with_plus' && (second_start_value == values_tab[(values_tab.length - 1)] || !second_start_value)) {
		showPlus = '+ ';
		nolimit = true;
	}

	if (values_tab) {
		var wsp = ((max_val - min_val) / (pboxWidth));
		var first_left, second_left;
		// utawienie suwaków na odpowiednich pozycjach. jesli podano wartosci startowe, to ustawiamy - jak nie, to nic nie robimy - suwaki ustawia sie na brzegach
		if (first_start_value) {
			//first_left = (Math.ceil((values_tab.findIndex(first_start_value) - min_val) / wsp));
			first_left = ((values_tab.findIndex(first_start_value) - min_val) / wsp);
			$(first).style.left = first_left + 'px';
		}
		if (second_start_value) {
			//second_left = (Math.ceil((values_tab.findIndex(second_start_value) - min_val) / wsp));
			second_left = ((values_tab.findIndex(second_start_value) - min_val) / wsp);
			$(second).style.left = second_left + 'px';
		}

		// ustawianie tła
		if(typeof(first_left) == "undefined") {
			first_left = 0;
		}
		if(typeof(second_left) == "undefined" || second_left == 0) {
			second_left = pboxWidth;
		}
		adjust_slider_bg(background, first_left, second_left, img_width);

	}


	if (values_tab) { //jesli podana jest tablica wartosci, to ustawiamy wartosci z tablicy, jesli tablica pusta - z obliczen
		if(first_start_value) { //jesli podano wartosci startowe, to ustaw
			$(first_input).value = first_start_value;
			$(first_span).innerHTML = 'od ' + first_start_value + span_suffix;
		}
		else {
			$(first_input).value = values_tab[1];
			$(first_span).innerHTML = 'od ' + values_tab[1] + span_suffix;
		}

		if(second_start_value) { //jesli podano wartosci startowe, to ustaw
			$(second_input).value = second_start_value;
			$(second_span).innerHTML = 'do ' + second_start_value + showPlus + span_suffix;
		}
		else {
			$(second_input).value = values_tab[(values_tab.length - 1)];
			$(second_span).innerHTML = 'do ' + values_tab[(values_tab.length - 1)] + showPlus  + span_suffix;
		}
	}
	else {
		$(first_input).value = min_val;
		$(second_input).value = max_val;
		$(first_span).innerHTML = 'od ' + min_val + span_suffix;
		$(second_span).innerHTML = 'do ' + max_val + showPlus + span_suffix;
	}

	if (nolimit) {
		$(noLimitInput).value = 1;
	}
	else if (type == 'max_with_plus'){
		$(noLimitInput).value = 0;
	}

	// podzialki - tylko jesli wartosci suwaka sa definiowane w tablicy
	if (values_tab) {
		var temp_jump = pboxWidth / (values_tab.length-2);
		for (var n = 1; n < values_tab.length-2; n++) { //nie rysujamy pierwszej i ostatniej podziałki
			$(scale_id).innerHTML += '<span style="position:absolute;margin-left:' + ((n * temp_jump) + 3) + 'px">|</span>';
		}
	}

};


function mouseDown(e,tab) {

	if(timer)
	window.clearInterval(timer);
	if (e == null) e = window.event;
	var target;

	if(e.target != null)
		target = e.target;
	else
		target = e.srcElement;

	setProperties(tab);

	if ((e.button == 1 && window.event != null || e.button == 0) && target.className == 'drag')
		{
			_startX = e.clientX;
			_startY = e.clientY;

			_offsetX = retNumber(target.style.left);
			_offsetY = retNumber(target.style.top);

			_oldZIndex = target.style.zIndex;
			target.style.zIndex = 10000;

			_dragElement = target;

			old_first_value = $(first_input).value;
			old_second_value = $(second_input).value;

			document.onmousemove = mouseMove;

			document.body.focus();

			document.onselectstart = function () { return false; };
			target.ondragstart = function() { return false; };

			return false;
		}
	else
		_dragElement = null;
};


function mouseMove(e){
	 if (e == null) var e = window.event;

	 var new_pos='';
	 var reporting = true;

 	if (type == 'max_with_plus' && _dragElement.id == first && ((_offsetX + e.clientX - _startX) <= (retNumber($(second).style.left) + jump_px) && (_offsetX + e.clientX - _startX) >= (retNumber($(second).style.left) - jump_px)) || (_offsetX + e.clientX - _startX) < (0 -jump_px) ) {
 		reporting = false;
 	}
 	else if (type == 'max_with_plus' && _dragElement.id == second && ((_offsetX + e.clientX - _startX) <= (retNumber($(first).style.left) + jump_px) && (_offsetX + e.clientX - _startX) >= (retNumber($(first).style.left) - jump_px)) || (_offsetX + e.clientX - _startX) >= pboxWidth + jump_px) {
 		reporting = false;
 		}
	else {
	 	new_pos = _offsetX + e.clientX - _startX; //pozycja w trakcie przeciagania
		}

	var box_width = pboxWidth - retNumber(_dragElement.style.width);  // szerokosc boxu dookola

	for(var n=0; n<=pboxWidth; n=n+jump_px) { // zmuszenie suwaka do dzialania skokowego
		if(new_pos-(jump_px/2) <= n) {

			if(reporting == false) { // reporting decyduje o tym, czy maja byc zmieniane wartosci inputow w momencie, gdy suwaki ceny nakladaja sie na siebie
		 		;
		 	}
			else {
			 	new_pos = n;
			 	break;
			 }
		}
	}

	// jesli maja nie przenikac przez siebie, odkomentowac i dodac else do ifa ponizej
	//if (_dragElement.id==first && new_pos >= (retNumber($(second).style.left) - retNumber(_dragElement.style.width)))
	// 	new_pos = retNumber($(second).style.left) - retNumber(_dragElement.style.width);
	//
	// else if (_dragElement.id==second && new_pos <= (retNumber($(first).style.left) + retNumber(_dragElement.style.width)))
	// 	{
	//		new_pos = retNumber($(second).style.left);
	//	}

	if (new_pos>box_width)
	 	new_pos = box_width;
	else if (new_pos <= (1 - retNumber(_dragElement.style.left)))
	 	new_pos = 0;

	if(!isNaN(parseInt(new_pos))) _dragElement.style.left = new_pos + 'px';

	var first_pos = retNumber($(first).style.left);
	var second_pos = retNumber($(second).style.left);
	var bg = $(background);
	bg.style.width= (Math.max(first_pos,second_pos) - Math.min(first_pos,second_pos)) + 'px';
	bg.style.left= (Math.min(first_pos,second_pos) + Math.floor(img_width/2)) + 'px';


	if (reporting) {
		report(new_pos, box_width, _dragElement.id);
	}
};


function mouseUp(e){
	if (_dragElement != null) {
		_dragElement.style.zIndex = _oldZIndex;
		document.onmousemove = null;
		document.onselectstart = null;
		_dragElement.ondragstart = null;
		_dragElement = null;

		var a=parseInt($(first_input).value);
		var b=parseInt($(second_input).value);
		$(first_input).value = Math.min(a,b);  // zamiana wartosci tak, aby w pierwszym inpucie zawsze byla wartosc mniejsza
		$(second_input).value = Math.max(a,b); // a w drugim wieksza

		if ($(first_input).value != old_first_value || $(second_input).value != old_second_value) {
			timer = window.setTimeout(send, 700);
			setTimeout(function(){
				show_curtain('curtain')
			}, 100);
		}
	}
};


function send(form_name) {
	if($(sugProp.typpingInput).value = start_txt) {
		$(sugProp.typpingInput).value = '';
	}
	document.forms[0].submit();
	setTimeout(function(){show_curtain('curtain')},100);
};


function report (x, maxX, what) {

	if(what == first)
		reportBox = first_input;
	else
		reportBox = second_input;

	var wsp=((max_val-min_val)/maxX); //wspolczynnik
	var present_value = (Math.ceil(((x*wsp) + min_val)/precision)*precision); //zaokraglana aktualna wartosc
	$(reportBox).value = present_value; //przypisanie wartosci do wybranego inputa

	if (values_tab) { //jesli podana jest tablica wartosci, to ustawiamy wartosci z tablicy, a nie z obliczen
		$(reportBox).value = values_tab[$(reportBox).value];
	}
	else {
		$(reportBox).value = present_value;
	}


	var a=parseInt($(first_input).value);
	var b=parseInt($(second_input).value);
	if(isNaN(a)) a=min_val;
	if(isNaN(b)) b=max_val;

	var showPlus = ''; //plus dodawany dla spana przy maxie
	var nolimit = false;
	if (type == 'max_with_plus' && Math.max(a,b) == values_tab[(values_tab.length - 1)]) {
		showPlus = '+ ';
		nolimit = true;
	}

	if (nolimit) {
		$(noLimitInput).value = 1;
	}
	else if (type == 'max_with_plus') {
		$(noLimitInput).value = 0;
	}


	$(first_span).innerHTML = 'od ' + Math.min(a,b) + span_suffix;
	$(second_span).innerHTML = 'do ' + Math.max(a,b) + showPlus + span_suffix;
	//$("przedzial").value='przedział od ' + Math.min(a,b) + ' do ' + Math.max(a,b);

};
/* -------------- DRAG END --------------  */



// podswietlanie elementow li po kliknieciu checkboxow - filtry w lewej kolumnie
function switch_li_bg (obj,class_active,class_inactive) {
	//if(timer)
	//window.clearInterval(timer);

	if (obj.checked === true) {
		obj.parentNode.className = class_active;
	}
	else {
		obj.parentNode.className = '';
	}

	if (obj.disabled) {
		obj.parentNode.className = class_inactive;
	}
	//timer = window.setTimeout(send,2000);
};



// przypisuje wszystkim checkboxom funkcje send() po kliknieciu
function setOnAllCheckbox (class_active, class_inactive) {
	var dzieci = document.getElementsByTagName("input");
	for (var n=0; n <= (dzieci.length - 1); n++) {
		if(dzieci[n].type == 'checkbox')
		 {
		 	var temp = dzieci[n];
		 	switch_li_bg(dzieci[n], class_active, class_inactive);
			//addEvent(dzieci[n], 'click', function() { switch_li_bg(this,class_name); }, true); //wlacza podswietlanie checkboxow po kliknieciu
			addEvent(dzieci[n], 'click', function() { send(); }, true);
		 }
	}
};



// ----------------------- suggest START ------------------------

var suggest_tab = new Array();
var header_count = 0; //ilosc naglowkow dla podpowiedzi

sugProp = { // wlasciwosci dla sugestera - zmieniane podczas przelaczania okna z noclegami/wczasami
	writing_timeout : null,
	selectedItem : -1,
	arrow_active : false,
	itemChoosen : false,
	search_type : 'w',
	sugBoxName : 'sugWczasy',
	typpingInput : 'miejsceWczasy',
	hiddenInput : 'textWczasy'
};


function hideSuggest() { // ukrywa okno sugestera i czysci tablice z danymi
	$(sugProp.sugBoxName).style.visibility='hidden';
	$(sugProp.sugBoxName).innerHTML='';
	suggest_tab = new Array();
	sugProp.arrow_active = false;
};


function inputBlur () { // funkcja uruchamiana podczas wyjscia z pola miejscowosc - wybiera pierwsza wartosc, lub czysci pole jesli nie ma podpowiedzi
	if (sugProp.itemChoosen == false && suggest_tab.length > 0) { //jesli pojawiła sie lista i nic nie wybrano, to wstaw pierwsza pozycje
		//$(sugProp.typpingInput).value = suggest_tab[0][0].replace(/(<([^>]+)>)/ig,"").replace( / (\(([^>]+)\))/ig,"");
		$(sugProp.typpingInput).value = suggest_tab[1][0].replace(/(<([^>]+)>)/ig,"");
		$(sugProp.hiddenInput).value = suggest_tab[1][1]; //czytamy drugi element tablicy, bo pierwszy jest zarezerwowany na <span>
	}
	//else if (sugProp.itemChoosen == false) {
	//	$(sugProp.typpingInput).value='';
	//}
	suggest_tab = new Array();
	hideSuggest();

	if($(sugProp.typpingInput).value == '')
		$(sugProp.typpingInput).value = start_txt;
};


function submitDateField(type,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	setSearchType(type);
	if(keycode == 13) {
		if($('miejsceWczasy').value == start_txt) {
			$('miejsceWczasy').value = '';
		}
		if($('miejsceNoclegi').value == start_txt) {
			$('miejsceNoclegi').value = '';
		}

		document.f1.submit();
	}
};

function setSearchType(type){
	if (type == undefined) {
		type = $('type_search').value;
	}
	if(type == 'w') {
		$('searchNoclegi').value = '';
		$('searchWczasy').value = 1;
		$('textNoclegi').value=''; // zahashowane wyzej, czyszczone dopiero w momencie klikniecia 'szukaj'
	}
	else if(type == 'n') {
		$('searchWczasy').value = '';
		$('searchNoclegi').value = 1;
		$('textWczasy').value='';
	}
};


function start_writing(input_obj,e) { // ustawia akcje dla wybranych klawiszy podczas pisania w polu 'miejsce'
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode != 13 && keycode != 9) {
		$(sugProp.hiddenInput).value = '';
	}

	if (keycode == 13 || keycode == 9) {
		if (keycode == 13 && sugProp.selectedItem == -1 && $(sugProp.sugBoxName).style.visibility == 'hidden') {
			setSearchType();
			document.forms[0].submit();
		}
		else {
			$(sugProp.sugBoxName).innerHTML = '';
			$(sugProp.sugBoxName).style.visibility = 'hidden';
			sugProp.selectedItem = -1;
			if (e.preventDefault) e.preventDefault();
       		if (e.stopPropagation) e.stopPropagation();
			return false;
		}
	}
	else if ((keycode == 40 || keycode == 38 || (keycode>=33 && keycode<=36)) && $(sugProp.sugBoxName).style.visibility=='visible' && sugProp.arrow_active) {
		childSize = $(sugProp.sugBoxName).childNodes.length - 1;

		if (keycode == 40) { //arrow down
				if (sugProp.selectedItem <= childSize && sugProp.selectedItem >= 0) $(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className = '';
				if (sugProp.selectedItem < childSize) sugProp.selectedItem++;


				if($(sugProp.sugBoxName).childNodes[sugProp.selectedItem].nodeName == "SPAN" && sugProp.selectedItem!=1) {
					sugProp.selectedItem++;
					//asd=asd;
				}

		}
		else if (keycode == 38) { //arrow up
				if (sugProp.selectedItem <= childSize && sugProp.selectedItem >= 0) $(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className = '';
				if (sugProp.selectedItem > 1) sugProp.selectedItem--;


				if($(sugProp.sugBoxName).childNodes[sugProp.selectedItem].nodeName == "SPAN") {
					sugProp.selectedItem--;
				}


				if (sugProp.selectedItem < 0) sugProp.selectedItem++;
			}
		else if (keycode == 34) { //pageDwn
			if(sugProp.selectedItem>=0) $(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className='';
			sugProp.selectedItem+=10;

			if (sugProp.selectedItem > childSize) {
				sugProp.selectedItem = childSize;
			}

			else if($(sugProp.sugBoxName).childNodes[sugProp.selectedItem].nodeName == "SPAN") {
					sugProp.selectedItem++;
				}
		}
		else if (keycode == 33) { //pageUp
				$(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className='';
				sugProp.selectedItem-=10;

				if(sugProp.selectedItem <= 1) sugProp.selectedItem=1;

				else if($(sugProp.sugBoxName).childNodes[sugProp.selectedItem].nodeName == "SPAN") {
					sugProp.selectedItem--;
				}
			}
		else if (keycode == 35) { //end
				if(sugProp.selectedItem <= 0) sugProp.selectedItem=0;
				$(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className='';
				sugProp.selectedItem = childSize;
			}
		else if (keycode == 36) { //home
				if(sugProp.selectedItem <= 1) sugProp.selectedItem=1;
				$(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className='';
				sugProp.selectedItem=1;
			}

		$(sugProp.sugBoxName).scrollTop = ((sugProp.selectedItem-1) *24);
		$(sugProp.sugBoxName).childNodes[sugProp.selectedItem].className='active';

		//$(sugProp.typpingInput).value = suggest_tab[sugProp.selectedItem][0].replace(/(<([^>]+)>)/ig,"").replace( / (\(([^>]+)\))/ig,"");
		$(sugProp.typpingInput).value = suggest_tab[sugProp.selectedItem][0].replace(/(<([^>]+)>)/ig,"");

		$(sugProp.hiddenInput).value = suggest_tab[sugProp.selectedItem][1];
		//$('miejsceWczasy').value = $(sugProp.sugBoxName).childNodes[sugProp.selectedItem].innerHTML.replace(/(<([^>]+)>)/ig,"").replace( / (\(([^>]+)\))/ig,"");
		sugProp.itemChoosen = true;
	}
	else if ((keycode >=65 && keycode <=90) || (keycode >=48 && keycode <=57) || keycode==32 || keycode==8) { //litery, cyfry, spacja, bakspace
		clearTimeout(sugProp.writing_timeout);
		sugProp.writing_timeout = window.setTimeout("show_suggest('" + input_obj.id + "')", 200);
		sugProp.selectedItem=-1;
		sugProp.itemChoosen = false;
	}

};


function show_suggest(input_obj_name) { // wysyla requesta
	send_request($(input_obj_name).value);
};


function send_request(txt){
	if (txt.length >= 3) {
		txt=txt.replace('&','&amp;');
		xmlHttp = GetXmlHttpObject();

		var url= '/?page=xml_miejsca&type=text/xml&typ_wysz=' + sugProp.search_type + '&tekst=' + encodeURIComponent(txt); //typ_wysz = w || n

		if (xmlHttp == null) {
			alert("Niestety przegl±darka nie obsługuje wybranej funkcjonalno¶ci");
			return;
		}
		xmlHttp.onreadystatechange = stateChanged;

		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);


		//xmlHttp.overrideMimeType('text/html; charset=ISO-8859-2');
	}
	else { // jesli mniej niz 3 litery, to nie przekazuj id obiektu/miasta/regionu
		hideSuggest();
		$(sugProp.hiddenInput).value='';
	}
};


function stateChanged(){ // pobieranie danych z xmla i uzupelnienie tablicy z danymi
	if (xmlHttp.readyState == 1) {
		$(sugProp.sugBoxName).style.visibility='visible';
		clearTimeout(suggestTimeout);
		$(sugProp.sugBoxName).innerHTML = "<img src='http://static.wakacje.pl/wakacje/images/ajax-loader_small.gif' alt='' style='padding: 110px 135px;' />";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		 xmlDoc = xmlHttp.responseXML;

		 if (xmlDoc.documentElement.nodeName == "parsererror" || !xmlDoc.getElementsByTagName("place")[0]) {
		 	sugProp.arrow_active = false;
		 	$(sugProp.sugBoxName).innerHTML = 'niestety nic nie znaleziono.';
			$(sugProp.sugBoxName).style.height='20px';
			$(sugProp.sugBoxName).style.fontStyle='italic';
			$(sugProp.sugBoxName).style.color='#8B0000';
			$(sugProp.sugBoxName).style.overflow='hidden';
			$(sugProp.hiddenInput).value='';
		 }
		 else if(xmlDoc.getElementsByTagName("place")[0].childNodes[0]){
		 	/*
		 	 * jesli pojawil sie xml, to czytam z niego i zapisauje zawartosc do zmiennych (czyszczac wczesniej poprzednie)
		 	 * suggest_tab[] - zawiera pary wartosci - tekst html + id_obiektu/miasta/regionu
		 	 * jesli zmienia sie label, to do suggest_code dodawany jest span z naglowiek, a to suggest_tab wstawiany jest pusty element tablicy - potrzeben do poruszania sie klawiatura. ilosc childNodes musi sie rownac ilosci elemenetow w tablicy
		 	 * temp_n - zmienna pomocnicza do wstawiania danych do tablicy suggest_tab[]. increment zawsze na koncu petli oraz po trafieniu na zmiane labela (dodanie spana)
		 	 *
		 	 */
		 	var suggest_code='';
			suggest_tab = new Array();
			var temp_n = 0;
			header_count = 0;		 	for (var n = 0; n < xmlDoc.getElementsByTagName("place").length; n++) {


				if (temp_n == 0) { //dodawanie naglowkow do listy
					suggest_code += '<span>' + xmlDoc.getElementsByTagName("place")[n].getAttribute("label") + '</span>';
					suggest_tab[temp_n] = new Array('', '');
					temp_n++;
					header_count++;
				}
				else if(typeof(xmlDoc.getElementsByTagName("place")[n]) != "undefined" && xmlDoc.getElementsByTagName("place")[n].getAttribute("label") != xmlDoc.getElementsByTagName("place")[n-1].getAttribute("label")){ //jesli zmienił się label, to go pokaż
					suggest_code += '<span>' + xmlDoc.getElementsByTagName("place")[n].getAttribute("label") + '</span>';
					suggest_tab[temp_n] = new Array('', '');
					temp_n++;
					header_count++;
				}

		 		suggest_code += "<a href='javascript:void(0);' onclick=\"select_href('" + xmlDoc.getElementsByTagName("place")[n].childNodes[0].nodeValue + "','" + xmlDoc.getElementsByTagName("place")[n].getAttribute("id") +  "');\">" + xmlDoc.getElementsByTagName("place")[n].childNodes[0].nodeValue + "</a>";
				suggest_tab[temp_n] = new Array (xmlDoc.getElementsByTagName("place")[n].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("place")[n].getAttribute("id"));

				temp_n++;
		 	}
			sugProp.arrow_active = true; //pozwol uzywac strzalek
			$(sugProp.sugBoxName).style.height=((n * 24) + ((header_count) *20)) + 'px'; //dopasuj wysokosc
			if (parseInt($(sugProp.sugBoxName).style.height) > 300) {
				$(sugProp.sugBoxName).style.height = '300px';  //ogranicz wysokosc i pokaz suwak
				$(sugProp.sugBoxName).style.overflow='scroll';
				$(sugProp.sugBoxName).style.overflowX='hidden';
			}
			else {
				$(sugProp.sugBoxName).style.overflow='hidden'; //jesli suwak niepotrzebny - ukryj
			}
			$(sugProp.sugBoxName).innerHTML = suggest_code;
			if(n==0) hideSuggest();
		 }
		 else {
		 	$(sugProp.sugBoxName).innerHTML='<span style="color:#000;padding 2px 10px;">brak wyników</span>';
			$(sugProp.sugBoxName).style.height='20px';
			sugProp.arrow_active = false;
			$(sugProp.hiddenInput).value='';
			suggest_tab = new Array;
		 }
	}

};


function GetXmlHttpObject(){
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
};


function select_href(name,id) { // funkcja odpalana po kliknieciu na pozycje w sugesterze
	sugProp.itemChoosen = true;
	//$(sugProp.typpingInput).value = name.replace(/(<([^>]+)>)/ig,"").replace( / (\(([^>]+)\))/ig,"");
	$(sugProp.typpingInput).value = name.replace(/(<([^>]+)>)/ig,"");
	$(sugProp.hiddenInput).value = id;
	hideSuggest();
};
// ------------------------------- suggest END --------------------------



// ------------------------------- PREZENTACJA OBIEKTU ------------------
function select_tab(tab_header_obj, tab_id) {

	var header_divs = document.getElementById('tab_header_container').childNodes;
	for (var n = 0; n < header_divs.length; n++) {
		if(header_divs[n].className!='disabled') header_divs[n].className = '';
	}
	tab_header_obj.className = 'active';

	var content_divs = document.getElementById('tab_content_container').childNodes;
	for(var n=0; n < content_divs.length; n++) {

		if(content_divs[n].nodeName == 'DIV') {
			if (content_divs[n].id == tab_id) {
				content_divs[n].style.display = 'block';
			}
			else {
				content_divs[n].style.display = 'none';
			}
		}
	}

	if(tab_header_obj.id == 'lokalizacja_header') { //pokazanie mapy dopiero po otwarciu zakladki lokalizacja
		mapa_big_start();
	}
};



// ------------------- mapy gooogle ------------------
var markers_tab = new Array();
var mapa_big;
var red_img_array = Array(	"/images/wypoczynek.pl/maps/czerwony-A.png",
							"/images/wypoczynek.pl/maps/czerwony-B.png",
							"/images/wypoczynek.pl/maps/czerwony-C.png",
							"/images/wypoczynek.pl/maps/czerwony-D.png",
							"/images/wypoczynek.pl/maps/czerwony-E.png",
							"/images/wypoczynek.pl/maps/czerwony-F.png",
							"/images/wypoczynek.pl/maps/czerwony-G.png",
							"/images/wypoczynek.pl/maps/czerwony-H.png",
							"/images/wypoczynek.pl/maps/czerwony-I.png",
							"/images/wypoczynek.pl/maps/czerwony-J.png");
var green_img_array = Array(	"/images/wypoczynek.pl/maps/zielony-A.png",
								"/images/wypoczynek.pl/maps/zielony-B.png",
								"/images/wypoczynek.pl/maps/zielony-C.png",
								"/images/wypoczynek.pl/maps/zielony-D.png",
								"/images/wypoczynek.pl/maps/zielony-E.png",
								"/images/wypoczynek.pl/maps/zielony-F.png",
								"/images/wypoczynek.pl/maps/zielony-G.png",
								"/images/wypoczynek.pl/maps/zielony-H.png",
								"/images/wypoczynek.pl/maps/zielony-I.png",
								"/images/wypoczynek.pl/maps/zielony-J.png");


function search_open_map(clicked_id) {
	$('search_map_cont').style.display='block';
	$('map_curtain').style.display = 'block';

	setClassActive('map_object_list', clicked_id);
	markers_tab[clicked_id].openInfoWindowHtml(markers_tab[clicked_id].txt);
};


function setClassActive(container_id, clicked_id) {
	var children = $(container_id).getElementsByTagName('li');

	for (var i=0; i < children.length; i++)
	 {
	 	if (i == clicked_id && typeof(markers_tab[i]) == 'object') {
			children[i].className = 'active';
			markers_tab[i].setImage(markers_tab[i].getIcon().image.replace('zielony', 'czerwony'));

			//markers_tab[i].Tq[0].style.zIndex = 10;
			if(typeof(markers_tab[i].Tq) != 'undefined') markers_tab[i].Tq[0].style.zIndex = 10;
			else if (typeof(markers_tab[i].NA) != 'undefined') markers_tab[i].NA.style.zIndex = 10;

			// ustaiwanie czerwonej ikony po klikniecu na liste po prawej:
			children[i].getElementsByTagName('img')[0].src = children[i].getElementsByTagName('img')[0].src.replace('zielony', 'czerwony');
		}
		else if(typeof(markers_tab[i]) == 'object'){
			children[i].className = '';
			markers_tab[i].setImage(markers_tab[i].getIcon().image.replace('czerwony', 'zielony'));

			if(typeof(markers_tab[i].Tq) != 'undefined') markers_tab[i].Tq[0].style.zIndex = 0;
			else if (typeof(markers_tab[i].NA) != 'undefined') markers_tab[i].NA.style.zIndex = 0;
			children[i].getElementsByTagName('img')[0].src = children[i].getElementsByTagName('img')[0].src.replace('czerwony', 'zielony');
		}
	 }
};


function mapa_search_draw(){
	if (GBrowserIsCompatible()) {
		if (typeof(lat1) != "undefined") {
			var punkt = new GLatLng(lat1, lng1);
			mapa_big = new GMap2($('search_map'), {
				size: new GSize(500, 390)
			});
			mapa_big.addControl(new GSmallZoomControl3D());
			mapa_big.addControl(new GHierarchicalMapTypeControl());
			mapa_big.setCenter(punkt, 8);
		}


		//wypelniam tablice markerow zawsze 10 elementami, tablica jest z. globalna
		var marker_count = 0; //markery musza wejsc do tablicy po kolei a nie wg zmiennej sterujacej z pętli
		for(var n=0; n<10; n++) {
			if (typeof(window['lat' + (n + 1)]) != "undefined") {
				markers_tab.push(dodajMarker(marker_count, (n+1), window['lat' + (n + 1)], window['lng' + (n + 1)], window['cloud_html' + (n + 1)]));
				marker_count++;
			}
			else {
				markers_tab.push('');
			}
		}

		//ukrywanie mapy, dopiero po jej narysowaniu
		$('search_map_cont').style.display = 'none';
		$('search_map_cont').style.visibility = 'visible';

		//tworze 10 elementowa tablice z nazwami obiektow
		var nazwa_tab = new Array();
		for(var m=0; m<10; m++) {

			if (typeof(window['nazwa_obiektu' + (m + 1)]) != "undefined") {
				nazwa_tab.push(window['nazwa_obiektu' + (m + 1)]);
			}
			else {
				nazwa_tab.push('');
			}

		}

		//wypisuje elementy listy, puste ukrywam - celowo jest ich 10, aby mozna bylo sie poruszac po wezlach
		marker_count = 0;

		var limit;
		if (is_ie) {
			limit = 28
		}
		else {
			limit = 33
		}

		for (var i = 0; i < 10; i++) {
			if(nazwa_tab[i]!='') {
				document.write('<li onclick="markers_tab[' + i + '].openInfoWindowHtml(markers_tab[' + i + '].txt);setClassActive(\'map_object_list\', ' + i + ');">');

				var kropki;
				if (nazwa_tab[i].length >= limit)
					kropki = '...';
				else
					kropki = '';
				document.write('<img src="' + green_img_array[marker_count] + '" alt=""/> <span>' + nazwa_tab[i].substring(0, limit) + kropki + '</span> </li>')

				marker_count++;
			}
			else {
				document.write('<li style="display:none;"> </li>');
			}
		}

	}

};


function mapa_mini_start() {
    if(GBrowserIsCompatible() && typeof(lat1) != "undefined" && lat1 != 0 && lat1 != null)
    {
		var punkt = new GLatLng(lat1, lng1);
        var mapa_mini = new GMap2($('map_mini'));
		//var marker = new GMarker(punkt);

		var new_icon = new GIcon();
		new_icon.image = "/images/wypoczynek.pl/maps/czerwony-A.png";
		new_icon.shadow = "/images/wypoczynek.pl/maps/shadow.png";
		new_icon.iconSize = new GSize(20, 34);
		new_icon.infoWindowAnchor = new GPoint(20,34);
		new_icon.iconAnchor = new GPoint(16,16);
		new_icon.shadowSize = new GSize(37, 34);

		var marker = new GMarker(punkt, {icon: new_icon});

		mapa_mini.addOverlay(marker);
		mapa_mini.setCenter(punkt, zoom_mini);
		mapa_mini.disableDragging();
    }
	else { // jesli oferta nie ma wspolrzednych do mapy, to nie pokazuj malej mapki
		$('map_mini_cont').style.display = 'none';
	}


	// jesli zaden obiekt nie ma danych do mapy, to ukryj zakladke z duza mapa
	if ( (typeof(lat1) == "undefined" || lat1 == 0 || lat1 == null) && (typeof(lat2) == "undefined" || lat2 == 0 || lat2 == null) && (typeof(lat3) == "undefined" || lat3 == 0 || lat3 == null) && (typeof(lat4) || "undefined" && lat4 == 0 || lat4 == null) ) {
		$('lokalizacja_header').className = 'disabled';
		$('lokalizacja_header').innerHTML = '';
	}
	// w przeciwnym wypadku dodaj event do zakladki pokazujacy mape po kliknieciu
	else {
		addEvent($('lokalizacja_header'), 'click', function() { select_tab($('lokalizacja_header'), 'mapa_big'); }, false);
	}
};


function dodajMarker(marker_num,red,lat,lon,txt) {
	var new_icon = new GIcon();

	var marker_img_array = new Array();
	if(red == 1) {
		marker_img_array = red_img_array;
	}
	else {
		marker_img_array = green_img_array;
	}

	new_icon.image = marker_img_array[marker_num];
	new_icon.shadow = "/images/wypoczynek.pl/maps/shadow.png";
	new_icon.iconSize = new GSize(20, 34);
	new_icon.infoWindowAnchor = new GPoint(20,5);
	new_icon.iconAnchor = new GPoint(10,17);
	new_icon.shadowSize = new GSize(37, 34);

	var marker = new GMarker(new GLatLng(lat,lon), {icon: new_icon});

	marker.txt=txt;
	mapa_big.addOverlay(marker);
	GEvent.addListener(marker,"click",function() {
		marker.openInfoWindowHtml(marker.txt);
	});
	return marker;
};


function mapa_big_start() {
    if(GBrowserIsCompatible() && big_map_on == false)
    {
		if (typeof(lat1) != "undefined") {
			//var mapa_big;
			var punkt = new GLatLng(lat1, lng1);
			mapa_big = new GMap2($('map_big'), {
				size: new GSize(690, 290)
			});

			mapa_big.addControl(new GSmallZoomControl3D());
			mapa_big.addControl(new GHierarchicalMapTypeControl());
			mapa_big.setCenter(punkt, zoom_big);

			big_map_on = true;
		}

		if (typeof(lat1) != "undefined" && lat1 != 0) {
			markers_tab.push(dodajMarker(0, 1, lat1, lng1, cloud_html1));
			if(typeof(markers_tab[0].Tq) != 'undefined') markers_tab[0].Tq[0].style.zIndex = 100;
			else if (typeof(markers_tab[0].NA) != 'undefined') markers_tab[0].NA.style.zIndex = 100;
		}
		if (typeof(lat2) != "undefined" && lat2 != 0) {
			markers_tab.push(dodajMarker(1, 0, lat2, lng2, cloud_html2));
			if(typeof(markers_tab[1].Tq) != 'undefined') markers_tab[1].Tq[0].style.zIndex = 90;
			else if (typeof(markers_tab[1].NA) != 'undefined') markers_tab[1].NA.style.zIndex = 90;
		}
		if (typeof(lat3) != "undefined" && lat3 != 0) {
			markers_tab.push(dodajMarker(2, 0, lat3, lng3, cloud_html3));
			if(typeof(markers_tab[2].Tq) != 'undefined') markers_tab[2].Tq[0].style.zIndex = 80;
			else if (typeof(markers_tab[2].NA) != 'undefined') markers_tab[2].NA.style.zIndex = 80;
		}
		if (typeof(lat4) != "undefined" && lat4 != 0) {
			markers_tab.push(dodajMarker(3, 0, lat4, lng4, cloud_html4));
			if(typeof(markers_tab[3].Tq) != 'undefined') markers_tab[3].Tq[0].style.zIndex = 70;
			else if (typeof(markers_tab[3].NA) != 'undefined') markers_tab[3].NA.style.zIndex = 70;
		}

		if(typeof(markers_tab[0]) != "undefined") markers_tab[0].openInfoWindowHtml(markers_tab[0].txt);

    }

};
// ------------------ mapy google end ----------



// --------------------- STATYCZNE -------------------

function toggleFaqDiv(event){

	obj = event.srcElement || event.target;

	var onode, otarget;
	onode = obj;
	onode = onode.nextSibling;
	while (onode) {
		if (onode.nodeType == 1) {
			otarget = onode;
			break;
		}
		onode = onode.nextSibling;
	}
	if (otarget) {

		if(otarget.style.display=='block') {

			otarget.style.display = 'none';
			obj.className = '';
		}
		else {
			otarget.style.display = 'block';
			obj.className = 'active';
		}
	}
	else {
		;
	}
};


// ------------------------------- Rezerwacja ------------------
//rozszerza diva z opisem (id boxu z opisem, id linku 'wiecej', od jakiej wysokosci ukrywac diva z opisem)
function expand_opis(opis_box, more_link, max_height){
	var obj = $(opis_box);
	if(obj == null) return false;
	var old_height = obj.clientHeight;
	if (obj.clientHeight > max_height) {
		obj.style.overflow = 'hidden';
		obj.style.height = max_height+'px';

		$(more_link).style.display = 'block';
		addEvent($(more_link), 'click', function(){
			animate(opis_box, max_height, old_height, 'height');
			$(more_link).style.display = 'none';
		}, false);
	}
};


function validate_reservation() {
	if(!validate.test_name('imie')) return false;
	if(!validate.test_surname('nazwisko')) return false;
	if(!validate.test_email('email')) return false;
	if(!validate.test_agreement('zgoda1')) return false;
};


function validate_ask() {
	if(!validate.test_name('imie')) return false;
	if(!validate.test_surname('nazwisko')) return false;
	if(!validate.test_email('email')) return false;
	if(!validate.test_agreement('zgoda1')) return false;
};

function validate_logowanie() {
	if(!validate.test_is_filled('login', 'Niepoprawnie uzupełnione pole Login')) return false;
	if(!validate.test_is_filled('haslo', 'Niepoprawnie uzupełnione pole Hasło')) return false;
};

function validate_newsletter() {
	if(!validate.test_email('email')) return false;
	if(!validate.test_name('imie')) return false;
	if(!validate.test_is_checked('zgoda', 'Musisz wyrazić zgodę na przetwarzanie danych osobowych')) return false;
}


// ------------------------------- Rezerwacja ------------------
var validate = {
	form : '',

    test_email : function (field) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var field_val = document.forms[this.form].elements[field].value;
		if(reg.test(field_val) == false) {
			alert('Niepoprawnie uzupełnione pole adres e-mail');
			return false;
		}
		else {
			return true;
		}
    },

	test_agreement : function (field) {
		if (document.forms[this.form].elements[field].checked == true) {
			return true;
		}
		else {
			alert('Musisz wyrazić zgodę na przetwarzanie danych\n w celach podjęcia czynno¶ci wyboru zamówienia i jego realizacji')
			return false;
		}
	},

	test_name : function (field) {
		var reg = /^[a-zA-Z-ęó±¶łżĽćńĘÓˇ¦ŁŻ¬ĆŃ]+$/;
		var field_val = document.forms[this.form].elements[field].value;
		if(reg.test(field_val) == false) {
			alert('Niepoprawnie uzupełnione pole Imię');
			return false;
		}
		else {
			return true;
		}
    },

	test_surname : function (field) {
		var reg = /^[a-zA-Z-ęó±¶łżĽćńĘÓˇ¦ŁŻ¬ĆŃ]+$/;
		var field_val = document.forms[this.form].elements[field].value;
		if(reg.test(field_val) == false) {
			alert('Niepoprawnie uzupełnione pole Nazwisko');
			return false;
		}
		else {
			return true;
		}
    },

	test_is_filled : function (field, msg) {
		var field_val = document.forms[this.form].elements[field].value;
		if(field_val.length <=0 ) {
			alert(msg);
			return false;
		}
		else {
			return true;
		}
    },

	test_double_submit : function (field, msg) {
		var field_val = document.forms[this.form].elements[field].value;
		if(field_val == 'tak' ) {
			alert(msg);
			return false;
		}
		else {
			return true;
		}
    },

	test_is_checked : function (field, msg) {
		var field_val = document.forms[this.form].elements[field].checked;
		if(field_val == 0 ) {
			alert(msg);
			return false;
		}
		else {
			return true;
		}
    }

};


// czyszczenie i ustawianie domyslnego tekstu w polu z nazwa miejscowosc
function search_click(type){
	//var start_txt='np. Sopot, Tatry, U Bacy';
	if($('miejsceWczasy').value == start_txt) {
		$('miejsceWczasy').value = '';
	}
	if($('miejsceNoclegi').value == start_txt) {
		$('miejsceNoclegi').value = '';
	}

	setSearchType();

	document.f1.submit();
}


// funkcja wykonywana w celu ustawienia porpawnych wartosci przy wcisnieciu przycisku 'wstecz' w przegladarce
function after_history_back() {

	//przed resetem formularza zapamietujemy wszystkie kasujace sie pola
	if(location.pathname.indexOf('/wczasy') >= 0) { // sprawdzanie musi byc na podstawie adresu strony
		var temp_miejsce_w = $('miejsceWczasy').value;
		var temp_rodzaj_w = $('typyWczasy').options[document.f1.typyWczasy.selectedIndex].value;
		var temp_od_w = $('od').value;
		var temp_do_w = $('do').value;
		var temp_text_w = $('textWczasy').value;
		var temp_search_wczasy = $('searchWczasy').value;

		var temp_cena_od = $('cena-od').value;
		var temp_cena_do = $('cena-do').value;
		var temp_cena_no_limit = $('cena-do-nolimit').value;
		var temp_dni_od = $('ile-dni-od').value;
		var temp_dni_do = $('ile-dni-do').value;

	}
	else
		if(location.pathname.indexOf('/noclegi')>=0) {
			var temp_miejsce_n = $('miejsceNoclegi').value;
			var temp_rodzaj_n = $('typyNoclegi').options[document.f1.typyNoclegi.selectedIndex].value;
			var temp_text_n = $('textNoclegi').value;
			var temp_search_noclegi = $('searchNoclegi').value;

			var temp_cena_od = $('cena-od').value;
			var temp_cena_do = $('cena-do').value;
			var temp_cena_no_limit = $('cena-do-nolimit').value;
			var temp_ilosc_od = $('ilosc-miejsc-od').value;
			var temp_ilosc_do = $('ilosc-miejsc-do').value;
			var temp_ilosc_no_limit = $('ilosc-do-nolimit').value;
		}


	document.forms[0].reset();
	document.f1.type_search.value = type_search_val;

	//po resecie przypisujemy wartosci z powrotem do pol formularza
	if(location.pathname.indexOf('/wczasy') >= 0) {
		$('miejsceWczasy').value = temp_miejsce_w;
		$('typyWczasy').value = temp_rodzaj_w;
		$('od').value = temp_od_w;
		$('do').value = temp_do_w;
		$('textWczasy').value = temp_text_w;
		$('searchWczasy').value = temp_search_wczasy;

		$('cena-od').value = temp_cena_od;
		$('cena-do').value = temp_cena_do;
		$('cena-do-nolimit').value = temp_cena_no_limit;
		$('ile-dni-od').value = temp_dni_od;
		$('ile-dni-do').value = temp_dni_do;

		setTimeout(function(){
			$('curtain').style.display = 'none';
			setOnAllCheckbox('highlighted_wczasy', 'disabled_wczasy');
		}, 100);
	}
	else
		if(location.pathname.indexOf('/noclegi') >= 0) {
			$('miejsceNoclegi').value = temp_miejsce_n;
			$('typyNoclegi').value = temp_rodzaj_n;
			$('textNoclegi').value = temp_text_n;
			$('searchNoclegi').value = temp_search_noclegi;

			$('cena-od').value = temp_cena_od;
			$('cena-do').value = temp_cena_do;
			$('cena-do-nolimit').value = temp_cena_no_limit;
			$('ilosc-miejsc-od').value = temp_ilosc_od;
			$('ilosc-miejsc-do').value = temp_ilosc_do;
			$('ilosc-do-nolimit').value = temp_ilosc_no_limit;

			setTimeout(function(){
				$('curtain').style.display = 'none';
				setOnAllCheckbox('highlighted_noclegi', 'disabled_noclegi');
			}, 100);
		}

};




/* SLIDER CLICK */
function scale_click(event, tab) {
	setProperties(tab);

	obj = event.srcElement || event.target;
	var onode, otarget;
	onode = obj;
	onode = onode.nextSibling;
	while (onode) {
		if (onode.nodeType == 1) {
			otarget = onode;
			break;
		}
		onode = onode.nextSibling;
	}
	if (otarget) {
		if (event == null) {
			event = window.event;
		}
		var target;

		if (event.target != null) {
			target = event.target;
		}
		else {
			target = event.srcElement;
		}

		_startX = event.clientX;
		if(obj.className == 'drag') { // zapobieganie opcji, gdy klikniety zostal suwak, a nie div pod nim
			return false;
		}

		//var relative_click_px = (_startX - findPos(otarget)[0]); //ilosc px na suwaku od jego lewej krawedzi

		var make_change = false;
		var relative_click_px = (_startX - findPos($('pbox1'))[0]); //ilosc px na suwaku od jego lewej krawedzi
		var temp_jump = pboxWidth / (values_tab.length - 2);

		// wykonuj operacje tylko wtedy, jesli klikniecie jest 'na zewnatrz' przedzialu
		if(relative_click_px < (retNumber($(first).style.left)) || relative_click_px > (retNumber($(second).style.left)) ) {
			make_change = true;
			if(relative_click_px < retNumber($(first).style.left)) { // sprawdz, z ktorej strony kliknieto i wybierz odpowieni element do przesuwania
				element_to_move = first;
				$(element_to_move).style.left = Math.ceil(retNumber($(element_to_move).style.left) - temp_jump) + 'px';
				$(first_input).value = values_tab[values_tab.findIndex($(first_input).value) - 1]; // ustaw wartosc pola
				$(first_span).innerHTML = 'od ' + $(first_input).value + span_suffix; // ustaw opis suwaka
			}
			else {
				element_to_move = second;
				$(element_to_move).style.left = Math.ceil(retNumber($(element_to_move).style.left) + temp_jump) + 'px';
				$(second_input).value = values_tab[values_tab.findIndex($(second_input).value) + 1];
				$(second_span).innerHTML = 'do ' + $(second_input).value + span_suffix;
			}
		}
		else { // jesli kliknieto miedzy suwakami
			make_change = true;
			var space_first = Math.abs( retNumber($(first).style.left) - relative_click_px );
			var space_second = Math.abs( retNumber($(second).style.left) - relative_click_px );

			if (values_tab[values_tab.findIndex($(first_input).value) + 1] == $(second_input).value || ($(first_input).value == 0 && values_tab[values_tab.findIndex($(first_input).value) + 2] == $(second_input).value) ) {
				return false; // jesli miedzy suwakami jest tylko jedno pole przerwy, to nic nie robimy
			}

			if(space_first < space_second) {
				element_to_move = first;
				$(element_to_move).style.left = Math.ceil(retNumber($(element_to_move).style.left) + temp_jump) + 'px';
				$(first_input).value = values_tab[values_tab.findIndex($(first_input).value) + 1];
				if ($(first_input).value == 0) {
					$(first_input).value = values_tab[values_tab.findIndex($(first_input).value) + 2]; //jesli tablica zaczyna sie od dwoch zer
				}
				$(first_span).innerHTML = 'od ' + $(first_input).value + span_suffix;
			}
			else {
				element_to_move = second;
				$(element_to_move).style.left = Math.ceil(retNumber($(element_to_move).style.left) - temp_jump) + 'px';
				$(second_input).value = values_tab[values_tab.findIndex($(second_input).value) - 1];
				$(second_span).innerHTML = 'do ' + $(second_input).value + span_suffix;
			}

			if(tab[16] == 'max_with_plus' ) { // czyszczenie pola nolimit (klikajac miedzy suwakami nigdy nie wybierzemy max wartosci
				$(tab[17]).value = 0;
			}
		}

		if(make_change == true) {
			adjust_slider_bg(tab[7], retNumber($(first).style.left), retNumber($(second).style.left), tab[4]);
			timer = window.setTimeout(send,100);
		}
	}
};

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) {}
}}
