// +------------------------------------------------+
// | SDDepot Presents                               |
// +------------------------------------------------+
// | 'Mass Media Pro' Plugin for Subdreamer         |
// | - Ajax Support File - requires jQuery 1.2+     |
// | Copyright (c) 2007 SDDepot                     |
// | This File May Not be Redistributed, or Resold  |
// +------------------------------------------------+
// |  Site: http://www.sddepot.com                  |
// | Email: staff@sddepot.com                       |
// +------------------------------------------------+

pluginpath = 'plugins/p803_mass_media/';
mpp_url = pluginpath + 'inc/mass_procaj.php';

function p803_AddFav(uid,fid,sid,uri){
  p803_uid = uid; // global!
  p803_uri = uri; // global!
  $.get(mpp_url, { p803_func: "FavAdd", p803_uid: uid, p803_fid: fid, p803_sid: sid, p803_uri: uri}, 
    function(txt){ p803_FavoritesShowResponse(txt); } )
}

function p803_DelFav(uid,fid,sid,uri){
  p803_uid = uid;
  p803_uri = uri;
  $.get(mpp_url, { p803_func: "FavDel", p803_uid: uid, p803_fid: fid, p803_sid: sid, p803_uri: uri}, 
    function(txt){ p803_FavoritesShowResponse(txt); } )
}

function p803_FavoritesShowResponse(newData){
  if(newData == 'R'){ // 1 = error
    $('#p803_FavButtonA').hide();
    $('#p803_FavButtonR').show();
  } else {
    $('#p803_FavButtonA').show();
    $('#p803_FavButtonR').hide();
  }
  // Fire new request to update the favorites list table:
  $.get(mpp_url, { p803_func: "FavList", p803_uid: p803_uid, p803_uri: p803_uri}, 
    function(txt){ p803_ShowFavList(txt); } )
}

function p803_ShowFavList(newData){
  document.getElementById('p803_FavList').innerHTML = newData;
}

// ***************************************************************************

function p803_RatingOptionsShow()
{
  $('#p803_RS').show();
  document.getElementById('p803_RS').innerHTML = '<strong><img src="' + pluginpath + 
    'images/misc/mmaj_loading.gif" alt="" width="16" height="16">&nbsp;Checking&nbsp;Ratings...</strong>';
  $('#p803_RS1').hide();
  $('#p803_RS2').hide();
  $('#p803_RS').hide();
  $.get(mpp_url, { p803_func: "RShow", p803_fid: fid, p803_uname: uname}, 
    function(txt){ p803_RatingShowResponse(txt); } )
}

function p803_RatingShowResponse(newData){
  $('#p803_RS').hide();
  if(newData < 0){
    $('#p803_RS1').show();
  } else {
    $('#p803_RS2').show();
  }
}

// ***************************************************************************

function p803_RatingSubmit(formname){
  p803_v = 0; // global - used in response function!
  frm = document.forms[formname];
  var rategroup = frm["p803_rad_rate"];
  if(rategroup != null){
    $('#p803_RS').show();
    $('#p803_RS1').hide();
    $('#p803_RS2').hide();

    // Loop through all form elements
    for(var p803i=0; p803i<rategroup.length; p803i++)
    {
      if(rategroup[p803i].checked == true)
      {
        p803_v = rategroup[p803i].value;
        break;
      }
    }
    p803_f = frm.elements['p803_fileid'].value; //global!
    p803_u = frm.elements['p803_user'].value;   //global!
    $.get(mpp_url, { p803_func: "RSub", p803_fid: p803_f, p803_uname: p803_u, p803_uval: p803_v}, 
      function(txt){ p803_RatingSubmitResponse(txt); } )
  }
}

function p803_RatingSubmitResponse(newData){
  $('#p803_RS').hide();
  $('#p803_RS1').hide();
  $('#p803_RS2').show();
  document.getElementById('p803_RS2').innerHTML = newData;
  // Fire new request to update the rating image DIV:
  $.get(mpp_url, { p803_func: "RImg", p803_fid: p803_f, p803_uval: 1}, 
    function(txt){ document.getElementById('p803_ratimg').innerHTML = txt; } )
}

// ***************************************************************************
// ************************ Additional Functions *****************************
// ***************************************************************************

function p803_ShowElement(infoid){
  $('#'+infoid).show();
}
  
function p803_HideElement(infoid){
  $('#'+infoid).hide();
}
  
function p803_SwitchShowHide(infoid){
  var infoelem = document.getElementById(infoid);
  if(infoelem != null)
  {
    if(infoelem.style.display == 'none'){
      $('#'+infoid).show();
      $('#'+infoid+'S').hide();
      $('#'+infoid+'H').show();
    } else {
      $('#'+infoid).hide();
      $('#'+infoid+'H').hide();
      $('#'+infoid+'S').show();
    }
  }
}