window.onerror = function( )
  {
    return true;
  }

  
  function GSE_GetSmsLength( strMessage )
  {
    var iLength = 0;
  
    for ( var i = 0; i < strMessage.length; i++ )
    {
      iLength++;
            
      if ( /[\r^{}\\\[~\]|€]/.test(strMessage.charAt(i)) )
        iLength++;
    }
  
    return iLength;
  }


  function GSE_CheckSmsLength( hTextField, hUsedCharsElement, iMaxMessageLength )
  {
    var bCanUserType = false;

    if ( GSE_GetSmsLength(hTextField.value) > iMaxMessageLength )
    {
      var iCuttedChars = 0;

      while ( GSE_GetSmsLength(hTextField.value) > iMaxMessageLength && iCuttedChars <= iMaxMessageLength )
      {
        hTextField.value = hTextField.value.substring( 0, iMaxMessageLength-iCuttedChars );
        iCuttedChars++;
      }

      alert( 'Il testo del commento \xe8 limitato a ' + iMaxMessageLength + ' caratteri.' );
    }

    else
      bCanUserType = true;

    if ( hUsedCharsElement != null )
      hUsedCharsElement.innerHTML = GSE_GetSmsLength( hTextField.value );

    return bCanUserType;
  }

