--- windowslivemessenger.module	2009-01-15 12:30:26.000000000 +0000
+++ windowslivemessengerNew.module	2010-04-05 22:38:55.000000000 +0100
@@ -1,19 +1,19 @@
-<?php
-  // $Id: windowslivemessenger.module,v 1.1.4.2 2009/01/15 12:30:26 coworks Exp $
-  
-  /*
-   * @file
-   * Windows Live Chat in Drupal
-   */
-
-  /*
-   * Implemenation of hook_menu
-   */
-
-  /*
-   * Local includes
-   */
-  include_once(drupal_get_path('module', 'windowslivemessenger') .'/windowslivemessenger_theming.inc');
+<?php
+  // $Id: windowslivemessenger.module,v 1.1.4.2 2009/01/15 12:30:26 coworks Exp $
+
+  /*
+   * @file
+   * Windows Live Chat in Drupal
+   */
+
+  /*
+   * Implemenation of hook_menu
+   */
+
+  /*
+   * Local includes
+   */
+  include_once(drupal_get_path('module', 'windowslivemessenger') .'/windowslivemessenger_theming.inc');
 
   /*
    * Implementation of hook_help
@@ -29,411 +29,469 @@
         $helptext .= '<li>'. t('Copy the text string between invitee= & @apps.messenger...') .'</li>';
         $helptext .= '<li>'. t('Use this string in the administration add profile form of this module') .'</li>';
         $helptext .= '</ul>';
-        
+      
       break;
     }
-    
+  
     return $helptext;
   }
-  
+
   /*
    * Implementation of hook_menu
-   */
-  function windowslivemessenger_menu() {
-    $items = array();
-    
-    $items['admin/settings/windowslivemessenger'] = array(
-      'title' => 'Windows Live Messenger',
-      'description' => 'Create Windows Live Messenger profiles',
+   */
+  function windowslivemessenger_menu() {
+    $items = array();
+  
+    $items['admin/settings/windowslivemessenger'] = array(
+      'title' => 'Windows Live Messenger',
+      'description' => 'Create Windows Live Messenger profiles',
       'type' => MENU_NORMAL_ITEM,
-      'access arguments' => array('administer'),
-      'page callback' => 'windowslivemessenger_list_profiles',
-    );
-      
-    $items['admin/settings/windowslivemessenger/profiles'] = array(
-      'title' => 'Profiles',
+      'access arguments' => array('administer site configuration'),
+      'page callback' => 'windowslivemessenger_list_profiles',
+    );
+    
+    $items['admin/settings/windowslivemessenger/profiles'] = array(
+      'title' => 'Profiles',
+      'description' => 'Window Live Messenger Profiles',
       'type' => MENU_DEFAULT_LOCAL_TASK,
-      'access arguments' => array('administer'),
-      'page callback' => 'windowslivemessenger_list_profiles',
-    );
-      
-    $items['admin/settings/windowslivemessenger/addprofile'] = array(
-      'title' => 'Profile add',
-      'description' => 'Each profile will create a block',
+      'access arguments' => array('administer site configuration'),
+      'page callback' => 'windowslivemessenger_list_profiles',
+    );
+    
+    $items['admin/settings/windowslivemessenger/addprofile'] = array(
+      'title' => 'Profile add',
+      'description' => 'Each profile will create a block',
       'type' => MENU_LOCAL_TASK,
-      'access arguments' => array('administer'),
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('windowslivemessenger_addprofile_form'),
-    );
-      
-    $items['admin/settings/windowslivemessenger/editprofile/%'] = array(
+      'access arguments' => array('administer site configuration'),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('windowslivemessenger_addprofile_form'),
+    );
+    
+    $items['admin/settings/windowslivemessenger/editprofile/%'] = array(
       'title' => 'Profile edit',
-      'access arguments' => array('administer'),
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('windowslivemessenger_addprofile_form'),
-      'type' => MENU_CALLBACK,
-    );
-      
-    $items['admin/settings/windowslivemessenger/deleteprofile/%'] = array(
+      'access arguments' => array('administer site configuration'),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('windowslivemessenger_addprofile_form'),
+      'type' => MENU_CALLBACK,
+    );
+    
+    $items['admin/settings/windowslivemessenger/deleteprofile/%'] = array(
       'title' => 'Profile delete',
-      'access arguments' => array('administer'),
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('windowslivemessenger_deleteprofile_form'),
-      'type' => MENU_CALLBACK,
-    );
-
-    return $items;
-  }
-  
-  /*
-   * Callback list profiles
-   */
+      'access arguments' => array('administer site configuration'),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('windowslivemessenger_deleteprofile_form'),
+      'type' => MENU_CALLBACK,
+    );
+
+    return $items;
+  }
+
+  /*
+   * Callback list profiles
+   */
   function windowslivemessenger_list_profiles() {
-    $profiles = _windowslivemessenger_get_profiles();
+    $profiles = _windowslivemessenger_get_profiles();
+
+    $output = "";
+    $output = theme('profilelist_header');
 
-    $output = "";
-    $output = theme('profilelist_header');
-  
     foreach ($profiles as $profile) {
-      $output .= theme('profilelist_profile', array('id' => $profile->id, 'name' => $profile->name));
-    }
-    
-    $output .= theme('profilelist_footer');
-
-    return $output;
-  }
-  
-  /*
-   * Interal function to get the profiles
-   */
-  function _windowslivemessenger_get_profiles() {
-    $profiles = array();
-    
-    $dbprofiles = db_query("SELECT profile_id FROM {windowslivemessenger}");
-    
-    while ($dbprofile = db_fetch_object($dbprofiles)) {
-      $profile = _windowslivemessenger_load_profile($dbprofile->profile_id);
-      $profiles[] = $profile;
-    }
-    
-    return $profiles;
-  }
-  
-  /*
-   * Internal function to load the full profile
-   */
-  function _windowslivemessenger_load_profile($pid) {
-    $dbprofile = db_fetch_object(db_query("SELECT * FROM {windowslivemessenger} WHERE profile_id = %d", $pid));
-    $profile = new stdClass();
-    
-    $profile->id = $dbprofile->profile_id;
-    $profile->name = $dbprofile->profile_name;
-    $profile->liveid = $dbprofile->profile_liveid;
-    $profile->block = $dbprofile->profile_block;
-    $profile->block_style = $dbprofile->profile_block_style;
-    $profile->settings = unserialize($dbprofile->profile_settings);
-    
-    return $profile;
-  }
-  
-  /*
-   * Add profile form
-   */
-  function windowslivemessenger_addprofile_form() {
-    if (arg(3) == 'editprofile') {
-      $profile = _windowslivemessenger_load_profile(arg(4));
-    }
-    
-    //TODO Add link to help page
-    //Add the JS
-    drupal_add_js(drupal_get_path('module', 'windowslivemessenger') .'/js/windowslivemessenger_addprofile.js');
-    
-    $form = array();
-    
-    //Defaults for all
-    $form["name"] = array(
-      '#type' => 'textfield',
-      '#title' => t('Name'),
-      '#required' => TRUE,
-      '#default_value' => $profile->name,
-    );
-    
-    $form["liveid"] = array(
-      '#type' => 'textfield',
-      '#title' => t('Windows Live ID'),
-      '#description' => t('Read the help text on top how to get this ID'),
-      '#required' => TRUE,
-      '#default_value' => $profile->liveid,
-    );
-    
-    $form["block"] = array(
-      '#type' => 'radios',
-      '#title' => t('Block'),
-      '#options' => array(0 => t('Messenger Window'), 1 => t('Button'), 2 => t('Status')),
-      '#default_value' => ($profile->block != "")?$profile->block:0,
-      '#required' => TRUE,
-    );
-    
-    $form["block_style"] = array(
-      '#type' => 'radios',
-      '#title' => t('Block style'),
-      '#options' => array(0 => t('Use default style'), 1 => t('Create your own style')),
-      '#default_value' => ($profile->block_style != "")?$profile->block_style:0,
-      '#required' => TRUE,
-    );
-    
-    //Dependent on block_style
-    $form["block_size"] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Block size'),
-    );
-    
-    $form["block_size"]['window_width'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Size'),
-      '#size' => 20,
-      '#field_suffix' => 'px',
-      '#default_value' => (arg(3) == 'editprofile' && $profile->settings != FALSE)?$profile->settings['width']:300,
-    );
-    
-    $form["block_size"]["window_height"] = array(
-      '#type' => 'textfield',
-      '#title' => t('Height'),
-      '#size' => 20,
-      '#field_suffix' => 'px',
-      '#default_value' => (arg(3) == 'editprofile' && $profile->settings != FALSE)?$profile->settings['height']:300,
-    );
-    
-    //Color pallet
-    $arr_colors = array('foreColor', 'backColor', 'linkColor', 'borderColor', 'buttonForeColor', 'buttonBackColor', 'buttonBorderColor', 'buttonDisabledColor', 'headerForeColor', 'headerBackColor', 'menuForeColor', 'menuBackColor', 'chatForeColor', 'chatBackColor', 'chatDisabledColor', 'chatErrorColor', 'chatLabelColor', 'altBackColor');
-    $default_palette = _windowslivemessenger_default_palette();
-    
-    $form["colors"] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Color'),
-      '#theme' => 'windowslivemessenger_color_form',
-      '#attributes' => array('id' => 'msnlive_color_scheme_form'),
-    );
-    
-    foreach ($arr_colors as $color) {
-      $form["colors"]["window_" . $color] = array(
-        '#type' => 'textfield',
-        '#title' => t($color),
-        '#size' => 8,
-        '#default_value' => (arg(3) == 'editprofile' && isset($profile->settings["foreColor"]))?$profile->settings[$color]:$default_palette[$color],
-      );
-    }
-    
-    if (arg(3) == 'editprofile') {
-      $form["pid"] = array(
-        '#type' => 'hidden',
-        '#title' => t('Profile id'),
-        '#default_value' => arg(4),
-      );
-    }
-    
-    $form["submit"] = array(
-      '#type' => 'submit',
-      '#value' => (arg(3) != 'editprofile')?t('Add profile'):t('Edit profile'),
-    );
-    
-    return $form;
-  }
-  
-  /*
-   * Add profile form submit
-   */
+      $output .= theme('profilelist_profile', array('id' => $profile->id, 'name' => $profile->name));
+    }
+  
+    $output .= theme('profilelist_footer');
+
+    return $output;
+  }
+
+  /*
+   * Interal function to get the profiles
+   */
+  function _windowslivemessenger_get_profiles() {
+    $profiles = array();
+  
+    $dbprofiles = db_query("SELECT profile_id FROM {windowslivemessenger}");
+  
+    while ($dbprofile = db_fetch_object($dbprofiles)) {
+      $profile = _windowslivemessenger_load_profile($dbprofile->profile_id);
+      $profiles[] = $profile;
+    }
+  
+    return $profiles;
+  }
+
+  /*
+   * Internal function to load the full profile
+   */
+  function _windowslivemessenger_load_profile($pid) {
+    $dbprofile = db_fetch_object(db_query("SELECT * FROM {windowslivemessenger} WHERE profile_id = %d", $pid));
+    $profile = new stdClass();
+  
+    $profile->id = $dbprofile->profile_id;
+    $profile->name = $dbprofile->profile_name;
+    $profile->liveid = $dbprofile->profile_liveid;
+    $profile->block = $dbprofile->profile_block;
+    $profile->block_style = $dbprofile->profile_block_style;
+    $profile->settings = unserialize($dbprofile->profile_settings);
+  
+    return $profile;
+  }
+
+  /*
+   * Add profile form
+   */
+  function windowslivemessenger_addprofile_form() {
+    if (arg(3) == 'editprofile') {
+      $profile = _windowslivemessenger_load_profile(arg(4));
+    }
+  
+    // @todo Add link to help page
+    // Add the JS
+    drupal_add_js(drupal_get_path('module', 'windowslivemessenger') .'/js/windowslivemessenger_addprofile.js');
+  
+    $form = array();
+  
+    // Defaults for all
+    $form["name"] = array(
+      '#type' => 'textfield',
+      '#title' => t('Name'),
+      '#required' => TRUE,
+      '#default_value' => $profile->name,
+    );
+  
+    $form["liveid"] = array(
+      '#type' => 'textfield',
+      '#title' => t('Windows Live ID'),
+      '#description' => t('Read the help text on top how to get this ID'),
+      '#required' => TRUE,
+      '#default_value' => $profile->liveid,
+    );
+  
+    $form["block"] = array(
+      '#type' => 'radios',
+      '#title' => t('Block'),
+      '#options' => array(0 => t('Messenger Window'), 1 => t('Button'), 2 => t('Status')),
+      '#default_value' => ($profile->block != "")?$profile->block:0,
+      '#required' => TRUE,
+    );
+  
+    $form["block_style"] = array(
+      '#type' => 'radios',
+      '#title' => t('Block style'),
+      '#options' => array(0 => t('Use default style'), 1 => t('Create your own style')),
+      '#default_value' => ($profile->block_style != "")?$profile->block_style:0,
+      '#required' => TRUE,
+    );
+  
+    // Dependent on block_style
+    $form["block_size"] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Block size'),
+    );
+  
+    $form["block_size"]['window_width'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Size'),
+      '#size' => 20,
+      '#field_suffix' => 'px',
+      '#default_value' => (arg(3) == 'editprofile' && $profile->settings != FALSE)?$profile->settings['width']:300,
+    );
+  
+    $form["block_size"]["window_height"] = array(
+      '#type' => 'textfield',
+      '#title' => t('Height'),
+      '#size' => 20,
+      '#field_suffix' => 'px',
+      '#default_value' => (arg(3) == 'editprofile' && $profile->settings != FALSE)?$profile->settings['height']:300,
+    );
+  
+    // Color pallet
+    $arr_colors = array('foreColor', 'backColor', 'linkColor', 'borderColor', 'buttonForeColor', 'buttonBackColor', 'buttonBorderColor', 'buttonDisabledColor', 'headerForeColor', 'headerBackColor', 'menuForeColor', 'menuBackColor', 'chatForeColor', 'chatBackColor', 'chatDisabledColor', 'chatErrorColor', 'chatLabelColor', 'altBackColor');
+    $default_palette = _windowslivemessenger_default_palette();
+  
+    $form["colors"] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Color'),
+      '#theme' => 'windowslivemessenger_color_form',
+      '#attributes' => array('id' => 'msnlive_color_scheme_form'),
+    );
+  
+    foreach ($arr_colors as $color) {
+      $form["colors"]["window_" . $color] = array(
+        '#type' => 'textfield',
+        '#title' => t($color),
+        '#size' => 8,
+        '#default_value' => (arg(3) == 'editprofile' && isset($profile->settings["foreColor"]))?$profile->settings[$color]:$default_palette[$color],
+      );
+    }
+
+    // @see http://msdn.microsoft.com/en-us/library/cc742832.aspx for supported Culture ID's
+    $form['language'] = array(
+      '#type' => 'select',
+      '#title' => t('Language'),
+      '#default_value' => (arg(3) == 'editprofile' && $profile->settings != FALSE)?$profile->settings['language']:'en',
+      '#options' => array(
+        'ar' => t('Arabic'),
+        'eu' => t('Basque'),
+        'bg' => t('Bulgarian'),
+        'ca' => t('Catalan'),
+        'zh-CN' => t('Chinese (Simplified)'),
+        'zh-TW' => t('Chinese (Traditional)'),
+        'hr' => t('Croatian'),
+        'cs' => t('Czech'),
+        'da' => t('Danish'),
+        'nl' => t('Dutch'),
+        'en' => t('English'),
+        'et' => t('Estonian'),
+        'fi' => t('Finnish'),
+        'fr' => t('French'),
+        'de' => t('German'),
+        'el' => t('Greek'),
+        'gu' => t('Gujarati'),
+        'he' => t('Hebrew'),
+        'hi' => t('Hindi'),
+        'hu' => t('Hungarian'),
+        'id' => t('Indonesian'),
+        'it' => t('Italian'),
+        'ja' => t('Japanese'),
+        'kn' => t('Kannada'),
+        'ko' => t('Korean'),
+        'lt' => t('Lithuanian'),
+        'lv' => t('Latvian'),
+        'ml' => t('Malayalam'),
+        'mr' => t('Marathi'),
+        'ms' => t('Malay'),
+        'no' => t('Norwegian (Bokml)'),
+        'pl' => t('Polish'),
+        'pt-BR' => t('Portuguese (Brazilian)'),
+        'pt-PT' => t('Portuguese (Portugal)'),
+        'ro' => t('Romanian'),
+        'ru' => t('Russian'),
+        'sr-cyrl' => t('Serbian - Cyrillic'),
+        'sr-latn' => t('Serbian - Latin'),
+        'sk' => t('Slovak'),
+        'sl' => t('Slovenian'),
+        'es' => t('Spanish'),
+        'sv' => t('Swedish'),
+        'ta' => t('Tamil'),
+        'te' => t('Telugu'),
+        'th' => t('Thai'),
+        'tr' => t('Turkish'),
+        'uk' => t('Ukrainian'),
+        'vi' => t('Vietnamese'),
+      ),
+      '#description' => t('Interface language for Windows Live Messenger'),
+    );
+
+    if (arg(3) == 'editprofile') {
+      $form["pid"] = array(
+        '#type' => 'hidden',
+        '#title' => t('Profile id'),
+        '#default_value' => arg(4),
+      );
+    }
+  
+    $form["submit"] = array(
+      '#type' => 'submit',
+      '#value' => (arg(3) != 'editprofile')?t('Add profile'):t('Edit profile'),
+    );
+  
+    return $form;
+  }
+
+  /*
+   * Add profile form submit
+   */
   function windowslivemessenger_addprofile_form_submit($form, &$form_state) {
-    //Handle the settings
-    $settings = "";
-
-    if ($form_state['values']["block_style"] == 1 || $form_state['values']["block"] == 1) {
-      $arr_settings = array();
-      
-      foreach ($form_state['values'] as $setting => $value) {
-        if (ereg("window_", $setting)) {
-          $setting = substr($setting, strpos($setting, "_") + 1);
-          $arr_settings[$setting] = $value;
-        }
-      }
-      
-      $settings = serialize($arr_settings);
-    }
-
-    $arr_settings["width"] = $form_state['values']["window_width"];
-    $arr_settings["height"] = $form_state['values']["window_height"];
-      
-    $settings = serialize($arr_settings);
-    
-    if (arg(3) != 'editprofile') {
-      //Save the new block
-      db_query("INSERT INTO {windowslivemessenger} (profile_name, profile_liveid, profile_block, profile_block_style, profile_settings) VALUES ('%s', '%s', '%s', '%s', '%s')", $form_state['values']["name"], $form_state['values']["liveid"], $form_state['values']["block"], $form_state['values']["block_style"], $settings);
+    // Handle the settings
+    $settings = "";
+
+    if ($form_state['values']["block_style"] == 1 || $form_state['values']["block"] == 1) {
+      $arr_settings = array();
+    
+      foreach ($form_state['values'] as $setting => $value) {
+        if (ereg("window_", $setting)) {
+          $setting = substr($setting, strpos($setting, "_") + 1);
+          $arr_settings[$setting] = $value;
+        }
+      }
+    
+      $settings = serialize($arr_settings);
+    }
+
+    $arr_settings["width"] = $form_state['values']["window_width"];
+    $arr_settings["height"] = $form_state['values']["window_height"];
+    $arr_settings["language"] = $form_state['values']["language"];
+    
+    $settings = serialize($arr_settings);
+  
+    if (arg(3) != 'editprofile') {
+      // Save the new block
+      db_query("INSERT INTO {windowslivemessenger} (profile_name, profile_liveid, profile_block, profile_block_style, profile_settings) VALUES ('%s', '%s', '%s', '%s', '%s')", $form_state['values']["name"], $form_state['values']["liveid"], $form_state['values']["block"], $form_state['values']["block_style"], $settings);
     } 
-    else {
-      //Update the block
-      db_query("UPDATE {windowslivemessenger} SET profile_name = '%s', profile_liveid = '%s', profile_block = '%s', profile_block_style = '%s', profile_settings = '%s' WHERE profile_id = %d", $form_state['values']["name"], $form_state['values']["liveid"], $form_state['values']["block"], $form_state['values']["block_style"], $settings, $form_state['values']["pid"]);
-    }
-  }
-  
-  /*
-   * Delete profile form
-   */
-  function windowslivemessenger_deleteprofile_form() {
-    $form = array();
-    
-    $form["yes"] = array(
-      '#type' => 'submit',
-      '#value' => t('Yes'),
-      '#suffix' => '<input type="button" value="'. t('No') .'" onclick="window.location.href=\'' . base_path() . 'admin/settings/windowslivemessenger\';" />',
-    );
-    
-    return $form;
-  }
-  
-  /*
-   * Delete profile form submit
-   */
-  function windowslivemessenger_deleteprofile_form_submit($form, &$form_state) {
-    $pid = arg(4);
-    
-    db_query("DELETE FROM {windowslivemessenger} WHERE profile_id = %d", $pid);
-    drupal_set_message(t('Profile was deleted.'));
-    drupal_goto('admin/settings/windowslivemessenger');
-  }
-
-  /*
-   * Implementation of hook_block
-   */
-  function windowslivemessenger_block($op = 'list', $delta = 0, $edit = array()) {
-    switch ($op) {
-      case 'list':
-        $profiles = _windowslivemessenger_get_profiles();
-        
-        if (count($profiles) != 0) {
-          $blocks = array();
-          
-          foreach ($profiles as $profile) {
-            $blocks[] = array(
-              'info' => t('Windows Live Messenger ') . $profile->name,
-            );
-          }
-          
-          return $blocks;
-        }
-        break;
-      
-      case 'save':
-        variable_set('windowslivemessenger_liveid', $edit['liveid']);
-        variable_set('windowslivemessenger_blockstyle', $edit['blockstyle']);
-        
-        //colors        
-        variable_set('msnlive_colors', $edit['msnlive_colors']);
-        variable_set('msnlive_color_type', $edit['msnlive_color_type']);        
-        
-        break;
-      case 'view':
-        $profiles = _windowslivemessenger_get_profiles();
-        $profile = $profiles[$delta];
-
-        return array(
-          'subject' => t('Windows Live Messenger'),
-          'content' => _windowslivemessenger_generate_code($profile),
-        );
-
-        break;
-    }
-  }
-  
-  /*
-   * Internal function which generates the code
-   */
-  function _windowslivemessenger_generate_code($profile) {
-    switch ($profile->block) {
-      case 0:
-        if ($profile->block_style == 0) {
-          return _windowslivemessenger_get_code('window_default', $profile);
+    else {
+      // Update the block
+      db_query("UPDATE {windowslivemessenger} SET profile_name = '%s', profile_liveid = '%s', profile_block = '%s', profile_block_style = '%s', profile_settings = '%s' WHERE profile_id = %d", $form_state['values']["name"], $form_state['values']["liveid"], $form_state['values']["block"], $form_state['values']["block_style"], $settings, $form_state['values']["pid"]);
+    }
+  }
+
+  /*
+   * Delete profile form
+   */
+  function windowslivemessenger_deleteprofile_form() {
+    $form = array();
+  
+    $form["yes"] = array(
+      '#type' => 'submit',
+      '#value' => t('Yes'),
+      '#suffix' => '<input type="button" value="'. t('No') .'" onclick="window.location.href=\'' . base_path() . 'admin/settings/windowslivemessenger\';" />',
+    );
+  
+    return $form;
+  }
+
+  /*
+   * Delete profile form submit
+   */
+  function windowslivemessenger_deleteprofile_form_submit($form, &$form_state) {
+    $pid = arg(4);
+  
+    db_query("DELETE FROM {windowslivemessenger} WHERE profile_id = %d", $pid);
+    drupal_set_message(t('Profile was deleted.'));
+    drupal_goto('admin/settings/windowslivemessenger');
+  }
+
+  /*
+   * Implementation of hook_block
+   */
+  function windowslivemessenger_block($op = 'list', $delta = 0, $edit = array()) {
+    switch ($op) {
+      case 'list':
+        $profiles = _windowslivemessenger_get_profiles();
+      
+        if (count($profiles) != 0) {
+          $blocks = array();
+        
+          foreach ($profiles as $profile) {
+            $blocks[] = array(
+              'info' => t('Windows Live Messenger ') . $profile->name,
+            );
+          }
+        
+          return $blocks;
+        }
+        break;
+    
+      case 'save':
+        variable_set('windowslivemessenger_liveid', $edit['liveid']);
+        variable_set('windowslivemessenger_blockstyle', $edit['blockstyle']);
+      
+        // colors        
+        variable_set('msnlive_colors', $edit['msnlive_colors']);
+        variable_set('msnlive_color_type', $edit['msnlive_color_type']);        
+      
+        break;
+      case 'view':
+        $profiles = _windowslivemessenger_get_profiles();
+        $profile = $profiles[$delta];
+
+        return array(
+          'subject' => t('Windows Live Messenger'),
+          'content' => _windowslivemessenger_generate_code($profile),
+        );
+
+        break;
+    }
+  }
+
+  /*
+   * Internal function which generates the code
+   */
+  function _windowslivemessenger_generate_code($profile) {
+    switch ($profile->block) {
+      case 0:
+        if ($profile->block_style == 0) {
+          return _windowslivemessenger_get_code('window_default', $profile);
         } 
-        else {
-          return _windowslivemessenger_get_code('window_custom', $profile);
-        }
-        break;
-        
-      case 1:
-        if ($profile->block_style == 0) {
-          return _windowslivemessenger_get_code('button_default', $profile);
+        else {
+          return _windowslivemessenger_get_code('window_custom', $profile);
+        }
+        break;
+      
+      case 1:
+        if ($profile->block_style == 0) {
+          return _windowslivemessenger_get_code('button_default', $profile);
         } 
-        else {
-          return _windowslivemessenger_get_code('button_custom', $profile);
-        }
-        break;
-        
-      case 2:
-        if ($profile->block_style == 0) {
-          return _windowslivemessenger_get_code('status_default', $profile);
+        else {
+          return _windowslivemessenger_get_code('button_custom', $profile);
+        }
+        break;
+      
+      case 2:
+        if ($profile->block_style == 0) {
+          return _windowslivemessenger_get_code('status_default', $profile);
         } 
-        else {
-          return _windowslivemessenger_get_code('status_custom', $profile);
-        }
-        break;
-    }
-  }
-  
-  /*
-   * Internal function with the default color palette
-   */
-  function _windowslivemessenger_default_palette() {
-    $default_palette = array();
-    
-    $default_palette['foreColor'] = '#333333';
-    $default_palette['backColor'] = '#E8F1F8';
-    $default_palette['linkColor'] = '#333333';
-    $default_palette['borderColor'] = '#AFD3EB';
-    $default_palette['buttonForeColor'] = '#333333';
-    $default_palette['buttonBackColor'] = '#EEF7FE';
-    $default_palette['buttonBorderColor'] = '#AFD3EB';
-    $default_palette['buttonDisabledColor'] = '#EEF7FE';
-    $default_palette['headerForeColor'] = '#0066A7';
-    $default_palette['headerBackColor'] = '#8EBBD8';
-    $default_palette['menuForeColor'] = '#333333';
-    $default_palette['menuBackColor'] = '#FFFFFF';
-    $default_palette['chatForeColor'] = '#333333';
-    $default_palette['chatBackColor'] = '#FFFFFF';
-    $default_palette['chatDisabledColor'] = '#F6F6F6';
-    $default_palette['chatErrorColor'] = '#760502';
-    $default_palette['chatLabelColor'] = '#6E6C6C';
-    $default_palette['altBackColor'] = '#FFFFFF';
-    
-    return $default_palette;
-  }
-  
-  /*
-   * Internal function which gets the code
-   */
-  function _windowslivemessenger_get_code($code, &$profile) {
-    $code = $code .'.source';
-    
-    $fp = fopen(drupal_get_path('module', 'windowslivemessenger') .'/codes/'. $code, 'r');
-
-    $script = "";
-    
-    while (!feof($fp)) {
-      $script .= fread($fp, 1024);
-    }
-    
-    fclose($fp);
-    
-    //Token replace
-    $script = str_replace('[liveid]', $profile->liveid, $script);
-    
-    if ($profile->settings != FALSE) {
-      foreach ($profile->settings as $token => $value) {
-        $script = str_replace('['. $token .']', str_replace('#', '', $value), $script);
-      }
-    }
-    
-    return $script;
+        else {
+          return _windowslivemessenger_get_code('status_custom', $profile);
+        }
+        break;
+    }
+  }
+
+  /*
+   * Internal function with the default color palette
+   */
+  function _windowslivemessenger_default_palette() {
+    $default_palette = array();
+  
+    $default_palette['foreColor'] = '#333333';
+    $default_palette['backColor'] = '#E8F1F8';
+    $default_palette['linkColor'] = '#333333';
+    $default_palette['borderColor'] = '#AFD3EB';
+    $default_palette['buttonForeColor'] = '#333333';
+    $default_palette['buttonBackColor'] = '#EEF7FE';
+    $default_palette['buttonBorderColor'] = '#AFD3EB';
+    $default_palette['buttonDisabledColor'] = '#EEF7FE';
+    $default_palette['headerForeColor'] = '#0066A7';
+    $default_palette['headerBackColor'] = '#8EBBD8';
+    $default_palette['menuForeColor'] = '#333333';
+    $default_palette['menuBackColor'] = '#FFFFFF';
+    $default_palette['chatForeColor'] = '#333333';
+    $default_palette['chatBackColor'] = '#FFFFFF';
+    $default_palette['chatDisabledColor'] = '#F6F6F6';
+    $default_palette['chatErrorColor'] = '#760502';
+    $default_palette['chatLabelColor'] = '#6E6C6C';
+    $default_palette['altBackColor'] = '#FFFFFF';
+  
+    return $default_palette;
   }
+
+  /*
+   * Internal function which gets the code
+   */
+  function _windowslivemessenger_get_code($code, &$profile) {
+    $code = $code .'.source';
   
+    $fp = fopen(drupal_get_path('module', 'windowslivemessenger') .'/codes/'. $code, 'r');
+
+    $script = "";
+  
+    while (!feof($fp)) {
+      $script .= fread($fp, 1024);
+    }
+  
+    fclose($fp);
+    // Token replace
+    $script = str_replace('[liveid]', $profile->liveid, $script);
+  
+    if ($profile->settings != FALSE) {
+      foreach ($profile->settings as $token => $value) {
+        $script = str_replace('['. $token .']', str_replace('#', '', $value), $script);
+      }
+    }
+    return $script;
+  }
+
   /*
    * Implementation of hook_theme
    */
@@ -452,4 +510,4 @@
         'arguments' => array('form' => NULL),
       ),
     );
-  }
\ No newline at end of file
+  }
