
/**
 * Asynchronous Get Call backs
 */
var tag_callbacks = {
    
    success : function (o) {
        var tagresponse = [];
        try {
            tagresponse = YAHOO.lang.JSON.parse(o.responseText);
        }
        catch (x) {
            alert("JSON Parse Failed!" + x);
            return;
        }
        var err = 0;
        if (tagresponse.error == 1)
        {
            alert (tagresponse.text);
            err=1;
            
            if (tagresponse.entry_id > 0)
            {
                set_tag_edit_invisible(tagresponse.entry_id);
            }
            
        }
        
        if (err == 0)
        {
            set_tag_edit_invisible(tagresponse.entry_id);
            document.getElementById("entry_tags_show_" + tagresponse.entry_id).innerHTML = tagresponse.text;
        }
    },
    
    failure : function (o) {
        if (!YAHOO.util.Connect.isCallInProgress(o)) {
            alert('Async call failed');
        }
    },
    
    timeout : 6000
}

/**
 * Asynchronous Get Call backs
 */
var gettag_callbacks = {
    
    success : function (o) {
        var tagresponse = [];
        try {
            tagresponse = YAHOO.lang.JSON.parse(o.responseText);
        }
        catch (x) {
            alert("JSON Parse Failed!" + x);
            return;
        }

        if (tagresponse.entry_id > 0)
        {
            document.getElementById('entry_tags_input_' + tagresponse.entry_id).value = tagresponse.tags;
            document.getElementById("entry_tags_show_" + tagresponse.entry_id).style.display = "none";
            document.getElementById("entry_tags_edit_" + tagresponse.entry_id).style.display = "inline";
        }
    },
    
    failure : function (o) {
        if (!YAHOO.util.Connect.isCallInProgress(o)) {
            alert('Async call failed');
        }
    },
    
    timeout : 6000
}
/**
 * Vote
 */
function set_tags(entry_id)
{
    if (entry_id > 0)
    {
        tags = document.getElementById("entry_tags_input_" + entry_id).value;
        var postData = "tags="+encodeURIComponent(tags);
        YAHOO.util.Connect.asyncRequest('POST', tagset_location + "?entry_id=" + entry_id, tag_callbacks, postData);
    }
}

/**
 *
 */
function set_tag_edit_visible(entry_id)
{
    if (entry_id> 0)
    {
        YAHOO.util.Connect.asyncRequest('GET', tagget_location + "?entry_id=" + entry_id, gettag_callbacks);
        
    }
}

/**
 *
 */
function set_tag_edit_invisible(entry_id)
{
    if (entry_id> 0)
    {
        document.getElementById("entry_tags_show_" + entry_id).style.display = "inline";
        document.getElementById("entry_tags_edit_" + entry_id).style.display = "none";
    }
}
