//sniffer.js MUST be called before this
//updcookie.js MUST be called before this
//appletupload.js must be included

var updcookie = new UPDCookie();
function reloadPage() {
  window.location.reload();
}
function postVideoInfo(streamName, streamLength) {
  //alert("postVideoInfo: " + streamName + " " + streamLength);
  document.getElementById("pn1659").value = streamName;
  document.getElementById("pn1660").value = streamLength;
  setMyCookie();
}
function recordingDisabled() {
  featureDisabled('Record a Video');
}
function uploadPhotoDisabled() {
  featureDisabled('Upload a Photo');
}
function uploadVideoDisabled() {
  featureDisabled('Upload a Video');
}
function featureDisabled(feature) {
  alert("The " + feature + " feature is unavailable at this time. Please check back at a later time.");
}
function swfMusicOn() {
  if (document.getElementById("pnMusicOn")) {
    document.getElementById("pnMusicOn").value = 1;
    setMyCookie();
  }
}
function swfMusicOff() {
  if (document.getElementById("pnMusicOn")) {
    document.getElementById("pnMusicOn").value = 0;
    setMyCookie();
  }
}
function setMyCookie() {
  if (document.getElementById("paidmbr").value == "false") {
    updcookie.setPVCookie(document.getElementById('pn1658').value, document.getElementById('pn1657').value, document.getElementById("pn1659").value, document.getElementById("pn1660").value, document.getElementById("pnMusicIdx").value, document.getElementById("pnMusicOn").value);
  }
}
//constructor for PhotoVideo object 

function PhotoVideo(ahost, khost, imghost, phost, sg, photoMaxW, photoMaxH, vPath, env, ihostau) {
  this.ahost = ahost;
  this.khost = khost;
  this.imghost = imghost;
  this.phost = phost;
  this.sg = sg;
  this.photoMaxW = photoMaxW;
  this.photoMaxH = photoMaxH;
  this.vPath = vPath;
  this.env = env;
  this.ihostau = ihostau; 
  this.orientation = "landscape";
  this.crusherPlugin = null;
  this.applet = null;
  this.atxCrusherHTML = '<object id="crusher" style="visibility: hidden;" hspace="0" vspace="0" border="0" width="100" height="100" classid="clsid:BD8667B7-38D8-4C77-B580-18C3E146372C" codebase="'+imghost+'/cp/install/Crusher.cab#version=1,0,0,10" viewastext></object>';
  this.vdCrusherPlugin = null;
  this.blnPaidUser = false;
  this.uploadHtml1 = "";
  this.uploadHtml2a = "";
  this.uploadHtml2b = "";
  this.uploadVideoHtml1 = "";
  this.uploadVideoHtml2a = "";
  this.uploadVideoHtml2b = "";
  this.clicked = false;
  this.uplVDClicked = false;
  this.uploadPhotoOn = true;
  this.recordVideoOn = true;
  this.uploadVideoOn = true;
  this.uploadOption = "both";
  this.flashMusicCtrl = null;
  this.musicPath = null;
  this.musicName = 'nomusic';
  this.musicOn = 'no';
  this.musicCtrlColor = null;
  this.frameBGColor = null;
  this.frameTextColor = null;
  this.videoFileInputHtml = ''; 
  this.photoFileInputHtml = ''; 
  return this;
}

PhotoVideo.prototype.mouseOverVideoTab = function() {
  document.getElementById("addvideotab").src = this.imghost + "/" + this.sg + "/title_video_f2.gif";
};

PhotoVideo.prototype.mouseOutVideoTab = function() {
  document.getElementById("addvideotab").src = this.imghost + "/" + this.sg + "/title_video_f1.gif";
};

PhotoVideo.prototype.mouseOverPhotoTab = function() {
  document.getElementById("addphototab").src = this.imghost + "/" + this.sg + "/title_photo_f2.gif";
};

PhotoVideo.prototype.mouseOutPhotoTab = function() {
  document.getElementById("addphototab").src = this.imghost + "/" + this.sg + "/title_photo_f1.gif";
};

PhotoVideo.prototype.showNoRightMsg = function(what) {
  alert("You must own the rights to your uploaded " + what + " and agree to our terms of service to send this eCard."); 
};
PhotoVideo.prototype.showWithoutPhotoOrVideoMsg = function() {
  alert("To continue, please add a Photo or Video."); 
};

PhotoVideo.prototype.showNotPaidUserMsg = function() {
  alert('The Photo/Video eCard features are only available for our Members.  Please click on the "Join Now to Send" button to become a Member today!');
};

PhotoVideo.prototype.showNotWinIEMsg = function() {
  alert("Add photo and upload video features are only available for Internet Explorer on Win OS. Sorry!");
};
PhotoVideo.prototype.setUploadOption= function(optionVal) {
  //optionVal can be both, photo, or video
  this.uploadOption = optionVal;
  if (this.uploadOption != "both") {
    document.getElementById("pphototab").style.visibility = "hidden";
    document.getElementById("pvideotab").style.visibility = "hidden";
    document.getElementById("vphototab").style.visibility = "hidden";
    document.getElementById("vvideotab").style.visibility = "hidden";
  }
};
//This function might need to be moved to make "customForm" dynamic
PhotoVideo.prototype.postToCustom = function(from) {
  if (!this.blnPaidUser) {
     this.showNotPaidUserMsg();
     return false;
  }
  if ((from == 'photo') && (!document.getElementById("ryes").checked)) {
     this.showNoRightMsg('photo');
     return false;
  } 
  if ((from == 'video') && (!document.getElementById("vdryes").checked)) {
     this.showNoRightMsg('video');
     return false;
  }
  if (from == 'photo') {
    if (document.getElementById("pn1658").value) {
      document.getElementById('pn1659').value = '';
      document.getElementById('pn1660').value = '';
      document.customForm.submit();
    } else {
      this.showWithoutPhotoOrVideoMsg();
    }
  } else {
    if (document.getElementById("pn1659").value) {
      document.getElementById('pn1657').value = '';
      document.getElementById('pn1658').value = '';
      document.customForm.submit();
    } else {
      this.showWithoutPhotoOrVideoMsg();
    }
  }
  return true;
};
PhotoVideo.prototype.grayPersonalizeButton = function(what) {
  if (what == 'photo') {
    document.getElementById("personalizebtn_photo").style.filter = 'alpha(opacity = 50)';
    document.getElementById("personalizebtn_photo").style.MozOpacity = 0.5;
  } else {
    document.getElementById("personalizebtn_video").style.filter = 'alpha(opacity = 50)';
    document.getElementById("personalizebtn_video").style.MozOpacity = 0.5;
  }
};
PhotoVideo.prototype.restorePersonalizeButton = function(what) {
  if (what == 'photo') {
    document.getElementById("personalizebtn_photo").style.filter = 'alpha(opacity = 100)';
    document.getElementById("personalizebtn_photo").style.MozOpacity = 1.0;
  } else {
    document.getElementById("personalizebtn_video").style.filter = 'alpha(opacity = 100)';
    document.getElementById("personalizebtn_video").style.MozOpacity = 1.0;
  } 
};
PhotoVideo.prototype.initialize = function() {
  this.checkIsPaidUser();
  var recordingSG = this.sg;
  if (this.sg == 'agbeta') {
    recordingSG = 'ag';
  }
  var flashPath = this.imghost + '/product/preview/flash/addvideo.swf?ahost='+this.ahost+'&ihost='+this.imghost+'&strm1=/flashalbum/audio&strm2='+this.vPath+'&sg='+recordingSG+'&mode=display';
  if (typeof this.frameBGColor != "undefined") {
    flashPath += '&frmbgclr=' + '0x' + this.frameBGColor.substring(1);
  }
  if (typeof this.frameTextColor != "undefined") {
    flashPath += '&frmtxtclr=' + '0x' + this.frameTextColor.substring(1);
  }
  if (typeof this.env != "undefined") {
    flashPath += '&env=' + this.env;
  }
  if (typeof this.ihostau != "undefined") {
    flashPath += '&ihostau=' + this.ihostau;
  }
  if (this.blnPaidUser) {
    flashPath += '&mtype=1';
  } else {
    flashPath += '&mtype=0';
  }
  if (!this.recordVideoOn) {
    flashPath += '&disabled=1';
  }

  if (!this.blnPaidUser) {
    this.grayPersonalizeButton('photo');
    this.grayPersonalizeButton('video');
    document.getElementById("Creative_photo_id").align = 'center'; 
    document.getElementById("Creative_photo_id").innerHTML = this.getSamplePhotoHtml();
    document.getElementById("Creative_LPCaptn_id").innerHTML = "&lt;Your Caption will Appear Here&gt;";
    document.getElementById('Creative_videoseg_id').innerHTML = this.getFlashHtml(flashPath); 
  } else {
    var savedPhotoLoc = updcookie.getPVSavedPhotoLoc();
    var savedVideoLoc = updcookie.getPVSavedVideoLoc();
    var savedMusicIdx = updcookie.getPVSavedMusicIdx();
    var savedMusicOn  = updcookie.getPVSavedMusicOn();

    if (savedMusicIdx) {
      //alert("found savedMusicIdx " + savedMusicIdx);
      document.getElementById("pnMusicIdx").value = savedMusicIdx;
      document.getElementById("mc").selectedIndex = savedMusicIdx;
      this.musicName = document.getElementById("mc").options[savedMusicIdx].value;
      document.getElementById("pnMusicOn").value = savedMusicOn;
      if (savedMusicOn == 1) {
         this.musicOn = 'y'; 
      } 
    }

    if (savedPhotoLoc) {
      var savedPhotoCap = updcookie.getPVSavedPhotoCap();
      if (!savedPhotoCap) {
        savedPhotoCap = '';
      }
      document.getElementById("pn1657").value = savedPhotoCap; 
      document.getElementById("pn1658").value = savedPhotoLoc; 
      this.showPhoto(savedPhotoLoc, savedPhotoCap);
      this.selectUploadType('photo');
    } else {
      document.getElementById("Creative_photo_id").align = 'center'; 
      document.getElementById("Creative_photo_id").innerHTML = this.getSamplePhotoHtml();
      document.getElementById("Creative_LPCaptn_id").innerHTML = "&lt;Your Caption will Appear Here&gt;";
    }
      
    if (savedVideoLoc) {
      //alert("found saved video at " + savedVideoLoc); 
      var savedVideoDuration = updcookie.getPVSavedVideoDuration();
      document.getElementById("pn1659").value = savedVideoLoc; 
      document.getElementById("pn1660").value = savedVideoDuration; 
      this.showVideo(savedVideoLoc, savedVideoDuration, 'display');
      this.selectUploadType('video');
    } else {
      document.getElementById('Creative_videoseg_id').innerHTML = this.getFlashHtml(flashPath); 
    }

    updcookie.clearPVCookie();

  }
  if (this.musicPath) {
    this.flashMusicCtrl = new FlashMusicCtrl(this.imghost, this.musicPath, this.musicName);
    this.flashMusicCtrl.createControl("musicCtrl_div", this.khost, this.musicOn, this.musicCtrlColor); 
  }

  if (!this.checkVDCrusher()) {
    this.videoFileInputHtml = document.getElementById('videofileid').innerHTML;
    document.getElementById('videofileid').innerHTML = '';
  }

  if (!this.checkCrusher()) {
    this.photoFileInputHtml = document.getElementById('photofileid').innerHTML;
    document.getElementById('photofileid').innerHTML = '';
  }
  document.getElementById("PVphotoloaded").style.display = "none";
  document.getElementById("PVvideoloaded").style.display = "none";
};
PhotoVideo.prototype.setMusicCtrlColor = function(musicCtrlColor) {
  this.musicCtrlColor = musicCtrlColor;
};
PhotoVideo.prototype.setFrameBGColor = function(frameBGColor) {
  this.frameBGColor = frameBGColor;
};
PhotoVideo.prototype.setFrameTextColor = function(frameTextColor) {
  this.frameTextColor = frameTextColor;
};
PhotoVideo.prototype.setFeatureOnOff = function(uploadPhotoOn, recordVideoOn, uploadVideoOn) {
  this.uploadPhotoOn = eval(uploadPhotoOn.toLowerCase()); 
  this.recordVideoOn = eval(recordVideoOn.toLowerCase()); 
  this.uploadVideoOn = eval(uploadVideoOn.toLowerCase());
};

PhotoVideo.prototype.selectUploadType = function(uploadType) {
  //alert("selectUploadType: uploadType " + uploadType + " " + this.orientation);
  if (uploadType == "video") {	
    document.getElementById("videoDiv").style.visibility = "visible";
    document.getElementById("photoDiv").style.visibility = "hidden";
    document.getElementById("Creative_photoseg_id").style.display = "none";
    document.getElementById("Creative_videoseg_id").style.display = "inline";
    document.getElementById("photovideoMainDiv").style.height = "550px";

    if (this.flashMusicCtrl) {
      if (document.getElementById("pnMusicOn")) {
        if (document.getElementById("pnMusicOn").value == 1) { 
          this.musicOn = 'y';
          this.flashMusicCtrl.turnOffMusic();
        } else {
          this.musicOn = 'n';
        }
      }
    }
  }
  if (uploadType == "photo") {	
    document.getElementById("photoDiv").style.visibility = "visible";
    document.getElementById("videoDiv").style.visibility = "hidden";
    document.getElementById("Creative_photoseg_id").style.display = "inline";
    document.getElementById("Creative_videoseg_id").style.display = "none";
    document.getElementById("photovideoMainDiv").style.height = "670px";   
    if (this.flashMusicCtrl) {
      if (this.musicOn == 'y') {
          this.flashMusicCtrl.turnOnMusic();
      }
    }
  }
};

PhotoVideo.prototype.checkIsPaidUser = function(blnPaidUser) {
  if (document.getElementById("paidmbr").value == "false") {
    this.blnPaidUser = false;
  } else {
    this.blnPaidUser = true;
  }
};
PhotoVideo.prototype.setOrientation = function() {
  if (document.getElementById('landscape').checked) {
    this.orientation = 'landscape';
  } else {
    this.orientation = 'portrait';
  }
  if (document.getElementById("pn1658").value) {
    document.getElementById("PVphotoloaded").style.display = "none";
    document.getElementById("pn1658").value = "";
  }
  document.getElementById("Creative_photo_id").align = 'center';
  document.getElementById("Creative_photo_id").innerHTML = this.getSamplePhotoHtml();
};
PhotoVideo.prototype.setRight = function(what) {
  if ((what == 'photo') && document.getElementById('ryes').checked && this.blnPaidUser) {
    this.restorePersonalizeButton('photo');
  } else if ((what == 'video') && document.getElementById('vdryes').checked && this.blnPaidUser) {
    this.restorePersonalizeButton('video');
  } else {
    this.grayPersonalizeButton(what);
  }
};
PhotoVideo.prototype.switchTabAndAnchor = function() {
  this.selectUploadType("video");
  location.hash = "photovideoMainDiv";
};
PhotoVideo.prototype.getSamplePhotoHtml = function() {
   var w, h;
   if (this.orientation == 'landscape') {
     w = this.photoMaxW-20;
     h = this.photoMaxH-20;
   } else {
     w = this.photoMaxH-20;
     h = this.photoMaxW-20;
   }
   var sampleHTML = '<div id="photocont" style="background-color:#F8EFDC; padding:10px; text-align:center; width:'+w+'px; height:'+h+'px; color: ' + this.frameTextColor + '; font-size: 12px; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif;">';
   sampleHTML += '<div style="height:20px"></div>';
   sampleHTML += '<p style="text-align:center; font-size:17px;">Photo Frame eCards</p>';
   if (this.uploadOption == "both") {
     sampleHTML += '<p style="text-align:center">Click a button below to get started</p>';
   }
   if (this.uploadOption != "video") {
     sampleHTML += '<a href="#photovideoMainDiv"><img src="'+this.imghost+'/'+this.sg+'/button/b_addphoto.gif" border="0" hspace="5" vspace="20"></a>';
   }
   if (this.uploadOption != "photo") {
     sampleHTML += '<a href="javascript:photoVideo.switchTabAndAnchor()"><img src="'+this.imghost+'/'+this.sg+'/button/b_addvideo.gif" border="0" hspace="5" vspace="20"></a>';
   }
   if (!this.blnPaidUser) {
     sampleHTML += '<p style="text-align:center">Remember that only Members can send these eCards. "Sign In" above or click the "Join Now" button to become a member today!</p>';
   }
   sampleHTML += '</div>';

   return sampleHTML;
};
PhotoVideo.prototype.addCaption = function() {
   document.getElementById("Creative_LPCaptn_id").innerHTML = document.getElementById('pn1657').value;
   setMyCookie();
   try {
     document.getElementById("photofocus_id").focus();
   }
   catch(error)
   {
   }
};
PhotoVideo.prototype.getFlashHtml = function(showPath) {
   strReturn = '';
   if ((!is_Flash) || (is_FlashVersion < 7)) {
     strReturn = '<center><font color="FF0000" face="arial, helvetica" size=2>The latest version of Macromedia Flash Player is recommended for this presentation. Please click on the image below to upgrade to the latest Flash Player and come back to revisit us.</font><br><br><a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"><IMG SRC="http://www.macromedia.com/shockwave/download/images/download_now_flash.gif" WIDTH=88 HEIGHT=31 BORDER=0></a></center><br>';
   }
   strReturn += '<OBJECT ID="FlashProduct" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH=550 HEIGHT=320> <PARAM NAME="movie" VALUE="' + showPath + '"> <PARAM NAME="LOOP" VALUE="false"> <PARAM NAME="QUALITY" VALUE=high><PARAM NAME="wmode" VALUE="transparent"> <EMBED name="FlashProduct" src="' + showPath + '" quality=high swLiveConnect=true WIDTH=550 HEIGHT=320 SCALE="NOBORDER" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" wmode=transparent></EMBED> </OBJECT>';
  //alert(strReturn);
  return strReturn;
};
PhotoVideo.prototype.isValidVideoExtension = function()
{
  if ((strFileExt == ".asf") || (strFileExt == ".avi") || (strFileExt == ".dv") || (strFileExt == ".flv") || (strFileExt == ".mov") || (strFileExt == ".mpg") || (strFileExt == ".mpeg") || (strFileExt == '.vob') || (strFileExt == '.wmv')) {
    return true;
  } else {
    return false;
  }
};
PhotoVideo.prototype.setUploadHtml = function(uploadHtml1, uploadHtml2a, uploadHtml2b) {
  this.uploadHtml1 = uploadHtml1;
  this.uploadHtml2a = uploadHtml2a;
  this.uploadHtml2b = uploadHtml2b;
};
PhotoVideo.prototype.setUploadVideoHtml = function(uploadVideoHtml1, uploadVideoHtml2a, uploadVideoHtml2b) {
  this.uploadVideoHtml1 = uploadVideoHtml1;
  this.uploadVideoHtml2a = uploadVideoHtml2a;
  this.uploadVideoHtml2b = uploadVideoHtml2b;
};
PhotoVideo.prototype.showPhoto = function(photoPath, photoCaption, mode) {
  var rightHost = this.phost;
  if (!mode) {
    mode = 'pickup';
  }
  if (mode == 'pickup') {
    rightHost = this.imghost;
  }
  document.getElementById("Creative_videoseg_id").style.display = "none"; 
  document.getElementById("Creative_LPCaptn_id").innerHTML = photoCaption; 
  document.getElementById("Creative_photo_id").innerHTML = '<a href="#photo" id="photofocus_id"><img src="' + rightHost + '/flashalbum/' + photoPath + '" border=0></a>'; 
  document.getElementById("Creative_photo_id").align = 'center'; 
  document.getElementById("Creative_photoseg_id").style.display = "block"; 
  document.getElementById("photofocus_id").focus();
};
PhotoVideo.prototype.showVideo=function(videoPath, videoLength, mode) {
  //alert("showVideo: " + videoPath + " " + videoLength + " " + mode);
  var flvhost = this.phost;
  if (!mode) {
    mode = 'pickup';
  } 
  if (mode == 'pickup') {
    flvhost = this.imghost;
  }
  var recordingSG = this.sg;
  if (this.sg == 'agbeta') {
    recordingSG = 'ag';
  }
  document.getElementById("Creative_photoseg_id").style.display = "none";
  var flashPath;
  var fileName = videoPath.substring(videoPath.lastIndexOf('/')+1);
  //alert("fileName " + fileName);
  if ((fileName.substring(0,4) == 'crvd') && (fileName.substring(fileName.length-4) == '.flv')) {
    flashPath = this.imghost + '/product/preview/flash/addvideo.swf?phost='+flvhost+'&len='+videoLength+'&uplflv='+videoPath;
  } else {
    flashPath = this.imghost + '/product/preview/flash/addvideo.swf?ahost='+this.ahost+'&ihost='+this.imghost+'&strm1=/flashalbum/audio&strm2='+videoPath+'&len='+videoLength+'&sg='+recordingSG+'&mode='+mode;
    if (typeof this.env != "undefined") {
      flashPath += '&env=' + this.env;
    }
    if (typeof this.ihostau != "undefined") {
      flashPath += '&ihostau=' + this.ihostau;
    }
  }
  //alert("showVideo: " + flashPath);
  //document.getElementById('Creative_videoseg_id').innerHTML = this.getFlashHtml(flashPath); 
  document.getElementById('Creative_videoseg_id').innerHTML = '<a href="video" id="videofocus_id">' + this.getFlashHtml(flashPath) + '</a>'; 
  document.getElementById("Creative_videoseg_id").style.display = "block"; 
  try {
     document.getElementById("videofocus_id").focus();
  }
  catch(error)
  {
  }
};

PhotoVideo.prototype.uploadClicked = function()
{
  if ((!is_win) || (!is_ie)) {
    this.clicked = true;
    return true;
  } else {
    if (!this.checkCrusher()) {
      document.getElementById('photofileid').innerHTML = this.photoFileInputHtml;
      var isYes = confirm("Please install the plugin and try again.");
      if (isYes) {
        document.getElementById('atx').innerHTML = this.atxCrusherHTML;
      }
      return false;
    } else {
      this.clicked = true;
      return true;
    }
  }
};

PhotoVideo.prototype.uploadVideoClicked = function()
{
  if ((!is_win) || (!is_ie)) {
    this.showNotWinIEMsg();
    return false;
  }
  if (!this.checkVDCrusher()) {
    document.getElementById('videofileid').innerHTML = this.videoFileInputHtml;
    alert("You will be asked to download and install the Creative Toolbox Video Plugin. Click on 'Run' to install it and then proceed.");
    var strVideoPluginURL = this.imghost + "/cp/install/CreativeToolboxVideoSetup.exe";
    var iPopupWidth = 325;
    var iPopupHeight = 225;
    var strPopupOptions = 'location=0,menubar=0,toolbar=0,status=1,scrollbars=1,resizable=1,directories=0';
    var l = (screen.width - iPopupWidth) / 2;
    var t = (screen.height - iPopupHeight) / 2;
    if (l < 0) {l = 0;}
    if (t < 0) {t = 0;}
    var w = iPopupWidth - 12;
    var h = iPopupHeight - 61;
    var strPopupSize = 'width=' + w + ',height=' + h + ',left=' + l + ',top=' + t;
    var installWin = window.open(strVideoPluginURL, 'Install', strPopupSize + ',' + strPopupOptions);
    installWin.focus();
  }
  this.uplVDClicked = true;
};
PhotoVideo.prototype.uploadPhoto = function()
{
  var fileKeyValueSep = ":~";
  var keyValueSep = ":";
  var itemSep = "|\n";
  var intMW, intMH;

  var photoVideoType = '1'; 
  var pvPhotoHandler = 'pvphoto';

  if (this.orientation == 'landscape') {
    intMW = this.photoMaxW;
    intMH = this.photoMaxH;
  } else {
    intMW = this.photoMaxH;
    intMH = this.photoMaxW;
  }

  var strFileExt, strForm;

  var userFileName = document.getElementById('userfile').value;
  //alert("uploadPhoto: userFileName " + userFileName + " " + this.clicked);
  if ((!this.clicked) || (!userFileName)) {
    //alert("nothing to load"); 
    return false;
  }
  strFileExt = userFileName.substring(userFileName.length-4).toLowerCase();
  strForm = "userfile" + fileKeyValueSep + userFileName + itemSep;
  if (this.sg == 'agbeta') {
    strForm += "sg" + keyValueSep + 'ag' + itemSep; 
  } else {
    strForm += "sg" + keyValueSep + this.sg + itemSep; 
  }
  strForm += "photoVideo" + keyValueSep + photoVideoType + itemSep;
  strForm += "mode" + keyValueSep + "submit" + itemSep; 
  strForm += "_handler" + keyValueSep + pvPhotoHandler + itemSep;
  var strURL = "/cgi-bin/share/upload.py";
  if ((is_win) && (is_ie)) {
    this.useCrusherForPhoto(this.phost, strURL, strForm, intMW, intMH);
  } else {
    this.useAppletForPhoto(this.phost, strURL, strForm, intMW, intMH);
  }
  return true;
};
PhotoVideo.prototype.useCrusherForPhoto = function(strHost, strURL, strForm, intMW, intMH)
{
  var blnSuccess = true;
  var FL_SILENT = 1;
  var FL_DEBUG = 2;
  var FL_NOUPSIZE = 4;
  var FL_NOCLEANUPTMP = 8;
  var intQ = 70;
  strURL = strHost + strURL;
  try {
      var strReturn = this.crusherPlugin.UploadImages(strURL, strForm, intMW/*iMaxWidth*/, intMH/*iMaxHeight*/, intQ/*nQuality*/, FL_SILENT|FL_NOCLEANUPTMP/*flag*/);
      //var strReturn = this.crusherPlugin.UploadImages(strURL, strForm, intMW/*iMaxWidth*/, intMH/*iMaxHeight*/, intQ/*nQuality*/, FL_DEBUG|FL_NOCLEANUPTMP/*flag*/);
      strReturn = strReturn.replace(/<BODY>/i, "");
      strReturn = strReturn.replace(/<\/BODY>/i, "");
      this.clicked = false;
      if ((strReturn.indexOf("Error") === 0) || (strReturn.match(/^\s*$/) !== null)) {
        blnSuccess = false;
        alert("Sorry, an error has occurred while preparing your photos to upload, please try again.  Thanks!");
      } else {
        this.uploadPhotoDone(strReturn);
      } 
    } catch(error) {
      blnSuccess = false;
      this.clicked = false;
      alert("Sorry, an error has occurred while updating your photos, please try again.  Thanks!");
    }
  document.getElementById("photouploadID").innerHTML = this.uploadHtml1 + this.uploadHtml2b;
  if (!blnSuccess) {
    document.getElementById("PVphotoloaded").style.display = "none";
  }
};
PhotoVideo.prototype.useAppletForPhoto = function(strHost, strURL, strForm, intMW, intMH)
{
    this.applet = new CrusherApplet(this.imghost + "/applets/Crusher.jar");
    this.applet.create({"host":strHost, "url": strURL, "formdata": strForm, "iwidth": intMW, "iheight": intMH, "this": this});
};
PhotoVideo.prototype.getAppletCallback = function(self)
{
    return function() {
        //alert("getAppletCallback " + self.applet.return_value);
        self.clicked = false;
        document.getElementById("photouploadID").innerHTML = self.uploadHtml1 + self.uploadHtml2b;
        self.uploadPhotoDone(self.applet.return_value);
    };
};
PhotoVideo.prototype.uploadVideo = function()
{
  var userFileName = document.getElementById('uservideo').value;
  if ((!this.uplVDClicked) || (!userFileName)) {
    //alert("nothing to load"); 
    return false;
  }
  var FL_SILENT = 1;
  var FL_DEBUG = 2;
  var FL_NOUPSIZE = 4;
  var FL_NOCLEANUPTMP = 8;

  var fileKeyValueSep = ":~";
  var keyValueSep = ":";
  var itemSep = "|\n";

  var pvVideoHandler = "pvvideo";

  var uservideoName = document.getElementById('uservideo').value;

  strFileExt = uservideoName.substring(uservideoName.lastIndexOf('.')).toLowerCase();
  if (!this.isValidVideoExtension(strFileExt)) {
     document.getElementById("videouploadID").innerHTML = this.uploadVideoHtml1 + this.uploadVideoHtml2b;
     document.getElementById("PVvideoloaded").style.display = "none";
     alert("You cannot upload " + strFileExt + " files, please try again.");
     return false;
  }

  strForm = "uservideo" + fileKeyValueSep + uservideoName + itemSep;
  if (this.sg == 'agbeta') {
    strForm += "sg" + keyValueSep + 'ag' + itemSep; 
  } else {
    strForm += "sg" + keyValueSep + this.sg + itemSep; 
  }
  strForm += "_handler" + keyValueSep + pvVideoHandler + itemSep;

    var blnSuccess = true;
    try
    {
      var strURL = this.phost + "/cgi-bin/share/upload.py";
      var strOptions = "-fs 1500 -r 12 -s 320x240 -aspect 4:3 -acodec mp3 -ar 22050 -ab 56";
      //var strReturn = this.vdCrusherPlugin.UploadVideo(strURL, strForm, strOptions, FL_NOUPSIZE|FL_NOCLEANUPTMP|FL_DEBUG);
      var strReturn = this.vdCrusherPlugin.UploadVideo(strURL, strForm, strOptions, FL_SILENT);
      strReturn = strReturn.replace(/<BODY>/i, "");
      strReturn = strReturn.replace(/<\/BODY>/i, "");
      if ((strReturn.indexOf("Error") === 0) || (strReturn.match(/^\s*$/) !== null)) {
        blnSuccess = false;
        alert("Sorry, an error has occurred while uploading your video.");
      } else {
        eval(strReturn);
      }
    }
  catch(error)
    {
      blnSuccess = false;
      alert("Sorry, an error has occurred while uploading your video.");
    }
    document.getElementById("videouploadID").innerHTML = this.uploadVideoHtml1 + this.uploadVideoHtml2b;
  if (!blnSuccess) {
    document.getElementById("PVvideoloaded").style.display = "none";
  }
  return true;
};
PhotoVideo.prototype.checkCrusher = function()
{
  if (this.crusherPlugin) {
      return true;
  } else {
      try {
        this.crusherPlugin = new ActiveXObject('Crusher.Plugin'); 
        return true; 
      } catch (e) {
        return false;
      }
  }
};
PhotoVideo.prototype.checkVDCrusher = function()
{
  var requiredVersion = "1,0,0,0";
  try {
    this.vdCrusherPlugin = new ActiveXObject('VDCrusher.Plugin'); 
    if (this.vdCrusherPlugin.Version() != requiredVersion) {
      throw '';
    }
    return true; 
  } catch (e) {
    return false;
  }
};
PhotoVideo.prototype.uploadPhotoDone = function(storedFile) {
  //alert("uploadPhotoDone " + storedFile);
  //document.getElementById("photouploadID").innerHTML = this.uploadHtml1 + this.uploadHtml2b;
  document.getElementById("pn1658").value = storedFile;
  setMyCookie();
  this.showPhoto(storedFile, document.getElementById("pn1657").value, 'display');
  document.getElementById("photofocus_id").focus();
  document.getElementById("PVphotoloaded").style.display = "inline";
};
PhotoVideo.prototype.uploadVideoDone = function(storedFile, inputFile, duration) {
  //alert("uploadVideoDone: " + storedFile + " " + inputFile + " " + duration);
  //document.getElementById("videouploadID").innerHTML = this.uploadVideoHtml1 + this.uploadVideoHtml2b;
  document.getElementById("pn1659").value = storedFile;
  document.getElementById("pn1660").value = duration;
  setMyCookie();
  this.showVideo(storedFile, duration, 'display');
  document.getElementById("PVvideoloaded").style.display = "block";
};
PhotoVideo.prototype.setMusicPathAndName = function(musicPath, musicName) {
  this.musicPath = musicPath;
  if (!musicName) {
    this.musicName = 'nomusic';
  } else {
    this.musicName = musicName;
  }
};
PhotoVideo.prototype.changeMusic = function(selectionIdx) {
  document.getElementById("pnMusicIdx").value = selectionIdx;
  this.flashMusicCtrl.changeMusic(document.getElementById("mc").options[selectionIdx].value); 
};
