document.observe("dom:loaded", add_visual_effects);

function add_visual_effects() { // {{{
  // Clicking the "Change Plan" image toggles the corresponding lightbox and upgrade/downgrade confirmation.
  set_onclick_events_for_changing_plans();

  // Clicking these radio buttons toggles the visibility of the "DivBlackBerry" and "DivOtherPhones" elements.
  $('ctl00_ContentBody_BlackberryYes' ).onclick = function() {user_has_a_blackberry();}
  $('ctl00_ContentBody_BlackberryNo'  ).onclick = function() {user_doesnt_have_a_blackberry();}

  // Clicking this checkbox toggles the BlackBerry service.
  $('ctl00_ContentBody_BlackberryAddOn').onclick = function() {toggle_showing_blackberry_service();}

  // Clicking these radio buttons displays the ChangePlan lightbox and the "upgrade" or "downgrade" explanation div.
  if ($('ctl00_ContentBody_OutlookYes') && $('ctl00_ContentBody_OutlookNo')) {
      $('ctl00_ContentBody_OutlookYes').onclick = function() {confirm_upgrade_to_mobile_email_pro_trial_plan();}
      $('ctl00_ContentBody_OutlookNo' ).onclick = function() {confirm_downgrade_to_mobile_email_trial_plan();}
  }

  // Show and hide the password and email address tooltips.
  add_blinding_to_form_field('ctl00_ContentBody_ExchangeSignup1_Password',      'Password_Tooltip');
  add_blinding_to_form_field('ctl00_ContentBody_ExchangeSignup1_EmailAddress',  'EmailAddress_Tooltip');

  // When the email address input field loses focus:
  //  * Hide the email address tooltip;
  //  * Check if the username is available.
  $('ctl00_ContentBody_ExchangeSignup1_EmailAddress').onblur = function() {
    if ($('EmailAddress_Tooltip').visible())
      {Effect.BlindUp('EmailAddress_Tooltip', {duration: blind_duration});}

    check_username();
  }

  // In the "choose-plan" div, show details about whichever plan is chosen.
  $(get_chosen_plan()).show();
} // }}}

/* function user_has_a_blackberry() {{{
*
* Description:
*  If the "DivBlackBerry" element is hidden, it's shown, and the "DivOtherPhones" element is hidden.
*
* Arguments:
*  None
*
* Returns:
*  Nothing
*
*/
function user_has_a_blackberry() {
  if ($('DivBlackBerry').style.display == 'none')
    {hide_and_show_with_blind('DivOtherPhones', 'DivBlackBerry');}
} // }}}

/* function user_doesnt_have_a_blackberry() {{{
*
* Description:
*  If the "DivOtherPhones" element is hidden, it's shown, and the "DivBlackBerry" element is hidden.
*
* Arguments:
*  None
*
* Returns:
*  Nothing
*
*/
function user_doesnt_have_a_blackberry() {
  // If the "DivBlackBerry" div isn't visible, do nothing because the user is clicking the "No" radio button repeatedly.
  if ($('DivOtherPhones').visible())
    {return;}

  // If the user has checked the BlackBerry Add-On checkbox, uncheck it and display a notification.
  if ($('ctl00_ContentBody_BlackberryAddOn').checked)
    {toggle_showing_blackberry_service();}

  hide_and_show_with_blind('DivBlackBerry', 'DivOtherPhones');
  hide_blackberry_service();
} // }}}

/* function hide_blackberry_service() {{{
*
* Description:
*  Hides the BlackBerry service in the "chosen plans" div.
*
* Arguments:
*  None
*
* Returns:
*  Nothing
*
*/
function hide_blackberry_service() {
    var blackberry_service_div = $('mail2web-blackberry-service');

    if (blackberry_service_div.visible())
      {Effect.BlindUp(blackberry_service_div, {duration: blind_duration});}

    $('ctl00_ContentBody_BlackberryAddOn').checked = false;
} // }}}

/* function toggle_showing_blackberry_service() {{{
*
* Description:
*  Toggles showing and hiding the BlackBerry service in the "chosen plans" div,
*  and showing a notification message.
*
* Arguments:
*  None
*
* Returns:
*  Nothing
*
*/
function toggle_showing_blackberry_service() {
  var blackberry_service_div = $('mail2web-blackberry-service');

  if (blackberry_service_div.visible()) {
    Effect.BlindUp(blackberry_service_div, { duration: blind_duration });
    show_notification('removed BlackBerry');
  }
  else {
    Effect.BlindDown(blackberry_service_div, { duration: blind_duration });
    show_notification('added BlackBerry');
  }
} // }}}


