function ListaMiastRequest(id_geo, div_id, select_id, online_only){
	if (!div_id)
		var div_id = 'pozycja_geo';
	if (!select_id)
		select_id = 'geo';
	if(document.getElementById(div_id)) {
		if(document.getElementById(select_id).options.length==1){
			setInner('<center><img alt="" src="http://img.nocowanie.pl/gfx/main/ajax-loader.gif" style="vertical-align: middle;"/></center>', div_id);
			var aj = new Ajax('/files/ajax/lista_miast.php' + ((online_only) ? '?online=1' : ''), document.location);
			aj.onSuccess = function () { 
				setInner(this.HTTP.responseText, div_id);  
				var sel = document.getElementById(select_id).options[0].selected = true;
			    var i=0;
			    while(i<document.getElementById(select_id).options.length-1 && document.getElementById(select_id).options[i].value!=id_geo) {
					i++;
			    }
			    document.getElementById(select_id).selectedIndex=i;
			    document.getElementById(select_id).focus();
			}
			aj.GET();
		}
	}
	return false;
}



function ZaawansowaneLoad(url,show_on_start) {
	if (show_on_start) {
		if(document.getElementById('box_zaawansowane')) {
			setInner('<center><img alt="" src="http://img.nocowanie.pl/gfx/main/zaaw-loader.gif" style="margin-top: 3px;"/></center>', 'box_zaawansowane');
			var aj2 = new Ajax(url, document.location);
			//aj.AddGETParam('costam', 'abc');
			aj2.onSuccess = function () { 
				document.getElementById('box_zaawansowane').style.height="170px";
				setInner(this.HTTP.responseText, 'box_zaawansowane');  
				
				//setInner('', 'naglowek_zaawansowane');
			}
			aj2.GET();
		}
	}
	return false;
}

function ZaawansowaneLoadHeight(url,show_on_start,wysokosc) {
	if (show_on_start) {
		if(document.getElementById('box_zaawansowane')) {
			setInner('<center><img alt="" src="http://img.nocowanie.pl/gfx/main/zaaw-loader-orange.gif" style="margin-top: 3px;"/></center>', 'box_zaawansowane');
			var aj2 = new Ajax(url, document.location);
			//aj.AddGETParam('costam', 'abc');
			aj2.onSuccess = function () { 
				document.getElementById('box_zaawansowane').style.height=wysokosc+"px";
				setInner(this.HTTP.responseText, 'box_zaawansowane');  
				
				//setInner('', 'naglowek_zaawansowane');
			}
			aj2.GET();
		}
	}
	return false;
}

function OstOgladaneLoad(url) {
	
		if(document.getElementById('box_ost_ogladane')) {
			var aj3 = new Ajax(url, document.location);
			aj3.onSuccess = function () { 
				//document.getElementById('box_ost_ogladane').style.height="155px";
				setInner(this.HTTP.responseText, 'box_ost_ogladane');  
				if (this.HTTP.responseText!='') document.getElementById('box_ost_ogladane').style.display="block";
			}
			aj3.GET();
		}
	
	return false;
}

function OstOgladaneAdd(id_lokalizacji,id_geo) {
			var aj4 = new Ajax('/files/ajax/ostatnio_ogladane_add.php?id_lokalizacji=' + id_lokalizacji+'&geo='+id_geo, document.location);
			aj4.GET();
			return false;
}

function CounterAdd(get,get2) {
			var aj5 = new Ajax('/files/ajax/increase_counter.php' + get + get2, document.location);
			aj5.onSuccess = function () { 
				var liczniki=this.HTTP.responseText;
				if(document.getElementById('licznik')) 
					setInner(liczniki.substring(0, liczniki.indexOf('|')), 'licznik'); 
				if(document.getElementById('licznik_od_kiedy'))
					setInner(liczniki.substring(liczniki.indexOf('|')+1,liczniki.lastIndexOf("|")), 'licznik_od_kiedy');
				if(document.getElementById('licznik_dzisiaj'))
					setInner(liczniki.substring(liczniki.lastIndexOf("|")+1), 'licznik_dzisiaj');
					//alert(liczniki.substring(liczniki.lastIndexOf("|")+1));
			}
			aj5.GET();
			return false;
}

function ListaMiastPanstwa(id_panstwa,id_geo){
	if(document.getElementById('pozycja_geo')) {
		
			setInner('<center><img alt="" src="http://img.nocowanie.pl/gfx/main/ajax-loader.gif" style="vertical-align: middle;"/></center>', 'pozycja_geo');
			var aj = new Ajax('/files/ajax/panel_redaktora.php?command=lista_miast&id_panstwa='+id_panstwa, document.location);
			aj.onSuccess = function () { 
				setInner(this.HTTP.responseText, 'pozycja_geo');  
				var sel = document.getElementById('geo').options[0].selected = true;
			    var i=0;
			    while(i<document.getElementById('geo').options.length-1 && document.getElementById('geo').options[i].value!=id_geo) {
					i++;
			    }
			    document.getElementById('geo').selectedIndex=i;
			    document.getElementById('geo').focus();
			}
			aj.GET();
		}
	return false;
}

function ListaLokalizacjiPanstwa(id_panstwa,id_lokalizacji){
	if(document.getElementById('pozycja_lok')) {
			setInner('<center><img alt="" src="http://img.nocowanie.pl/gfx/main/ajax-loader.gif" style="vertical-align: middle;"/></center>', 'pozycja_lok');
			var aj = new Ajax('/files/ajax/panel_redaktora.php?command=lista_lokalizacji&id_panstwa='+id_panstwa, document.location);
			aj.onSuccess = function () { 
				setInner(this.HTTP.responseText, 'pozycja_lok');  
				var sel = document.getElementById('id_lok').options[0].selected = true;
			    var i=0;
			    while(i<document.getElementById('id_lok').options.length-1 && document.getElementById('id_lok').options[i].value!=id_lokalizacji) {
					i++;
			    }
			    document.getElementById('id_lok').selectedIndex=i;
			    document.getElementById('id_lok').focus();
			}
			aj.GET();
		}
	return false;
}

function TopicNewsLoad(topic_id,topic_lp){
	if(document.getElementById('newsbox'+topic_lp)) {
	   var lp=0;
	   while (document.getElementById('t'+lp+'l')) {
	   	if (lp==topic_lp) {
	   		document.getElementById('t'+lp+'l').className='actl';
	   		document.getElementById('t'+lp+'in').className='actin';
    	    		document.getElementById('t'+lp+'r').className='actr';
    	    		document.getElementById('newsbox'+lp).className='box_block';
	   	} else {
	   		document.getElementById('t'+lp+'l').className='nonactl';
	   		document.getElementById('t'+lp+'in').className='nonactin';
    	    		document.getElementById('t'+lp+'r').className='nonactr';
    	    		document.getElementById('newsbox'+lp).className='box_none';
	   	}
    	    	lp++;
	   }
	   if(document.getElementById('newsbox'+topic_lp).innerHTML=='') { 
			setInner('<br><br><center><img alt="" src="http://img.nocowanie.pl/gfx/kazimierzdolny_pl/ajax-loader.gif" style="vertical-align: middle;"/></center><br><br>', 'newsbox'+topic_lp);
			var aj = new Ajax('/files/ajax/news_topics.php?topic_id='+topic_id, document.location);
			aj.onSuccess = function () { 
				odpowiedz=this.HTTP.responseText;
				setInner(odpowiedz, 'newsbox'+topic_lp);
				LoadNewsCounters(document.getElementById('id_news_in_'+topic_id).innerHTML);
				
			}
			aj.GET();
	   }
	}
	return false;
}

function BanerLoad(url) {
	if(document.getElementById('baner_box')) {
		var aj2 = new Ajax(url, document.location);
		aj2.onSuccess = function () { 
			setInner(this.HTTP.responseText, 'baner_box');  
		}
		aj2.GET();
	}
	return false;
}


function ajaxDivLoad(url, id) {
	
		if(document.getElementById(id)) {
			var aj3 = new Ajax(url, document.location);
			aj3.onSuccess = function () { 
				setInner(this.HTTP.responseText, id);  
			}
			aj3.GET();
		}
	
	return false;
}

function getCalendarXmlResponse(url, id, update_selection) {
	var cal = (id) ? calendar[id] : calendar;
	var aj = new Ajax(url, document.location);
	aj.onSuccess = function () { 
		var output = cal.outputAjaxQueryString('dates','Y-m-d',false);
		var spliter = output.split("&");
		
		cal.dates = new Array();
		cal.resetSelections();
		cal.importXML(this.HTTP.responseText);  

		// powracamy do zaznaczenia ktore mielismy przed chwila - wystawianie uslug
		if (update_selection)
		{
			var selected_dates = new Array();		
			var i = 0;
			for(indeks in spliter)
			{
				var curdate = spliter[indeks].substring(spliter[indeks].indexOf('=')+1);
				if (curdate.length)
				{
					var dt = new Date();
					dt.setDate(curdate.substring(8,10));
					dt.setMonth(parseInt(ltrim(curdate.substring(5,7),'0'))-1);
					dt.setYear(curdate.substring(0,4));
				   // dt = Date.parse(curdate);
				    if (cal.dateInArray(cal.dates,dt) && 
				    	cal.dates[cal.dateInArray(cal.dates,dt)].canSelect)
				    {
				    	var ind = cal.dateInArray(cal.dates,dt);
				    	selected_dates[i] = dt;//.format('F d, Y');
						i++;
				    }
				}
			}
			cal.selectDates(selected_dates, true, true);
			cal.reDraw();
		}	
		
		if (document.getElementById('usluga_div') && 
			document.getElementById('sztuk_div') && 
			document.share_service_form.id_uslugi)
		{
			document.getElementById('usluga_div').innerHTML = document.share_service_form.id_uslugi.options[document.share_service_form.id_uslugi.selectedIndex].text;
			document.getElementById('sztuk_div').innerHTML = document.share_service_form.liczba_uslug.options[document.share_service_form.liczba_uslug.selectedIndex].text;
		}
		
		// jezeli mamy podane daty init_od i init_do, to zaznaczamy je na kalendarzyku
		if (document.getElementById('init_od') && document.getElementById('init_od').value && 
			document.getElementById('init_do') && document.getElementById('init_do').value)
		{
			var date1 = cal.cells[cal.getCellIndex(new Date(document.getElementById('init_od').value))];
			date1.cellClick();
			var date2 = cal.cells[cal.getCellIndex(new Date(document.getElementById('init_do').value))];
			date2.cellClick();
			var init_dates = 1;
		}		
										
		// instrukcje do rezerwacji od strony internauty
		if (document.service_booking_form.data_od2 &&
			document.service_booking_form.data_od2)
		{
			document.service_booking_form.data_od2.value = getExtremeDateFromCalendarOutput(0, 'min'); 
			document.service_booking_form.data_do2.value = getExtremeDateFromCalendarOutput(0, 'max'); 
			if (output.length || init_dates)
 				setInnerByUrl('/files/ajax/rezerwacje.php?command=check_booking_term&id_uslugi='+document.service_booking_form.id_uslugi.options[document.service_booking_form.id_uslugi.selectedIndex].value+'&ilosc='+document.service_booking_form.ilosc.options[document.service_booking_form.ilosc.selectedIndex].value+'&data_od='+document.service_booking_form.data_od2.value+'&data_do='+document.service_booking_form.data_do2.value,'booking_info');			
		}
	}
	aj.GET();
}

function reservationCalendarClick()
{
	if (document.service_booking_form.data_od2.value!=getExtremeDateFromCalendarOutput(0, 'min') || document.service_booking_form.data_do2.value!=getExtremeDateFromCalendarOutput(0, 'max'))
	{
		document.service_booking_form.data_od2.value = getExtremeDateFromCalendarOutput(0, 'min'); 
		document.service_booking_form.data_do2.value = getExtremeDateFromCalendarOutput(0, 'max');
		setInnerByUrl('/files/ajax/rezerwacje.php?command=check_booking_term&id_uslugi='+document.service_booking_form.id_uslugi.options[document.service_booking_form.id_uslugi.selectedIndex].value+'&ilosc='+document.service_booking_form.ilosc.options[document.service_booking_form.ilosc.selectedIndex].value+'&data_od='+document.service_booking_form.data_od2.value+'&data_do='+document.service_booking_form.data_do2.value,'booking_info');
	}
}

function getExtremeDateFromCalendarOutput(id, ext)
{
	var cal = (id) ? calendar[id] : calendar;
	var output = cal.outputAjaxQueryString('dates','Y-m-d',false);
	var ret = '';
	var spliter = output.split("&");	
	for(indeks in spliter)
	{	
		var val = spliter[indeks].substring(spliter[indeks].indexOf('=')+1);
		if (!val.length)
			continue;
		if (!ret.length ||
			ext=='min' && val<ret ||
			ext=='max' && val>ret)
			ret = val; 
	}
	return ret;
}

function LoadNewsCounters(id_news_in) {
	var aj3 = new Ajax('/files/ajax/increase_counter.php?command=loadnewscounters&in='+id_news_in, document.location);
	aj3.onSuccess = function () { 
		wynik=this.HTTP.responseText;
		//alert(wynik);
		kon=id_news_in.indexOf(','); 
		while (document.getElementById('odslony_'+id_news_in.substring(0,kon))) {
			poczatek_id=wynik.indexOf('('+id_news_in.substring(0,kon)+')');
			poczatek_licznika=wynik.indexOf(')',poczatek_id)+1;
			gdzie='odslony_'+id_news_in.substring(0, kon);
			//alert(poczatek_licznika);
			if (poczatek_id!=-1) {
				co=wynik.substring(poczatek_licznika,wynik.indexOf('|',poczatek_licznika));
				setInner(co, gdzie);
			} else {
				setInner("...", gdzie);
			}
			id_news_in=id_news_in.substring(kon+1);
			kon=id_news_in.indexOf(',');
		}
		if (document.getElementById('odslony_'+id_news_in)) {
			poczatek_licznika=wynik.indexOf(')',wynik.indexOf('('+id_news_in+')'))+1;
			co=wynik.substring(poczatek_licznika,wynik.indexOf('|',poczatek_licznika));
			gdzie='odslony_'+id_news_in;
			setInner(co, gdzie);
		}	
	}
	aj3.GET();
	return false;
}

function loadStates(country) {
	if (country=='US' || country=='CA' || country=='AU') {
		ajaxDivLoad('/files/ajax/pobierz_stany.php?country='+country, 'stan');
	} else {
		setInner("", 'stan');
	}
	return false;
}

function OstTematyForum() {
		if(document.getElementById('ost_tematy_forum')) {
			setInner('<center><img alt="" src="http://img2.nocowanie.pl/gfx/main/forum-loader.gif" style="margin-top: 3px;"/></center>', 'ost_tematy_forum');
			var aj2 = new Ajax("/files/ajax/pobierz_strone.php?url=http://mapa.nocowanie.pl/ostatnio_na_forum/", document.location);
			//aj.AddGETParam('costam', 'abc');
			aj2.onSuccess = function () { 
				setInner(this.HTTP.responseText, 'ost_tematy_forum');  		
			}
			aj2.GET();
		}
	return false;
}