	var idOfertyIdBiura = document.location.href.match(/([0-9]{1,},[0-9]{1,})(\.html)/)[1].split(',');


	/* History.addAdditionalParam('id_oferty',idOfertyIdBiura[0]);
	History.addAdditionalParam('id_biura',idOfertyIdBiura[1]);*/

	/*
	*
	*
	*
	*	Krok 1.
	*	Ustawienie parametrów
	*	Parametrem koniecznym do jedo wykonania jest reserv=0 (stąd pole regexp).
	*	Jest on też krokiem domyślnym, więc ma defaultValue (jeśli w url'u nie będzie wartości reserv to przyjmie on właśnie wartość 0)
	*
	*
	*	id_terminy_wyjazdy nie ma domyślnej wartości, więc przy jego braku w url'u nie uruchomią się moduły, które są od niech zależne
	*
	*
	*/

 	var step0params=[];

	step0params['id_terminy_wyjazdy']=[];
	//step0params['id_terminy_wyjazdy']['defaultValue']='0';

	step0params['id_okol']=[];
	step0params['id_okol']['defaultValue']='0';

	step0params['id_terminy']=[];
	step0params['id_terminy']['defaultValue']='0';

	step0params['id_oferty']=[];
	step0params['id_oferty']['defaultValue']=idOfertyIdBiura[0];

	step0params['id_warianty']=[];
	step0params['id_warianty']['defaultValue']='0';

	step0params['dzien']=[];
	step0params['dzien']['defaultValue']='0';

	step0params['onlineReservation']=[];

	step0params['id_biura']=[];
	step0params['id_biura']['defaultValue']=idOfertyIdBiura[1];



	var step0 = new HistoryState('step0',step0params);

var id_okol_clicked=false;
var id_warianty_clicked=false;


	/*
	*
	*
	*
	*	Główny moduł kroku 0; ładowany przy zmianie parametru 'reserv' (a dokładnie gdy zmieni się na wartość 0, bo tak jest w ustawieniach stanu)
	*
	*
	*
	*/


/*
	var ofertaReservationStep0Params=[];
	//ofertaReservationStep0Params.push('reserv');
	var ofertaReservationStep0=new HistoryModule('ofertaReservationStep0','ofertaReservationContent','/?page=ofertaReservationStep0','');
	step0.registerModule(ofertaReservationStep0,ofertaReservationStep0Params);
*/


	/*
	*
	*
	*
	*	Moduł bez ładowania ajax'a. Ma tylko funkcję. Służy do zmiany selekta z terminami (po np. kliknięciu 'wstecz')
	*
	*	Zależy od elementu 'select_id_terminy', więc czeka na niego. Jeśli go znajdzie to funkcja się uruchamia a jeśli nie, to uruchamia interwał
	*	i co jakiś czas sprawdza, czy element pojawił się
	*
	*
	*/



	var ofertaReservationTermChangeParams=[];
	ofertaReservationTermChangeParams.push('dzien');
	var ofertaReservationTermChange=new HistoryModule('ofertaReservationTermChange','select_id_terminy','',function(state){
			//if(document.getElementById('select_id_terminy').value!=state.paramsTable['id_terminy']['value']){
				//document.getElementById('select_id_terminy').value=state.paramsTable['id_terminy']['value'];
			//}
		}
	);
	step0.registerModule(ofertaReservationTermChange,ofertaReservationTermChangeParams);



	/*
	*
	*
	*	Moduł ładujący page'a z miastami wylotu, wyżywieniem i elementem docelowym dla wariantów.
	*	Ładuje się zarówno przy zmianie id_terminy jak i miasta wylotu.
	*
	*
	*/



	var offerReservationDetailsParams=[];
	offerReservationDetailsParams.push('dzien');
	offerReservationDetailsParams.push('id_okol');
	var offerReservationDetails=new HistoryModule('offerReservationDetails','offerReservationDetailsContent','/?page=offerReservation_offerReservationDetailsAjax','');
	offerReservationDetails.ajaxLoadHTML=	'<div class="color_blue" style="border-top:1px solid #dcdcdc;background:#fafbfd; text-align: center; padding-bottom: 10px;">' +
												'<div style="padding: 15px;">' +
													'<img src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="loading...">' +
												'</div>' +
												'Proszę czekać na załadowanie danych.' +
											'</div>';
	step0.registerModule(offerReservationDetails,offerReservationDetailsParams);

	/*
	*
	*
	*	moduł korzysta z tych samych parametrów co ofertaResCities, więc przy każdej jego zmianie czeka aż dostępne będzie
	*	pole input o id='default_id_terminy_wyjazdy' i i zmienia parametr id_terminy_wyjazdy (co automatycznie pociąga za sobą doładowanie modułu z wariantami)
	*	Funkcja nie jest wstawiona bezpośrednio do ofertaResCities, bo czeka na inny div
	*
	*
	*/

/*
	var ofertaResCitiesListener=new HistoryModule('ofertaResCitiesListener','default_id_terminy_wyjazdy','',function(state){
			if(!History.paramsTable['id_terminy_wyjazdy']){
				params=[];
				params['id_terminy_wyjazdy']=document.getElementById('default_id_terminy_wyjazdy').value;
				if(params['id_terminy_wyjazdy']){
					History.changeParams(params,null);
				}
			}
		}
	);
	step0.registerModule(ofertaResCitiesListener,offerReservationDetailsParams);
*/


	/*
	*
	*
	*	Moduł ładujący tablicę z wariantami.
	*	Po załadowaniu zaznacza odpowiedni checkbox w wyżywieniu (w przypadku kliknięcia 'wstecz' lub wejścia bezpośrednio z linku)
	*
	*
	*/

	offerReservationVariantsParams=[];
	offerReservationVariantsParams.push('id_terminy_wyjazdy');
	var offerReservationVariants=new HistoryModule('offerReservationVariants','variantsTable','/?page=offerReservation_offerReservationVariantsAjax',function(state){
			if(state.paramsTable['id_terminy_wyjazdy']['value']>0){
				var catering=document.getElementById('offerReservation_offerReservationDetails_catering');
				if(catering){
					var inputs=catering.getElementsByTagName('input');
				}
				var id_terminy_wyjazdy=state.paramsTable['id_terminy_wyjazdy']['value'] || state.paramsTable['id_terminy_wyjazdy']['defaultValue'];
				for(i=0;i<inputs.length;i++){
					if(inputs[i].id=='catering_'+id_terminy_wyjazdy){
						inputs[i].checked=true;
					}else{
						inputs[i].checked=false;
					}
				}


				showDepartureDates(id_terminy_wyjazdy);
				if (document.getElementById('showSecret') && document.getElementById('showSecret').value== '1')
					History.loadSomeAjax('offerReservationNonStandard','/?page=offerReservation_offerReservationNonStandardAjax');
			}

		}
	);
	offerReservationVariants.ajaxLoadHTML=	'<div class="color_blue" style="width:590px;margin:auto;border:1px solid #dcdcdc;background:#fafbfd; text-align: center; padding-bottom: 10px;">' +
												'<div style="padding: 15px;">' +
													'<img src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="loading...">' +
												'</div>' +
												'Proszę czekać na załadowanie danych.' +
											'</div>';
	step0.registerModule(offerReservationVariants,offerReservationVariantsParams);




	offerReservationChangeDateParams=[];
	offerReservationChangeDateParams.push('id_terminy');
	var offerReservationChangeDate=new HistoryModule('offerReservationChangeDate','offerReservation_offerReservationDetails_catering','',function(state){
			if(state.paramsTable['id_terminy']['value']>0){
				var catering=document.getElementById('offerReservation_offerReservationDetails_catering');
				if(catering){
					var inputs=catering.getElementsByTagName('input');
				}
				for(i=0;i<inputs.length;i++){
					if(inputs[i].id=='catering_'+state.paramsTable['id_terminy']['value']){
						inputs[i].checked=true;
					}else{
						inputs[i].checked=false;
					}
				}


				showDepartureDates(state.paramsTable['id_terminy']['value']);

			}
		}
	);
	offerReservationChangeDate.ajaxLoadHTML=	'<div class="color_blue" style="width:590px;margin:auto;border:1px solid #dcdcdc;background:#fafbfd; text-align: center; padding-bottom: 10px;">' +
												'<div style="padding: 15px;">' +
													'<img src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="loading...">' +
												'</div>' +
												'Proszę czekać na załadowanie danych.' +
											'</div>';
	step0.registerModule(offerReservationChangeDate,offerReservationChangeDateParams);



	/*
	*
	*
	*
	*	Moduł, który zbiera informacje o zaznaczonych radiobuttonach w tablicy z wariantami.
	*	Przy zmiania parametru 'id_warianty' zaznacza radiobutton o takiej właśnie wartości
	*
	*
	*
	*/
/*

	var ofertaReservationVariantsListenerParams =[];
	ofertaReservationVariantsListenerParams.push('reserv');
	ofertaReservationVariantsListenerParams.push('id_warianty');
	var ofertaReservationVariantsListener=new HistoryModule('ofertaReservationVariantsListener','variantsTable','',function(state){
			var inputs = document.getElementById('variantsTable').getElementsByTagName('input');

			if((state.paramsTable['id_warianty'])&&(state.paramsTable['id_warianty']['value'])){
				id_warianty=state.paramsTable['id_warianty']['value'];
			}else{
				id_warianty='';
			}


			for (var i=0; i<inputs.length; i++){
				if (inputs[i].value==id_warianty){
					document.getElementById(inputs[i].id).checked = 'checked';
				}
			}
		}
	);
	step0.registerModule(ofertaReservationVariantsListener,ofertaReservationVariantsListenerParams);

*/

	/*
	*
	*
	*	Zarejestruj w Historii krok 0.
	*
	*
	*/



	/* KROKI GOOGLA */

	var offerReservationGoogleStep1Params=[];
	offerReservationGoogleStep1Params.push('dzien');
	var offerReservationGoogleStep1=new HistoryModule('offerReservationGoogleStep1','ofertaReservationContent','',function(state){
		/*
		if(typeof google_analytics!="undefined"){
			google_analytics.setStep('	/zapytanie/prezentacja_oferty.html');
			if(state.paramsTable['onlineReservation']['value']){
				google_analytics.setStep('/funnel_G1/step1.html');
			}
			else{
				//google_analytics.setStep('/funnel_offline/krok1.html');
			}
		}
		*/
	});
	step0.registerModule(offerReservationGoogleStep1,offerReservationGoogleStep1Params);

	var offerReservationGoogleStep2Params=[];
	offerReservationGoogleStep2Params.push('id_terminy_wyjazdy');
	var offerReservationGoogleStep2=new HistoryModule('offerReservationGoogleStep2','ofertaReservationContent','',function(state){
		/*
		if(typeof google_analytics!="undefined"){
			if(state.paramsTable['onlineReservation']['value']){
				google_analytics.setStep('/funnel_G1/step2.html');
			}
			else{
				//google_analytics.setStep('/funnel_offline/krok2.html');
			}
		}
		*/
	});
	step0.registerModule(offerReservationGoogleStep2,offerReservationGoogleStep2Params);


	History.registerState(step0);

	/*
	*
	*
	*	Zainicjowanie Historii
	*
	*
	*/

/*
	History.initialize();
*/


	/*
	*
	*
	*	Funkcja uruchamiana przy kliknięciu w checkbox przy wyżywieniu.
	*
	*
	*
	*/

/*
	function setCheckboxesTerminyWyjazdy(obj,id_terminy_wyjazdy){
		if(obj==true){
			params=[];
			params['id_terminy_wyjazdy']=id_terminy_wyjazdy;
			History.changeParams(params);

			if(typeof google!="undefined"){
				if(document.getElementById('isResOnline').value!=0){
					google.setStep('/funnel_G1/step2.html');
				}
				else{
					google.setStep('/funnel_offline/krok2.html');
				}
			}

		}else{
			History.changeParams([],['id_warianty','id_terminy_wyjazdy']);
		}
	}

	*/



function initReservation(){

	History.initialize();
	var id_rezerwacji = History.paramsTable['id_rezerwacji'];
	if (id_rezerwacji!=null && id_rezerwacji.length){
		RESERVATION.loadStep2('',id_rezerwacji,'','');
	}
	else
	{
	var tempTable=[];
	var isDay = false;
	for(attr in History.paramsTable){
		
		tempTable.push(attr+"="+History.paramsTable[attr]);
		if(attr=='dzien')
			isDay = true;
	}
	// poprawka związana z przyjaznymi URL-ami. Zaciąganie terminu z daty.
	var dataOd = document.location.href.match(/od-(20[0-9][0-9]-[0-9][0-9]-[0-9][0-9])/);
	
	if(dataOd && !isDay) tempTable.push('dzien='+dataOd[1]);
	
	var params=tempTable.join('&');
	
	var idOfertyIdBiura = document.location.href.match(/([0-9]{1,},[0-9]{1,})(\.html)/)[1].split(',');

	var callback =
		{
			success: function(o) {
				document.getElementById('ofertaReservationContent').innerHTML=o.responseText;

				step0.paramsTable['dzien']['defaultValue']=document.getElementById('select_id_terminy').value;
				step0.paramsTable['dzien']['value']=document.getElementById('select_id_terminy').value;
				if(History.paramsTable['dzien'])
					step0.paramsTable['dzien']['value']=History.paramsTable['dzien'];

				step0.paramsTable['id_okol']['defaultValue']=document.getElementById('default_id_okol').value;
				step0.paramsTable['id_okol']['value']=document.getElementById('default_id_okol').value;
				if(History.paramsTable['id_okol'])
					step0.paramsTable['id_okol']['value']=History.paramsTable['id_okol'];

				//step0.paramsTable['id_terminy_wyjazdy']['defaultValue']=document.getElementById('default_id_terminy_wyjazdy').value;
				//step0.paramsTable['id_terminy_wyjazdy']['value']=document.getElementById('default_id_terminy_wyjazdy').value;
				//if(History.paramsTable['id_terminy_wyjazdy'])
					//step0.paramsTable['id_terminy_wyjazdy']['value']=History.paramsTable['id_terminy_wyjazdy'];

				step0.paramsTable['id_terminy']['value']=document.getElementById('default_id_terminy').value;

				//step0.paramsTable['onlineReservation']['value']=document.getElementById('onlineReservation').value;
				step0.paramsTable['onlineReservation']['defaultValue']=document.getElementById('onlineReservation').value;
				History.currentState=step0;

				/*
				if(typeof google_analytics!="undefined"){
					if(step0.paramsTable['onlineReservation']['value']){
						google_analytics.setStep('/funnel_G1/step1.html');
					}
					else{
						google_analytics.setStep('/funnel_offline/krok1.html');
					}
				}
				*/
				//initializeCalendar();
			},
			failure: function(o) {}
		};
	if(document.getElementById('ofertaReservationContent')){
		document.getElementById('ofertaReservationContent').innerHTML='<div style="text-align:center;border:1px solid #dcdcdc;background:#eff3f6"><img style="margin-top:15px;margin-bottom:15px" src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="..." /></div>';
		YAHOO.util.Connect.asyncRequest('POST', '/?page=offerReservation_offerReservationAjax', callback, params+'&id_biura='+idOfertyIdBiura[1]+'&id_oferty='+idOfertyIdBiura[0]);
	}
	} // koniec else id_rezerwacji
}


if(window.addEventListener){
	window.addEventListener('load', initReservation, false);
}
else if(document.addEventListener){
	document.addEventListener('load', initReservation, false);
}
else if(window.attachEvent){
	window.attachEvent('onload', initReservation);
}






function showDepartureDates(id_terminy_wyjazdy){
	if(id_terminy_wyjazdy>0){
		var dates=document.getElementById('offerReservation_offerReservationDetails_dates');
		if(dates){
			var tables=dates.getElementsByTagName('table');
		}
		for(i=0;i<tables.length;i++){
			table=tables[i];
			if(table.id=='dates_'+id_terminy_wyjazdy){
				if(document.getElementById("clipboard_id_terminy") && document.getElementById("clipboard_id_terminy_"+id_terminy_wyjazdy)){
					document.getElementById("clipboard_id_terminy").value=document.getElementById("clipboard_id_terminy_"+id_terminy_wyjazdy).value;
				}
				table.style.display='';
			}else if(table.id.indexOf('dates')!=-1){
				table.style.display='none';
			}
		}
	}
}




function loadAskForm(){
	var tempTable=[];

	for(attr in History.currentState.paramsTable){
		if (attr!='id_warianty'){
		if(History.currentState.paramsTable[attr]['value']){
			tempTable.push(attr+"="+History.currentState.paramsTable[attr]['value']);
		}else if(History.currentState.paramsTable[attr]['defaultValue']){
			tempTable.push(attr+"="+History.currentState.paramsTable[attr]['defaultValue']);
		}else if(History.paramsTable[attr]){
			tempTable.push(attr+"="+History.paramsTable[attr]);
		}
		}
	}
	
	//trzeba pobrac jeszcze id_warianty
	var inputs = document.getElementsByTagName('input');
	var id_warianty = 0;
	for (var i=0; i<inputs.length; i++){
		if (inputs[i].type=='radio' && inputs[i].id.substr(0,8)=='variant_' && inputs[i].checked){
			tempTable.push("id_warianty="+inputs[i].value);
			
		}
	}
	
	var params=tempTable.join('&');


	var callback =
		{
			success: function(o) {
				document.getElementById('offerReservationAskDest').innerHTML=o.responseText;
				if (typeof google_analytics != "undefined") {
					google_analytics.setStep('/formularz_zapytania.html');
				}
			},
			failure: function(o) {}
		};
	if(document.getElementById('offerReservationAskDest')){
		document.getElementById('offerReservationAskDest').innerHTML='<div style="padding-top:20px;"><div style="text-align:center;border:1px solid #dcdcdc;margin:auto;width:575px;background:#fafbfd"><img style="margin-top:15px;margin-bottom:15px" src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="..." /></div></div>';
		YAHOO.util.Connect.setDefaultPostHeader(true);
		YAHOO.util.Connect.asyncRequest('POST', '/?page=offerReservation_offerReservationAskAjax', callback, params);
	}
}


function gotoStep1(splitTest){
	var tempTable=[];
	var id_warianty=0;
	if(document.getElementById('offerVariants')){
		var variantRadios=document.getElementById('offerVariants').getElementsByTagName('input');
		for(var z=0;z<variantRadios.length;z++){
			if(variantRadios[z].checked){
				id_warianty=variantRadios[z].value;
				break;
			}
		}
	}
	for(attr in History.currentState.paramsTable){
		if((attr=='id_okol')&&(id_okol_clicked==false)){
			tempTable.push("id_okol=0");
		}else if(attr=='id_warianty'){
			
				tempTable.push("id_warianty="+id_warianty);
				tempTable.push("id_warianty_a=0");
			
		}else if((attr=='id_terminy') && (id_term=getIdTerminy())){
			tempTable.push(attr+"="+id_term);
		}else{
			if(attr=='id_terminy_wyjazdy'){
				var id_t_w=getIdTerminyWyjazdy()
				if(id_t_w){
					tempTable.push(attr+"="+id_t_w);
				}
			}else if(History.currentState.paramsTable[attr]['value']){
				tempTable.push(attr+"="+History.currentState.paramsTable[attr]['value']);
			}else if(History.currentState.paramsTable[attr]['defaultValue']){
				tempTable.push(attr+"="+History.currentState.paramsTable[attr]['defaultValue']);
			}else if(History.paramsTable[attr]){
				tempTable.push(attr+"="+History.paramsTable[attr]);
			}
		}
	}
	tempTable.push("reserv=1");

	tempTable.push("id_terminy_a=0");

	if (document.getElementById('onlineCatalog'))
		tempTable.push("onlineCatalog="+document.getElementById('onlineCatalog').value);

	var params=tempTable.join('&');

	
	var callback =
		{
			success: function(o) {
				document.getElementById('ofertaReservationContent').innerHTML=o.responseText;
				if(typeof google_analytics!="undefined"){
					if(History.currentState.paramsTable['onlineReservation']['defaultValue']){
						//google_analytics.setStep('/funnel_G1/step3.html');
					}
					else{
						google_analytics.setStep('/szczegoly_rezerwacji.html');
						//google_analytics.setStep('/funnel_offline/krok3.html');
						//console.log('/rezerwacja/szczegoly_rezerwacji.html');
					}
				}
			},
			failure: function(o) {}
		};
	if (splitTest=='A'){
		RESERVATION.loadStep2(params);
	}else{
	
		if(document.getElementById('ofertaReservationContent')){
			document.getElementById('ofertaReservationContent').innerHTML='<div style="text-align:center;border:1px solid #dcdcdc;background:#eff3f6"><img style="margin-top:15px;margin-bottom:15px" src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="..." /></div>';
			YAHOO.util.Connect.asyncRequest('POST', '/?page=ofertaResStep1Content', callback, params);
		}
	}
}








function gobacktoStep0(){
	var tempTable=[];
	for(attr in History.currentState.paramsTable){
		if(History.currentState.paramsTable[attr]['value']){
			tempTable.push(attr+"="+History.currentState.paramsTable[attr]['value']);
		}else if(History.currentState.paramsTable[attr]['defaultValue']){
			tempTable.push(attr+"="+History.currentState.paramsTable[attr]['defaultValue']);
		}else if(History.paramsTable[attr]){
			tempTable.push(attr+"="+History.paramsTable[attr]);
		}
	}
	var params=tempTable.join('&');

	
	
	var callback =
		{
			success: function(o) {
				document.getElementById('ofertaReservationContent').innerHTML=o.responseText;
				/*
				if(typeof google_analytics!="undefined"){
					google_analytics.setStep('/funnel_zapytanie/krok1.html');
					if(History.currentState.paramsTable['onlineReservation']['value']){
						google_analytics.setStep('/funnel_G1/step1.html');
					}
					else{
						//google_analytics.setStep('/funnel_offline/krok1.html');
					}
				}
				*/
			},
			failure: function(o) {}
		};
	if(document.getElementById('ofertaReservationContent')){
		document.getElementById('ofertaReservationContent').innerHTML='<div style="text-align:center;border:1px solid #dcdcdc;background:#eff3f6"><img style="margin-top:15px;margin-bottom:15px" src="http://static.wakacje.pl/wakacje/images/ajax-loader.gif" alt="..." /></div>';
		YAHOO.util.Connect.setDefaultPostHeader(true);
		YAHOO.util.Connect.asyncRequest('POST', '/?page=offerReservation_offerReservationAjax', callback, params);
	}
}

function gobacktoStep0fromStep2(){
	gobacktoStep0();
}

function getIdTerminyWyjazdy(){
	catering=document.getElementById('offerReservation_offerReservationDetails_catering');
	if(catering){
		radios=catering.getElementsByTagName('input');
		for(var i=0;i<radios.length;i++){
			if(radios[i].getAttribute('name')=='radio_id_terminy_wyjazdy'){
				if(radios[i].checked){
					return radios[i].value;
				}
			}
		}
	}
	return null;
}

function getIdTerminy(){
	catering=document.getElementById('offerReservation_offerReservationDetails_catering');
	if(catering){
		radios=catering.getElementsByTagName('input');
		for(var i=0;i<radios.length;i++){
			if(radios[i].getAttribute('name')=='radio_id_terminy'){
				if(radios[i].checked){
					return radios[i].value;
				}
			}
		}
	}
	return null;
}

function reportBug(){
	var tempTable=[];
	for(attr in History.currentState.paramsTable){
		if((attr=='id_okol')&&(id_okol_clicked==false)){
			tempTable['id_okol']=0;
		}else{
			if(attr=='id_terminy_wyjazdy'){
				var id_t_w=getIdTerminyWyjazdy();
				if(id_t_w){
					tempTable[attr]=id_t_w;
				}
			}else if(History.currentState.paramsTable[attr]['value']){
				tempTable[attr]=History.currentState.paramsTable[attr]['value'];
			}else if(History.currentState.paramsTable[attr]['defaultValue']){
				tempTable[attr]=History.currentState.paramsTable[attr]['defaultValue'];
			}else if(History.paramsTable[attr]){
				tempTable[attr]=History.paramsTable[attr];
			}
		}
	}

	params='id_oferty='+tempTable['id_oferty'];
	params+='&id_biura='+tempTable['id_biura'];
	params+='&id_okol='+tempTable['id_okol'];
	if(tempTable['id_terminy_wyjazdy']){
		params+='&id_terminy_wyjazdy='+tempTable['id_terminy_wyjazdy'];
	}else if(tempTable['id_terminy']){
		params+='&id_terminy='+tempTable['id_terminy'];
	}




	AJAXPOST.load('submitBug','/?page=ofertaSubmitBugPage',params,'ładowanie formularza');
}


function reportBugSend(){
	var tempTable=[];
	for(attr in History.currentState.paramsTable){
		if((attr=='id_okol')&&(id_okol_clicked==false)){
			tempTable['id_okol']=0;
		}else{
			if(attr=='id_terminy_wyjazdy'){
				var id_t_w=getIdTerminyWyjazdy();
				if(id_t_w){
					tempTable[attr]=id_t_w;
				}
			}else if(History.currentState.paramsTable[attr]['value']){
				tempTable[attr]=History.currentState.paramsTable[attr]['value'];
			}else if(History.currentState.paramsTable[attr]['defaultValue']){
				tempTable[attr]=History.currentState.paramsTable[attr]['defaultValue'];
			}else if(History.paramsTable[attr]){
				tempTable[attr]=History.paramsTable[attr];
			}
		}
	}

	params='id_oferty='+tempTable['id_oferty'];
	params+='&id_biura='+tempTable['id_biura'];
	params+='&id_okol='+tempTable['id_okol'];
	if(tempTable['id_terminy_wyjazdy']){
		params+='&id_terminy_wyjazdy='+tempTable['id_terminy_wyjazdy'];
	}else if(tempTable['id_terminy']){
		params+='&id_terminy='+tempTable['id_terminy'];
	}

	params+='&';




	if((document.getElementById('typ_bledu4').checked==1 || document.getElementById('typ_bledu3').checked==1 || document.getElementById('typ_bledu5').checked==1) &&  document.getElementById('opis_bledu').value=='')
		alert('Przed wysłaniem musisz wypełnić pole uwagi!');
	else {AJAXPOST.load('submitBug','/?page=ofertaSubmitBugPage',params+AJAXPOST.getFormParamsToPost(document.getElementById('obsluga_bledow')),'ładowanie formularza');}
}

// funkcje dla wariantow niestandardowych



function ustaw_pokoje(ilosc_pokoi,id_oferty, id_terminy_wyjazdy,id_terminy, id_biura)
{
var params = 'ilosc_pokoi=' + ilosc_pokoi+'&id_oferty='+id_oferty+'&id_terminy_wyjazdy='+id_terminy_wyjazdy+'&id_terminy='+id_terminy+'&id_biura='+id_biura;
	AJAXPOST.load('panel_pokoje','/?page=ofertaReservationNonStandardVariantsRoom',params);
	ilosc_osob = ilosc_pokoi;
	if (document.getElementById("flights"))	sprawdz_samoloty(ilosc_osob, id_oferty, id_terminy_wyjazdy, id_terminy,id_biura);
}

function show_age_kid(ile, id)
{

	for(var i=1;i<=10;i++)
	{
		document.getElementById(id+'_ageKid_'+i).style.display='none';
	}
	if(ile>0)
	{
		for(var i=1;i<=ile;i++)
		{
			document.getElementById(id+'_ageKid_'+i).style.display='block';
		}
	}

}

function sprawdz_samoloty(ilosc_osob, id_oferty, id_terminy_wyjazdy, id_terminy, id_biura)
{
var params = 'DOR=' + ilosc_osob+'&id_oferty='+id_oferty+'&id_terminy_wyjazdy='+id_terminy_wyjazdy+'&id_terminy='+id_terminy+'&id_biura='+id_biura;
	AJAXPOST.load('flights','/?page=ofertaReservationNonStandardVariantsFlights',params);

}

function policz_osoby(id_oferty,id_terminy_wyjazdy, id_terminy, id_biura)
{
	if (document.getElementById('flights'))
	{
	var DOR = 0;
	var KID = 0;
	if(document.getElementById('ilosc_pokoi'))
	{
	var ilosc_pokoi = document.getElementById('ilosc_pokoi').value;
	for(var i=0; i<ilosc_pokoi; i++)
	{

		var ile = document.forms["ROOM_"+i].length;
		for(var q=0; q<ile; q++)
		{
			if(document.forms["ROOM_"+i][q].id=="DOR")
			{
				DOR = DOR + parseFloat(document.forms["ROOM_"+i][q].value);
			}
			if(document.forms["ROOM_"+i][q].id=="KID")
			{
				KID = KID + parseFloat(document.forms["ROOM_"+i][q].value);
			}
		}
	}

	}
	ilosc_osob = DOR+KID;
	sprawdz_samoloty(ilosc_osob,id_oferty, id_terminy_wyjazdy, id_terminy, id_biura);
	}
}

function generuj_linka(id_oferty, id_terminy_wyjazdy, id_terminy, id_biura, id_okol)
{
	var data = "&niestandardowe=1&test=1&reserv=1&id_warianty=0";
	
	if(document.getElementById('ilosc_pokoi'))	{
		var ilosc_pokoi = document.getElementById('ilosc_pokoi').value;
	}
	else {
		var ilosc_pokoi = 1;
	}
	data = data + "&ile_pokoi="+ilosc_pokoi;
	for(var i=0; i<ilosc_pokoi; i++){
		var ile = document.forms["ROOM_"+i].length;
		for(var q=0; q<ile; q++){
			if(document.forms["ROOM_"+i][q].value && document.forms["ROOM_"+i][q].value!="0"){
				data = data + "&ROOM_"+i+"__"+document.forms["ROOM_"+i][q].id+"="+document.forms["ROOM_"+i][q].value;
			}
		}
	} 

	if(document.forms["samoloty"]){
		var ile_samoloty = document.forms["samoloty"].length;
		for(var p=0; p<ile_samoloty; p++)	{
			if(document.forms["samoloty"][p].checked)	{
				data = data + "&wylot="+document.forms["samoloty"][p].value;
			}
		}
	}
	data = data + "&id_terminy="+id_terminy_wyjazdy; 
	data = data + "&id_okol="+id_okol;
	data = data + "&id_oferty="+id_oferty;
	data = data + "&id_biura="+id_biura;
	data = data + "&id_terminy_wyjazdy="+id_terminy_wyjazdy;
	data = data + "&reservationProcessStep1=1";

	YAHOO.util.Connect.setDefaultPostHeader(true);
	YAHOO.util.Connect.initHeader("Content-Type", "application/x-www-form-urlencoded");
	YAHOO.util.Connect.asyncRequest('POST','/?page=ofertaReservationStep1',{
			success:function(o){
					var div = document.getElementById('ofertaReservationContent');
					div.style.display='block';
					div.innerHTML = o.responseText;
					AJAXPOST.load('contentResStep1','/?page=ofertaResStep1Content',data);
				},
				failure:function(o){
				}
	},data);

}
