/**
 * Helper functions to handle upload of image via html
 */

// ecard object ID
var ecardObjectID = null;
// handle of popup window
var ecardPopup = null;
// name to return to flash
var ecardDisplayName = '';
// url to return to flash
var ecardImageUrl = '';

/**
 * Used by flash to detect ecardPopup support
 */
function ecardPopupSupport()
{
  return true;
}

/**
 * This function is called by flash to show upload popup.
 *
 * @param string anObjectID - id of flash object calling this function
 */
function ecardShowPopup(anObjectID)
{
  // store id
  ecardObjectID = anObjectID;
  // create window
  ecardPopup = window.open("/ecard/ecardpopup.php", "ecardpopup", "status=0,statusbar=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=0,height=250,width=350");
  // focus it
  ecardPopup.focus();
}

/**
 * Helper function get movie object
 */
function ecardGetMovie(aMovieName) 
{
  return navigator.appName.indexOf("Microsoft") != -1 ? window[aMovieName] : document[aMovieName];
}

/**
 * This function is called by the popup window when it gets closed
 *
 * @param aDisplayName - non empty: name of image, empty: user cancelled
 * @param anImageUrl - non empty: url of image, empty: user cancelled
 */
function ecardClosingPopup(aDisplayName, anImageUrl)
{
  // copy to global vars
  ecardDisplayName = aDisplayName;
  ecardImageUrl = anImageUrl;
  // popup may still not be closed, wait 250ms before checking if it is
  setTimeout("ecardCloseCheck()", 250);
}

/**
 * This method gets called some miliseconds after ecardClosingPopup, so the popup has time to close completly
 *
 * @param aDisplayName - non empty: name of image, empty: user cancelled
 * @param anImageUrl - non empty: url of image, empty: user cancelled
 */
function ecardCloseCheck()
{
  if (ecardPopup.closed) ecardGetMovie(ecardObjectID).closePopup(ecardDisplayName, ecardImageUrl);
}
