function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


if(typeof SEARCHBOX=="undefined")
{
	var SEARCHBOX  = {
		showAdvancedSearch:function(){
			document.getElementById('searchbox').className = document.getElementById('searchbox').className.replace(" simple", "");

			document.getElementById('searchbox').className+=" advanced";
			document.getElementById('searchbox').className = document.getElementById('searchbox').className.replace(" splBoxLeftSearchShort", "");

			document.getElementById('searchbox').className+=" advBoxLeftSearchShort";
		},

		showSimpleSearch:function(){

			if(document.getElementById('panstwo')){
				if(document.getElementById('panstwo').getAttribute('multiple')){
					SEARCHBOX.chooseOneDestination();
				}
			}

			document.getElementById('searchbox').className = document.getElementById('searchbox').className.replace(" advanced", "");

			document.getElementById('searchbox').className+=" simple";

			document.getElementById('searchbox').className = document.getElementById('searchbox').className.replace(" advBoxLeftSearchShort", "");

			document.getElementById('searchbox').className+=" splBoxLeftSearchShort";
		},


		showAdvancedSearchHotels:function(){

			document.getElementById('hotelSearchbox').className = document.getElementById('hotelSearchbox').className.replace(" splVersion", "");
			document.getElementById('hotelSearchbox').className+=" advVersion";
		},

		showSimpleSearchHotels:function(){
			if(document.getElementById('panstwo')){
				if(document.getElementById('panstwo').getAttribute('multiple')){
					SEARCHBOX.chooseOneDestination();
				}
			}
			document.getElementById('hotelSearchbox').className = document.getElementById('hotelSearchbox').className.replace(" advVersion", "");
			document.getElementById('hotelSearchbox').className+=" splVersion";
		},

		displayRegions:function(panstwo, param){
			var additionalParam = '';
			if(param)
			{
				param = '&'+param;
			}
			else
			{
				param = '';
			}

			var callback =
				{
				  success: function(o) {
						var regions=o.responseXML.getElementsByTagName('region');
						var i,regionName,regionValue;
						var id_destynacje=document.getElementById('id_destynacje');
						id_destynacje.setAttribute('disabled','disabled');
						id_destynacje.innerHTML='';
						for(i=0;i<regions.length;i++){
							regionValue=regions[i].getAttribute('value');
							regionName=regions[i].firstChild.nodeValue;
							id_destynacje.options[i]=new Option(regionName,regionValue);
						}

						if(regions.length==1){
							id_destynacje.setAttribute('disabled','disabled');
							id_destynacje.innerHTML="<option>\n"+
														"-- dowolny --\n"+
													"</option>";
						}else{
							id_destynacje.removeAttribute('disabled');
						}

				  },
				  failure: function(o) {}
				};
			YAHOO.util.Connect.asyncRequest('GET', '/?page=search_regionsAjax&type=text/xml&panstwo='+panstwo+param, callback, null);
		},

		displayRegionsNarty:function(panstwo){
			var callback =
				{
				  success: function(o) {
						var regions=o.responseXML.getElementsByTagName('region');
						var i,regionName,regionValue;
						var id_destynacje=document.getElementById('id_destynacje');
						id_destynacje.setAttribute('disabled','disabled');
						id_destynacje.innerHTML='';
						for(i=0;i<regions.length;i++){
							regionValue=regions[i].getAttribute('value');
							regionName=regions[i].firstChild.nodeValue;
							id_destynacje.options[i]=new Option(regionName,regionValue);
						}

						if(regions.length==1){
							id_destynacje.setAttribute('disabled','disabled');
							id_destynacje.innerHTML="<option>\n"+
														"-- dowolny --\n"+
													"</option>";
						}else{
							id_destynacje.removeAttribute('disabled');
						}

				  },
				  failure: function(o) {}
				};
			YAHOO.util.Connect.asyncRequest('GET', '/?page=search_regionsAjax&type=text/xml&panstwo='+panstwo+'&narty=on', callback, null);
		},


		displayRegionsHOT:function(panstwo){
			var callback =
				{
				  success: function(o) {
						var regions=o.responseXML.getElementsByTagName('region');
						var i,regionName,regionValue;
						var id_destynacje=document.getElementById('id_destynacje');
						id_destynacje.setAttribute('disabled','disabled');
						id_destynacje.innerHTML='';
						for(i=0;i<regions.length;i++){
							regionValue=regions[i].getAttribute('value');
							regionName=regions[i].firstChild.nodeValue;
							id_destynacje.options[i]=new Option(regionName,regionValue);
						}
						if(regions.length==1){
							id_destynacje.setAttribute('disabled','disabled');
							/*id_destynacje.innerHTML="<option>\n"+
														"- wybierz kierunek aby określia region -\n"+
													"</option>";*/
						}else{
							id_destynacje.removeAttribute('disabled');
						}

				  },
				  failure: function(o) {}
				};
			YAHOO.util.Connect.asyncRequest('GET', '/?page=search_regionsHotAjax&type=text/xml&panstwo='+panstwo, callback, null);
		},

		chooseFewDestinations:function(){
			document.getElementById('chooseOneDestination').className='';
			document.getElementById('chooseFewDestinations').className='hidden';

			var id_destynacje=document.getElementById('id_destynacje');
			id_destynacje.setAttribute('disabled','disabled');
			id_destynacje.innerHTML="<option>\n"+
										"- wybierz kierunek aby określia region -\n"+
									"</option>";

			var panstwa=document.getElementById('panstwo');

			panstwa.setAttribute('multiple','multiple');
			panstwa.setAttribute('size','7');
			panstwa.setAttribute('tabindex','1');
			panstwa.setAttribute('name','panstwo[]');
			panstwa.className='select_panstwo multiple';

			var clonedPanstwa=panstwa.cloneNode(true);
			clonedPanstwa.onchange=function(){

			};
			var parent=panstwa.parentNode;
			parent.replaceChild(clonedPanstwa,panstwa);
		},

		chooseOneDestination:function(){
			document.getElementById('chooseFewDestinations').className='';
			document.getElementById('chooseOneDestination').className='hidden';

			var panstwa=document.getElementById('panstwo');

			panstwa.removeAttribute('multiple');
			panstwa.removeAttribute('size');
			panstwa.setAttribute('name','panstwo');
			panstwa.className='select_panstwo';

			var clonedPanstwa=panstwa.cloneNode(true);
			clonedPanstwa.onchange=function(){
				SEARCHBOX.displayRegions(this.value)
			};
			var parent=panstwa.parentNode;
			parent.replaceChild(clonedPanstwa,panstwa);
		},


		chooseFewDepartures:function(){
			document.getElementById('chooseOneDeparture').className='';
			document.getElementById('chooseFewDepartures').className='hidden';

			var departure=document.getElementById('id_okol');

			departure.setAttribute('multiple','multiple');
			departure.setAttribute('size','7');
			departure.setAttribute('tabindex','1');
			departure.setAttribute('name','id_okol[]');
			departure.className='select_id_okol multiple';

			var clonedDeparture=departure.cloneNode(true);
			var parent=departure.parentNode;
			parent.replaceChild(clonedDeparture,departure);
		},

		chooseOneDeparture:function(){
			document.getElementById('chooseOneDeparture').className='hidden';
			document.getElementById('chooseFewDepartures').className='';

			var departure=document.getElementById('id_okol');

			departure.removeAttribute('multiple');
			departure.removeAttribute('size');
			departure.setAttribute('name','id_okol');
			departure.className='select_id_okol';

			var clonedDeparture=departure.cloneNode(true);
			var parent=departure.parentNode;
			parent.replaceChild(clonedDeparture,departure);
		},


		clearSearchForm:function(){
			var form=document.getElementById('form_wyszukaj');
			var inputs=form.getElementsByTagName('input');
			var selects=form.getElementsByTagName('select');
			var input;
			var select;

			for(i=0, input; input=inputs.item(i++); ){
				if (input.getAttribute('type') == "text"){
					input.value = '';
				}else if (input.getAttribute('type') == "checkbox"){
					input.checked = false;
				}
			}

			for(i=0, select; select=selects.item(i++); ){
				select.value="";
				select.value="0";
			}

		},


		validateHotelCategory:function(){
			minCategory=document.getElementById('kategoria_hotelu__gte');
			maxCategory=document.getElementById('kategoria_hotelu__lte');
			if(minCategory.value==50){
				maxCategory.value=0;
				maxCategory.setAttribute('disabled','disabled');
			}else{
				maxCategory.removeAttribute('disabled');
			}
		},

		showDepartureCalendar:function(posX,posY){
			startDate=null;
			selectedMonth=null;
			wyjazd=document.getElementById('dzien__gte');
			if(validDate(wyjazd.value)){
				currentMonth=(new Date()).getMonth()+1;
				pickedMonth=wyjazd.value.split('.')[1];
				if(currentMonth<=pickedMonth){
					selectedMonth=pickedMonth-currentMonth;
				}else{
					selectedMonth=pickedMonth-currentMonth+12;
				}
			}
			(new CALENDAR('dzien__gte',posX,posY,startDate,selectedMonth)).showCalendar();
		},

		showReturnCalendar:function(posX,posY){
			startDate=null;
			wyjazd=document.getElementById('dzien__gte');
			powrot=document.getElementById('dzien_zak__lte');
			if(validDate(wyjazd.value)){
				startDate=new Date(wyjazd.value.split('.')[2],wyjazd.value.split('.')[1]-1,wyjazd.value.split('.')[0]);
			}
			(new CALENDAR('dzien_zak__lte',posX,posY,startDate)).showCalendar();
		}
	}
}