function wyswietlSzegolyPolaczenia(id){
	if(id==undefined)return;
	list.displayListing(id);
	
	n.log('wyswietl dla miasta '+id);
	
	var ur = document.location;
	ur = ur.toString();
	
	if( ur.indexOf('#') != -1 ){
		ur = ur.split('#')[0];
	}
	window.setTimeout(function() {
		document.location = ur+'#mapa_listing';}, 
		 500
	);	
}

var submited = false;
function nsubmit(form,value){
    if( submited === true)return;
    submited = true;
    $(form).insert('<input type="hidden" name="tx_pksform_pi1[type_submit]" value="'+value+'" />')

    $(form).submit();
    return false;
}

function disableButton(form){
    $(form).select('button[type="submit"]').invoke('setAttribute','disabled',true);
    $(form).select('button[type="button"]').invoke('setAttribute','disabled',true);
}

var n = {
	debug : 0,
	
	log		: function(msg){
		if(n.debug){
			console.log(msg);
			console.trace();
		}
	},
	
	selectWhere	: function(el,key,value){
		el = $(el);
		n.log(el);
		
		$(el).each(function(item){
			n.log(item);
		});
	},
	
	jumpurl	: function(select){
		var url = select[select.selectedIndex].getAttribute('jumpurl');
    	var b = document.getElementsByTagName('base');
		if( url ){
			document.location.href = b[0].href + url;
		} else {
                        var ur = document.location;
                        ur = ur.toString();

                        if( ur.indexOf('#') != -1 ){
                                ur = ur.split('#')[0];
                        }
                        /** listing połączeń **/
                        $(select).up('form').setAttribute('action', ur + '#dostepne-polaczenia');
			$(select).up('form').submit();
		}
	},
	
	popup	: function(title,msg,x,y){
		var win = new Window({
			className: "dialog", 
			width:150, 
			height: ((msg.split('onclick').length/2)+1)*30, 
			zIndex: 500, 
			resizable: true, 
			title: '', 
			showEffect:Effect.BlindDown, 
			hideEffect: Effect.SwitchOff, 
			draggable:true, wiredDrag: true
		});
		win.getContent().innerHTML= msg; 
		win.setStatusBar(""); 
		win.showCenter(1);
		
		return false;
	}
}


var list = Class.create({
	listingDiv		: 'mapa_listing',
	url	: 'index.php?eID=pks',
	getData		: function(str){
		return str.split('***json***')[1].evalJSON(true);
	},	
	
	log 	: function(msg){
	//	console.log(msg);
	},	
	
	displayListing	: function (fromId){
		list.log(fromId);
		new Ajax.Request(list.url, {
			onSuccess	: function(tr){
				$(list.listingDiv).update( list.getData(tr.responseText) );
			},
			parameters	: {'data':$H({'city_from':fromId}).toJSON()}
		});		
	}
});


try {
	document.observe("dom:loaded", function(){		
		list = new list();
		
		$$('.jumpurl').each(function(el){
			el.observe('change',function(event){n.jumpurl(event.element() );});
		});
		
		$$('.n-w').each(function(el){
			el.observe('click',function(event){
				var el = event.element();
				if(el.tagName=='img' || el.tagName == 'IMG'){
					el = el.parentNode;
				}
				var content = [], v = el.getAttribute('v').split(';');
				var godziny = v[1].split(',');
				v = v[0];
	
				$(godziny).each(function(godzina){
					content.push(['<a href="#" onclick="return pksForm.doR(this);">',godzina,'</a>'].join(''));
				});
	
				return n.popup( el.getAttribute('title'), ['<div v="',v,'" class="popup">',content.join(''),'</div>'].join(''),event.clientX,event.clientY );
			});
			return false;
		});	
	});
} catch(e){
	
}
