$(document).ready(function()
{
  $('#segnala_abuso').hide();
});

function ext_act_addicon(clazz,msg)
{
  return '<div class="big-msg '+clazz+'" >'+msg+'</div>';
}



function ext_act_scossa(profileID)
{
  $.get('greet.php', { sendto: profileID },function(data){
    if (data==false)
      redirectCheckRes(1);//ACTION_ID_SEND_VKISS
    else
      ext_alert( ext_act_addicon('bg-scossa', data) );
  });
}

function ext_act_blocca(profileID)
{
  $.get('list_pop.php', { action: 'block', ID: profileID },function(data){
    ext_alert( ext_act_addicon('bg-blocca', data) );
  });
}

function ext_act_preferisci(profileID)
{
  $.get('list_pop.php', { action: 'hot', ID: profileID },function(data){
    if (data==false)
      redirectCheckRes(1001);//EXT_ACTION_ID_AGGIUNGERE_PREFERITO
    else
      ext_alert( ext_act_addicon('bg-preferito', data) );
  });
}

function ext_act_abuse()
{
  var win;
  var frm;

  frm = $('#segnala_abuso').html();

  // Dialog
  win = ext_alert(frm);
  
  // gestore del tasto cancella
  $('input:reset',win).click(function()
  {
    win.dialog( "close" );
  });
  
  // gestore della submit
  $('form',win).submit(function()
  {
    var txt = $('textarea',$(this)).val();
    
    if ( txt == '')
    {
      $('.alert_msg',$(this)).fadeIn("slow");
      $('.alert_msg',$(this)).fadeTo("slow", 0.33);
      $('.alert_msg',$(this)).fadeTo("slow", 1);
      $('.alert_msg',$(this)).fadeOut("slow");
    }
    else
    {
      // Serializza il form per l'invio ajax
      var pid = $('input[@name=ID]',$(this)).val();
      var txt = escape(txt);
      $.get('list_pop.php', { action: 'spam', ID: pid, descr: txt  },function(data){
        win.dialog( "close" );
        ext_alert(data);
      });
    }
    return false;
  });
}

function redirectCheckRes(ACTION_ID) {
  location.href = "http://www.happyisland.it/myisland_abbonamento.php?check_res="+ACTION_ID;
}