
/* $Id: class_blog.js 5 2009-01-11 06:01:16Z john $ */

SocialEngineAPI.Subscribe = new Class({
  
  Base: {},
  
  
  options: {
    'ajaxURL' : 'subscribe_ajax.php'
  },
  // Subscriptions
  subscribe: function(ownerId, topicID,type)
  {
    // Ajax
    var bind = this;
    var request = new Request.JSON({
      'method' : 'post',
      'url' : this.options.ajaxURL,
      'data' : {
        'task' : 'subscribe',
		'type_subscribe' : type,
		'owner_id' : ownerId,
		'topic_id' : topicID
      },
      'onComplete':function(responseObject)
      {
        if( !responseObject || $type(responseObject)!="object" || responseObject.result=="failure" )
        {
          alert ('Fail');
		  //alert(bind.Base.Language.Translate(1500123));
        }
        else
        {
          // Blog page
          if( $(document).getElement('.seSubscribe') )
          {
            $(document).getElement('.seSubscribe').style.display = 'none';
            $(document).getElement('.seUnsubscribe').style.display = '';
          }
          
          	if( $(document).getElement('.seSubscribe'+topicID) )
			{
				 $(document).getElement('.seSubscribe'+topicID).style.display = 'none';
				 $(document).getElement('.seUnsubscribe'+topicID).style.display = '';
			}
        }
      }
    });
    
    request.send();
  },  
  
  unsubscribe: function(ownerId, topicID,type)
  {
    // Ajax
    var bind = this;
    var request = new Request.JSON({
      'method' : 'post',
      'url' : this.options.ajaxURL,
      'data' : {
        'task' : 'unsubscribe',
        'type_subscribe' : type,
		'topic_id' : topicID
      },
      'onComplete':function(responseObject)
      {
        if( !responseObject || $type(responseObject)!="object" || responseObject.result=="failure" )
        {
		    //alert ('Fail');	
            //alert(bind.Base.Language.Translate(1500123));
        }
        else
        {
          
          // Blog page
          if( $(document).getElement('.seUnsubscribe') )
          {
            $(document).getElement('.seSubscribe').style.display = '';
            $(document).getElement('.seUnsubscribe').style.display = 'none';
          }
		  
		  // User page
		  
          if( $('seBlogSubscriptionRow_'+ownerId) )
          {
            $('seBlogSubscriptionRow_'+ownerId).destroy();
          }
          
          	if( $(document).getElement('.seSubscribe'+topicID) )
			{
				 $(document).getElement('.seSubscribe'+topicID).style.display = '';
				 $(document).getElement('.seUnsubscribe'+topicID).style.display = 'none';
			}
        }
      }
    });
    
    request.send();
  },
  
  subscribeall: function(actionss)
  {
    // Ajax  
		var bind = this;
		var request = new Request.JSON({
		  'method' : 'post',
		  'url' : this.options.ajaxURL,
		  'data' : {
			'task' : 'subscribeall',
			'topic_id' : actionss
		  },
		  'onComplete':function(responseObject)
		  {
			if( responseObject.result=="failure" )
			{
				alert("There was an error processing your request.");
			}
			else
			{
			 

			  if( document.getElementById('stopallfollowing') )
			  {
				 document.getElementById('stopallfollowing').checked = false;
				 if (actionss == 0)
				 {
					document.getElementById('stopallfollowing').value = 1;
					document.getElementById('stoppallinfo').innerHTML = 'Send me any notification emails.';
				 }
				else
				{
					document.getElementById('stopallfollowing').value = 0;
					document.getElementById('stoppallinfo').innerHTML = 'Do not send me any notification emails.';
				}
			  }
			  
			}
		  }
		});
		
		request.send();
	}
	

	
});
