/**
 * [AJAX] Threads Rating
 * Showing Rating Script
 * Version 2.5.1
 * @author mad@Max
 */
function TRate_Call(id){
    this.id = id;
    YAHOO.util.Connect.asyncRequest("POST", "threadratinginfo.php?threadid=" + this.id, {
        success: function(ajax){
            if (ajax.responseXML) {
                var showrate = ajax.responseXML.getElementsByTagName('showrate');
                if (showrate.length && showrate[0].firstChild && showrate[0].firstChild.nodeValue != "") {
		    var trsp = fetch_object('trsp');
		    if (trsp !== null) {
		        trsp.parentNode.removeChild(trsp);
		    }
		    else {
		        var trdiv = document.createElement('div');
		        trdiv.id = 'trsp';
		        trdiv.style.width = '640px';
		        trdiv.style.position = "absolute";
		        trdiv.style.zIndex = "100";
		        trdiv.innerHTML = showrate[0].firstChild.nodeValue;
		        document.body.appendChild(trdiv);
		        center_element(trdiv);
		    }
                }
            }
        },
        failure: vBulletin_AJAX_Error_Handler,
        timeout: vB_Default_Timeout,
        scope: this
    }, SESSIONURL + "securitytoken=" + SECURITYTOKEN + "&ajax=1");
}

function show_rating(id, vote){
    this.id = id;
    this.vote = vote;
    YAHOO.util.Connect.asyncRequest("POST", "threadratinginfo.php?do=whorate&threadid=" + this.id + "&vote=" + this.vote, {
        success: function(ajax){
            if (ajax.responseXML) {
                // check for error first
                var error = ajax.responseXML.getElementsByTagName('error');
                if (error.length) {
                    // Hide thread rating popup menu now
                    alert(error[0].firstChild.nodeValue);
                }
                else {
                    var raterlist = ajax.responseXML.getElementsByTagName('raters');
                    if (raterlist.length && raterlist[0].firstChild && raterlist[0].firstChild.nodeValue != "") {
                        fetch_object('raterlist').innerHTML = raterlist[0].firstChild.nodeValue;
                    }
                }
            }
        },
        failure: vBulletin_AJAX_Error_Handler,
        timeout: vB_Default_Timeout,
        scope: this
    }, SESSIONURL + "securitytoken=" + SECURITYTOKEN + "&ajax=1");
}

function delete_rating(id, uid, vote){
    this.id = id;
    this.uid = uid;
    this.vote = vote;
    YAHOO.util.Connect.asyncRequest("POST", "threadratinginfo.php?do=removerater&threadid=" + this.id + "&u=" + this.uid + "&vote=" + this.vote, {
        success: function(ajax){
            if (ajax.responseXML) {
                // check for error first
                var error = ajax.responseXML.getElementsByTagName('error');
                if (error.length) {
                    alert(error[0].firstChild.nodeValue);
                }
                else {
                    var updrate = ajax.responseXML.getElementsByTagName('updrate');
                    var updhead = ajax.responseXML.getElementsByTagName('updhead');
                    if (updrate.length && updrate[0].firstChild && updrate[0].firstChild.nodeValue != "") {
                        var trcont = fetch_object('oneclick_threadrating_current');
                        if (trcont) {
                            trcont.removeChild(trcont.firstChild);
                            trcont.innerHTML = updrate[0].firstChild.nodeValue;
                        }
                        fetch_object('trhead').innerHTML = updhead[0].firstChild.nodeValue;
                    }
                    fetch_object('rater_' + this.uid).parentNode.removeChild(fetch_object('rater_' + this.uid));
                }
            }
        },
        failure: vBulletin_AJAX_Error_Handler,
        timeout: vB_Default_Timeout,
        scope: this
    }, SESSIONURL + "securitytoken=" + SECURITYTOKEN + "&ajax=1");
}