
function loadHistogram(orlValue,anchorId,isAuthenticated)
{hideHistogram();moveHistogram(anchorId)
showSpinner();getHistogram(orlValue,anchorId,isAuthenticated);}
function getHistogram(orlValue,anchorId,isAuthenticated)
{var proxy=new Anonymous.Service();proxy.GetRatingContract(orlValue,onGetContractSuccess,onGetContractFail,anchorId);if(isAuthenticated)
{var authenticatedProxy=new Authenticated.AuthenticatedServices();authenticatedProxy.GetUsersRating(orlValue,onUserRatingSuccess,onUserRatingFail,anchorId);}}
function showSpinner()
{spinner.style.display='block';hist.style.display='none';totalRating.innerHTML="Getting ratings...";}
function onGetContractSuccess(result,anchorId)
{showHistogram(anchorId,result)}
function onGetContractFail(result,anchorId)
{spinner.style.display='none';hist.style.display='block';totalRating.innerHTML="error";}
function onUserRatingSuccess(result,anchorId)
{if(result==null)
myRating.innerHTML='Rate now';else
myRating.innerHTML='You rated: '+(result+3);}
function onUserRatingFail(result,anchorId)
{myRating.innerHTML='unknown';}
function moveHistogram(anchorId)
{var anchorPos;var obj=$get(anchorId);anchorPos=findPosition(obj);histogram.style.top=(anchorPos[0]+18)+"px";histogram.style.left=(anchorPos[1]-156)+"px";histogram.style.display='block';}
function showHistogram(anchorId,result)
{spinner.style.display='none';hist.style.display='block';if(result.length>0)
{setHistogramValues(result[0].Value,result[1].Value,result[2].Value,result[3].Value,result[4].Value);}
else
{totalRating.innerHTML="0 ratings";}}
function hideHistogram()
{histogram.style.display='none';histogram.style.top=0+"px";histogram.style.left=0+"px";removeHistogramValues();}
function setHistogramValues(val1,val2,val3,val4,val5)
{totalValue=val5+val4+val3+val2+val1;if(totalValue==1)
totalRating.innerHTML="1 rating";else
totalRating.innerHTML=totalValue+" ratings";bar5.style.width=((val5/totalValue)*100)+"%";bar4.style.width=((val4/totalValue)*100)+"%";bar3.style.width=((val3/totalValue)*100)+"%";bar2.style.width=((val2/totalValue)*100)+"%";bar1.style.width=((val1/totalValue)*100)+"%";bar5Value.innerHTML=val5;bar4Value.innerHTML=val4;bar3Value.innerHTML=val3;bar2Value.innerHTML=val2;bar1Value.innerHTML=val1;}
function removeHistogramValues()
{totalRating.innerHTML="no ratings";bar5.style.width=0;bar4.style.width=0;bar3.style.width=0;bar2.style.width=0;bar1.style.width=0;bar5Value.innerHTML=0;bar4Value.innerHTML=0;bar3Value.innerHTML=0;bar2Value.innerHTML=0;bar1Value.innerHTML=0;}