var Rating = { 
    init : function(desc,type,id) {
        this.desc = desc;
        this.type = type;
        this.id = id;
        this.score = 0;
        this.imgSize = 21;
        this.descObj = null;
        this.avgObj = null;
        this.avgScoreObj = null;
        this.myScoreObj = null;
        return true;
    },
    description : function(desc,myscore,avgscore,avg) {
        this.descObj = desc;
        this.avgObj = avg;
        this.avgScoreObj = avgscore;
        this.myScoreObj = myscore;
        desc.innerHTML = "Please rate this " + Rating.type + ":<br>" + this.desc + "<br><br>" ;
        this.oldScore();
    },
    rate : function(score) {
        this.score = score;
        var param = "id=" + this.id + "&type=" + this.type + "&pt=" + score;
        post("/members/bin/rate", param, this.avgCallback);
    },
    oldScore : function() {
        var param = "id=" + this.id + "&type=" + this.type; // + "&my=1";
        post("/members/bin/rate", param, this.scoreCallback);
    },
    scoreCallback : function (txtObj,xmlObj) {
        var avg = xmlObj.getElementsByTagName("avg").item(0).firstChild.data;
        Rating.avgObj.style.width = parseFloat(avg) * Rating.imgSize + "px";
        if(avg > 0)
            Rating.myScoreObj.innerHTML = "Current overall user rating is " + avg + "<br>";
        return true;
    },
    avgCallback : function (txtObj,xmlObj) {
        var stat = xmlObj.getElementsByTagName("status").item(0).firstChild.data;
        if(stat == 0) {
            Rating.myScoreObj.innerHTML = "An error has occured.  Please try again";
        } else {
            var avg = xmlObj.getElementsByTagName("avg").item(0).firstChild.data;
            Rating.avgObj.style.width = parseFloat(Rating.score) * Rating.imgSize + "px";
            Rating.myScoreObj.innerHTML = "Your rating for this " + Rating.type + " is now " + Rating.score;
            Rating.avgScoreObj.innerHTML = "<br>Average total user rating is now " + avg;
        }
        return true;
    }
}
