var map,lat,lng;
var marker_nr = 0;
var alfabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var tlat=new Array();
var tlng=new Array();
var turystyka = false;
	
function dodaj_marker(){
	
	var indeks = marker_nr;
	
    var ikona = new GIcon(); 
	if(turystyka) {
	    ikona.image = "http://www.google.com/intl/en_ALL/mapfiles/marker"+alfabet[marker_nr++]+".png";  
	    ikona.shadow = "http://www.google.com/intl/en_ALL/mapfiles/shadow50.png";  
		ikona.iconAnchor = new GPoint(9,33);  
	}
	else {
		ikona = G_DEFAULT_ICON;
	}
	var marker = new GMarker(map.getCenter(), {draggable: true, icon: ikona}); // drugi argument (opcje) można pominąć, tak jak tutaj  
	
   map.addOverlay(marker); 

   if(turystyka){
   tlat[indeks] = marker.getLatLng().lat();
   tlng[indeks] = marker.getLatLng().lng();
   
    GEvent.addListener(marker, "dragend", function() {
      tlat[indeks] = marker.getLatLng().lat().toFixed(4);
      tlng[indeks] = marker.getLatLng().lng().toFixed(4);
    });   
	}
	else {
    GEvent.addListener(marker, "dragend", function() {
      document.getElementById("lat").value = marker.getLatLng().lat().toFixed(4);
      document.getElementById("lng").value = marker.getLatLng().lng().toFixed(4);
    });   
	
	}

return false;
}

function zapisz_wsp(){ //zapisuje współrzędne punktów z tablic do ciągów tekstowych w polach formularza
	document.getElementById("lat").value = tlat.join(';');
	document.getElementById("lng").value = tlng.join(';');
return false;
}
function load() {
  if (GBrowserIsCompatible()) {
  
  tlat = document.getElementById("lat").value.split(';');
  tlng = document.getElementById("lng").value.split(';');

  tlat[0] = (tlat[0] > 0) ? tlat[0] : '49.5556';
  tlng[0] = (tlng[0] > 0) ? tlng[0] : '22.2061';
  
  
    map = new GMap2(document.getElementById("map"));
	
	for(i=0;i<tlat.length;i++)	{
    map.setCenter(new GLatLng(tlat[i], tlng[i]), 9);
	map.setUIToDefault();
	map.enableScrollWheelZoom();
	map.disableScrollWheelZoom();
   // map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
 
	dodaj_marker();
	}	
  }
}

function usun_markery() {
	if(!confirm("UWAGA! Wszystkie punkty na mapie zostaną bezpowrotnie usunięte. Kontynuować?")) return false;
	//przywrócenie domyślnego ustawienia
	marker_nr=0;
	document.getElementById("lat").value = '';
	document.getElementById("lng").value = '';
	load();
}

 function dodajMarker(lat,lon,opcje)  
    {  
        var marker = new GMarker(new GLatLng(lat,lon),opcje);  
        mapa.addOverlay(marker);  
    } 

function pokaz(ukryj, pokaz){    
	document.getElementById(ukryj).style.display="none";
	document.getElementById(pokaz).style.display="block";    
}
function zmien(aktywny, nieaktywny){    
	document.getElementById(aktywny).style.color="#666";
	document.getElementById(aktywny).style.background="url('./img/kr_zi.jpg') no-repeat 0px 0px";
	document.getElementById(aktywny).style.padding="4px 4px 2px 4px";

	document.getElementById(nieaktywny).style.background="url('./img/kr_bi.jpg')";	
	document.getElementById(nieaktywny).style.padding="4px 4px 0px 4px";
	document.getElementById(nieaktywny).style.height="19px";
	document.getElementById(nieaktywny).style.color="white";
}

function Potwierdz() {
var jest_potw = confirm('Na pewno chcesz usunąć?');
return jest_potw;
};
function PotwierdzGrupa() {
var jest_potw = confirm('Na pewno chesz się wypisać z grupy?');
return jest_potw;
};
function menu(id) 
{
	if (document.getElementById(id).style.display=="none") 
	{
		document.getElementById(id).style.display="block";
	    window.scrollTo(0,999999);
	} 
	else 
	{
		document.getElementById(id).style.display="none";
	}
}
function userinfo(w) 
{
	if (document.getElementById('userinfo').style.visibility=="hidden") 
	{
		document.getElementById('userinfo').style.visibility="visible";
		w.innerHTML="Mniej";
	    window.scrollTo(0,999999);
	} 
	else 
	{
		document.getElementById('userinfo').style.visibility="hidden";
		w.innerHTML="Więcej";
	}
}
function addKom(id) 
{
	if (document.getElementById(id).style.display=="none") 
	{
		document.getElementById(id).style.display="inline";
	   
	} 
	else 
	{
		document.getElementById(id).style.display="none";
	}
}


function okno(url, width, height) {
        var win = window.open(url,"okienko",'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no' );
}


function FontSize(size, wyb) {
	document.getElementById("srodek").style.fontSize = size;	
	document.getElementById("size1").style.color = "black";
	document.getElementById("size2").style.color = "black";
	document.getElementById("size3").style.color = "black";
	document.getElementById(wyb).style.color = "#FF6805";	
}

  /*----------------------------------data*/
DayName = new Array(7)
DayName[0] = "<b>niedziela</b> "
DayName[1] = "<b>poniedziałek</b> "
DayName[2] = "<b>wtorek</b> "
DayName[3] = "<b>środa</b> "
DayName[4] = "<b>czwartek</b>"
DayName[5] = "<b>piątek</b>"
DayName[6] = "<b>sobota</b> "

MonthName = new Array(12)
MonthName[0] = "stycznia "
MonthName[1] = "lutego "
MonthName[2] = "marca "
MonthName[3] = "kwietnia "
MonthName[4] = "maja "
MonthName[5] = "czerwca "
MonthName[6] = "lipca "
MonthName[7] = "sierpnia "
MonthName[8] = "września "
MonthName[9] = "października "
MonthName[10] = "listopada "
MonthName[11] = "grudnia "

function getDateStr(){
var Today = new Date()
var WeekDay = Today.getDay()
var Month = Today.getMonth()
var Day = Today.getDate()
var Year = Today.getFullYear()

if(Year <= 99)
Year += 1900

return DayName[WeekDay] + " " + " " + Day + " " + MonthName[Month] + " " + Year + "r"
} 
function antyspam(t) {
  t.spam.value=9;
  return true;
}



function strona(plik) {
  //if (plik!='reklamy_box' && plik!='s2' && plik!='s3') return false; // zabezpieczenie
  var xml = null;
  var wynik = document.getElementById("reklamy");
  //wynik.innerHTML = "<img src=\""+plik+"img/preloader.gif\" />";
 
	if (window.XMLHttpRequest) xml = new XMLHttpRequest();
	else if (window.ActiveXObject) xml = new ActiveXObject("Microsoft.XMLHTTP");
 
  if (xml) {
    xml.onreadystatechange = function() {
      if (xml.readyState==4) {
          wynik.innerHTML = xml.responseText;
      }
    }
    xml.open("GET", plik+"boksy/reklamy_box.php?sid="+Math.random(), true);
    xml.send(null);
  }
  return false;
}

function glosuj(adr, typ, id, glos) {
  
  var xml = null;
  var wynik = document.getElementById("oceny");
  //wynik.innerHTML = "wczytywanie...";
 
	if (window.XMLHttpRequest) xml = new XMLHttpRequest();
	else if (window.ActiveXObject) xml = new ActiveXObject("Microsoft.XMLHTTP");
 
  if (xml) {
    xml.onreadystatechange = function() {
      if (xml.readyState==4) {
          wynik.innerHTML = xml.responseText;
      }
    }
    xml.open("GET", adr+"glosuj_ajax.php?typ="+typ+"&id="+id+"&glos="+glos, true);
    xml.send(null);
  }
  return false;
}

function dodaj_ulubione(adr,kat,id) {
  
  var xml = null;
  var wynik = document.getElementById("wynik_ulubione");

  wynik.innerHTML='';
  
	if (window.XMLHttpRequest) xml = new XMLHttpRequest();
	else if (window.ActiveXObject) xml = new ActiveXObject("Microsoft.XMLHTTP");
 
  if (xml) {
    xml.onreadystatechange = function() {
      if (xml.readyState==4) {
          wynik.innerHTML = xml.responseText;
      }
    }
    xml.open("GET", adr+"ulubione_dodaj_ajax.php?kat="+kat+"&id="+id, true);
    xml.send(null);
  }
  return false;
}

function wybierz_kategorie(adr,kat) {

  try { //wyjątek, jeśli nie ma takich obiektów na tej stronie
  document.getElementById("wyniki_wyszukiwania").innerHTML = ''; //wyczyść stare wyniki wyszukiwania po zmianie kategorii
  document.getElementById("porcjowanie").innerHTML = ''; //wyczyść stare wyniki wyszukiwania po zmianie kategorii
  }
  catch (e){ }

  var xml = null;
  var wynik = document.getElementById("kategoria_select");
  var container = document.getElementById("serach");
  
  wynik.innerHTML='Wczytywanie danych...';
  
	if (window.XMLHttpRequest) xml = new XMLHttpRequest();
	else if (window.ActiveXObject) xml = new ActiveXObject("Microsoft.XMLHTTP");
 
  if (xml) {
    xml.onreadystatechange = function() {
      if (xml.readyState==4) {
          wynik.innerHTML = xml.responseText;
		  //container.style.height = (wynik.clientHeight+155)+"px";
      }
    }
    xml.open("GET", adr+"kategoria_select_ajax.php?kat="+kat, true);
    xml.send(null);
  }
  return false;
}

function zapytanie(id,t){//zapytanie o rekord
	kontakt = window.open(ADR + 'zapytanie.php?id='+id+'&t='+t,'okno','width=500,height=500,top=300,left=100');
}
function zapytanie_red(){//zapytanie do redakcji
	kontakt = window.open('./zapytanie.php','okno','width=500,height=480,top=300,left=100');
}
function popup_spr(){
if(window.opener == null) $('srodek').innerHTML = '<div class=\'bad\'>Nieprawidłowe wywołanie!</div>'
}

function pokaz_submenu(p,left){

	if(p == '') 
	{
		Element.setStyle($('pomenu'),{display:'none'});
	}
	else
	{
		Element.setStyle($('pomenu'),{display:'block',left:left+'px'});
		$A($('pomenu').getElementsByTagName('a')).each(function(ob){Element.setStyle(ob,{display:'none'});});

		$A($('pomenu').getElementsByClassName(p)).each(function(ob){Element.setStyle(ob,{display:'block'});});
		
		var a = function(){
			Element.setStyle($('pomenu'),{display:'none'});
		}

		$('blokada_wyswietlania_menu').onmouseover = a;
		$('gdzie_tekst').onmouseover = a;
		$('srodek').onmouseover = a;
		$('lewa').onmouseover = a;
	}
	
}

