var foto_dir = 'http://www.projekty.ign.com.pl/';
//var foto_dir = 'http://projekty/';
//var foto_dir = 'http://www.domfort.eu/';
//var foto_dir = 'http://domfort/';
var ETest  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var TTest  = /^([0-9\-\ \(\)])+$/;
var NTest  = /^([0-9\-\ ])+$/;
var KTest  = /^([0-9])+$/;

function displayWindow(url, width, height)
{
   window.open(url,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function zmien_projekt()
{
   if (document.getElementById('proj_id').value != '-')
      return true;
   else
      return false;
}

function nowe_okno(adres)
{
   window.open(adres,'','');
   return false;
}

function zm_mini(imgMini, imgZoom)
{
   Widok = imgZoom;
   document.getElementById('widoczek').src = foto_dir + 'pliki/widoki/' + imgMini;
}

function displayTablica(nazwa, width, height)
{
   window.open("popup/tablica.php?nazwa=" + nazwa,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayArchPakiet(nazwa, width, height)
{
   window.open("popup/archpakiet.php?nazwa=" + nazwa,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function duzyWidok(Widok, IDP)
{
   window.open('popup.php?f='+Widok+'&c=widoki&idp='+IDP, 'ZOOM', 'width=620,height=460,'+
               'resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,status=no');
}

function odbLustrzane(Idn)
{
   window.open('popup/lustro.php?p='+Idn, 'Odbicie', 'width=620,height=420,'+
               'resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,status=no');
}
function drukuj_proj(Idn)
{
   window.open('popup/drukuj.php?p='+Idn, 'Drukowanie', 'width=620,height=420,'+
               'resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,status=no');
}

function obrotSwiatla(Idn)
{
   window.open('popup/obracanie.php?p='+Idn, 'Obrot', 'width=786,height=550,'+
               'resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,status=no');
}

function obrot3d(Idn)
{
   window.open('popup/obrot.php?p='+Idn, 'Obrot', 'width=500,height=430,'+
               'resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,status=no');
}

function fotos(Idn, ktg)
{
   window.open('popup/foteczki.php?p='+Idn+'&k='+ktg, 'Obrot', 'width=620,height=400,'+
               'resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,status=no');
}

function pokaz_ukryj (idn, disp)
{
   document.getElementById(idn).style.display = disp;
   
   if (disp == 'block')
   {
      document.getElementById(idn+'_t').innerHTML = "&laquo; ukryj";
      disp = 'none';
   }
   else
   {
      document.getElementById(idn+'_t').innerHTML = "zobacz &raquo;";
      disp = 'block'
   }
   return disp;
}

function powiekszRzut(rzut, IDP)
{
   window.open('popup.php?f='+rzut+'&c=rzuty&idp='+IDP, 'ZOOM', 'width=700,height=470,'+
               'resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,status=no');
}

function danewysylka()
{
   if (document.getElementById('inne').checked == 1)
   {
      document.getElementById('dane_wysylka').style.display='block';
   }
   else
   {
     document.getElementById('dane_wysylka').style.display='none';
   }
}

function czk_formularz()
{
   var error= '';
   var wersja = 0;

   radio= document.getElementsByName('wersja');

   for(i=0; i<radio.length; i++)
   {
      if (radio[i].checked == 1) wersja = 1;
   }
   if (wersja != 1) error += "Proszę wybrać wersję projektu!\n";
   
   if (document.getElementById('firma').value == '') {
	if (document.getElementById('imie').value.length < 3) error += "Proszę podać imię!\n";
	if (document.getElementById('nazw').value.length < 3) error += "Proszę podać nazwisko!\n";
   } else {
	if (document.getElementById('nip').value == '') error += "Proszę podać numer NIP!\n";
   }
   if (document.getElementById('ulica').value.length < 3) error += "Proszę podać ulicę i nr domu!\n";
   if (document.getElementById('kod1').value.length < 2 || document.getElementById('kod2').value.length < 3)
      error += "Proszę podać kod pocztowy!\n";
   if (document.getElementById('kod1').value.length == 2 && document.getElementById('kod2').value.length == 3) {
       if(!KTest.test(document.getElementById('kod1').value) || !KTest.test(document.getElementById('kod2').value) ) error += "Podany kod jest błędny!\n";
   }
   if (document.getElementById('miasto').value.length < 3) error += "Proszę podać miejscowość!\n";
   
   if (document.getElementById('nip').value.length > 0) {
     if(!NTest.test(document.getElementById('nip').value)) error += "Podany numer nip jest błędny!\n";
   }
   
   if (document.getElementById('tel').value.length < 9) error += "Proszę podać telefon kontaktowy!\n";
   if (!TTest.test(document.getElementById('tel').value)) error += "Podany numer telefonu jest blędny!\n";   
   
   if (error != '')
   {
      alert (error);
      return false;
   }
   else
   {
      document.getElementById('subm').setAttribute('disabled','true');
      return true;
   }
}

function inp_email (idn)
{
   window.open('popup_wyslij_email.php?i='+idn, '', 'width=200,height=70,'+
               'resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,status=no');
}

function inp_drukuj (idn)
{
   window.open('popup_drukuj_zamowienie.php?p='+idn, '', 'width=600,height=400,'+
               'resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,status=no');
}

function reklamacja()
{
   error = '';
   if (document.getElementById('imie').value == '') error += "Podaj imię\n";
   if (document.getElementById('tel').value == '') error += "Podaj telefon\n";
   if (document.getElementById('meil').value == '') error += "Podaj adres e-mail\n";
   if (document.getElementById('tresc').value == '') error += "Podaj tresc reklamacji!\n";
   if (document.getElementById('WyrazamZgode').checked != 1) error += "Musisz wyrazić zgodę na przetwarzanie danych!";
   
   if (error != '')
   {
      alert (error);
      return false;
   }
   else
      return true;
}

function zglosblad()
{
   error = '';
   if (document.getElementById('tresc').value == '') error += "Podaj opis bledu\n";
   if (document.getElementById('lnk').value == '') error += "Podaj link do bledu\n";
   if (!ETest.test(document.getElementById('mejl').value)) error += "Podaj poprawny adres e-mail.\n";
   
   if (error != '')
   {
      alert (error);
      return false;
   }
   else
      return true;
}

function lewemenu(nr_id)
{
   if (document.getElementById(nr_id).style.display == 'none')
   {
      document.getElementById(nr_id).style.display = 'block';
      document.getElementById(nr_id+'i').src = 'pics/minus.gif';
   }
   else
   {
      document.getElementById(nr_id).style.display = 'none';
      document.getElementById(nr_id+'i').src = 'pics/plus.gif';
   }
}

function polaczenie_szyfrowane()
{
	if (location.protocol=="http:") {
  		location.href = location.href.replace(/^http:/, "https:")
	}
}

function polaczenie_nieszyfrowane()
{
	if (location.protocol=="https:") {
  		location.href = location.href.replace(/^https:/, "http:")
	}
}

function czyregulamin()
{
if (document.getElementById('regulamin').checked == 1)
   { return true; } 
   else {    
     alert ("Aby złożyć zamówienie trzeba zaakceptować regulamin");
     return false; 
   }
}

function pokaz_regulamin(url, width, height)
{
   window.open(url,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function szczegoly(plik, typ, Id, proj)
{
   window.open('popup/'+plik+'.php?p='+Id, typ+' do projektu '+proj, 'width=620,height=400,'+
               'resizable=no,scrollbars=yes,menubar=yo,personalbar=no,toolbar=no,status=no');
}

function wstecz()
{
  history.back();
}

function promesa(url, width, height, nazwa)
{
   window.open(url + '?nazwa=' + nazwa ,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function charakterystyka(url, width, height, nazwa)
{
   window.open(url + '?nazwa=' + nazwa ,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function rodzinanaswoim()
{
   window.open('popup/rodzinanaswoim.php',
   "displayWindow", 'width=620,height=400,' + 'resizable=no,scrollbars=yes,menubar=yo,personalbar=no,toolbar=no,status=no');
}

function dodajdoulubionych() {

    var tytul = 'Domfort - projekty domów';
    var adres = 'http://www.domfort.eu';

    //FireFox
    if (window.sidebar) {

        window.sidebar.addPanel(tytul, adres, "");

    //IE
    } else if (window.external) {

        window.external.AddFavorite(adres, tytul);

    }
}

function main_szukaj_func(co,gdzie) {
var pokaz = 'WYSZUKIWARKA PROJEKTÓW - rozwiń';
var ukryj = 'WYSZUKIWARKA PROJEKTÓW - ukryj';
	if(document.getElementById(gdzie).innerHTML == pokaz) { 
		document.getElementById(co).style.display = "block";
		document.getElementById(gdzie).innerHTML = ukryj;
	} else {
		if(document.getElementById(gdzie).innerHTML == ukryj) { 
			document.getElementById(co).style.display = "none";
			document.getElementById(gdzie).innerHTML = pokaz;
		}
	}
}

function promocja_func(co,gdzie) {
var pokaz = 'pokaż';
var ukryj = 'ukryj';
	if(document.getElementById(gdzie).innerHTML == pokaz) { 
		document.getElementById(co).style.display = "block";
		document.getElementById(gdzie).innerHTML = ukryj;
	} else {
		if(document.getElementById(gdzie).innerHTML == ukryj) { 
			document.getElementById(co).style.display = "none";
			document.getElementById(gdzie).innerHTML = pokaz;
		}
	}
}

function zgoda_func(co,gdzie) {
var pokaz = 'pokaż';
var ukryj = 'ukryj';
	if(document.getElementById(gdzie).innerHTML == pokaz) {
		document.getElementById(co).style.display = "block";
		document.getElementById(gdzie).innerHTML = ukryj;
	} else {
		if(document.getElementById(gdzie).innerHTML == ukryj) {
			document.getElementById(co).style.display = "none";
			document.getElementById(gdzie).innerHTML = pokaz;
		}
	}
}
