/**
 ******************************************************************************
 * Copyright © 2007 EMC Corporation.  All Rights Reserved.
 ******************************************************************************
 *
 * Project        WDK
 * File           inlinerequestcallbacks.js
 * Description    WDK Inline Request Callback Functions
 * Created on     January 11, 2007
 * Tab width      3
 *
 ******************************************************************************
 *
 * PVCS Maintained Data
 *
 * Revision       $Revision: 5$
 * Modified on    $Date: 5/12/2008 3:42:00 AM$
 *
 * Log at EOF
 *
 ******************************************************************************
 */

/**
 * Callback for addtofavorites (inline) action
 *
 * @param data    results from the action execution
 */
function onAddToFavorites(data)
{
   for (var i = 0; i < data.length; i++)
   {
      var completionMap = data[i];
      var title = completionMap["title"];
      var drl = completionMap["drl"];

      addToFavorites(title, drl, false);
   }
}

/**
 * Invoke the native browser Add Favorite dialog
 *
 * @param title            the title for the bookmark
 * @param url              the URL to be bookmarked
 * @param isTitleEncoded   True if title that is passed in is Base64-encoded.
 */
function addToFavorites(title, url, isTitleEncoded)
{  
   var decodedTitle = title;
   if (isTitleEncoded)
   {
      decodedTitle = Base64.decode(title);
   }
   if (g_clientInfo.isBrowser(ClientInfo.FIREFOX))
   {
      window.sidebar.addPanel(decodedTitle, url, "");
   }
   else if (g_clientInfo.isBrowser(ClientInfo.MSIE))
   {
   if(isModalPopup())
   {
      window.getWindowOpener().external.AddFavorite(url, decodedTitle);
   }
      else
   {
      window.external.AddFavorite(url, decodedTitle);
   }
   }
}

/*
 * Register the handler to be called in accessible mode.
*/

if (typeof(g_include_addToFavorites) == "undefined")
{
   g_include_addToFavorites = true;
   registerClientEventHandler(null, "addtobrowserfavorites", addToBrowserFavorites);
}

/**
 * Callback for addtofavorites action
 *
 * @param data    results from the action execution
 */
function addToBrowserFavorites(title, url)
{
   addToFavorites(title, url, false);
}


