/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
                var a = "Nieprawidłowy adres e-mail";
		if (str.indexOf(at)==-1){
		   alert(a)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(a)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(a)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(a)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(a)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(a)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(a)
		    return false
		 }

 		 return true					
	}

function checkform ( form )
{
  // see http://www.thesitewizard.com/archive/validation.shtml
  // for an explanation of this script and how to use it on your
  // own website
  // ** START **
  if ( (form.wybor.value == "firma") && ((form.nip1.value == "") || (form.nip2.value == "") || (form.nip3.value == "") || (form.nip4.value == "") || (form.nip1.value.length  < 3) || (form.nip2.value.length  < 2) || (form.nip3.value.length  < 2) || (form.nip4.value.length  < 3)) ) {
   alert( "Proszę uzupełnić pole NIP" );
   form.nip1.focus();
   return false ;
  }
  if ((form.imie.value.length < 2) || (form.imie.value == "")) {
    if(form.wybor.value == "firma") alert( "Proszę uzupełnić pole Nazwa firmy" );
    else if(form.wybor.value == "osoba") alert( "Proszę uzupełnić pole Imię i Nazwisko");
    form.imie.focus();
    return false ;
  }
  if ((form.email.value==null) || (form.email.value == "")) {
    alert( "Proszę uzupełnić pole e-mail" );
    form.email.focus();
    return false ;
  }
  if (echeck(form.email.value)==false){
	form.email.value="";
	form.email.focus();
	return false ;
  }

// ** END **
  return true ;
}

function checkname()
{
  wybor = document.getElementById('wybor');
  kolor = "<font color=\"#ff0000\">*</font>";
  if(wybor.value == "osoba") {
			wybor_w = "Imię i Nazwisko ";
			document.getElementById("formularz2").style.visibility = "hidden";
  }
  else if(wybor.value == "firma") { 
			wybor_w = "Nazwa firmy ";
			document.getElementById("formularz2").style.visibility = "visible";
  }  
  if(wybor) document.getElementById('nazwa').innerHTML = wybor_w + kolor;
}

function skok1() 
{
  var nip1 = document.getElementById("nip1").value;
  
  if(nip1.length == 3) {
	document.getElementById("nip2").focus();
	}
}


function skok2() 
{
  var nip2 = document.getElementById("nip2").value;

	if(nip2.length == 2) {
	document.getElementById("nip3").focus();
  }
}

function skok3() 
{
  var nip3 = document.getElementById("nip3").value;
  
	if(nip3.length == 2) {
	document.getElementById("nip4").focus();
  }
}
