function textCounter(field) {
var str = field.value;


if(str.match('\\\*') == null && str.match('\\\[') == null && str.match('\\\]') == null && str.match('_') == null && str.match('\\\$') == null && str.match('\\\%') == null && str.match('\\\^') == null && str.match('\\\+') == null && str.match('\\\=') == null && str.match('\\\<') == null && str.match('\\\>') == null && str.match('~') == null && str.match('`') == null && str.match('#') == null && str.match('\\\|') == null && str.match('\\\\') == null && str.match('\\\{') == null && str.match('\\\}') == null)
{

if (field != null)
{ // if too long...trim it!
       var i = 1;
      if(field.value.search('b') != -1)
      {
          var where_b = field.value.search('b') + 1;
          var nowy_b = field.value.slice(where_b);
          <!--document.write(nowy_b);document.write(i); -->
          i++;


          if(nowy_b.search('b') != -1)
          {
              var where2_b = nowy_b.search('b') + 1;
              var nowy2_b = nowy_b.slice(where2_b);
              <!--document.write(nowy2);document.write(i);  -->
              i++;

              if(nowy2_b.search('b') != -1)
              {
                  var where3_b = nowy2_b.search('b') + 1;
                  var nowy3_b = nowy2_b.slice(where3_b);
                  <!--document.write(nowy3);document.write(i); -->
                  i++;
                  alert('Użyto za duzo znakow "b"');
              }
          }
      }


}

if (field != null)
{ // if too long...trim it!
       var i = 1;
      if(field.value.search(':') != -1)
      {
          var where_sr = field.value.search(':') + 1;
          var nowy_sr = field.value.slice(where_sr);
          <!--document.write(nowy_b);document.write(i); -->
          i++;


          if(nowy_sr.search(':') != -1)
          {
              var where2_sr = nowy_sr.search(':') + 1;
              var nowy2_sr = nowy_sr.slice(where2_sr);
              <!--document.write(nowy2);document.write(i);  -->
              i++;

              if(nowy2_sr.search(':') != -1)
              {
                  var where3_sr = nowy2_sr.search(':') + 1;
                  var nowy3_sr = nowy2_sr.slice(where3_sr);
                  <!--document.write(nowy3);document.write(i); -->
                  i++;

                  if(nowy3_b.search(':') != -1)
                  {
                      var where4_sr = nowy3_sr.search(':') + 1;
                      var nowy4_sr = nowy3_sr.slice(where4_sr);
                      <!--document.write(nowy4);document.write(i);  -->
                      i++;
                      alert('Użyto za duzo znakow ":"');
                  }
              }
          }
      }



}

if (field != null)
{ // if too long...trim it!
       var i = 1;
      if(field.value.search('\\\(') != -1)
      {
          var where_naw_otw = field.value.search('\\\(') + 1;
          var nowy_naw_otw = field.value.slice(where_naw_otw);
          <!--document.write(nowy_b);document.write(i); -->
          i++;


          if(nowy_naw_otw.search('\\\(') != -1)
          {
              var where2_naw_otw = nowy_naw_otw.search('\\\(') + 1;
              var nowy2_naw_otw = nowy_naw_otw.slice(where2_naw_otw);
              <!--document.write(nowy2);document.write(i);  -->
              i++;
              alert('Użyto za duzo znakow "("');

          }
      }
}

if (field != null)
{ // if too long...trim it!
       var i = 1;
      if(field.value.search('\\\)') != -1)
      {
          var where_naw_zamk = field.value.search('\\\)') + 1;
          var nowy_naw_zamk = field.value.slice(where_naw_zamk);
          <!--document.write(nowy_b);document.write(i); -->
          i++;


          if(nowy_naw_zamk.search('\\\)') != -1)
          {
              var where2_naw_zamk = nowy_naw_zamk.search('\\\)') + 1;
              var nowy2_naw_zamk = nowy_naw_zamk.slice(where2_naw_zamk);
              <!--document.write(nowy2);document.write(i);  -->
              i++;
              alert('Użyto za duzo znakow ")"');

          }
      }
}
}
else //end of main statemant
{
    alert('Użyto jednego z niedostępnych znaków:\n * [ ] $ ^ _ % + < > ~ ` # | \ { } lub =');
}
}



function countChars(element, KeyCharCodes)
{
	var target = document.getElementById(element);	
		
	var KeyCount = new Array(KeyCharCodes.length);
	for (x=0; x<KeyCount.length; x++) KeyCount[x] = 0;		
	
	var EnteredText = target.value.split('');
	
	for (x=0; x<EnteredText.length; x++)
	{
		for (y=0; y<KeyCharCodes.length; y++)
		{
			if (KeyCharCodes[y] == EnteredText[x])
			{
				KeyCount[y] = KeyCount[y] + 1; 
			};		
		};
	};		
	return KeyCount;
}

function sprawdzmi(el){
	var pole = document.getElementById(el).value;
	var szukane= pole.indexOf("*")
	if(szukane == '-1'){
	
	}
	else {
		var re = /\*/gi;
		var wynik = pole.replace(re,"");
		document.getElementById(el).value = wynik;
	}
}

function szukajw(lit){
	var lista  = ["0","1","2","3","4","5","6","7","8","9","/","@","!","?","&","\"",";",",","-","(",")",".",":","a","ą","b","c","ć","d","e","ę","f","g","h","i","j","k","l","ł","m","n","ń","o","ó","p","q","r","s","ś","t","u","v","w","x","y","z","ź","ż","A","Ą","B","C","Ć","D","E","Ę","F","G","H","I","J","K","L","Ł","M","N","Ń","O","Ó","P","Q","R","S","Ś","T","U","V","W","X","Y","Z","Ź","Ż", " "];
	var wynik;
	for(j=0;j<lista.length;j++){
		if(lit == lista[j]){
				wynik = 'mam';
		}
	}
	return wynik;
}

function sprall(el){
	var pole = document.getElementById(el).value;
	var dlugosc = pole.length;
	for(i=0;i<dlugosc;i++){
		if(szukajw(pole.charAt(i)) == 'mam'){
		}
		else {
			var pole2 = document.getElementById(el).value;
			var wynik = pole2.replace(pole.charAt(i),"");
			document.getElementById(el).value = wynik;
		}
	}
}


function testallowedchars(e, element)
{
	// Zostanie do oprogramowania przypadek www (niby 3 w, ale z jednej matrycy)
	// www - liczba wystąpień - 1
/*
	var KeyCharCodes    = ["0","1","2","3","4","5","6","7","8","9","/","@","!","?","&","\"",";",",","-","(",")",".",":","a","ą","b","c","ć","d","e","ę","f","g","h","i","j","k","l","ł","m","n","ń","o","ó","p","q","r","s","ś","t","u","v","w","x","y","z","ź","ż","A","Ą","B","C","Ć","D","E","Ę","F","G","H","I","J","K","L","Ł","M","N","Ń","O","Ó","P","Q","R","S","Ś","T","U","V","W","X","Y","Z","Ź","Ż"];
	var KeyCodes 		= [ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,191, 50, 49,191, 55, 222,186,188,189, 57, 48,190,186, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 88, 90, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 88, 90];	
	var KeyShiftStates	= [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,   1,  0,  0,  0,  1,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1];
	var KeyAltStates	= [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  1,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  1,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  1,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  1];
	var KeyAvailability	= [  6,  3,  4,  4,  3,  3,  3,  3,  3,  3,  4,  1,  1,  1,  1,   2,  1,  3,  4,  1,  1,  4,  1, 22,  8,  2, 14,  8, 10, 18,  7,  2,  6,  2, 19,  6, 14,  4, 12,  6, 16,  4, 12,  8,  2,  1, 20, 16,  8,  8, 10,  2, 10,  3, 10,  6,  3,  4,  5,  4,  4,  2,  4,  2,  4,  3,  2,  2,  4,  2,  2,  5,  2,  4,  2,  2,  4,  2,  4,  4,  0,  2,  3,  3,  4,  2,  2,  2,  2,  2,  2,  4,  4];
	var KeyIgnoredChars	= [  8, 13, 16, 17, 18, 32, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46,116];
	

*/
	sprall(element);
	var e = window.event || e;	
	
	var shiftState 	= (e.shiftKey) ? 1 : 0;
	var altState 	= (e.altKey)   ? 1 : 0;
	// PJ
	if (navigator.appName=="Microsoft Internet Explorer") {
		var KeyCharCodes    = ["0","1","2","3","4","5","6","7","8","9","/","@","!","?","&","\"",";",",","-","(",")",".",":","a","ą","b","c","ć","d","e","ę","f","g","h","i","j","k","l","ł","m","n","ń","o","ó","p","q","r","s","ś","t","u","v","w","x","y","z","ź","ż","A","Ą","B","C","Ć","D","E","Ę","F","G","H","I","J","K","L","Ł","M","N","Ń","O","Ó","P","Q","R","S","Ś","T","U","V","W","X","Y","Z","Ź","Ż"];
		var KeyCodes 		=   	[ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,191, 50, 49,191, 55, 222,186,188,189, 57, 48,190, 186, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 88, 90, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 88, 90];	
		var KeyShiftStates	= [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,   1,  0,  0,  0,  1,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1];
		var KeyAltStates	= 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  1,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  1,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  1,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  1];
		var KeyAvailability	= [  6,  3,  4,  4,  3,  3,  3,  3,  3,  3,  4,  1,  1,  1,  1,   2,  1,  3,  4,  1,  1,  4,  1, 22,  8,  2, 14,  8, 10, 18,  7,  2,  6,  2, 19,  6, 14,  4, 12,  6, 16,  4, 12,  8,  2,  1, 20, 16,  8,  8, 10,  2, 10,  3, 10,  6,  3,  4,  5,  4,  4,  2,  4,  2,  4,  3,  2,  2,  4,  2,  2,  5,  2,  4,  2,  2,  4,  2,  4,  4,  0,  2,  3,  3,  4,  2,  2,  2,  2,  2,  2,  4,  4];
		var KeyIgnoredChars	= [  8, 13, 16, 17, 18, 32, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46,116];
	}
	else {
		var KeyCharCodes    = ["0","1","2","3","4","5","6","7","8","9","/","@","!","?","&","\"",";",",","-","(",")",".",":","a","ą","b","c","ć","d","e","ę","f","g","h","i","j","k","l","ł","m","n","ń","o","ó","p","q","r","s","ś","t","u","v","w","x","y","z","ź","ż","A","Ą","B","C","Ć","D","E","Ę","F","G","H","I","J","K","L","Ł","M","N","Ń","O","Ó","P","Q","R","S","Ś","T","U","V","W","X","Y","Z","Ź","Ż"];
		var KeyCodes 		=   	[ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,191, 50, 49,191, 55, 222,59,188,109, 57, 48,190, 59, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 88, 90, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 88, 90];	
		var KeyShiftStates	= [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,   1,  0,  0,  0,  1,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1];
		var KeyAltStates	= 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  1,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  1,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  0,  0,  1,  0,  1,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  1,  1];
		var KeyAvailability	= [  6,  3,  4,  4,  3,  3,  3,  3,  3,  3,  4,  1,  1,  1,  1,   2,  1,  3,  4,  1,  1,  4,  1, 22,  8,  2, 14,  8, 10, 18,  7,  2,  6,  2, 19,  6, 14,  4, 12,  6, 16,  4, 12,  8,  2,  1, 20, 16,  8,  8, 10,  2, 10,  3, 10,  6,  3,  4,  5,  4,  4,  2,  4,  2,  4,  3,  2,  2,  4,  2,  2,  5,  2,  4,  2,  2,  4,  2,  4,  4,  0,  2,  3,  3,  4,  2,  2,  2,  2,  2,  2,  4,  4];
		var KeyIgnoredChars	= [  8, 13, 16, 17, 18, 32, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46,116];
	} // rozpoznanie przegladarki
	
	var KeyCount = countChars(element, KeyCharCodes);


  // =====DA
  var keyPressed = null;
  if(window.event)
    keyPressed = e.keyCode; // IE
  else
    keyPressed = e.which; // Firefox
//window.alert(keyPressed);
	var myIndex = -1;
	for (x=0; x<KeyCodes.length; x++)
	{
	   // =====DA
		//if (KeyCodes[x] == e.keyCode)
		if (KeyCodes[x] == keyPressed)
		{
			if ( (KeyShiftStates[x] == shiftState) && (KeyAltStates[x] == altState) )
			{
				myIndex = x;
				break;
			};
		};
	};
	
	var CharCanBePut = true;
	
	if (myIndex >= 0)
	{
		CharCanBePut = !(KeyCount[myIndex] >= KeyAvailability[myIndex]);		
	}
	else
	{	
		var isIgnoredCharacter = false;
		for (x=0; x<KeyIgnoredChars.length; x++)
		{
		// =====DA
		//if (KeyIgnoredChars[x] == e.keyCode)
		if (KeyIgnoredChars[x] == keyPressed)
			{
				isIgnoredCharacter = true;
				break;
			};
		};		
		CharCanBePut = isIgnoredCharacter;		
		//if (!isIgnoredCharacter) document.title = document.title + e.keyCode + " | ";
	};
	
	if (!CharCanBePut)	
	{
		if (window.event)
		{
			window.alert("Przykro nam, wybrany znak jest niedostępny lub przekroczona została możliwa liczba wystąpień znaku!");			
			e.returnValue = false;			
		}
		else
		{	      	
      e.preventDefault();
      e.stopPropagation();
			
		};
	};
};
