function checkPostalCode(fld, Separator, e) {
   var sep = 0;
   var key = '';
   var i  = 0;
   var len = 0;
   var strCheck = '0123456789';
   var aux = '';
   var whichCode = (window.Event) ? e.which : e.keyCode;
   if (whichCode == 13) return true;  // Enter
   key = String.fromCharCode(whichCode);  // Get key value from key code
   if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
   len = fld.value.length;
   for(i = 0; i < len; i++)
         if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != Separator)) break; //Szuka w wartości pola
                                 //pierwszej cyfry
   aux = '';
   for(; i < len; i++)
         if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); //ustawia zmienna aux 
      //na wszystkie wprowadzone cyfry
      
   len = aux.length;
   if (len <= 5){
         aux += key;
         len +=1;
         if (len == 0) fld.value = '';
         if (len == 1) fld.value = '__' + Separator + '__' + aux;
         if (len == 2) fld.value = '__' + Separator + '_' + aux;
         if (len == 3) fld.value = '__' + Separator + aux;
         if (len == 4) fld.value = '_' + aux.substr(0,1) + Separator + aux.substr(1,3);
         if (len == 5) fld.value = aux.substr(0,2) + Separator + aux.substr(2,4);
   }
   return false;
}

function isDigitt(fld,decSep,e) 
// Funkcja sprawdza, czy wpisany znak jest cyfrą, przecinkiem dziesiętnym, Enterem lub Backspacem
// Aby sprawdzić czy liczba jest całkowita jako parametr decSep w wywołaniu funkcji należy podać ''.
{
   var key = '';
   var strCheck = '0123456789';
   var whichCode = (window.Event) ? e.which : e.keyCode;
   if (whichCode == 13) return true;
   if (whichCode == 8) return true;   // Enter i Backspace
   key = String.fromCharCode(whichCode);
   if (key == decSep) return true;
   if (strCheck.indexOf(key) == -1) return false;
   return true;
}



function echeck(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("Nieprawidłowy e-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Nieprawidłowy e-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Nieprawidłowy e-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Nieprawidłowy e-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Nieprawidłowy e-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Nieprawidłowy e-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Nieprawidłowy e-mail")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Prosze wypełnić pole e-mail")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }