function KasaUpdateKoszyk(param1,param2)  // aktualizacja koszyka klienta w kasie
{
var req = mint.Request();
req.AddParam("akcja", param1);
req.AddParam("products_id", param2);

req.OnSuccess = function() {
      $("kasa_koszyk").innerHTML = this.responseText;
      MaszWKoszyku();
  }
req.SendForm('koszyk');
}

function MaszWKoszyku()  // aktualizacja paska klienta z ilością i wartością produktów w koszyku
{
var req = mint.Request();
req.Send('masz_w_koszyku.php',"masz_w_koszyku"); 	
}

function KasaFormaDoreczenia(forma_doreczenia)
{
$("koszyk_forma_doreczenia").value=forma_doreczenia;
KasaUpdateKoszyk('forma_doreczenia',''); 
}

function KasaDokumentZakupu(dokument)
{
$("koszyk_dokument_zakupu").value=dokument;
KasaUpdateKoszyk('dokument_zakupu',''); 
}

function KasaSposobPlatnosci(sposob_platnosci,div)
{
KasaUpdateKoszyk('dokument_zakupu',''); 

if (div=='')
  {
  $('raty').style.display="none";
  $('karta').style.display="none";
  }
else if (div=='raty')
  {
  $('raty').style.display="block";
  $('karta').style.display="none";
  }
else if (div=='karta')
  {
  $('karta').style.display="block";
  $('raty').style.display="none";
  }

$('koszyk_sposob_platnosci').value=sposob_platnosci; 

KasaUpdateKoszyk('sposob_platnosci',''); 
}
	



function wndSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function show(pwidth,pheight)
  {
/*
var sel=document.getElementsByTagName("select");

for (var i=0; i< sel.length; i++) { 
	  sel[i].style.display ="none";
	 } 
*/
  if ( $("b_srodek") ) $("b_srodek").style.display="none";  // reklama włączenie wyłaczenie
  if ( $("reklama_bok") ) $("reklama_bok").style.display="none";  // reklama włączenie wyłaczenie

  if ( $("mpopup") ) $("mpopup").style.display="none";  // mpopup włączenie wyłaczenie  

  $("sh_popup").style.display="block";
  $("sh_popup").style.width=pwidth+"px";
  $("sh_popup").style.height=pheight+"px";
  var scrl=getScrollXY();
  var wSize=wndSize();
  $("sh_popup").style.left=Math.round(scrl[0]+(wSize[0]-pwidth)/2)+"px";
  $("sh_popup").style.top=Math.round(scrl[1]+(wSize[1]-pheight)/2)+"px";
  
  }

function sh_popup(strona,pwidth,pheight)
  {
  var req = mint.Request();
  req.OnTimeout=function() {
	alert("Serwer ma problemy z odebraniem zapytania. Spróbuj za chwilę.");
	}

  req.OnLoading = function() {
      ShLoader();
  }	

  req.OnSuccess = function() {
	  ShLoaderClose();
	  show(pwidth,pheight);
      $("sh_popup").innerHTML = req.responseText;
 
   }
   
   req.Send(strona,"sh_popup");
  }

function ShLoader()
  {
  $("sh_loader").style.display="block";
  var scrl=getScrollXY();
  var wSize=wndSize();
  $("sh_loader").style.left=Math.round(scrl[0]+(wSize[0]-200)/2)+"px";
  $("sh_loader").style.top=Math.round(scrl[1]+(wSize[1]-30)/2)+"px";
  }

function ShLoaderClose()
  {
  $("sh_loader").style.display="none";
  }

function sh_close()
{
/*
var sel=document.getElementsByTagName("select");

for (var i=0; i< sel.length; i++) { 
	  sel[i].style.display="inline";
	 } */

if ( $("b_srodek") ) $("b_srodek").style.display="block";  // reklama włączenie wyłaczenie
if ( $("reklama_bok") ) $("reklama_bok").style.display="block";  // reklama włączenie wyłaczenie	  
pasek_klienta();
MaszWKoszyku();
$("sh_popup").style.display="none";
ShLoaderClose();
}



function pasek_klienta()
  {
  var req = mint.Request();
  req.Send('pasek_klienta.php',"pasek_klienta"); 	
  }

function porownywarka()
{
var req = mint.Request();
req.Send('produkty_w_porownywarce.php',"w_porownywarce"); 	
}



function sprawdz_ilosc_sztuk_w_koszyku()
{
if ( $('k_ile_produktow').value<=0 ) $('wyslij').disabled=true;

var req2= mint.Request();
req2.Send('pasek_klienta.php',"pasek_klienta");

if ( $('wartosc_zamowienia').value<100 ) $('sposob_platnosci3').disabled=true;
else $('sposob_platnosci3').disabled=false;

}

function wysun(id)
{
document.getElementById(id).style.display = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
}



function przepisz(pole)
{
pola = { "customers_lastname" : "delivery_lastname", "customers_firstname" : "delivery_firstname", "entry_street_address" : "delivery_street_address", "entry_city" : "delivery_city", "customers_telephone" : "delivery_telephone", "entry_postcode1" : "delivery_postcode1", "entry_postcode2" : "delivery_postcode2" };

for (key in pola)
  if (pole == key) $(pola[key]).value=$(key).value;

valid_adres();
}

function valid_osoba()
  {
  valid_form = true;
  pola = new Array("entry_postcode1", "entry_postcode2", "entry_city", "customers_telephone","entry_street_address","customers_firstname", "customers_lastname", "customers_email_address");
  nazwa= new Array("Kod", "Kod", "Miasto", "Telefon", "Ulica i numer", "Imie", "Nazwisko", "Adres e-mail");
  sprawdz = new Array("is_numeric", "is_numeric", "is_null","is_null","is_null","is_null","is_null","is_null");
  wynik = new Array("ok","ok","ok","ok","ok","ok","ok","ok");

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]=="ok" )
      wynik[i]=is_null(pola[i], nazwa[i]);

  if (wynik[0]=="ok") wynik[0]=length(pola[0], nazwa[0], 2);
  if (wynik[1]=="ok") wynik[1]=length(pola[1], nazwa[1], 3);
  
  for (var i=0;i<pola.length;i++)
    if ( wynik[i]=="ok" )
      {
      if (sprawdz[i]=="is_alpha") wynik[i]=is_alpha(pola[i], nazwa[i]);
      else if (sprawdz[i]=="is_numeric") wynik[i]=is_numeric(pola[i], nazwa[i]);
      }

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]!= "ok")
      {
      valid_form = false;
      $("err_" + pola[i] ).innerHTML = wynik[i];
      $( pola[i] ).style.backgroundColor="#FFDFDF";
      }
    else
      {
      $("err_" + pola[i] ).innerHTML = '';
      $( pola[i] ).style.backgroundColor="white";
      }
      

  }
function valid_adres()
  {
  pola = new Array("delivery_postcode1", "delivery_postcode2", "delivery_firstname","delivery_lastname","delivery_street_address","delivery_city","delivery_telephone");
  nazwa= new Array("Kod", "Kod", "Imię", "Nazwisko", "Ulica i numer", "Miasto", "Telefon");
  sprawdz = new Array("is_numeric", "is_numeric", "is_null","is_null","is_null","is_null","is_null");
  wynik = new Array("ok","ok","ok","ok","ok","ok","ok");

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]=="ok" )
      wynik[i]=is_null(pola[i], nazwa[i]);

  if (wynik[0]=="ok") wynik[0]=length(pola[0], nazwa[0], 2);
  if (wynik[1]=="ok") wynik[1]=length(pola[1], nazwa[1], 3);
  
  for (var i=0;i<pola.length;i++)
    if ( wynik[i]=="ok" )
      {
      if (sprawdz[i]=="is_alpha") wynik[i]=is_alpha(pola[i], nazwa[i]);
      else if (sprawdz[i]=="is_numeric") wynik[i]=is_numeric(pola[i], nazwa[i]);
      }

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]!= "ok")
      {
      $("err_" + pola[i] ).innerHTML = wynik[i];
      $( pola[i] ).style.backgroundColor="#FFDFDF";
      }
    else
      {
      $("err_" + pola[i] ).innerHTML = '';
      $( pola[i] ).style.backgroundColor="white";
      }
  }



function valid_faktura(rodzaj)
  {
  if (rodzaj=='imienna')
    {
    pola = new Array("billing_postcode1", "billing_postcode2", "billing_name", "billing_street_address", "billing_city");
    nazwa= new Array("Kod", "Kod", "Imię Nazwisko", "Ulica i numer", "Miasto");
    sprawdz = new Array("is_numeric", "is_numeric", "is_null", "is_null", "is_null");
    wynik = new Array("ok", "ok", "ok", "ok", "ok");
    }
  else if (rodzaj=='vat')
    {
    pola = new Array("billing_postcode1", "billing_postcode2", "billing_name", "billing_street_address", "billing_city", "billing_nip");
    nazwa= new Array("Kod", "Kod", "Imię Nazwisko", "Ulica i numer", "Miasto", "NIP");
    sprawdz = new Array("is_numeric", "is_numeric", "is_null", "is_null", "is_null", "is_null");
    wynik = new Array("ok", "ok", "ok", "ok", "ok", "ok");
    }

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]=="ok" )
      wynik[i]=is_null(pola[i], nazwa[i]);

  if (wynik[0]=="ok") wynik[0]=length(pola[0], nazwa[0], 2);
  if (wynik[1]=="ok") wynik[1]=length(pola[1], nazwa[1], 3);

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]=="ok" )
      {
      if (sprawdz[i]=="is_alpha") wynik[i]=is_alpha(pola[i], nazwa[i]);
      else if (sprawdz[i]=="is_numeric") wynik[i]=is_numeric(pola[i], nazwa[i]);
      }

  for (var i=0;i<pola.length;i++)
    if ( wynik[i]!= "ok")
      {
      $("err_" + pola[i] ).innerHTML = wynik[i];
      $( pola[i] ).style.backgroundColor="#FFDFDF";
      }
    else
      {
      $("err_" + pola[i] ).innerHTML = '';
      $( pola[i] ).style.backgroundColor="white";
      }
  }
  
  
function is_alpha(id,nazwa)
  {
  var alphaExp = /^[a-zA-Z]+$/;
   if ( $(id).value.match(alphaExp) )
     return "ok";
   else
     return " pole <b>"+nazwa+"</b> może zawierać tylko litery";
  }
  
function is_numeric(id,nazwa)
  {
  var alphaExp = /^[0-9\s-]+$/;
   if ( $(id).value.match(alphaExp) )
     return "ok";
   else
     return " pole <b>"+nazwa+"</b> może zawierać tylko cyfry";
  }

function is_null(id,nazwa)
  {
  if ($(id).value.length == 0 )
     return " pole <b>" + nazwa + "</b> nie może być puste";
  else
     return "ok";
  }

function length(id,nazwa,dlg)
  {
  if ($(id).value.length != dlg )
     return " pole <b>" + nazwa + "</b> - zła ilość znaków ";
  else
     return "ok";
  }
  


function wyswietl(T,t){
	 $(T).style.display=t?'block':'none';
	}

function show_div(style)
{
$("raty").style.display = style;
}

