function btnup(iObj){
	if (document.getElementById) 
		document.getElementById(iObj).style.top = "-3px";
}

function btndown(iObj){
	if (document.getElementById) 
		document.getElementById(iObj).style.top = "0px";
}

function new_window(x,y,fileName){
	var xWin=(screen.availWidth-10);
	var yWin=(screen.availHeight-29);
	var xscrepos=((xWin-x)/2);
	var yscrepos=((yWin-y)/2);
	if (  (xWin<x)&&(yWin>=y)  ){
   	   eval('window.open("' + fileName + '","powiekszenie","menubar=no,status=no,toolbar=no,resizable=no,directories=no,scrollbars=yes,fullscreen=no,top='+yscrepos+',left=0,height='+y+',width='+xWin+'")')
	}
	else if (  (xWin>=x)&&(yWin<y)  ){
   	   eval('window.open("' + fileName + '","powiekszenie","menubar=no,status=no,toolbar=no,resizable=no,directories=no,scrollbars=yes,fullscreen=no,top=0,left='+xscrepos+',height='+yWin+',width='+x+'")')
	}
	else if( (xWin>=x)&&(yWin>=y) )
	{
	   eval('window.open("' + fileName + '","powiekszenie","menubar=no,status=no,toolbar=no,resizable=no,directories=no,scrollbars=no,fullscreen=no,top='+yscrepos+',left='+xscrepos+',height='+y+',width='+x+'")')
	}
}

function check_form()
{
	if (document.contactform.imie.value == "")
	{
		document.contactform.imie.style.background = "#b7cbde";
		alert("Proszę podać imię i nazwisko.");
		return;
	}
	if (document.contactform.email.value == "")
	{
		document.contactform.email.style.background = "#b7cbde";
		alert("Proszę podać adres email.");
		return;
	}
	else 
	{
		if (!check_validEmail(document.contactform.email.value)) 
		{
			 document.contactform.email.style.background = "#b7cbde";
			 alert("Proszę podać prawidłowy adres email.");
	 		 return;
		}
	}
	 if (document.contactform.miasto.value == "")
	{
		document.contactform.miasto.style.background = "#b7cbde";
		alert("Proszę wpisać miasto.");
		return;
	}
	if (document.contactform.nazwa.value == "")
	{
		document.contactform.nazwa.style.background = "#b7cbde";
		alert("Proszę wpisać nazwę firmy.");
		return;
	}
	if (document.contactform.telefon.value == "")
	{
		document.contactform.telefon.style.background = "#b2cef8";
		alert("Proszę wpisać numer telefonu.");
		return;
	}
	else 
	{
		validtel = /^[0-9 \(\)]+$/;
		if ( !validtel.exec(document.contactform.telefon.value) )
		{
			document.contactform.telefon.style.background = "#b7cbde";
			alert("Proszę wpisać poprawny numer telefonu.");
			return;
		}
	}
	document.contactform.sprawdz.value = "wyslij";
	document.contactform.submit();
}

function check_validEmail(adres_email)
{
 	validemail = /^[-^!#$%&'*+\/=?`{|}~.\w]+@[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*(\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*)+$/  
	if (validemail.exec(adres_email) )
		return true;
	else
		return false;
}

function checkEnter(e,item,action)
{
	var characterCode;
	if(e && e.which)
	{
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{
	 //if generated character code is equal to ascii 13 (if enter key)
        if (action == "change")
		{
		   change_item(item)
           return false
		}
		else
		{
		   add_item(item)
           return false
		} 
	}
	else
	{
		return true 
	}
}

function add_item(item)
{
   number = document.getElementById("ile"+item).value;
   validnumber = /^[0-9]+$/;
   if ( !validnumber.exec(number) )
   {
      alert("Proszę podać liczbę.");
	  return;    
   }
   if ( number==null || number<=0 )
   {
   	  alert("Proszę wprowadzić wartość większą od 0.");
	  return;
   }
   url_add ="/?site=koszyk&action=add&item="+ item +"&q="+number;
   this.document.location.href =url_add;
}

function change_item(item)
{
   number = document.getElementById("ile"+item).value;
   validnumber = /^[0-9]+$/;
   if ( !validnumber.exec(number) && number!='')
   {
      alert("Proszę podać liczbę.");
	  document.getElementById(indeks).value = prev_number
	  return;    
   }
   url_add ="/?site=koszyk&action=change&item="+ item +"&q="+number;
   this.document.location.href =url_add;
}

function aktualizuj()
{
   url_add ="/?site=logowanie&action=change";
   this.document.location.href =url_add;
}

function aktualizuj_haslo()
{
   url_add ="/?site=logowanie&action=change_pass";
   this.document.location.href =url_add;
}

function powrot(site)
{
   if(site)
   {
      url_add ="/"+site;
      this.document.location.href =url_add;
   }
   else
   {
      url_add ="/";
      this.document.location.href =url_add;
   }
}

function log_user()
{
   document.logowanie.submit();
}

function zapisz(update)
{
	if (document.zamowienie.imienazw.value == "")
	{
		document.zamowienie.imienazw.style.background = "#b7cbde";
		document.zamowienie.imienazw.style.color = "#004689";
		alert("Proszę podać imię i nazwisko osoby zamawiającej.");
		return;
	}
	if (document.zamowienie.ulica.value == "")
	{
		document.zamowienie.ulica.style.background = "#b7cbde";
		document.zamowienie.ulica.style.color = "#004689";
		alert("Proszę wpisać nazwę ulicy.");
		return;
	}
	if (document.zamowienie.kod_poczt.value == "")
	{
		document.zamowienie.kod_poczt.style.background = "#b7cbde";
		document.zamowienie.kod_poczt.style.color = "#004689";
		alert("Proszę wpisać kod pocztowy.");
		return;
	}
	if (document.zamowienie.miasto.value == "")
	{
		document.zamowienie.miasto.style.background = "#b7cbde";
		document.zamowienie.miasto.style.color = "#004689";
		alert("Proszę wpisać miasto.");
		return;
	}
	if (document.zamowienie.email.value == "")
	{
		document.zamowienie.email.style.background = "#b7cbde";
		document.zamowienie.email.style.color = "#004689";
		alert("Proszę podać adres email.");
		return;
	}
	else 
	{
		if (!check_validEmail(document.zamowienie.email.value)) 
		{
			 document.zamowienie.email.style.background = "#b7cbde";
			document.zamowienie.email.style.color = "#004689";
			 alert("Proszę podać prawidłowy adres email.");
	 		 return;
		}
	}
	if (document.zamowienie.telefon.value == "")
	{
		document.zamowienie.telefon.style.background = "#b7cbde";
		document.zamowienie.telefon.style.color = "#004689";
		alert("Proszę wpisać numer telefonu.");
		return;
	}
	else 
	{
		validtel = /^[0-9 \(\)]+$/;
		if ( !validtel.exec(document.zamowienie.telefon.value) )
		{
			document.zamowienie.telefon.style.background = "#b7cbde";
			document.zamowienie.telefon.style.color = "#004689";
			alert("Proszę wpisać poprawny numer telefonu.");
			return;
		}
	}
	if (document.zamowienie.nazwa.value != "")
	{
		if (document.zamowienie.nip.value == "")
		{
			document.zamowienie.nip.style.background = "#b7cbde";
			document.zamowienie.nip.style.color = "#004689";
			alert("Proszę wpisać NIP.");
			return;
		}
	} 
	if (document.zamowienie.nip.value != "")
	{
		if (document.zamowienie.nazwa.value == "")
		{
			document.zamowienie.nazwa.style.background = "#b7cbde";
			document.zamowienie.nazwa.style.color = "#004689";
			alert("Proszę wpisać nazwę firmy.");
			return;
		}
    }
	if ( (update!=1 && (document.zamowienie.pass.value || document.zamowienie.login.value)) || update ==2 )
	{
       if (document.zamowienie.login.value == "")
	   {
		   document.zamowienie.login.style.background = "#b7cbde";
		   document.zamowienie.login.style.color = "#004689";
           alert("Proszę wpisać login.");
           return;
       }
       if (document.zamowienie.login.value.length > 15)
       {
          document.zamowienie.login.style.background = "#b7cbde";
          document.zamowienie.login.style.color = "#004689";
          alert("Login musi się mieć mniej niż 15 znaków.");
          return;
       }
       if (document.zamowienie.pass.value == "")
	   {
		   document.zamowienie.pass.style.background = "#b7cbde";
		   document.zamowienie.pass.style.color = "#004689";
           alert("Proszę wpisać hasło.");
           return;
       }
       if (document.zamowienie.pass.value.length <= 4 || document.zamowienie.pass.value.length > 15)
       {
          document.zamowienie.ppass.style.background = "#b7cbde";
          document.zamowienie.ppass.style.color = "#004689";
          alert("Hasło musi się mieć od 5 do 15 znaków.");
          return;
       }
       if (document.zamowienie.ppass.value != document.zamowienie.pass.value)
       {
          document.zamowienie.ppass.style.background = "#b7cbde";
          document.zamowienie.ppass.style.color = "#004689";
          alert("Hasła muszą być identyczne.");
          return;
       }
	}
	document.zamowienie.sprawdz.value = "wyslij";
	document.zamowienie.submit();
}

function realizuj()
{
   document.zamowienie.sprawdz.value = "wyslij";
   document.zamowienie.submit()
}

function zapisz_login()
{
       if (document.zamowienie.login.value == "")
	   {
		   document.zamowienie.login.style.background = "#b7cbde";
           alert("Proszę wpisać login.");
           return;
       }
       if (document.zamowienie.login.value.length > 15)
       {
          document.zamowienie.login.style.background = "#b7cbde";
          alert("Login musi się mieć mniej niż 15 znaków.");
          return;
       }
       if (document.zamowienie.pass.value == "")
	   {
		   document.zamowienie.pass.style.background = "#b7cbde";
           alert("Proszę wpisać hasło.");
           return;
       }
       if (document.zamowienie.pass.value.length <= 4 || document.zamowienie.pass.value.length > 15)
       {
          document.zamowienie.ppass.style.background = "#b7cbde";
          alert("Hasło musi się mieć od 5 do 15 znaków.");
          return;
       }
       if (document.zamowienie.ppass.value != document.zamowienie.pass.value)
       {
          document.zamowienie.ppass.style.background = "#b7cbde";
          alert("Hasła muszą być identyczne.");
          return;
       }
    document.zamowienie.sprawdz.value = "wyslij";
	document.zamowienie.submit();
}

function przypomnij()
{
   if (document.zamowienie.login.value == "")
   {
      document.zamowienie.login.style.background = "#b7cbde";
      alert("Proszę wpisać login.");
      return;
   }
   if (document.zamowienie.email.value == "")
   {
      document.zamowienie.email.style.background = "#b7cbde";
      alert("Proszę podać adres email.");
      return;
   }
   else 
   {
      if (!check_validEmail(document.zamowienie.email.value)) 
      {
         document.zamowienie.email.style.background = "#b7cbde";
         alert("Proszę podać prawidłowy adres email.");
         return;
      }
   }
   document.zamowienie.sprawdz.value = "wyslij";
   document.zamowienie.submit();
}

function haslo()
{
   url_add ="/przypomnij";
   this.document.location.href =url_add;
}

function mail_write(user){
   var domena="bajansklep";
   var suffix="com.pl";
   document.write('<a href="' + 'mailto:' + user + '@' + domena + '.' + suffix + '" >' + user + '@' + domena + '.' + suffix + '</a>');
}

function odswiez(){
   document.koszyk.submit();
}

function back_prev(prev)
{
   url_add ="/"+prev;
   this.document.location.href =url_add;
}
