diff --git a/include/class.config.php b/include/class.config.php
index c43f2e305b405b992916324ce0a3813015cf83f8..e6271511239683703825dbdaedc4066e819c5d4b 100644
--- a/include/class.config.php
+++ b/include/class.config.php
@@ -18,8 +18,8 @@ require_once(INCLUDE_DIR.'class.email.php');
 
 class Config {
     
-    var $id=0;
-    var $config=array();
+    var $id = 0;
+    var $config = array();
 
     var $defaultDept;   //Default Department    
     var $defaultSLA;   //Default SLA
@@ -32,18 +32,27 @@ class Config {
     }
 
     function load($id=0) {
+
         if(!$id && !($id=$this->getId()))
             return false;
 
-        $sql='SELECT * FROM '.CONFIG_TABLE
+        $sql='SELECT *, (TIME_TO_SEC(TIMEDIFF(NOW(), UTC_TIMESTAMP()))/3600) as db_tz_offset '
+            .' FROM '.CONFIG_TABLE
             .' WHERE id='.db_input($id);
+        
         if(!($res=db_query($sql)) || !db_num_rows($res))
             return false;
 
             
-        $this->config=db_fetch_array($res);
-        $this->id=$this->config['id'];
-        $this->setMysqlTZ(db_timezone());
+        $this->config = db_fetch_array($res);
+        $this->id = $this->config['id'];
+
+        //Get the default time zone
+        // We can't JOIN timezone table above due to upgrade support.
+        if($this->config['default_timezone_id'])
+            $this->config['tz_offset'] = Timezone::getOffsetById($this->config['default_timezone_id']);
+        else
+            $this->config['tz_offset'] = 0;
 
         return true;
     }
@@ -91,17 +100,9 @@ class Config {
 
         return null;
     }
-
-    function setMysqlTZ($tz) {
-        //TODO: Combine the 2 replace regex
-        if($tz=='SYSTEM')
-            $this->mysqltzoffset=preg_replace('/([+-]\d{2})(\d{2})/','\1',date('O'));
-        else
-            $this->mysqltzoffset=preg_replace('/([+-]\d{2})(:)(\d{2})/','\1',$tz);
-    }
     
-    function getMysqlTZoffset() {
-        return $this->mysqltzoffset;
+    function getDBTZoffset() {
+        return $this->config['db_tz_offset'];
     }
 
     /* Date & Time Formats */
@@ -148,7 +149,7 @@ class Config {
     }
 
     function getTZOffset() {
-        return $this->config['timezone_offset'];
+        return $this->config['tz_offset'];
     }
 
     function getPageSize() {
diff --git a/include/class.format.php b/include/class.format.php
index 9de1197edbb3d4272193f67af48826851f72296e..aaa6667d32c2fce14da2cb9f5e15387ec9608b0c 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -180,7 +180,7 @@ class Format {
     }
 
     /* elapsed time */
-    function elapsedTime($sec){
+    function elapsedTime($sec) {
 
         if(!$sec || !is_numeric($sec)) return "";
 
@@ -197,32 +197,32 @@ class Format {
     /* Dates helpers...most of this crap will change once we move to PHP 5*/
     function db_date($time) {
         global $cfg;
-        return Format::userdate($cfg->getDateFormat(),Misc::db2gmtime($time));
+        return Format::userdate($cfg->getDateFormat(), Misc::db2gmtime($time));
     }
 
     function db_datetime($time) {
         global $cfg;
-        return Format::userdate($cfg->getDateTimeFormat(),Misc::db2gmtime($time));
+        return Format::userdate($cfg->getDateTimeFormat(), Misc::db2gmtime($time));
     }
     
     function db_daydatetime($time) {
         global $cfg;
-        return Format::userdate($cfg->getDayDateTimeFormat(),Misc::db2gmtime($time));
+        return Format::userdate($cfg->getDayDateTimeFormat(), Misc::db2gmtime($time));
     }
 
-    function userdate($format,$gmtime) {
-        return Format::date($format,$gmtime,$_SESSION['TZ_OFFSET'],$_SESSION['TZ_DST']);
+    function userdate($format, $gmtime) {
+        return Format::date($format, $gmtime, $_SESSION['TZ_OFFSET'], $_SESSION['TZ_DST']);
     }
     
-    function date($format,$gmtimestamp,$offset=0,$daylight=false){
-        if(!$gmtimestamp || !is_numeric($gmtimestamp)) return ""; 
-       
-        $offset+=$daylight?date('I',$gmtimestamp):0; //Daylight savings crap.
-        return date($format,($gmtimestamp+($offset*3600)));
-    }
-                        
+    function date($format, $gmtimestamp, $offset=0, $daylight=false){
         
-
-    
+        if(!$gmtimestamp || !is_numeric($gmtimestamp))
+            return ""; 
+        
+        $offset+=$daylight?date('I', $gmtimestamp):0; //Daylight savings crap.
+        
+        return date($format, ($gmtimestamp+ ($offset*3600)));
+    }
+                      
 }
 ?>
diff --git a/include/class.misc.php b/include/class.misc.php
index 9fd6744ba8913061a5e34c2b10bf705216d286fa..8149a1fce37ea3a26106f6bb217d1c92cc17395e 100644
--- a/include/class.misc.php
+++ b/include/class.misc.php
@@ -35,7 +35,7 @@ class Misc {
         if(!$var) return;
         
         $dbtime=is_int($var)?$var:strtotime($var);
-        return $dbtime-($cfg->getMysqlTZoffset()*3600);
+        return $dbtime-($cfg->getDBTZoffset()*3600);
     }
 
     //Take user time or gmtime and return db (mysql) time.
@@ -50,7 +50,7 @@ class Misc {
             $time=$time-($offset*3600);
         }
         //gm to db time
-        return $time+($cfg->getMysqlTZoffset()*3600);
+        return $time+($cfg->getDBTZoffset()*3600);
     }
     
     /*Helper get GM time based on timezone offset*/
diff --git a/include/staff/settings-system.inc.php b/include/staff/settings-system.inc.php
index 1bc9b3ee4daf79688164593ca59daab8a1bb0ebc..3fba7f15977390d6882f00894523b90d92d4aced 100644
--- a/include/staff/settings-system.inc.php
+++ b/include/staff/settings-system.inc.php
@@ -45,7 +45,7 @@ $gmtime = Misc::gmtime();
                     <?php
                     $sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE.' WHERE ispublic=1';
                     if(($res=db_query($sql)) && db_num_rows($res)){
-                        while (list($id,$name) = db_fetch_row($res)){
+                        while (list($id, $name) = db_fetch_row($res)){
                             $selected = ($config['default_dept_id']==$id)?'selected="selected"':''; ?>
                             <option value="<?php echo $id; ?>"<?php echo $selected; ?>><?php echo $name; ?> Dept</option>
                         <?php
@@ -62,7 +62,7 @@ $gmtime = Misc::gmtime();
                     <?php
                     $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_TABLE.' WHERE isactive=1 AND cfg_id='.db_input($cfg->getId()).' ORDER BY name';
                     if(($res=db_query($sql)) && db_num_rows($res)){
-                        while (list($id,$name) = db_fetch_row($res)){
+                        while (list($id, $name) = db_fetch_row($res)){
                             $selected = ($config['default_template_id']==$id)?'selected="selected"':''; ?>
                             <option value="<?php echo $id; ?>"<?php echo $selected; ?>><?php echo $name; ?></option>
                         <?php
@@ -119,7 +119,7 @@ $gmtime = Misc::gmtime();
                   <?php
                     for ($i = 1; $i <= 12; $i++) {
                         echo sprintf('<option value="%d" %s>%s%s</option>',
-                                $i,(($config['passwd_reset_period']==$i)?'selected="selected"':''),$i>1?"Every $i ":'',$i>1?' Months':'Monthly');
+                                $i,(($config['passwd_reset_period']==$i)?'selected="selected"':''), $i>1?"Every $i ":'', $i>1?' Months':'Monthly');
                     }
                     ?>
                 </select>
@@ -137,14 +137,14 @@ $gmtime = Misc::gmtime();
                 <select name="staff_max_logins">
                   <?php
                     for ($i = 1; $i <= 10; $i++) {
-                        echo sprintf('<option value="%d" %s>%d</option>',$i,(($config['staff_max_logins']==$i)?'selected="selected"':''),$i);
+                        echo sprintf('<option value="%d" %s>%d</option>', $i,(($config['staff_max_logins']==$i)?'selected="selected"':''), $i);
                     }
                     ?>
                 </select> failed login attempt(s) allowed before a
                 <select name="staff_login_timeout">
                   <?php
                     for ($i = 1; $i <= 10; $i++) {
-                        echo sprintf('<option value="%d" %s>%d</option>',$i,(($config['staff_login_timeout']==$i)?'selected="selected"':''),$i);
+                        echo sprintf('<option value="%d" %s>%d</option>', $i,(($config['staff_login_timeout']==$i)?'selected="selected"':''), $i);
                     }
                     ?>
                 </select> minute lock-out is enforced.
@@ -161,7 +161,7 @@ $gmtime = Misc::gmtime();
                 <select name="client_max_logins">
                   <?php
                     for ($i = 1; $i <= 10; $i++) {
-                        echo sprintf('<option value="%d" %s>%d</option>',$i,(($config['client_max_logins']==$i)?'selected="selected"':''),$i);
+                        echo sprintf('<option value="%d" %s>%d</option>', $i,(($config['client_max_logins']==$i)?'selected="selected"':''), $i);
                     }
 
                     ?>
@@ -169,7 +169,7 @@ $gmtime = Misc::gmtime();
                 <select name="client_login_timeout">
                   <?php
                     for ($i = 1; $i <= 10; $i++) {
-                        echo sprintf('<option value="%d" %s>%d</option>',$i,(($config['client_login_timeout']==$i)?'selected="selected"':''),$i);
+                        echo sprintf('<option value="%d" %s>%d</option>', $i,(($config['client_login_timeout']==$i)?'selected="selected"':''), $i);
                     }
                     ?>
                 </select> minute lock-out is enforced. 
@@ -191,24 +191,24 @@ $gmtime = Misc::gmtime();
             <td>
                 <input type="text" name="time_format" value="<?php echo $config['time_format']; ?>">
                     &nbsp;<font class="error">*&nbsp;<?php echo $errors['time_format']; ?></font>
-                    <em><?php echo Format::date($config['time_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em></td>
+                    <em><?php echo Format::date($config['time_format'], $gmtime, $config['tz_offset'], $config['enable_daylight_saving']); ?></em></td>
         </tr>
         <tr><td width="220" class="required">Date Format:</td>
             <td><input type="text" name="date_format" value="<?php echo $config['date_format']; ?>">
                         &nbsp;<font class="error">*&nbsp;<?php echo $errors['date_format']; ?></font>
-                        <em><?php echo Format::date($config['date_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em>
+                        <em><?php echo Format::date($config['date_format'], $gmtime, $config['tz_offset'], $config['enable_daylight_saving']); ?></em>
             </td>
         </tr>
         <tr><td width="220" class="required">Date &amp; Time Format:</td>
             <td><input type="text" name="datetime_format" value="<?php echo $config['datetime_format']; ?>">
                         &nbsp;<font class="error">*&nbsp;<?php echo $errors['datetime_format']; ?></font>
-                        <em><?php echo Format::date($config['datetime_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em>
+                        <em><?php echo Format::date($config['datetime_format'], $gmtime, $config['tz_offset'], $config['enable_daylight_saving']); ?></em>
             </td>
         </tr>
         <tr><td width="220" class="required">Day, Date &amp; Time Format:</td>
             <td><input type="text" name="daydatetime_format" value="<?php echo $config['daydatetime_format']; ?>">
                         &nbsp;<font class="error">*&nbsp;<?php echo $errors['daydatetime_format']; ?></font>
-                        <em><?php echo Format::date($config['daydatetime_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em>
+                        <em><?php echo Format::date($config['daydatetime_format'], $gmtime, $config['tz_offset'], $config['enable_daylight_saving']); ?></em>
             </td>
         </tr>
         <tr><td width="220" class="required">Default Time Zone:</td>
@@ -218,9 +218,9 @@ $gmtime = Misc::gmtime();
                     <?php
                     $sql='SELECT id, offset,timezone FROM '.TIMEZONE_TABLE.' ORDER BY id';
                     if(($res=db_query($sql)) && db_num_rows($res)){
-                        while(list($id,$offset, $tz)=db_fetch_row($res)){
+                        while(list($id, $offset, $tz)=db_fetch_row($res)){
                             $sel=($config['default_timezone_id']==$id)?'selected="selected"':'';
-                            echo sprintf('<option value="%d" %s>GMT %s - %s</option>',$id,$sel,$offset,$tz);
+                            echo sprintf('<option value="%d" %s>GMT %s - %s</option>', $id, $sel, $offset, $tz);
                         }
                     }
                     ?>