Index: trunk/lib/App.inc.php
===================================================================
--- trunk/lib/App.inc.php	(revision 507)
+++ trunk/lib/App.inc.php	(revision 518)
@@ -61,4 +61,7 @@
     protected $_carry_queries = array();
 
+    // Array of raised message counters.
+    protected $_raised_msg_counter = array(MSG_NOTICE => 0, MSG_SUCCESS => 0, MSG_WARNING => 0, MSG_ERR => 0);
+
     // Dictionary of global application parameters.
     protected $_params = array();
@@ -514,4 +517,29 @@
         if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
             $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_NOTICE, __FILE__, __LINE__);
+        }
+
+        // Increment the counter for this message type.
+        $this->_raised_msg_counter[$type] += 1;
+    }
+
+    /*
+    * Returns the number of raised message (all, or by type) for the current script execution (this number may not match the total number of messages stored in session for multiple script executions)
+    *
+    * @access   public
+    * @param
+    * @return
+    * @author   Quinn Comendant <quinn@strangecode.com>
+    * @version  1.0
+    * @since    30 Apr 2015 17:13:03
+    */
+    public function getRaisedMessageCount($type='all')
+    {
+        if ('all' == $type) {
+            return array_sum($this->_raised_msg_counter);
+        } else if (isset($this->_raised_msg_counter[$type])) {
+            return $this->_raised_msg_counter[$type];
+        } else {
+            $this->logMsg(sprintf('Cannot return count of unknown raised message type: %s', $type), LOG_WARNING, __FILE__, __LINE__);
+            return false;
         }
     }
Index: trunk/lib/Upload.inc.php
===================================================================
--- trunk/lib/Upload.inc.php	(revision 507)
+++ trunk/lib/Upload.inc.php	(revision 518)
@@ -304,5 +304,5 @@
 
             // Clean the file name of bad characters.
-            $file_name = $this->cleanFileName($file_name);
+            $file_name = cleanFileName($file_name);
 
             // FINAL path and file name, lowercase extension.
@@ -475,30 +475,4 @@
 
     /**
-     * Removes non-latin characters from file name, using htmlentities to convert known weirdos into regular squares.
-     *
-     * @access  public
-     * @param   string  $file_name  A name of a file.
-     * @return  string              The same name, but cleaned.
-     */
-    public function cleanFileName($file_name)
-    {
-        $file_name = preg_replace(array(
-            '/&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/ui',
-            '/&(?:amp);/ui',
-            '/[&;]+/u',
-            '/[^a-zA-Z0-9()@._=+-]+/u',
-            '/^_+|_+$/u'
-        ), array(
-            '$1',
-            'and',
-            '',
-            '_',
-            ''
-        ), htmlentities($file_name, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'));
-        return mb_substr($file_name, 0, 250);
-    }
-
-
-    /**
      * Returns the extension of a file name, or an empty string if non exists.
      *
Index: trunk/lib/Utilities.inc.php
===================================================================
--- trunk/lib/Utilities.inc.php	(revision 507)
+++ trunk/lib/Utilities.inc.php	(revision 518)
@@ -82,7 +82,7 @@
     if (!empty($var)) {
         ?>
-        <script type="text/javascript" charset="utf-8">
+        <script type="text/javascript">
         /* <![CDATA[ */
-        window.console && console.log('<?php printf('%s: %s (on line %s of %s)', $prefix, str_replace("'", "\\'", getDump($var, true)), $line, $file); ?>');
+        console.log('<?php printf('%s: %s (on line %s of %s)', $prefix, str_replace("'", "\\'", getDump($var, true)), $line, $file); ?>');
         /* ]]> */
         </script>
@@ -536,4 +536,31 @@
 }
 
+/**
+ * Removes non-latin characters from file name, using htmlentities to convert known weirdos into regular squares.
+ *
+ * @access  public
+ * @param   string  $file_name  A name of a file.
+ * @return  string              The same name, but cleaned.
+ */
+function cleanFileName($file_name)
+{
+    $app =& App::getInstance();
+
+    $file_name = preg_replace(array(
+        '/&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/ui',
+        '/&(?:amp);/ui',
+        '/[&;]+/u',
+        '/[^a-zA-Z0-9()@._=+-]+/u',
+        '/^_+|_+$/u'
+    ), array(
+        '$1',
+        'and',
+        '',
+        '_',
+        ''
+    ), htmlentities($file_name, ENT_NOQUOTES | ENT_IGNORE, $app->getParam('character_set')));
+    return mb_substr($file_name, 0, 250);
+}
+
 /*
 * Convert a php.ini value (8M, 512K, etc), into integer value of bytes.
