function dodajdoulubionych()
{
bookmarkurl="http://www.aptekadobrychcen.pl/"
bookmarktitle="Platforma ADC"
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function isInt (str)
{
	var i = parseInt (str);

	if (isNaN (i))
		return false;

	i = i . toString ();
	if (i != str)
		return false;

	return true;
}

function f_test_liczby_rzeczywistej(pole){
  var v_liczba=pole.value;
  if (isNaN(v_liczba) || (v_liczba=='')){
    alert('Proszę wprowadzić wyłącznie liczby!');
    pole.value='0';
  }
}

function f_test_liczby(pole){
  if (!isInt(pole.value)){
  	 alert('Proszę wprowadzić wyłącznie liczby całkowite!');
  	 pole.value='1';
  }
}

function f_puste_pola(formularz)
{

  for (i = 0; i < formularz.length; i++)
  {

    var pole = formularz.elements[i];
  
    if ((pole.type == 'text' || pole.type == 'textarea') && pole.value == '')
    {
      alert('Proszę wypełnić wszystkie pola!');
      return false;
    }
  }
  return true;
}

function f_rejestruj_mg(formularz)
{

  for (i = 0; i < formularz.length; i++)
  {
  	 
    var pole = formularz.elements[i];
    if ((pole.type == 'text' || pole.type == 'textarea' || pole.type=='password') && pole.value == '')
    {
      alert('Proszę wypełnić wszystkie pola!');
      return false;
    }
  }
  if (formularz.elements[7].value!=formularz.elements[8].value){
  	alert('Hasło nie jest zgodne z jego potwierdzeniem');
   return false;
  }
  return true;
}

function f_dodaj_usr(formularz)
{

  for (i = 0; i < formularz.length; i++)
  {
  	 
    var pole = formularz.elements[i];
   // alert(i+pole.name);
    if ((pole.type == 'text' || pole.type == 'textarea' || pole.type=='password') && pole.value == '')
    {
      alert('Proszę wypełnić wszystkie pola!');
      return false;
    }
  }
  if (formularz.elements[7].value!=formularz.elements[8].value){
  	alert('Hasło nie jest zgodne z jego potwierdzeniem');
   return false;
  }
  if (ValidateForm_priv(formularz.elements[6])==false){
    return false;
  }
  return true;
}

function f_zapisz_us(formularz)
{
  for (i = 0; i < formularz.length; i++)
  {
  	 
   var pole = formularz.elements[i];
    //alert(i+pole.value);
    if (formularz.v_zmiana_hasla.checked==true){
      if ((pole.type == 'text' || pole.type == 'textarea' || pole.type == 'password') && pole.value == '')
     {
       alert('Proszę wypełnić wszystkie pola!');
       return false;
     }
    }else{
      if ((i!=7)&&(i!=9)){
        if ((pole.type == 'text' || pole.type == 'textarea') && pole.value == '')
        {
          alert('Proszę wypełnić wszystkie pola!');
          return false;
        }
     }
   }
  }
  if (formularz.v_zmiana_hasla.checked==true){
    if (formularz.elements[7].value!=formularz.elements[9].value){
  	  alert('Hasło nie jest zgodne z jego potwierdzeniem');
     return false;
    }
 }
 
  if (ValidateForm_priv(formularz.elements[6])==false){
    return false;
  }
 //return false;
 return true;
}



function f_zapisz_mg(formularz)
{

  for (i = 0; i < formularz.length; i++)
  {
  	 
    var pole = formularz.elements[i];
    //alert(i+pole.value);
    if (formularz.v_zmiana_hasla.checked==true){
      if ((pole.type == 'text' || pole.type == 'textarea' || pole.type == 'password') && pole.value == '')
      {
        alert('Proszę wypełnić wszystkie pola!');
        return false;
      }
    }else{
      if ((i!=7)&&(i!=9)){
        if ((pole.type == 'text' || pole.type == 'textarea') && pole.value == '')
        {
          alert('Proszę wypełnić wszystkie pola!');
          return false;
        }
      }
    }
  }
  
  if (formularz.v_zmiana_hasla.checked==true){
    if (formularz.elements[7].value!=formularz.elements[9].value){
  	  alert('Hasło nie jest zgodne z jego potwierdzeniem');
     return false;
    }
  }
  
  return true;
}


function f_zapisz_kontroler(formularz)
{

  for (i = 0; i < formularz.length; i++)
  {
  	 
    var pole = formularz.elements[i];
    //alert(i+pole.value);
    if (formularz.v_zmiana_hasla_k.checked==true){
      if ((pole.type == 'text' || pole.type == 'textarea' || pole.type == 'password') && pole.value == '')
      {
        alert('Proszę wypełnić wszystkie pola!');
        return false;
      }
    }else{
      if ((i!=7)&&(i!=9)){
        if ((pole.type == 'text' || pole.type == 'textarea') && pole.value == '')
        {
          alert('Proszę wypełnić wszystkie pola!');
          return false;
        }
      }
    }
  }
  
  if (formularz.v_zmiana_hasla_k.checked==true){
    if (formularz.elements[7].value!=formularz.elements[9].value){
  	  alert('Hasło nie jest zgodne z jego potwierdzeniem');
     return false;
    }
  }

  return true;
}

function f_zapisz_usr(formularz)
{

  for (i = 0; i < formularz.length; i++)
  {
  	 
    var pole = formularz.elements[i];
    alert(i+pole.value);
    if (formularz.v_zmiana_hasla.checked==true){
      if ((pole.type == 'text' || pole.type == 'textarea' || pole.type == 'password') && pole.value == '')
      {
        alert('Proszę wypełnić wszystkie pola!');
        return false;
      }
    }else{
      if ((i!=7)&&(i!=9)){
        if ((pole.type == 'text' || pole.type == 'textarea') && pole.value == '')
        {
          alert('Proszę wypełnić wszystkie pola!');
          return false;
        }
      }
    }
  }
  if (formularz.v_zmiana_hasla.checked==true){
    if (formularz.elements[7].value!=formularz.elements[9].value){
  	  alert('Hasło nie jest zgodne z jego potwierdzeniem');
     return false;
    }
  }

  return true;
}


function f_sprawdz_szukaj(formularz)
{

  if (formularz.v_szukaj.value==''){
  	alert('Proszę wprowadzić frazę w pole wyszukiwarki.');
  	return false;
 }else{  	
   if (formularz.v_polecenie.value=="produkty_wg_kategorii" && formularz.v_szukaj.value.length<3)
   {
     alert('Proszę wprowadzić przynajmniej 3 znaki.');
     return false;
   }else{
return true;
    }
 };
}


function f_sprawdz_liczbe(iv_liczba){
  if (isNaN(iv_liczba)){
    alert('Wpisana');
    return false;
  };
  return true; 		
}

function f_sprawdz_liczby(iv_formularz){
  var v_ok=true;
  var v_koncowka='';
  for (i = 0; i < iv_formularz.length; i++)
  {
    var pole = iv_formularz.elements[i];
    if (pole.type == 'text')
      {
      /*
      if (isNaN(pole.value)){
        v_koncowka=' nie jest liczbą.';
	     v_ok=false;
	   }
	   if (pole.value==''){
	     v_koncowka=' jest pustym ciągiem znaków.';
	     v_ok=false;
	   }*/
	   if (!isInt(pole.value)) {
	     v_koncowka=' nie jest liczbą całkowitą.';
	     v_ok=false;
	 	}    

    }
  }
  if (v_ok==false){
    alert("W jednym(lub wielu) polach wpisano wartość,która"+v_koncowka);
    return false;
  }else{

   return true;
  }
  
}

function f_sprawdz_sku(iv_formularz){
  var v_ok=true;
//  alert('aa');
  /*
  for (i = 0; i < iv_formularz.length; i++)
  {
    var pole = iv_formularz.elements[i];
    alert(i+':'+pole.value);
    if (pole.type == 'text')
      {
      if (isNaN(pole.value) || (pole.value=='')){
	    v_ok=false;
	   }
    }
  }
  if (v_ok==false){
    alert("W jednym(lub wielu) polach wpisano wartość,która nie jest liczbą (lub zostawiono puste pole)!");
    return false;
  }else{

   return true;
  }
  */
  
}

function f_alert(){
//  alert('hgjhgjhg');
  return false;
}



/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck_priv(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Błędny adres e-mail.");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Błędny adres e-mail.");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Błędny adres e-mail.");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Błędny adres e-mail.");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Błędny adres e-mail.");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Błędny adres e-mail.");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Błędny adres e-mail.");
		    return false;
		 }

 		 return true;	
	}

function ValidateForm_priv(emailID){
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Wprowadź adres e-mail");
		emailID.focus();
		return false;
	}
	if (echeck_priv(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }


function wysli_ten_formularz(zdarzenie){
//sprawdza kod wprowadzony w polu input 'kod_klienta'
//po nacisnieciu klawisza enter
zdarzenie = (zdarzenie)?zdarzenie:((window.event)?event:null);
  if (zdarzenie.keyCode==13) {
			   document.formularz_logowania.v_modul.value='mod_sesja';
	          document.formularz_logowania.v_polecenie.value='zaloguj';
	          document.formularz_logowania.submit();
			      }


}


function f_wstaw_dane_zamaw() {


if (document.prenumerata.v_typ_danych.checked==true){
document.getElementById('w_dane').value=document.getElementById('z_dane').value;
document.getElementById('w_nazwa').value=document.getElementById('z_nazwa').value;
document.getElementById('w_adres').value=document.getElementById('z_adres').value;                                                                    
document.getElementById('w_miasto').value=document.getElementById('z_miasto').value;     
document.getElementById('w_kod_pocztowy').value=document.getElementById('z_kod_pocztowy').value;                                                                  
document.prenumerata.v_typ_danych.checked=true;
}else{
document.getElementById('w_dane').value='';
document.getElementById('w_nazwa').value='';
document.getElementById('w_adres').value=''; 
document.getElementById('w_miasto').value=''; 
document.getElementById('w_kod_pocztowy').value=''; 
document.prenumerata.v_typ_danych.checked=false;
}

}

function f_inp_item(v_ilosc,v_ilosc_cena) {
document.getElementById('ile_egz_szt').value='0';
przelicz_zam(v_ilosc,v_ilosc_cena);
}

function przelicz_zam(v_ilosc,v_ilosc_cena) {

v_cena=document.getElementById('h_ile_egz_'+v_ilosc_cena).value;

v_vat=1.23; 
v_netto=   format(v_cena * v_ilosc,2);

v_brutto= format(v_netto*v_vat,2);
v_komunikat=v_netto + " netto, "+ v_brutto +" brutto";
document.getElementById('v_wart_fakt').innerHTML=v_komunikat;

}


function format(liczba, lmpp) {

  ile = ""+Math.round(liczba*Math.pow(10,lmpp))/Math.pow(10,lmpp);
  if (ile.indexOf(".")<0) ile+=".0";
  while ((ile.length-ile.indexOf(".")-1)<lmpp) ile = ile+"0";
  return ile;

}

function f_spr_format_admin(obiekt) {
regexp = eval("/,/g");
v_liczba=obiekt.value.replace(regexp,'.'); 

if (!v_liczba.match(/^-?\d\d*(.\d)?\d*$/)) {
  obiekt.value='0.00';
  v_liczba=-1;
  alert('Wprowadź prawidłową wartość');
}else{
  obiekt.value=format(v_liczba,2);
}
return v_liczba;
}

function  f_przlicz_admin(obiekt) { 
v_liczba=f_spr_format_admin(obiekt);
if (v_liczba!=-1) {

f_spr_ilosc_admin(document.getElementById('ile_egz_1'));

}

}

function f_spr_pola_inp(v_ilosc) {
  x=1;  
  var licz='tak';
  while(document.getElementById('ile_egz_'+x)){
     if (document.getElementById('ile_egz_'+x).value==v_ilosc) {
         przelicz_zam(v_ilosc,v_ilosc);
         var licz='nie';
     }
   v_max_egz=document.getElementById('ile_egz_'+x).value;  
   document.getElementById('ile_egz_'+x).checked=false;
   x++;
   }
;
   if (licz=='tak') przelicz_zam(v_ilosc,v_max_egz);
  

}


function f_spr_ilosc(o_obiekt) {
v_ilosc=o_obiekt.value;
v_ilosc_spr=v_ilosc/100;
//spr czy podana ilosc jest wieokrotnoscia 100
if (!isInt(v_ilosc_spr)){
alert("Proszę wprowadzić ilość równą wielokrotności 100 szt egzemplarzy.");
f_spr_pola_inp(v_ilosc);
o_obiekt.value=0;
v_komunikat="0.00 netto, 0.00 brutto";
document.getElementById('v_wart_fakt').innerHTML=v_komunikat;

}else{
//spr czy podana ilosc jest wieksza od najwiekszej

f_spr_pola_inp(v_ilosc);

}

return false;
}


function f_spr_ilosc_admin(o_obiekt) {

v_ilosc=o_obiekt.value;
v_ilosc_spr=v_ilosc/100;
//spr czy podana ilosc jest wieokrotnoscia 100

if (!isInt(v_ilosc_spr)){
alert("Proszę wprowadzić ilość równą wielokrotności 100 szt egzemplarzy.");
o_obiekt.value=0;
v_komunikat="0.00 netto, 0.00 brutto";
document.getElementById('v_wart_fakt').innerHTML=v_komunikat;
}else{

przelicz_zam(v_ilosc,1);

}

return false;
}


function  f_przlicz_admin_poz(obiekt,v_ilosc) { 
v_liczba=f_spr_format_admin(obiekt);
if (v_liczba!=-1) {
v_cena=obiekt.value;

  if (v_cena>0) {
    v_vat=1.23; 
    v_netto=   format(v_cena * v_ilosc,2);
    v_brutto=  format(v_netto*v_vat,2);
    
    document.getElementById('i_netto_'+v_ilosc).innerHTML=v_netto;
    document.getElementById('i_brutto_'+v_ilosc).innerHTML=v_brutto;
    document.getElementById('h_cena_n_'+v_ilosc).value=v_cena;
  }else{
  alert("Cena powinna być większa od zera.");
  obiekt.value = document.getElementById('h_cena_n_'+v_ilosc).value;
  }
}else{
obiekt.value = document.getElementById('h_cena_n_'+v_ilosc).value;
}
 return false;
}

function f_licz_rew() {
v_ile_egz_szt=document.getElementById('ile_egz_szt').value;

if (v_ile_egz_szt>0 ) {
f_spr_ilosc(document.getElementById('ile_egz_szt'));
}else{

  x=1;  
  v_ilosc=0;
  while(document.getElementById('ile_egz_'+x)){
     if (document.getElementById('ile_egz_'+x).checked==true) {
         v_ilosc= document.getElementById('ile_egz_'+x).value;
     }
     
  x++;
  }
  ///alert( v_ilosc);
  if ( v_ilosc>0 ) przelicz_zam(v_ilosc,v_ilosc);
}

}
