var THANKS_MSG = 'Thank you for rating this quiz'; 
var flag = 0; 

function showRating(thisField)
{
   var pos = thisField.id.split('star');           
   var rest    = parseInt(pos[1]) +1;
   
   if(ratingNum)
   {
       rest = parseInt(ratingNum)+1;
   }
   
   for(i=1;i<=pos[1];i++ )
   {
   	  document.getElementById('star'+i).src="/tools/star/star2.gif";  
   } 
              
   for(i=rest;i<=5;i++ )
   {
      document.getElementById('star'+i).src="/tools/star/star1.gif";  
      
   }
}

function setRating(thisField)
{      
   var pos = thisField.id.split('star');   
   var quizId    = $F('quiz_id');      

   setrating   = true;
   ratingNum   = pos[1];
   
   rest        = parseInt(pos[1]) +1;
   
   for(i=1;i<=pos[1];i++ )
   {
      document.getElementById('star'+i).src="/tools/star/star2.gif";  
   } 
   for(i=rest;i<=5;i++ )
   {
      document.getElementById('star'+i).src="/tools/star/star1.gif";
   }
     
   var url     = '/run.php/Rate';
   var pars    ='cmd=rate&rating=' + escape(ratingNum)+'&quiz_id='+quizId;
   var myAjax  = new Ajax.Request(url, {method:  'post', parameters: pars, onComplete: showstarResponse});
} 


function showstarResponse(serverResponse) 
{
   var response = serverResponse.responseText;
   $('showmsg').innerHTML = THANKS_MSG;    
}

function resetRating()
{   
   for(i=1;i<=ratingNum;i++ )
   {
      document.getElementById('star'+i).src="/tools/star/star2.gif";        
   }
   
   for(i=ratingNum+1;i<=5;i++ )
   {
      document.getElementById('star'+i).src="/tools/star/star1.gif";  
      
   }
   
   if(OMNITURE == true) createPageView('Quizfarm');
   
}

function showpreviousrating(pos)
{
   if(pos) 
   {
     ratingNum = pos;
     setRating(document.getElementById('star'+pos));
   }
   
   return;             
}
