var ratingimgs = new Array(3);
ratingimgs[0] = new Image(13, 12); ratingimgs[0].src = "images/star_b.gif";
ratingimgs[1] = new Image(13, 12); ratingimgs[1].src = "images/star_d.gif";
ratingimgs[2] = new Image(13, 12); ratingimgs[2].src = "images/star_u.gif";
function SetupRatings()
{
 var ratingsAreas
 var ratingsArea;
 var maxrating = 5;
 var link;
 var rateImage;
 var x;
 var y;
 ratingsAreas = document.getElementsByName("ratingimage");
 for( y = 0; y < ratingsAreas.length; y++ )
 {
 ratingsArea = ratingsAreas[y];
 for( x = 1; x <= maxrating; x++ )
 {
 link = document.createElement("a");
 link.setAttribute("href", "javascript:submitRating('" + ratingsArea.cnshandle + "', '" + x + "', '" + ratingsArea.clientid + "')");
 rateImage= document.createElement("img");
 rateImage.setAttribute("border", "0");
 rateImage.setAttribute("alt", c_ratingsTooltip);
 rateImage.className = "star";
 if ( x <= ratingsArea.rating )
 {
 rateImage.src = ratingimgs[0].src;
 rateImage.height = ratingimgs[0].height;
 rateImage.width = ratingimgs[0].width;
 }
 else
 {
 rateImage.src = ratingimgs[1].src;
 rateImage.height = ratingimgs[1].height;
 rateImage.width = ratingimgs[1].width;
 }
 rateImage.id = x + "star" + ratingsArea.cnshandle;
 rateImage.onmouseover = Function("HoverRating('" + ratingsArea.cnshandle + "', '" + x + "', '0')");
 rateImage.onmouseout = Function("LeaveRating('" + ratingsArea.cnshandle + "')");
 link.appendChild( rateImage );
 ratingsArea.appendChild( link );
 }
 }
}
// voting functionality
function HoverRating(listid, rating, totalrating)
{
 var x;
 var starImage;
 for ( x = 5; x > 0 ; x-- )
 {
 starImage = document.getElementById(x + "star" + listid);
 if ( x <= rating )
 {
 starImage.oldSrc = starImage.src;
 starImage.src = ratingimgs[2].src;
 starImage.height = ratingimgs[2].height;
 starImage.width = ratingimgs[2].width;
 }
 else
 {
 if ( starImage.oldSrc == null )
 {
 starImage.oldSrc = starImage.src;
 }
 starImage.src = ratingimgs[1].src;
 starImage.height = ratingimgs[1].height;
 starImage.width = ratingimgs[1].width;
 }
 }
}
function LeaveRating(listid)
{
 var x;
 var starImage;
 for ( x = 5; x > 0 ; x-- )
 {
 starImage = document.getElementById(x + "star" + listid);
 if ( starImage.oldSrc == null )
 {
 starImage.src = ratingimgs[1].src;
 starImage.height = ratingimgs[1].height;
 starImage.width = ratingimgs[1].width;
 }
 else
 {
 starImage.src = starImage.oldSrc;
 }
 }
}
function UpdateStarCount(listid, rating)
{
 var x;
 var tablecell;
 var parent;
 tableCell = document.createElement("td");
 for( x = 1; x < 6 ; x++ )
 {
 starImage = document.getElementById(x + "star" + listid);
 if ( x <= rating)
 {
 starImage.src = ratingimgs[2].src;
 starImage.height = ratingimgs[2].height;
 starImage.width = ratingimgs[2].width;
 }
 else
 {
 starImage.src = ratingimgs[1].src;
 starImage.height = ratingimgs[1].height;
 starImage.width = ratingimgs[1].width;
 }
 parent = starImage.parentElement.parentElement;
 tableCell.appendChild( starImage );
 starImage.className = "";
 starImage.onmouseover = null;
 starImage.onmouseout = null;
 }
 parent.innerHTML = tableCell.innerHTML;
}
function submitRating(listid, rating, urlkey)
{
 var results;
 var url = GetActionUrl(urlkey);
 var args = "ListId=" + listid + "&FormMethod=post&MethodType=rateimage&rating=" + rating
 var confirmatonString = "<center><img src='images/star_u.gif'>&nbsp;" + c_rateConfirmation.replace("{0}", rating) + "</center>";
 dataArray = new ComplexDialogData(new Array(confirmatonString, null), null, null, null, null, null, true);
 returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=ratesong", dataArray, "dialogWidth=450px;dialogHeight=175px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if ( returnValObj !=null && returnValObj.Action == "OK" )
 {
 results = _sd_Post(url, args);
 UpdateStarCount(listid, results);
 if ( document.getElementById("musicRatingText") != null )
 {
 document.getElementById("musicRatingText").innerText = c_ratedMusic;
 }
 }
}
// use for myspace lists to display confirmation dialog and do the deletes
function _sd_Post(Url, Args)
{
 var xmlhttp;
 var error;
 eval('try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {xmlhttp = null;error=e;}');
 if(null != xmlhttp)
 {
 xmlhttp.Open("POST", Url, false);
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 xmlhttp.Send(Args);
 strText = xmlhttp.responseText;
 // if our response starts with http than redirect there
 if ( strText != null && strText.toLowerCase().indexOf("http") == 0 )
 {
 location.href = strText;
 }
 }
 else
 {
 location.href = c_errorUrl;
 }
 return strText;
}
function GetActionUrl(listKey)
{
 return document.getElementById("ActionUrl:" + listKey).url
}
