
function del() {
	var back = confirm('czy na pewno skasować to zdjęcie?');
	if(back==true) {
		var form = document.forms['z2'];
		form.elements['wtd'].value = 'del';
		form.submit();
	}
};

function ev_keyup(e, t) {
	if(getH==null && window.getHTML) {
		getH = new getHTML();
	}

	if(getH!=null) {
		var _fra = t.value;
		var _url = 'sindex.php?a=get_list_data&fraza='+encodeURI(_fra);
		getH.getDataNoXML(_url, pull_city);
	}
};

function set_city(a, b) {
	document.getElementById('ms').value = b;
	document.getElementById('ms2').value = b;
	document.getElementById('ds').value = a;
	document.getElementById('ss4').innerHTML = '';
};

function pull_city(data) {
	var tmp01 = null;
	var data_ob = '';
	var re = new RegExp(/(([^\n]+)\n)/ig);
	//var re = new RegExp(/(.+)\n/ig);
	while ((tmp01= re.exec(data))!==null)
	{
		var tmp02 = tmp01[2].split(';');
		data_ob += '<li><a href="javascript:void(0)" onClick="set_city(\''+tmp02[3]+'\', \''+tmp02[0]+'\')";><b>'+tmp02[0]+'</b>, (gmina '+tmp02[1]+', powiat '+tmp02[2]+', woj. '+tmp02[2]+')</a></li>';
	}
	data_ob = '<ul>'+data_ob+'</ul>';
	document.getElementById('ss4').innerHTML = data_ob;
};

function testW() {

  var win = window;

  if(typeof(win.pageXOffset) != 'undefined')
    var xobj = win.document.getElementsByTagName('body').item(0);
  else
    var xobj = (win.document.compatMode && win.document.compatMode == "CSS1Compat")?win.document.documentElement.getElementsByTagName('body').item(0):win.document.body 
|| null;

  return {w:xobj.offsetWidth};
};

var back = '';

function test_pos(id) {
	var is_opera = ( /opera/i.test(navigator.userAgent) );
	var el = document.getElementById(id);
	var left = 0;
	var top = 0;
	var aTag = el;
	do {
		aTag  = aTag.offsetParent;
		left += aTag.offsetLeft;
		top  += aTag.offsetTop;
        if (!(is_opera))
        {
			var add_left=parseInt(aTag.clientLeft);
            var add_top=parseInt(aTag.clientTop);
    		if (!(isNaN(add_left))) left += add_left;
	    	if (!(isNaN(add_top)))  top += add_top;
        }
		//if(id=='ts')
		//	back += "\n\n\n\n" + aTag.tagName + ' ' + aTag.className + ' ' + aTag.offsetLeft + ' ,' + aTag.clientLeft + "\n\n\n\n";
			//objectProperty(aTag.attributes);

	} while (aTag.tagName != 'BODY' && aTag.tagName != 'HTML');

	//document.getElementById('tstest').value = back;
	return {l:left,t:top};
};

function test_resize() {
	//var tmp1 = testW();
	//var tmp2 = test_pos('map');
	var map_co = document.getElementById('map');
	/*
	var skip = new Array();
	skip['innerHTML'] = 1; skip['outerHTML'] = 1; skip['HTML'] = 1;
	var select = new Array()
	select['offsetWidth'] = 1;
	var undef;
	deb_write(deb_prop(skip, true));
	deb_write(deb_prop(document.getElementById('map-container'), true, skip, select));
	var m_width = tmp1.w - tmp2.l - 31;
	*/
	if(map_co!=undefined) {
		var m_width = map_co.offsetWidth - 5;	
		mapobject.resize(m_width, 600);
	}
};

function rotate(a){
	document.z2.rotate.value=a;
	document.z2.wtd.value="rotate";
	document.z2.submit()
};

function cs1(){
	var a='';
	if(document.z1.ms.value!=document.z1.ms2.value || !document.z1.id.value)
		a='1. wpisz nazwę miejscowości lub jej część\n2. wybierz miejscowość z listy poniżej\n3. kliknij przycisk "dalej"';

	if(a){
		alert(a);
		return false;
	}
	document.z1.action=document.z1.action+'/'+document.z1.id.value;
	return true;
};

function cs2(){
	var a='';
	if(!document.z2.foto.value)a=a+'\n - wybierz zdjęcie';
	if(!document.z2.regulamin.checked)a=a+'\n - zaakceptuj regulamin';

	if(a){
		alert('UWAGA!'+a);
		return false;
	} else{
		document.z2.add.disabled=true;
	}
	return true;
};

function regulamin(){
	window.open("/popup/regulamin.html","","toolbar=1,top=0,left=0,location=0,resizable=0,directories=0,status=0,menubar=0,scrollbars=1,height=600,width=700");
};

function getE(id) {
	return document.getElementById(id);
};

function imgIcon(id, kt) {
	var img = 'img/mapicons/marker.png';
	if(id!='' || id==0) {
		if(kt!=undefined&&(kt.t=='p'))
		img = 'img/poi_categories/poi_cat_'+id+'.png';
		else
		img = 'img/mapicons/marker'+id+'.png';
	}
	return img;
};

function addIcon(id, tmp, f_zw, q_url, kt) {
	var icon1=new MapgoIcon();    
	var height = 160;
	var width = 330;
	var desc = '';
	var tmp2;
	icon1.id=id;
	if(tmp.lon==undefined) {
	tmp2=sk(tmp);
    l2[0]=parseFloat(tmp2.t1);
    l2[1]=parseFloat(tmp2.t2);
	} else {
    l2[0]=parseFloat(tmp.lon);
    l2[1]=parseFloat(tmp.lat);
	}
    icon1.image=imgIcon(tmp.mrk, kt);
	if(tmp.a=='u' || tmp.a=='m') {
		width=330;
		height=75;
		if(tmp.a=='u') { 
			desc=tmp.n;
			height=45;
		}
		if(tmp.a=='m' && tmp.u!='') {
			desc='<a href="'+tmp.u+'">'+tmp.n+'</a> <br> &nbsp; <a href="'+tmp.u+'"><b>zobacz mapę &#187;</b></a>';
			width=330;		 
			if(tmp.n.length>60)
			height=75;
		}
		icon1.descr=addDymek2(tmp,'pl', f_zw, q_url); //desc;
	} else if(kt.t=='p') {
		icon1.descr=addDymek3(tmp,'pl', f_zw, null, kt);
		height=55;
	} else {	
		icon1.descr=addDymek(tmp,'pl', f_zw, null, kt);
	}
    icon1.width=20;
    icon1.height=34;
    icon1.icon_offx=-8;
    icon1.icon_offy=-34;	
    icon1.lon=l2[0];
    icon1.lat=l2[1];
	//tmp.lon = icon1.lon;
	//tmp.lat = icon1.lat;
    icon1.tip_width=width;
    icon1.tip_height=height;
	icon1.tip_anchorx=10;
	icon1.tip_anchory=15;
	return icon1;
};

function addDymek(o, a, f_zw, q_url, kt) {
	if(a=='en'){var e='more';
	var f='accommodation'}else if(a=='de'){var e='mehr';
	var f='ubernachtung'}else{var e='Zobacz więcej';
	var f='noclegi'}
	var h='';var t='';

	if(o.i) {
		if(o.k=='online') {
			t='http://photos.hotele.pl/thumb3/'+o.t;
			o.u = 'http://www.eholiday.pl/online-'+o.i+'.html';
		}
		else {
			t='http://www.eholiday.pl/img/foto/'+o.t;
			o.u = 'http://www.eholiday.pl/noclegi-'+o.i+'.html';
		}
	}

	if(o.t) {}
	else
	t='http://www.eholiday.pl/img/no_image.gif';

	var g='';
	g=g+'<table width="350" height="170"><tr><td valign="middle"><table id="dymek" cellpadding="3" cellspacing="3" border="0" align="center"><tr><td colspan="2" width="100%" class="tdtitle"><div class="title"><a href="'+o.u+'" id="linkb" target="_blank">'+o.n+'</a></div></td></tr><tr><td valign="top" width="30%"><div class="foto"><a href="'+o.u+'" target="_blank"><img src="'+t+'" border="0" class="img"></a></div></td><td valign="top" width="70%" class="opis">'+o.d.replace(RegExp(",","g"),"<br>")+'<div class="typ">'+o.k+'</div><div class="wiecej"><span>&#187;</span><a href="'+o.u+'" id="linkb" target="_blank">'+e+'</a></div></td></tr></table></td></tr></table>';
	return g;
};

function addDymek2(o,a,f_zw,q_url) {
	if(q_url==undefined) q_url = '';
	if(a=='en'){var e='more';
	var f='accommodation'}else if(a=='de'){var e='mehr';
	var f='ubernachtung'}else{
	if(f_zw==1)	{var e='Przejdź do mapy tej miejsowości'; } else {var e='Zobacz więcej';}
	var f='noclegi'}
	var h='';var t='';
	var height = 85;
	if(o.a=='u') height = 45;
	var g='';
	g=g+'<table width="350" height="'+height+'"><tr><td valign="middle"><table id="dymek" cellpadding="3" cellspacing="3" border="0"><tr><td width="100%" class="tdtitle2"><div class="title">';
	if(o.a=='m') g=g+'<a href="'+o.u+'" id="linkb">'+o.n+'</a>';
	else		 g=g+o.n;
	g=g+'</div></td></tr>';
	if(o.a=='m') {
	g=g+'<tr><td valign="top" width="70%" class="opis2">'+o.d;
	if(f_zw==1) 
	g=g+'<div class="wiecej"><span>&#187;</span><a href="'+o.u+q_url+'" id="linkb">'+e+'</a></div>';
	g=g+'</td></tr>';
	}
	g=g+'</table></td></tr></table>';
	return g;
};

function addDymek3(o,a,f_zw,q_url) {
	var height = 55;
	var g='';
	g=g+'<table width="350" height="'+height+'"><tr><td valign="middle"><table id="dymek" cellpadding="3" cellspacing="3" border="0"><tr><td width="100%" class="tdtitle2"><div class="title">';
	g=g+'<span>'+o.k+'</span><br/>';
	g=g+o.n;
	g=g+'</div></td></tr>';
	g=g+'<tr><td valign="top" width="70%" class="opis2">'+o.d;
	g=g+'</td></tr>';
	g=g+'</table></td></tr></table>';
	return g;
};

function showIcons(layer){
	mapobject.showLayer(layer);
};

function hideIcons(layer){
	mapobject.hideLayer(layer);
};

function delIcons(layer){
	if(layer==undefined || layer=='') layer = "city";

	if(window.poi_ts[layer]!=undefined) {
		window.poi_ts[layer].show = 0;
		hideIcons(layer);
	}
	setIcons(layer, kt);
};

function addIcons(layer, kt){

	if(layer==undefined || layer=='') layer = "city";

	if(window.poi_ts[layer]==undefined) {
		var points = new Array();
		window.poi_ts[layer]={name:layer, show:2, points: points};
	} else {
		window.poi_ts[layer].show = 1;
		showIcons(layer);
	}

	//deb_write(layer+ ' ' +kt.t);
	setIcons(layer, kt);

	if(kt!=undefined && kt.t=='p' || kt.t=='o' || kt.t=='n') {
		window.poi_ts[layer].show = 1;
	}
};

var x2;var l2=[];var poi_ts=[];var poi_td=[];
var icon1;

function setIcons(layer, kt) {

	//deb_write('setIcons:'+layer);
	if(x2==undefined) return;

	var j = 0;
	var f_zw = 1;
	if(kt!=undefined && x2[j]!=undefined && kt.l==1 && x2[j].a=='m')  {
		f_zw = 0;
	}

	var q_url = q_in_url(window.location.href);
	if(q_url) {
		q_url = '?q='+q_url;
	}
	
	var icon_list1=[];
	if(window.poi_ts[layer]!=undefined && window.poi_ts[layer].show==2) {
		for(j in x2) {
			x2[j].i = j;
			window.icon1 = addIcon((j+1), x2[j], f_zw, q_url, kt);
			icon_list1.push(window.icon1);
			window.poi_ts[layer].points.push(window.icon1);
		}

	    window.mapobject.addIconsToMap(icon_list1, layer);	
	}

	var icon_list2=[];
	for(j in window.poi_ts) {		
		if(window.poi_ts[j].show>0) {
			for(k in window.poi_ts[j].points) {
				icon_list2.push(window.poi_ts[j].points[k]);
			}
		}
	}

	window.mapobject.positionMap(icon_list2);

	if(kt!=undefined && kt.l==1) {	 
  		window.mapobject.centerTo(l2[0],l2[1],(kt.t=='n'?5:10));
		window.mapobject.showIconTip(window.icon1);
		if(kt.t=='n_off') {
			window.mapobject.tip_icon = window.icon1;
			window.mapobject.showTip();

			var map_co = document.getElementById('map');
			if(map_co!=undefined) {
				var m_width = map_co.offsetWidth
			}
			var map_tip = document.getElementById('_mapgo_tipmapa_imagis');
			if(map_tip!=undefined) {
				map_tip.style.left = (m_width/2-370/2+20)+'px';
			}
		}
		//window.mapobject.tip_icon = window.icon1;
		//window.mapobject.showIconTip(window.icon1);
	}
};

var init_geo_map_u_status = 0;

function geoListener(geo_ans){
	//jeśli w odpowiedzi otrzymamy listę miejscowości to generujemy listę danych o miejscowościach do wyboru	
	//alert(deb_prop(geo_ans, true));
	if (geo_ans.city_list || geo_ans.street_list){
		alert("brak adresu:\n\nmiasto: "+getE('ts').value+"\nulica: "+getE('ulica').value);
		if(init_geo_map_u_status==1) {
			init_geo_map_u_status = 0;
			start_init_map_m();
		}
		//objectProperty(geo_ans.city_list);
	}
	else if (geo_ans.street_list){
		objectProperty(geo_ans.city_list);
	}
	else if (geo_ans.state && geo_ans.state>2){
		mapobject.removeLayer("mrkc");
		mapobject.removeLayer("address_layer");
		var object_list=new Array();
		var icon1=addIcon(1, {n:getE('ts').value+', '+getE('ulica').value,lon:geo_ans.X,lat:geo_ans.Y,a:'u',mrk:''});
		object_list.push(icon1);
		//alert(deb_prop(icon1,true));
		mapobject.addIconsToMap(object_list, "address_layer");		
		mapobject.centerTo(geo_ans.X,geo_ans.Y,5);			
		mapobject.showIconTip(icon1);
	}
};


function check_submit(form) {

	if(form.miejscowosc.value!=form.o_miejscowosc.value)
		return true;

	wu(form.miejscowosc.value, form.ulica.value);
	return false;
};

function wu(city,street_no) {	

	if (street_no.length==0)
		return;

	mapobject.findAddress(city,street_no,geoListener);
};


function cities_pull_my_draw(arr)
{
  // return '<i>'+arr.val+'</i>, gm. '+arr.g +', pow. '+arr.d+', woj. '+arr.p;
  return arr.val+(arr.tab[1]>1 ?' ['+arr.tab[1]+']':'');
};

function gal_pull_my_draw(arr)
{
  return arr.val+' ['+arr.tab[1]+']';
};

function sel_run(data, ss)
{
  ss.array=new Array();
  var xxxx=new Array();
  var re = new RegExp(/(([^\n]+)\n)/ig);
  var sre = new RegExp(/(([^;]+)([;]|$))/ig);
  var tmp01=null;
  var el_val=null;
  while ((tmp01= re.exec(data))!==null)
  {
    var n=xxxx.length;
    xxxx[n]=new Array();

	//objectProperty(tmp01);

    var tmp02=null;
    while ((tmp02=sre.exec(tmp01[2]))!==null)
    {
      xxxx[n][xxxx[n].length]=tmp02[2];
    }
	if(xxxx[n].length>1)
		ss.array[ss.array.length]={val:xxxx[n][0], tab:xxxx[n]};
	else
		ss.array[ss.array.length]={val:xxxx[n][0]};
  }
};

function q_in_url(url) {

	var idx = 0;
	var q = '';
	idx = url.indexOf('q=');
	if(idx!=-1) {
	  q = url.substr(idx+2, url.length);
	  if(q!='') {
		  return q;
	  }
	}
	return q;
};

function start_init_map_u() {

	var idx = 0;
	var idx1 = 0;
	var idx2 = 0;
	var cnt = 0;
	var street = '';
	var city = '';
	var url = window.location.href;

	if(url.indexOf("noclegi-")!=-1)
		return 'acc';

	idx1=url.lastIndexOf("/");
	idx2=url.indexOf("?", idx1);
	city = url.substr(idx1, idx2-idx1);
	for(i=0; i<city.length; i++) {
		if(city.charAt(i)=='-') cnt++;
	}
	if(cnt==1) return 'city';

	var street = q_in_url(url);
	if(street!='') {
		  init_geo_map_u_status = 1;
		  street = decodeURI(street);
		  wu(getE('ts').value, street);
		  return 'street';
	}
	return 'city';
};

function after_init_map() {
	status_after_init_map=true;
	if(site_loaded)
		start_init_map();
};

function start_init_map_m() { m(); };
function start_init_map_n() { mn(); };

function start_init_map() {
	
	var back = start_init_map_u();

	if(back=='city')
		start_init_map_m();
	else if(back=='acc')
		start_init_map_n();
};

var getH = null;
var site_loaded=false;
var menu1close=false;
var status_after_init_map=false;

var new_start_function=function() 
{	
	if(window.m_start) {
		if(m_start==1) {
			// load();
		}
	}
	test_resize();
	if(status_after_init_map)
		start_init_map();

	//if(document.getElementById('obiekty_noclegowe')&&!menu1close) {
	//	document.getElementById('obiekty_noclegowe').className='expand';
	//}
		//init();
	/*
	if(window.quick_info)
		window.cex = new quick_info({hideTime: -1, defCN:'q_info'});
	if(window.pull_select) {
		var ts = ''; var sel = 'city'; var funct = cities_pull_my_draw;
		if (document.getElementById('ts')) { ts = 'ts'; }
		if (document.getElementById('ts2')) { ts = 'ts2'; sel = 'gal'; funct = gal_pull_my_draw; }
		if (ts!='') {
			window.pull_from=new pull_select(ts, [], {def:'nsel',sel:'sel', h:350, ajax_url:'sindex.php?a=get_sel_'+sel+'_data', ajax_get_params:[], ajax_run:sel_run, draw_func:funct});
			//var test = test_pos('ts');
			//alert(test.l);
		}
	}
	*/
	window.site_loaded=true;
};

if (typeof(addLoadEvent)=='function')
{
	addLoadEvent(new_start_function);
}
else
{
	window.onload=new_start_function;
}