
/**
 * Asynchronous Get Call backs
 */
var favset_callbacks = {
    
    success : function (o) {
        var theresponse = [];
        try {
            theresponse = YAHOO.lang.JSON.parse(o.responseText);
        }
        catch (x) {
            alert("JSON Parse Failed!" + x);
            return;
        }
       var err = 0;
        if (theresponse.error == "no_auth")
        {
            if ((typeof(no_auth_alert) !== 'undefined') && no_auth_alert != '')
            {
                alert(no_auth_alert);
            }
            else
            {
                alert ("You need to be logged into perform this action. Please login to MySQL.com and try again.");
            }
            err=1;
        }
        if (theresponse.error == "invalid_fav")
        {
            if ((typeof(no_auth_alert) !== 'undefined') && no_auth_alert != '')
            {
                alert(no_auth_alert);
            }
            else
            {
                alert ("Invalid attempt to add to Favourites.");
            }
            err=1;
        }
        
        if (err == 0)
        {
            if (theresponse.success == "1")
            {
                if (theresponse.type == "inserted")
                {
                    document.getElementById('star_' + theresponse.entryid).innerHTML = "<img align=\"middle\" src=\"/common/images/star_on.jpg\" border=\"0\">";
                }
                
                if (theresponse.type == "deleted")
                {
                    document.getElementById('star_' + theresponse.entryid).innerHTML = "<img align=\"middle\" src=\"/common/images/star_off.jpg\" border=\"0\">";
                }
            }
        }
    },
    
    failure : function (o) {
        if (!YAHOO.util.Connect.isCallInProgress(o)) {
            alert('Async call failed');
        }
    },
    
    timeout : 6000
}

/**
 * Vote
 */
function toggle_favourite(entry_id)
{
    if (entry_id > 0)
    {
        YAHOO.util.Connect.asyncRequest('GET', favset_location + "?entry_id=" + entry_id, favset_callbacks);
    }
}

