function displayWindow(url, name, width, height)
{
        var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no' );
}

function echoDodaj(i)
{
     if(i==0)
     {
          if(document.getElementById("echoDodajPlik").style.display == "block")
               document.getElementById("echoDodajPlik").style.display = "none";
          else
               document.getElementById("echoDodajPlik").style.display = "block"
     }
     else
     {
          if(document.getElementById("echoDodajOpis").style.display == "block")
               document.getElementById("echoDodajOpis").style.display = "none";
          else
               document.getElementById("echoDodajOpis").style.display = "block"
     }
}

function katalogDodaj(i)
{
     if(i==0)
     {
          if(document.getElementById("katalogDodajPlik").style.display == "block")
               document.getElementById("katalogDodajPlik").style.display = "none";
          else
               document.getElementById("katalogDodajPlik").style.display = "block"
     }     

     if(i==1)
     {
        if(document.getElementById("katalogDodajMapa").style.visibility == "visible")
	{
                document.getElementById("katalogDodajMapa").style.visibility = "hidden";
		document.getElementById("katalogDodajMapa").style.height = "0px";
		document.getElementById("pomiarMapa").style.display = "none";
	}
        else
	{
                document.getElementById("katalogDodajMapa").style.visibility = "visible"
		document.getElementById("katalogDodajMapa").style.height = "300px";
		document.getElementById("pomiarMapa").style.display = "block";
	}
     }

     if(i==2)
     {
          if(document.getElementById("katalogDodajOpis").style.display == "block")
               document.getElementById("katalogDodajOpis").style.display = "none";
          else
               document.getElementById("katalogDodajOpis").style.display = "block"
     }
}

function katalogKwota()
{
	var okres = document.getElementById("okresReklamy").value;
	document.getElementById("kwotaReklamy").value=okres;
	document.getElementById("kwota").value=okres;
}

function echoMiasto(i,j)
{
     if(i==1)
     {
          document.getElementById("echoMiastoTlo"+j).style.backgroundColor = "#007fcc";
          document.getElementById("echoMiastoRamka"+j).style.backgroundColor = "#ffffff";
     }
     else
     {
          document.getElementById("echoMiastoTlo"+j).style.backgroundColor = "#efefef";
          document.getElementById("echoMiastoRamka"+j).style.backgroundColor = "#efefef";
     }
}

function zmiana(ile)
{
     var kategoria = document.getElementById("kategoria");

     var i=0;
     var j=kategoria.selectedIndex;

        var select = document.getElementsByName("podkategoria");

     while(i<ile)
     {
          if(i==j)
          {
               select[i].style.display = "block";
               select[i].disabled=false;
          }
          else
          {
               select[i].disabled=true;
               select[i].style.display = "none";
          }

          i=i+1;
     }

     if(j==ile)
     {
          select[0].style.display = "block";
          select[i].disabled=false;
     }

     document.getElementById('brak').style.display="none";
}

function miasto(s,k,p)
{
	var gourl = s.options[s.selectedIndex].value;

	if(p!=-1)
	{
		if(gourl==5)
			location.href='index.php?id=ogloszenia&k='+k+'&p='+p;
		else
			location.href='index.php?id=ogloszenia&m='+gourl+'&k='+k+'&p='+p;
	}
	else
	{
		if(gourl==5)
			location.href='index.php?id=ogloszenia&k='+k;
		else
			location.href='index.php?id=ogloszenia&m='+gourl+'&k='+k;
	}
}

function dopisanie(nazwa,znaki)
{
     var pole = document.getElementById(nazwa);
     pole.value=pole.value.substring(0,pole.selectionStart)+znaki+pole.value.substring(pole.selectionEnd,pole.value.length)
}

function sondaStart(i)
{
	setCookie("gazetaPowiatowaSonda",i,365);
}

function uruchom(ms,tmp,ktoraWiadomosc,ileWiadomosci)
{
     if(document.getElementById("contentTlo"+tmp).style.backgroundColor=="rgb(255, 221, 0)" ||
     document.getElementById("contentTlo"+tmp).style.backgroundColor=="#ffdd00")
     {
          loadNewContent(ktoraWiadomosc);
          contentGazeta(ktoraWiadomosc,ileWiadomosci);

          tmp=ktoraWiadomosc;

          ktoraWiadomosc++;
          if(ktoraWiadomosc>ileWiadomosci)
               ktoraWiadomosc=1;

          setTimeout(function(){uruchom(ms,tmp,ktoraWiadomosc,ileWiadomosci);}, ms);
     }
     else
          return ""
}

function contentStart()
{
     document.getElementById("contentTlo1").style.backgroundColor = "#ffdd00";
     document.getElementById("contentStrzalka1").style.backgroundColor = "#ffdd00";
}

function contentGazeta(n,ile)
{
     var j;

     for(j=1; j<=ile; j++)
     {
          if(j==n)
          {
               document.getElementById("contentTlo"+j).style.backgroundColor = "#ffdd00";
               document.getElementById("contentStrzalka"+j).style.backgroundColor = "#ffdd00";
          }
          else
          {
               document.getElementById("contentTlo"+j).style.backgroundColor = "#e0e0e0";
               document.getElementById("contentStrzalka"+j).style.backgroundColor = "#e0e0e0";
          }
     }
}

function contentZmien(n,ile)
{
     var j;

     for(j=1; j<=ile; j++)
     {
          if(j==n)
          {
               document.getElementById("contentTlo"+j).style.backgroundColor = "#ffdd00";
               document.getElementById("contentStrzalka"+j).style.backgroundColor = "#ffdd00";
          }
          else
          {
               document.getElementById("contentTlo"+j).style.backgroundColor = "#e0e0e0";
               document.getElementById("contentStrzalka"+j).style.backgroundColor = "#e0e0e0";
          }
     }

     uruchom(8000,n,n,ile);
}

function createXMLHttp()
{
    if (typeof XMLHttpRequest != "undefined")
    {
        return new XMLHttpRequest();
    }
    else
    {
        var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp" ];
        for (var i = 0; i<aVersions.length; i++)
        {
             try
             {
                 var oXmlHttp = new ActiveXObject(aVersions[i]);
                 return oXmlHttp;
             }
             catch (oError)
             {
             }
        }
    }
    throw new Error("Nie można utworzyć obiektu XMLHttp.");
}

function loadNewContent(contentID)
{
    var divContent = document.getElementById("divContent");

     var oXmlHttp = createXMLHttp();

     oXmlHttp.open("post", "content.php?numerWiadomosci="+contentID, true);


         oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function()
    {
      //divContent.innerHTML = "Proszę czekać, trwa ładowanie strony...";

         if(oXmlHttp.readyState == 4)
         {
             if (oXmlHttp.status == 200)
             {
                 divContent.innerHTML = oXmlHttp.responseText;
             }
             else
             {
                 divContent.innerHTML = "Wystąpił błąd: "+oXmlHttp.statusText;
             }
         }
    }
    //oXmlHttp.overrideMimeType('text/html; charset=ISO-8859-2');
    oXmlHttp.send(null);
}

function loadContentlogowanie(typ)
{
     var divContent = document.getElementById("divLogowanie");
     var oXmlHttp = createXMLHttp();

     if(typ==1)
     {
          //alert('loguje');
          var login = document.getElementById("login").value;
          var haslo = document.getElementById("haslo").value;

          if(login==""||haslo=="")
          {
               oXmlHttp.open("post", "logowanie.php?ileUzytkownikow=-2&typ=0", true);
          }
          else
          {
               oXmlHttp.open("post", "logowanie.php?login="+login+"&haslo="+haslo+"&typ="+typ, true);
          }
     }
     else
     {
          if(typ==2)
          {
               //alert('wylogowuje');
               //var login = document.getElementById("login").value;
               oXmlHttp.open("post", "logowanie.php?login="+login+"&typ="+typ, true);
          }
          else
          {
               //alert('nic');
               oXmlHttp.open("post", "logowanie.php?typ="+typ, true);
          }
     }

         oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function()
    {
         if(oXmlHttp.readyState == 4)
         {
             if (oXmlHttp.status == 200)
             {
                 divContent.innerHTML = oXmlHttp.responseText;
             }
             else
             {
                 divContent.innerHTML = "Wystąpił błąd: "+oXmlHttp.statusText;
             }
         }
    }
    oXmlHttp.send(null);

}

function loadContentKategorie(contentID)
{
		var k=0;
		var kategoria = document.getElementById("kategoria"+contentID);
		if(kategoria!=null)
		{
			k=kategoria.value;
		}		
		
		var divContent = document.getElementById("divContent"+contentID);

		var oXmlHttp = createXMLHttp();

		oXmlHttp.open("post", "kategorie.php?n="+contentID+"&k="+k, true);

		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function()
    {
      //divContent.innerHTML = "Proszę czekać, trwa ładowanie strony...";

         if(oXmlHttp.readyState == 4)
         {
             if (oXmlHttp.status == 200)
             {
                 divContent.innerHTML = oXmlHttp.responseText;
             }
             else
             {
                 divContent.innerHTML = "Wystąpił błąd: "+oXmlHttp.statusText;
             }
         }
    }
    //oXmlHttp.overrideMimeType('text/html; charset=ISO-8859-2');
    oXmlHttp.send(null);
}

function loadContentOgloszenia()
{
		var k=0;
		var kategoria = document.getElementById("kategoria");
		if(kategoria!=null)
		{
			k=kategoria.value;
		}		
		
		var divContent = document.getElementById("divContent");

		var oXmlHttp = createXMLHttp();

		oXmlHttp.open("post", "ogloszeniaKategorie.php?k="+k, true);

		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function()
    {
      //divContent.innerHTML = "Proszę czekać, trwa ładowanie strony...";

         if(oXmlHttp.readyState == 4)
         {
             if (oXmlHttp.status == 200)
             {
                 divContent.innerHTML = oXmlHttp.responseText;
             }
             else
             {
                 divContent.innerHTML = "Wystąpił błąd: "+oXmlHttp.statusText;
             }
         }
    }
    //oXmlHttp.overrideMimeType('text/html; charset=ISO-8859-2');
    oXmlHttp.send(null);
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    }
  }
return ""
}

function setCookie(c_name,value,expiredays)
{
     var exdate=new Date()
     exdate.setDate(exdate.getDate()+expiredays)
     document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
  {alert('Welcome again '+username+'!')}
else
  {
  username=prompt('Please enter your name:',"")
  if (username!=null && username!="")
    {
    setCookie('username',username,365)
    }
  }
}

function echoZmiana(typ,n)
{
     if(typ==0)
     {
          var x = document.getElementById("echoTlo"+n).style.backgroundColor;
          if((x!='rgb(0, 127, 204)')&&(x!='#007fcc'))
          {
               document.getElementById("echoTlo"+n).style.borderColor = "#e0e0e0";
               document.getElementById("echoTlo"+n).style.backgroundColor = "#e0e0e0";
               document.getElementById("echoNapis"+n).style.color = "#555555";
          }
     }

     if(typ==1)
     {
          var x = document.getElementById("echoTlo"+n).style.backgroundColor;
          if((x!="rgb(0, 127, 204)") && (x!="#007fcc"))
          {
	       document.getElementById("echoTlo"+n).style.borderColor = "#007fcc";
               document.getElementById("echoTlo"+n).style.backgroundColor = "#fafafa";
               document.getElementById("echoNapis"+n).style.color = "#007fcc";
          }
     }

     if(typ==2)
     {
          var ileMiast=4;
          var i;

          for(i=0; i<ileMiast; i++)
          {
               if(i==n)
               {
		    document.getElementById("echoTlo"+i).style.borderColor = "#007fcc";
                    document.getElementById("echoTlo"+i).style.backgroundColor = "#007fcc";
                    document.getElementById("echoNapis"+i).style.color = "#ffffff";

                    setCookie("gazetaPowiatowaMiasto",i,365);
                    echoDisplay(i);
               }
               else
               {
		    document.getElementById("echoTlo"+i).style.borderColor = "#e0e0e0";
                    document.getElementById("echoTlo"+i).style.backgroundColor = "#e0e0e0";
                    document.getElementById("echoNapis"+i).style.color = "#555555";
               }
          }
     }

     if(typ==3)
     {
          var ileMiast=4;
          var i;

          for(i=0; i<ileMiast; i++)
          {
               if(i==n)
               {
		    document.getElementById("echoTlo"+i).style.borderColor = "#007fcc";
                    document.getElementById("echoTlo"+i).style.backgroundColor = "#007fcc";
                    document.getElementById("echoNapis"+i).style.color = "#ffffff";

                    //setCookie("gazetaPowiatowaMiasto",i,365);

		    if(i==0)
                    	location.href='index.php?id=echoWiadomosci&numer=4';
		    else
			location.href='index.php?id=echoWiadomosci&numer='+i;
               }
               else
               {
		    document.getElementById("echoTlo"+i).style.borderColor = "#e0e0e0";
                    document.getElementById("echoTlo"+i).style.backgroundColor = "#e0e0e0";
                    document.getElementById("echoNapis"+i).style.color = "#555555";
               }
          }
     }

     if(typ==4)
     {
          var ileMiast=4;
          var i;

          for(i=0; i<ileMiast; i++)
          {
               if(i==n)
               {
		    document.getElementById("echoTlo"+i).style.borderColor = "#007fcc";
                    document.getElementById("echoTlo"+i).style.backgroundColor = "#007fcc";
                    document.getElementById("echoNapis"+i).style.color = "#ffffff";

                    //setCookie("gazetaPowiatowaMiasto",i,365);

		    if(i==0)
                    	location.href='http://www.zgorzelec.gazeta-info.pl';

		    if(i==1)
			location.href='http://www.boleslawiec.gazeta-info.pl';

		    if(i==2)
			location.href='http://www.jeleniagora.gazeta-info.pl';

		    if(i==3)
			location.href='http://www.luban.gazeta-info.pl';
               }
               else
               {
		    document.getElementById("echoTlo"+i).style.borderColor = "#e0e0e0";
                    document.getElementById("echoTlo"+i).style.backgroundColor = "#e0e0e0";
                    document.getElementById("echoNapis"+i).style.color = "#555555";
               }
          }
     }
}

function echoDisplay(n)
{
     var ile=4;
     var j;

     for(j=0; j<ile; j++)
     {
          if(j==n)
               document.getElementById("miasto"+j).style.display = "block";
          else
               document.getElementById("miasto"+j).style.display = "none";
     }
}

function echoStart(n)
{
     var ile=4;
     var k;

     for(k=0; k<ile; k++)
     {
          if(k==n)
          {
	       document.getElementById("echoTlo"+k).style.borderColor = "#007fcc";
               document.getElementById("echoTlo"+k).style.backgroundColor = "#007fcc";
               document.getElementById("echoNapis"+k).style.color = "#ffffff";
          }
          else
          {
	       document.getElementById("echoTlo"+k).style.borderColor = "#e0e0e0";
               document.getElementById("echoTlo"+k).style.backgroundColor = "#e0e0e0";
               document.getElementById("echoNapis"+k).style.color = "#555555";
          }
     }
}

function gazeta(i)
{
     if(i==1)
     {
          document.getElementById("gazetaNapis").style.backgroundColor = "#ffdd00";
          document.getElementById("gazetaArrow").style.backgroundColor = "#ffdd00";
     }
     else
     {
          document.getElementById("gazetaNapis").style.backgroundColor = "#e0e0e0";
          document.getElementById("gazetaArrow").style.backgroundColor = "#e0e0e0";
     }
}

function over(nazwa,kolor)
{
	document.getElementById(nazwa).style.backgroundColor = kolor;
}

function sonda(n,i)
{
     if(n==1)
     {
          document.getElementById("pasek0"+i).style.display = "none";
          document.getElementById("pasek1"+i).style.display = "block";
          document.getElementById("napis"+i).style.color = "#da251c";
     }
     else
     {
          document.getElementById("pasek1"+i).style.display = "none";
          document.getElementById("pasek0"+i).style.display = "block";
          document.getElementById("napis"+i).style.color = "#007fcc";
     }
}

function wiadomosci(i,n,m)
{
     if(i==1)
     {
          document.getElementById("wiadomosciZnak"+n+m).style.backgroundColor = "#007fcc";
          document.getElementById("wiadomosciNapis"+n+m).style.color = "#007fcc";
     }
     else
     {
          document.getElementById("wiadomosciZnak"+n+m).style.backgroundColor = "#666666";
          document.getElementById("wiadomosciNapis"+n+m).style.color = "#444444";
     }
}

function wiadomosciTemat(i,n)
{
     if(i==1)
     {
          document.getElementById("wiadomosciTemat"+n).style.color = "#007fcc";
          document.getElementById("wiadomosciZapowiedz"+n).style.color = "#007fcc";
     }
     else
     {
          document.getElementById("wiadomosciTemat"+n).style.color = "#555555";
          document.getElementById("wiadomosciZapowiedz"+n).style.color = "#555555";
     }
}

function komentarze(i)
{
     if(i==1)
     {
          document.getElementById("komentarzeTekst").style.color = "#000000";
          document.getElementById("komentarze").style.textDecoration = "underline";
     }
     else
     {
          document.getElementById("komentarzeTekst").style.color = "#888888";
          document.getElementById("komentarze").style.textDecoration = "none";
     }
}

function lights(nazwa)
{
     if(document.getElementById(nazwa).style.display=="block")
     {
          document.getElementById(nazwa).style.display="none";
     }
     else
     {
          document.getElementById(nazwa).style.display="block";
     }

     setTimeout(function(){lights(nazwa);}, 250);
}

function katalog(i,n)
{
     if(i==1)
     {
          document.getElementById("katalogA"+n).style.display="block";
          document.getElementById("katalogB"+n).style.display="block";
          document.getElementById("katalogC"+n).style.display="block";
     }
     else
     {
          document.getElementById("katalogA"+n).style.display="none";
	  document.getElementById("katalogB"+n).style.display="none";
	  document.getElementById("katalogC"+n).style.display="none";
     }
}

function podstronaLink(i)
{
     if(i==1)
     {
          document.getElementById("pierwszaStrona").style.color="#999999";
     }
     else
     {
          document.getElementById("pierwszaStrona").style.color="#ffffff";
     }
}

function katalogMenu(i,typ)
{
     if(i==1)
     {
          document.getElementById("tabelaKatalog"+typ).style.backgroundColor = "#f0f0f0";
          document.getElementById("napisKatalog"+typ).style.color = "#da251c";
     }
     else
     {
          document.getElementById("tabelaKatalog"+typ).style.backgroundColor = "#f5f5f5";
          document.getElementById("napisKatalog"+typ).style.color = "#555555";
     }
}

function wywiadyMenu(i,typ)
{
     if(i==1)
     {
          document.getElementById("tabelaWywiady"+typ).style.backgroundColor = "#f0f0f0";
          document.getElementById("osobaWywiady"+typ).style.color = "#da251c";
          document.getElementById("miejsceWywiady"+typ).style.color = "#da251c";
          document.getElementById("dataWywiady"+typ).style.color = "#da251c";
     }
     else
     {
          document.getElementById("tabelaWywiady"+typ).style.backgroundColor = "#f5f5f5";
          document.getElementById("osobaWywiady"+typ).style.color = "#555555";
          document.getElementById("miejsceWywiady"+typ).style.color = "#555555";
          document.getElementById("dataWywiady"+typ).style.color = "#555555";
     }
}

function ogloszeniaRodzaj(i)
{
     if(i==1)
     {
          document.getElementById("czas1").style.display="none";
          document.getElementById("czas2").style.display="block";
	  document.getElementById("tekstSms").style.display="block";
     }
     else
     {
          document.getElementById("czas1").style.display="block";
          document.getElementById("czas2").style.display="none";
	  document.getElementById("tekstSms").style.display="none";
     }
}

function ogloszenia(i,n)
{
     if(i==1)
     {
          document.getElementById("ogloszeniaA"+n).style.display="block";
          document.getElementById("ogloszeniaB"+n).style.display="block";
     }
     else
     {
          document.getElementById("ogloszeniaA"+n).style.display="none";
	  document.getElementById("ogloszeniaB"+n).style.display="none";
     }
}

function wyboryZmiana(typ,n,ile)
{
	var j;
	var x;


	if(typ==0)
	{
		x=document.getElementById("wyboryPartia"+n).style;
		if(x.display=="none")
		{

			document.getElementById("wyboryLogo"+n).style.borderColor = "#f0f0f0";
		}
	}

	if(typ==1)
	{
		x=document.getElementById("wyboryPartia"+n).style;
		if(x.display=="none")
		{

			document.getElementById("wyboryLogo"+n).style.borderColor = "#e5e5e5";
		}
	}


	if(typ==2)
	{
		x=document.getElementById("wyboryPartia"+n).style;
		if(x.display=="none")
		{		
     			for(j=1; j<=ile; j++)
     			{
				if(j==n)
				{
					document.getElementById("wyboryLogo"+j).style.borderLeftColor = "#e5e5e5";
					document.getElementById("wyboryLogo"+j).style.borderRightColor = "#e5e5e5";
					document.getElementById("wyboryLogo"+j).style.borderTopColor = "#e5e5e5";
					document.getElementById("wyboryLogo"+j).style.borderBottomColor = "#f5f5f5";

					document.getElementById("wyboryPartia"+j).style.display = "block";
				}
         			else
				{
					document.getElementById("wyboryLogo"+j).style.borderLeftColor = "#f0f0f0";
					document.getElementById("wyboryLogo"+j).style.borderRightColor = "#f0f0f0";
					document.getElementById("wyboryLogo"+j).style.borderTopColor = "#f0f0f0";
					document.getElementById("wyboryLogo"+j).style.borderBottomColor = "#f0f0f0";

					document.getElementById("wyboryPartia"+j).style.display = "none";
				}
     			}
		}
		else
		{
					document.getElementById("wyboryLogo"+n).style.borderLeftColor = "#f0f0f0";
					document.getElementById("wyboryLogo"+n).style.borderRightColor = "#f0f0f0";
					document.getElementById("wyboryLogo"+n).style.borderTopColor = "#f0f0f0";
					document.getElementById("wyboryLogo"+n).style.borderBottomColor = "#f0f0f0";

			document.getElementById("wyboryPartia"+n).style.display = "none";
		}
	}
}
