function taggings_show_tag_form() {
  $('tag_option').hide();
  $('tag_form').show();
}

function taggings_add_tag() {
  var tag_text = $('tag_text').value;
  var tag_target_id = $('tag_target_id').value;
  var tag_target_type_id = $('tag_target_type_id').value;
	
  new Ajax.Request('ajax.php',
  {
    parameters: {
      _action: 'tag_add', 
      target_type_id: tag_target_type_id, 
      target_id:tag_target_id, 
      tag: tag_text
    },
    onSuccess: function(response) {
      var json_response = response.responseText.evalJSON();
      
      if(json_response.ajax_status == 1) {
        $('taglist').innerHTML = json_response.html;
        $('tag_text').value = '';
      }
      else {
        alert(json_response.error_msg);
      }
		},
    onFailure: function() {
      alert('Couldn\'t add tag...') 
    }
  });
}

function taggings_remove_tag(tagging_id, target_id, target_type_id, tag) {
	var answer = confirm("Are you sure you want to remove your tag of \""+tag+"\" ?");
	
	if(!answer)
		return;
    
	new Ajax.Request('ajax.php',
	{
		parameters: {
      _action:'tag_delete', 
      target_type_id: target_type_id, 
      target_id: target_id, 
      tagging_id: tagging_id 
    }, 
		onSuccess: function(response) {
      var json_response = response.responseText.evalJSON();
      
      if(json_response.ajax_status == 1) {
        $('taglist').innerHTML = json_response.html;
        $('tag_text').value = '';
      }
      else {
        alert(json_response.error_msg);
      }
		},
		onFailure: function() { 
      alert('Couldn\'t add tag...') 
    }
	});
}

