// Message Functions
function doVideo(mediaId, userId, thumbnail, description) {
  var indx = lastFormIndex(document);

  document.forms[indx].launchPage.value  = 0; 

  if ((mediaId == "") || (userId == "")) {
    document.forms[indx].MediaOptOut.value = 1; 
    document.forms[indx].MediaId.value     = "";
    document.forms[indx].MediaUser.value   = "";
    document.forms[indx].submit(); 
    return false;
  }

  document.forms[indx].MediaId.value        = mediaId;
  document.forms[indx].MediaUser.value      = userId;
  document.forms[indx].MediaThumbUrl.value  = thumbnail;
  document.forms[indx].MediaThumbDesc.value = description;
  document.forms[indx].submit(); 
}

function doPhotos(thumburl, playurl, registerurl, saveimages, numattach) {
  var indx = lastFormIndex(document);

  document.forms[indx].launchPage.value  = 0;

  if (playurl == "") {
    document.forms[indx].MediaOptOut.value  = 1;
    document.forms[indx].MediaPlayUrl.value = "";
    document.forms[indx].submit();
    return false;
  }
 
  document.forms[indx].MediaThumbUrl.value     = thumburl;
  document.forms[indx].MediaPlayUrl.value      = playurl;
  document.forms[indx].MediaRegisterUrl.value  = registerurl;
  document.forms[indx].MediaSave.value         = saveimages;
  document.forms[indx].MediaNumAttach.value    = numattach;
  document.forms[indx].submit(); 
}

function gotoMedia(purl, width, height) {

  if (FocusPopup("MediaPopup")) return;

  // figure out which media provider to goto based on purl

  if (purl == "video") {
    width   = 670;
    height  = 700;
//    mediaStr = "http://" + location.host + "/test/video.html?A=B";
    mediaStr = "http://" + location.host + "/cgi-bin/vsselectvideo";
  }
  else if (purl == "photo") {
    if (!width)
      width = 515;
    if (!height)
      height = 430;
    mediaStr = "http://webshots.bluemountain.com/scripts/chooser_tester.fcgi?mode=chooser&MAX_X_SIZE=800&MAX_Y_SIZE=600&MAX_COUNT=4&COBRAND=BMA&THUMBNAIL_X_SIZE=100&THUMBNAIL_Y_SIZE=100";
  }
  else {
    width    = 200;
    height   = 200;
    mediaStr = "http://" + location.host + "/test/none.html";
  }

  // open it up
  newWin = window.open(mediaStr,
                       "MediaPopup", 
                       "height=" + height + ",width=" + width +                                        
                       ",hotkeys,dependent");
  AddPopup("MediaPopup",newWin);
  FocusPopup("MediaPopup");
}
 
function playVideo(mediaId, userId) {
  var playerUrl = "http://" + location.host + "/cgi-bin/vsviewattach";
 
  playerUrl += "?m=" + mediaId + "&u=" + userId;

  // open up video attachment player
  if (FocusPopup("VideoPopup")) return;
  newWin = window.open(playerUrl,"VideoPopup","height=600,width=650,hotkeys,dependent");
  AddPopup("VideoPopup",newWin);
  FocusPopup("VideoPopup");
}
 
function playPhoto(playUrl) {
  // open up photo attachment player
  if (FocusPopup("PhotoPopup")) return;
  newWin = window.open(playUrl,"PhotoPopup","height=430,width=515,hotkeys,dependent");
  AddPopup("PhotoPopup",newWin);
  FocusPopup("PhotoPopup");
}
 
function successPopup(url, height, width) {
  // open media popup on success page
  if (FocusPopup("SuccessPopup")) return;
  newWin = window.open(url,
                       "SuccessPopup",
                       "height=" + height + ",width=" + width +
                       ",hotkeys,dependent");
  AddPopup("SuccessPopup",newWin);
  FocusPopup("SuccessPopup");
}
