54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
function RateItem(varParentId, varItemId, varRating)
|
|
{
|
|
var elementId = varParentId+"_"+varItemId;
|
|
var varOrigClassName = document.getElementById(elementId).className;
|
|
|
|
// Retrieve Ajax Feeds
|
|
new Ajax.Request('ajax.rate.item.php',
|
|
{
|
|
method: 'post',
|
|
parameters: {parent: varParentId, item: varItemId, rating: varRating, classes: varOrigClassName},
|
|
onSuccess: ReloadRating,
|
|
onFailure: RatingError
|
|
}
|
|
);
|
|
|
|
}
|
|
|
|
function ReadNameValuePairs(nameValuePair)
|
|
{
|
|
var trimspaces = /(\s)+/;
|
|
var returnData = new Array();
|
|
var pairs = nameValuePair.split('&');
|
|
|
|
for (var i = 0; i < pairs.length; i++)
|
|
{
|
|
var pair = pairs[i].split('=');
|
|
returnData[pair[0].replace(trimspaces, "")] = pair[1];
|
|
}
|
|
|
|
return returnData;
|
|
}
|
|
|
|
function ReloadRating(requestObj, jsonObj)
|
|
{
|
|
var newlines = /(\r\n|\r|\n)/;
|
|
var returnData = ReadNameValuePairs(requestObj.responseText.replace(newlines, ""));
|
|
var elementId = returnData['parent']+"_"+returnData['item'];
|
|
|
|
document.getElementById(elementId).className = returnData['classes'];
|
|
var liObj = document.getElementById(elementId).getElementsByTagName('a');
|
|
|
|
for (var i = 0; i < liObj.length; i++)
|
|
{
|
|
liObj[i].onclick = function(){};
|
|
}
|
|
document.getElementById(returnData['parent']).className = returnData['parentClass'];
|
|
}
|
|
|
|
function RatingError()
|
|
{
|
|
|
|
//alert ("Error");
|
|
|
|
} |