// JavaScript Document
	
	$(document).ready(function() {

		// get current rating
		x=document.ratingfrm;
		var ItemCode=document.getElementById("ItemCode").value
//		alert(ItemCode)
//	 	alert ("hi")
		getRating();
//		alert(ItemCode)

		// get rating function
		function getRating()
		{
				$.ajax({
				type: "GET",
				url: "updatestar.php",
				data: "do=getrate" +"&itemcode="+x.ItemCode.value,
				cache: false,
				async: false,
				success: function(result) {
					// apply star rating to element
					$("#current-rating").css({ width: "" + result + "%" });
				
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
			
		}
		
		// link handler
		$('#ratelinks li a').click(function(){
			$.ajax({
			
				type: "GET",
				url: "updatestar.php",
				data: "rating="+$(this).text()+"&do=rate"+"&itemcode="+x.ItemCode.value,
//				data: "itemcode=str",
				cache: false,
				async: false,
				success: function(result) {
					// remove #ratelinks element to prevent another rate
					$("#ratelinks").remove();
				// get rating after click
					getRating();
					
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
			
		});
	});

