function trim(stringToTrim) {
   return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function check_and_secure() {
   var elem = document.getElementById('login');
   if(elem!=null) {
      var login = trim(elem.value);
      if(login=='') {
         alert('Musisz poda\u0107 sw\u00F3j pseudonim!');
         elem.focus();
         return false;
      }
      if(login.length>24 || login.length<3) {
         alert('Pseudonim powinien mie\u0107 od 3 do 24 znak\u00F3w!');
         elem.focus();
         return false;
      }
      login = login.toLowerCase();
      var reg = new RegExp("[^A-Za-z0-9]");
      if(login.match(reg)) {
         alert('Pseudonim mo\u017ce zawiera\u0107 tylko litery i cyfry');
         elem.focus();
         return false;
      }
   }
   elem = document.getElementById('name');
   if(elem!=null) {
      var tmp = trim(elem.value);
      if(tmp=='') {
         alert('Musisz poda\u0107 swoje imi\u0119!');
         elem.focus();
         return false;
      }
      if(tmp.length<3 || tmp.length>32) {
         alert('Imi\u0119 powinno mie\u0107 od 3 do 32 znak\u00F3w!');
         elem.focus();
         return false;
      }
   }
   elem = document.getElementById('surname');
   if(elem!=null) {
      tmp = trim(elem.value);
      if(tmp=='') {
         alert('Musisz poda\u0107 swoje nazwisko!');
         elem.focus();
         return false;
      }
      if(tmp.length<2 || tmp.length>45) {
         alert('Nazwisko powinno mie\u0107 od 2 do 45 znak\u00F3w!');
         elem.focus();
         return false;
      }
   }
   reg = new RegExp("^([A-Za-z0-9_\\-\\.])+\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$");
   elem = document.getElementById('email');
   if(elem!=null) {
      if(reg.test(elem.value) == false) {
         alert('Adres e-mail nie wygl\u0105da na poprawny!');
         elem.focus();
         return false;
      }
   }
   elem = document.getElementById('accept');
   if(elem!=null && !elem.checked) {
      alert('Musisz zaakceptowa\u0107 regulamin!');
      elem.focus();
      return false;
   }
   var password = document.getElementById('password');
   if(password!=null) {
      if(trim(password.value)=='') {
         alert('Musisz poda\u0107 swoje has\u0142o!');
         password.focus();
         return false;
      }
      var password2 = document.getElementById('password2');
      if(password.value!=password2.value) {
         alert('Has\u0142o nie zosta\u0142o poprawnie powt\u00F3rzone!');
         return false;
      }
      password.value = hex_md5(password.value);
      password2.value = password.value;
      document.getElementById('md5').value="1";
   }

   return true;
}


