// pokazywanie / ukrywanie dodatkowych pol formularza
function zmienForme(pForma)
{
  var obiekt;
  var i = 1;

  while (obiekt = document.getElementById('fir_0' + i))
  {
    if (pForma == 0)
    {
      obiekt.style.display = "none";
    }
      else
    {
      obiekt.style.display = "block";
    }

    i++;
  }

  if (pForma == 0) {
    document.forms['zamowienie'].pesel.disabled = false;
    document.forms['zamowienie'].pesel.style.background = '#ffffff';
    document.forms['zamowienie'].d_seria.disabled = false;
    document.forms['zamowienie'].d_seria.style.background = '#ffffff';
    document.forms['zamowienie'].d_numer.disabled = false;
    document.forms['zamowienie'].d_numer.style.background = '#ffffff';
  } else {
    document.forms['zamowienie'].pesel.disabled = true;
    document.forms['zamowienie'].pesel.style.background = '#eeeeee';
    document.forms['zamowienie'].d_seria.disabled = true;
    document.forms['zamowienie'].d_seria.style.background = '#eeeeee';
    document.forms['zamowienie'].d_numer.disabled = true;
    document.forms['zamowienie'].d_numer.style.background = '#eeeeee';
  }
}
// / pokazywanie / ukrywanie dodatkowych pol formularza



// resetowanie stylow elementow formularza
function styleReset(pForm) {
  var i = 0;

  for (i = 0; i < document.forms[pForm].elements.length; i++) {
    document.forms[pForm].elements[i].style.background = '#ffffff';
    document.forms[pForm].elements[i].style.color = '#49535c';
    document.forms[pForm].elements[i].style.border = '#cfcfcf 1px solid';
  }
} // / resetowanie stylow elementow formularza



// ustawianie stylow dla blednego elementu formularza
function styleError(pElement) {
  pElement.style.background = '#ff6b0b';
  pElement.style.color = '#ffffff';
  pElement.style.border = '#999999 1px solid';
} // / ustawianie stylow dla blednego elementu formularza



// sprawdzanie formularza zamowienia
function checkOrderForm(pForm, pRules) {
  var form = document.forms[pForm];
  var msg = '';
  var val = '';
  var patt1;
  var patt2;

  styleReset(pForm);

  if (form[pRules].checked) { // zapoznano sie z regulaminem
    // sprawdzenie czy pola nie sa puste - osoba fizyczna lub firma [0]
    
    if (form.forma[0].checked) { // osoba fizyczna
      document.forms['zamowienie'].pesel.disabled = false;
      document.forms['zamowienie'].pesel.style.background = '#ffffff';
      document.forms['zamowienie'].d_seria.disabled = false;
      document.forms['zamowienie'].d_seria.style.background = '#ffffff';
      document.forms['zamowienie'].d_numer.disabled = false;
      document.forms['zamowienie'].d_numer.style.background = '#ffffff';

      // pesel
      val = form.pesel.value;
      
      // imie
    
    if (form.imie.value == '') { msg += '- brak imienia\n'; styleError(form.imie); }
    //

    // nazwisko
    if (form.nazwisko.value == '') { msg += '- brak nazwiska\n'; styleError(form.nazwisko); }
    //
    
      
      if (val == '') {
        msg += '- brak numeru PESEL\n';
        styleError(form.pesel);
      } else {
        patt1 = /^[0-9]{11}$/;
        
        if (val.match(patt1) == null) { msg += '- nieprawidłowy format numeru PESEL\n'; styleError(form.pesel); }
      }
      //

      // seria dowodu
      if (form.d_seria.value == '') { msg += '- brak serii dowodu osobistego\n'; styleError(form.d_seria); }
      //

      // numer dowodu
      val = form.d_numer.value;

      if (val == '') {
        msg += '- brak numeru dowodu osobistego\n';
        styleError(form.d_numer);
      } else {
        patt1 = /^[0-9]*$/;
        
        if (val.match(patt1) == null) { msg += '- numer dowodu może zawierać wyłącznie cyfry\n'; styleError(form.d_numer); }
      }
      //
    } else { // firma
      document.forms['zamowienie'].pesel.disabled = true;
      document.forms['zamowienie'].pesel.style.background = '#eeeeee';
      document.forms['zamowienie'].d_seria.disabled = true;
      document.forms['zamowienie'].d_seria.style.background = '#eeeeee';
      document.forms['zamowienie'].d_numer.disabled = true;
      document.forms['zamowienie'].d_numer.style.background = '#eeeeee';

      // nazwa
      if (form.firma.value == '') { msg += '- brak nazwy firmy\n'; styleError(form.firma); }
      //
 /*
      // regon
      val = form.regon.value;

      if (val == '') {
        msg += '- brak numeru REGON\n';
        styleError(form.regon);
      } else {
        patt1 = /^[0-9]{9}$/;
        
        if (val.match(patt1) == null) { msg += '- nieprawidłowy format numeru REGON\n'; styleError(form.regon); }
      }
      //

      // nip
      val = form.nip.value;

      if (val == '') {
        msg += '- brak numeru NIP\n';
        styleError(form.nip);
      } else {
        patt1 = /^[0-9]{10}$/;
        patt2 = /^[A-Z]{2,3}[0-9]{10}$/;

        if ((val.match(patt1) == null) && (val.match(patt2) == null)) { msg += '- nieprawidłowy format numeru NIP\n'; styleError(form.nip); }
      }
      //
*/
      // kontakt techniczny - imie
      if (form.kt_imie.value == '') { msg += '- brak imienia kontaktu technicznego\n'; styleError(form.kt_imie); }
      //

      // kontakt techniczny - nazwisko
      if (form.kt_nazwisko.value == '') { msg += '- brak nazwiska kontaktu technicznego\n'; styleError(form.kt_nazwisko); }
      //
    }
    // / [0]

    // sprawdzenie czy pola nie sa puste - osoba fizyczna i firma [1]
    // ulica
    if (form.ul.value == '') { msg += '- brak ulicy\n'; styleError(form.ul); }
    //

    // numer domu
    if (form.nr.value == '') { msg += '- brak numeru domu / mieszkania\n'; styleError(form.nr); }
    //

    // miejscowosc
    if (form.miejscowosc.value == '') { msg += '- brak nazwy miejscowości\n'; styleError(form.miejscowosc); }
    //

    // kod pocztowy
    if ((form.kodpocz1.value == '') || (form.kodpocz2.value == '')) {
      msg += '- brak kodu pocztowego\n';
      styleError(form.kodpocz1);
      styleError(form.kodpocz2);
    } else {
      
      patt1 = /^[0-9]{2}$/;
      patt2 = /^[0-9]{3}$/;

      if ((form.kodpocz1.value.match(patt1) == null) || (form.kodpocz2.value.match(patt2) == null)) {
        msg += '- nieprawidłowy format kodu pocztowego\n';
        styleError(form.kodpocz1);
        styleError(form.kodpocz2);
      }
    }
    //

    // telefon
    val = form.telefon.value;

    if (val == '') {
      msg += '- brak numeru telefonu\n';
      styleError(form.telefon);
    } else {
      patt1 = /^[0-9]*$/;
        
      if (val.match(patt1) == null) {
        msg += '- numer telefonu może zawierać wyłącznie cyfry\n';
        styleError(form.telefon);
      }
    }
    //
    // / [1]

    // pola opcjonalne - sprawdzenie poprawnosci wprowadzonych danych [2]
    // fax
    val = form.fax.value;

    if (val != '') {
      patt1 = /^[0-9]*$/;

      if (val.match(patt1) == null) { msg += '- numer faxu może zawierać wyłącznie cyfry\n'; styleError(form.fax); }
    }
    //

    // email
    val = form.email.value;

    if (val != '') {
      var i = val.indexOf('@');
      var j = val.length - 1;
      var k = 0;
      var res = true;

      if (val.charAt(j) == '.')  res = false;

      while ((j > 0) && (k == 0))
      {
        if (val.charAt(j) == '.')  k = j;
        j--;
      }

      if ((i < 1) || (k < i)) res = false;

      if (!res) { msg += '- niepoprawny format adresu email\n'; styleError(form.email); }
    } else {
      msg += '- brak adresu email\n';
      styleError(form.email);
    }
    //
    // / [2]

    // wybor pakietu
    if (form.uid.value == '0') { msg += '- wybierz pakiet\n'; styleError(form.uid); }
    //

    if (msg != '') alert('Popraw następujące błędy:\n' + msg);
      else {
        form.pakiet.value = form.uid.options[form.uid.selectedIndex].text;
        document.forms[pForm].submit();
      }
  } else { // nie zapoznano sie z regulaminem
    alert('Przed realizacją zamówienia niezbędne jest oświadczenie o zapoznaniu się z regulaminem.');
  }
}
// / sprawdzanie formularza zamowienia



// dymki
/*
Graculini's Popup Engine - GPE v1.0
CopyrightŠ Gracjan Lech 2003.
Contact me: gracjan.lech@poczta.fm
This notice must remain untouched at all times.
*/

var cienX = 1;
var cienY = 1;
var cienKolor = '#aaaaaa';

function dostosuj(pX, pY, pKolor)
{
  var z = document.getElementById('info').scrollHeight;
  var tpX = 0;
  var tpY = 0;
  var sX = 0;
  pX++; pY++;
  
  //alert(navigator.userAgent + ', ' + navigator.userAgent.indexOf('IE'));
  
  if ((popupBorderWidth == 0) && (navigator.userAgent.indexOf('IE') > -1)) pX++;
  if ((textPadding > 0) && (navigator.userAgent.indexOf('IE') < 0))
  {
    pX -= 1;
    pY -= 1;
    tpX = textPadding + 1;
    tpY = textPadding - 1;
    sX = -1;
  }
  //pX += 2*textPadding;
  //pY += 2*textPadding;
  

  document.getElementById('main').style.height = z + pY + popupBorderWidth;
  document.getElementById('main').style.width = popupWidth + pX - 1;

  document.getElementById('info').style.width = popupWidth - (popupBorderWidth - 1);

  document.getElementById('shadow').style.height = z + pY;
  document.getElementById('shadow').style.top = popupBorderWidth + pY - 2;
  document.getElementById('shadow').style.left = popupBorderWidth + pX - 2;
  document.getElementById('shadow').style.width = popupWidth + 2*tpX + 2 + sX;
  document.getElementById('shadow').style.backgroundColor = pKolor;
}

function displayConfig() {
 //KONFIGURACJA START
 //Odstęp popup'a od kursora w poziomie
 if ((popupOffsetX=getValue("popupOffsetX"))==NA)
  popupOffsetX=15
 //Odstęp popup'a od kursora w pionie
 if ((popupOffsetY=getValue("popupOffsetY"))==NA)
  popupOffsetY=20
 //Położenie popup'a względem myszki
 if ((popupAlign=getValue("popupAlign"))==NA)
  popupAlign="right" //Inne opcje - left, center
 //Długość popup'a
 if ((popupWidth=getValue("popupWidth"))==NA)
  popupWidth=155
 //Szerokość obramowania całego popup'a
 if ((popupBorderWidth=getValue("popupBorderWidth"))==NA)
  popupBorderWidth=1
 //Kolor obramowania popup'a
 if ((popupBorderColor=getValue("popupBorderColor"))==NA)
  popupBorderColor="#777714"
 //Styl obramowania popup'a (dotted, double...)
 if ((popupBorderStyle=getValue("popupBorderStyle"))==NA)
  popupBorderStyle="solid"
 //Domyślna przeĽroczystość popup'a
 if ((popupOpacity=getValue("popupOpacity"))==NA)
  popupOpacity=97
 //Kolor czcionki nagłówka
 if ((captionColor=getValue("captionColor"))==NA)
  captionColor="#ffffff"
 //Styl czcionki nagłówka
 if ((captionFontStyle=getValue("captionFontStyle"))==NA)
  captionFontStyle="normal"
 //Pogrubienie czcionki nagłówka
 if ((captionFontWeight=getValue("captionFontWeight"))==NA)
  captionFontWeight="bold"
 //Wielkość czcionki nagłówka
 if ((captionFontSize=getValue("captionFontSize"))==NA)
  captionFontSize="9px"
 //Czcionka nagłówka
 if ((captionFontFamily=getValue("captionFontFamily"))==NA)
  captionFontFamily="Verdana, sans-serif"
 //Wypełnienie ogólne
 if ((captionPadding=getValue("captionPadding"))==NA)
  captionPadding="0px";
 //Kolor tła nagłówka
 if ((captionBackgroundColor=getValue("captionBackgroundColor"))==NA)
  captionBackgroundColor=popupBorderColor
 //Tło nagłówka
 if ((captionBackgroundImage=getValue("captionBackgroundImage"))==NA)
  captionBackgroundImage=""
 //Dodatki do tła
 if ((captionBackgroundImageProperties=getValue("captionBackgroundImageProperties"))==NA)
  captionBackgroundImageProperties=""
 //Kolor czcionki tekstu
 if ((textColor=getValue("textColor"))==NA)
  textColor="#ffffff"
 //Styl czcionki tekstu
 if ((textFontStyle=getValue("textFontStyle"))==NA)
  textFontStyle="normal"
 //Pogrubienie czcionki tekstu
 if ((textFontWeight=getValue("textFontWeight"))==NA)
  textFontWeight="normal"
 //Wielkość czcionki tekstu
 if ((textFontSize=getValue("textFontSize"))==NA)
  textFontSize="7pt"
 //Czcionka tekstu
 if ((textFontFamily=getValue("textFontFamily"))==NA)
  textFontFamily="Tahoma"
 //Wypełnienie ogólne
 if ((textPadding=getValue("textPadding"))==NA)
  textPadding=5;
 //Kolor tła tekstu
 if ((textBackgroundColor=getValue("textBackgroundColor"))==NA)
  textBackgroundColor="#ff7714"
 //Tło tekstu
 if ((textBackgroundImage=getValue("textBackgroundImage"))==NA)
  textBackgroundImage=""
 //Dodatki do tła 
 if ((textBackgroundImageProperties=getValue("textBackgroundImageProperties"))==NA)
  textBackgroundImageProperties=""
 //fadeIn
 if ((fadeIn=params.indexOf("fadeIn"))!=-1)
  fadeIn=true
 //Domyślny czas fadeIn
 if (fadeIn && ((fadeInTime=getValue("fadeInTime"))==NA))
  fadeInTime=1
 //fadeOut
 if ((fadeOut=params.indexOf("fadeOut"))!=-1)
  fadeOut=true
 //Domyślny czas fadeOut
 if (fadeOut && ((fadeOutTime=getValue("fadeOutTime"))==NA))
  fadeOutTime=1
 
 //DODATKOWE SZATY
 
 layout[1]="textBackgroundColor: #ffffe1; popupBorderColor: #000000; textFontFamily: verdana; textFontSize: 11px;"
 layout[2]="textFontStyle: italic;"
 
 //KONFIGURACJA KONIEC  
}

document.write("<div id=\"popupDiv\" style=\"position: absolute; display: none; z-index: 1000; filter: alpha(opacity=100); -moz-opacity: 1;\">GPE v1.1 - popup engine</div>")
popup=document.getElementById("popupDiv")
OP=NS=IE=false
if (navigator.userAgent.indexOf("Opera")!=-1) OP=true
else if (navigator.appName=="Netscape") NS=true
else if (navigator.appName=="Microsoft Internet Explorer") IE=true

function gpe(arguments) {
 fadingIn=false
 fadeOut=false
 params=arguments
 layout=new Array()
 captionClass=getValue("captionClass")
 caption=getValue("caption")
 textClass=getValue("textClass")
 text=getValue("text")
 popupLayout=getValue("popupLayout")
 if (popupLayout!=null) params+=grabLay()
 NA=null
 displayConfig()
 if (popupBorderColor==NA && captionBackgroundColor!=NA) popupBorderColor=captionBackgroundColor
 po=eval(popupOpacity)
 if (NS) NSpo=(po/100)
 if (textBackgroundImage!=null) textBackgroundImage="url('"+textBackgroundImage+"') "+textBackgroundImageProperties+""
 if (captionBackgroundImage!=null) captionBackgroundImage="url('"+captionBackgroundImage+"') "+captionBackgroundImageProperties+""


  //Przesuniecie cienia w prawo
  var shadowWidth = 3;
  // Przesuniecie cienia w dol
  var shadowHeight = 3;
  
  var popupWidthPadding = "";
  var tmp = 0;
  var l1 = 0;
  var mainWidth = 0;
  
  //mainWidth=popupWidth+shadowWidth+parseInt(textPadding.substr(0, textPadding.length - 2));
  mainWidth=popupWidth+shadowWidth+textPadding;

  l1 = textPadding;
  tmp = popupWidth + 2*l1;
  popupWidthPadding = tmp;
  
 popupContent="<div id = \"main\" style = \"width: " + mainWidth + "px; height: 0px; border: 0px;\">"
 popupContent+="<div id = \"info\" style=\"z-index: 101; position: absolute; border: " + popupBorderColor + " " + popupBorderWidth + "px " + popupBorderStyle + ";"
 popupContent+="color: " + textColor + "; font-family: " + textFontFamily + "; font-style: " + textFontStyle
 popupContent+="font-weight: " + textFontWeight + "; font-size: " + textFontSize
 popupContent+="; padding: " + textPadding + "px; width: "+popupWidth+"px; border: "+popupBorderWidth
 popupContent+=" "+popupBorderStyle+" "+popupBorderColor+"; background: " + textBackgroundColor + ";\">"
 popupContent+=text
 popupContent+="</div>"
 popupContent+="<div id = \"shadow\" style = \"z-index: 100; position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; background: #0000ff;\">"
 popupContent+="</div>"

 if (NS) {
  content=document.createRange();
  content.setStartBefore(popup);
  content=content.createContextualFragment(popupContent);
  with (popup) {
   if (hasChildNodes()) removeChild(lastChild)
   appendChild(content)
  }
 }
 else popup.innerHTML=popupContent
 pO(po)
 if (IE) gpePos()
 document.onmousemove=function gpePos(evt) {
  if (NS) {
   coordX=evt.pageX
   coordY=evt.pageY
   winWidth=innerWidth
  }
  else {
   coordX=event.clientX+document.body.scrollLeft
   coordY=event.clientY+document.body.scrollTop
   winWidth=document.body.clientWidth
  }
  switch (popupAlign) {
   case "left" :
    if (coordX-popupWidth-popupOffsetX<0) coordX=popupWidth+popupOffsetX
     coordX-=popupWidth+(popupOffsetX*2)
   break
   case "center" :
    if (coordX+popupWidth/2>winWidth) {coordX=winWidth-popupWidth/2; popupOffsetX=0}
    if (coordX-popupWidth/2<0) {coordX=popupWidth/2; popupOffsetX=0}
    coordX-=popupWidth/2+popupOffsetX
   break
   case "right" :
    if (coordX+popupWidth+popupOffsetX>winWidth) coordX=winWidth-popupWidth-popupOffsetX
  }
  popup.style.left=coordX+popupOffsetX
  popup.style.top=coordY+popupOffsetY
 }
 popup.style.display="block"
 if (fadeIn==true) {
  pO(0)
  fade(1)
 }
 popup.style.display="block"
 document.onmouseout=function() {
  if (fadeOut==true) {
   if (fadeIn) fadeIn=false
   else pO(po)
   fade(2)
  }
  else popup.style.display="none"
 }
 
 dostosuj(cienX, cienY, cienKolor);
}
function getValue(keyWord) {
 with (params) {
  if (indexOf(keyWord+":")==-1) return
  keyInd=lastIndexOf(keyWord+":")
  value=substring(keyInd+(keyWord.length+1),indexOf(";",keyInd))
 }
 while (value.indexOf("|:|")!=-1) {
  with (value) {
   value=substring(0,indexOf("|:|"))+";"+substring(indexOf("|:|")+3)
  }
 }
 while (value.indexOf(" ")!=-1 && keyWord!="text" && keyWord!="caption") {
  with (value) {
   value=substring(0,indexOf(" "))+substring(indexOf(" ")+1)
  }
 }
 if (keyWord=="popupOffsetX" || keyWord=="popupOffsetY" || keyWord=="popupWidth") {
  value=eval(value)
 }
 return value
}
function grabLay() {
 layParam=displayConfig+""
 with (layParam) {
  layParam=substring(indexOf("layout["+popupLayout+"]"),indexOf(";\"",indexOf("layout["+popupLayout+"]"))+1)
 }
 return layParam;
}
function fade(num) {
 if (num==1 && fadeIn==true) {
  if (pO()!=po) {
   pO(2,"+")
   fadingIn=setTimeout("fade(1)",fadeInTime)
  }
  else fadeIn=false
 }
 if (num==2 && fadeOut==true) {
  if (pO()!=0) {
   pO(2,"-")
   fadingOut=setTimeout("fade(2)",fadeOutTime)
  }
  else {
   fadeOut=false
   if (NS==false && IE==false) popup.style.display="none"
  }
 }
}
function pO(oL,op) {
 if (IE) {
  with (popup.filters.alpha) {
   if (oL==NA) return opacity
   if (op==NA) opacity=oL
   if (op=="+") {
    if (opacity>=po) opacity=po
	else opacity+=oL
   }
   if (op=="-") opacity-=oL
  }
 }
 else if (NS) {
  with (popup.style) {
   if (oL==NA) return MozOpacity
   else oL=(oL/100)
   if (op==NA) MozOpacity=oL
   if (op=="+") {
    if (MozOpacity>=NSpo) MozOpacity=NSpo
    else MozOpacity=parseFloat(MozOpacity)+oL
   }
   if (op=="-") MozOpacity=parseFloat(MozOpacity)-oL
  }
 }
 else return false
}
// / dymki
