function cleanedTxt(txt){
     do //se ci sono 2 spazi accanto gli elimino
       txt = txt.replace(/\s{2,}/, /\s/);
     while (txt != txt.replace(/\s{2,}/, /\s/));
 if (txt.search(/[^\s]/) != -1){//se txt inizia con almeno 1 spazio lo elimino
    txt = txt.substring(txt.search(/[^\s]/));
 }
 else{
      txt = "";
 }
 return txt;
}

function fieldsAreEmpty(nForm, nTotElement){
         var msg = "";
         for (var i = 0; i <= nTotElement; i++){
             if (cleanedTxt(document.forms[nForm].elements[i].value) == "") msg += "Il campo numero " + (i + 1) + " deve essere ancora compilato\n";
         }
 if (msg != ""){ 
    window.alert(msg);
  return false;
 }
 return true;
}

function checkPw(nForm, nPw, nPw2Check){
         if (document.forms[nForm].elements[nPw].value != document.forms[nForm].elements[nPw2Check].value){
            window.alert("Il campo password non coincide con il campo verifica password!!!");
          return false;
         }
 return true;
}

function stringLengthValidity(s, minLength, maxLength){
 if (s.length >= minLength){
  if (s.length <= maxLength) return true;
  else minLength = maxLength;
 }
 return s.length - minLength;//restituisce +N°car in eccesso o -N°car mancanti
}

function changeLineEndings(s, eol){
 s = s.replace(/(\r\n)/, '\n', s);
 s = s.replace(/\r/, '\n', s);
 return s.replace(/\n/, eol, s);
}
