//cookie_util.js should be imported before this 
function UPDCookie()
{
  this.prodnum = undefined;
  this.pathnum = undefined;

  this._findPathProduct();
}
UPDCookie.prototype._findPathProduct = function()
{
  var query = window.location.search.substring(1);
  var pairs = query.split("&");
  for (var i=0; i < pairs.length; i++) {
      var pos = pairs[i].indexOf('=');
      if (pos == -1) continue;
      var argname = pairs[i].substring(0,pos);
      var value = pairs[i].substring(pos+1);
      if (argname == 'prodnum') {
         this.prodnum = value;
      } else if (argname == 'path') {
         this.pathnum = value;
      }
  }
}
UPDCookie.prototype._isRightCookieSet = function()
{
  var savedPathNum = MagicCookie.getCookieValue('pvph');
  var savedProdNum = MagicCookie.getCookieValue('pvpn');
  if ((parseInt(savedPathNum) != parseInt(this.pathnum)) || (parseInt(savedProdNum) != parseInt(this.prodnum))) {
    return false;
  } else {
    return true; 
  }
}
UPDCookie.prototype._getPVInfo = function(key)
{
  try {
    if (this._isRightCookieSet()){
      return MagicCookie.getCookieValue(key); 
    } else {
      this.clearPVCookie();
      return null;
    }
  } catch(error) {
    return null; 
  }
}
UPDCookie.prototype.setPVCookie = function(photoLoc, photoCap, videoLoc, videoDuration, musicIdx, musicOn)
{
  try {
    if ((this.prodnum != undefined) && (this.pathnum != undefined)) {
      if (photoLoc || videoLoc || musicIdx) {
        MagicCookie.setCookieValue('pvph', this.pathnum, false); 
        MagicCookie.setCookieValue('pvpn', this.prodnum, false); 
        MagicCookie.setCookieValue('pvpl', photoLoc, false); 
        MagicCookie.setCookieValue('pvpc', photoCap, false); 
        MagicCookie.setCookieValue('pvvl', videoLoc, false); 
        MagicCookie.setCookieValue('pvvd', videoDuration, false); 
        MagicCookie.setCookieValue('pvmi', musicIdx, false); 
        MagicCookie.setCookieValue('pvmo', musicOn, false); 
      } 
    }
  } catch(error) {
    ;
  }
}
UPDCookie.prototype.getPVSavedPhotoLoc = function()
{
  return this._getPVInfo('pvpl');
}
UPDCookie.prototype.getPVSavedPhotoCap = function()
{
  return this._getPVInfo('pvpc');
}
UPDCookie.prototype.getPVSavedVideoLoc = function()
{
  return this._getPVInfo('pvvl');
}
UPDCookie.prototype.getPVSavedVideoDuration = function()
{
  return this._getPVInfo('pvvd');
}
UPDCookie.prototype.getPVSavedMusicIdx = function()
{
  return this._getPVInfo('pvmi');
}
UPDCookie.prototype.getPVSavedMusicOn = function()
{
  return this._getPVInfo('pvmo');
}
UPDCookie.prototype.clearPVCookie = function()
{
  try {
    MagicCookie.delCookieValue('pvph', false);
    MagicCookie.delCookieValue('pvpn', false);
    MagicCookie.delCookieValue('pvpl', false);
    MagicCookie.delCookieValue('pvpc', false);
    MagicCookie.delCookieValue('pvvl', false); 
    MagicCookie.delCookieValue('pvvd', false); 
    MagicCookie.delCookieValue('pvmi', false); 
    MagicCookie.delCookieValue('pvmo', false); 
  } catch(error) {
    ;
  }
}
