<!-- The controller use for this rating system is the RatingController -->


function ajaxMagic2(url, divName){
	
	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: url,
		data: {}, //  <- set empty data otherwise we get a content-length error (411)
		success: function(msg) {
			$('#' + divName).html(msg);
		}
	});
}

function rateIt(id,rating){
	var url = encodeURI(baseUrl + '/rating/updaterating' + '/id/' + id +'/rating/'+rating);
	ajaxMagic2(url, 'rating');
	document.getElementById('user_rating').value = rating;
	//reloadStaticRating(id,'static_rating');	<!-- this is optional as in this page we have 2 rating function -->
}
	
function changeStar(partdiv,replacediv){
	document.getElementById('zero-stars').className = partdiv;
}

function resetStar(partdiv){
	document.getElementById('zero-stars').className = partdiv;
}

function updateRating(id,rating){
	var url = encodeURI(baseUrl + '/rating/tmpupdaterating' + '/id/' + id +'/rating/'+rating);
	ajaxMagic2(url, 'rating');
	document.getElementById('user_rating').value = rating;
	//reloadStaticRating(id,'static_rating');	<!-- this is optional as in this page we have 2 rating function -->
}

function loadRating(id, divName, dbName, tableName){
	var url = encodeURI(baseUrl + '/rating/loadrating/id/' + id + '/dbName/' + dbName + '/tableName/' + tableName);
	ajaxMagic2(url, divName);
}

function reloadStaticRating(id,divName){ <!-- this is optional as in this page we have 2 rating function -->
	var xmlHttp;
	try
	  {
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    try
	      {
	      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      }
	    catch (e)
	      {
	      alert("Your browser does not support AJAX!");
	      return false;
	      }
	    }
	  }
  var url = encodeURI(baseUrl + '/Rating/staticrating' + '/id/' + id);
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById(divName).innerHTML=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  
}