// JavaScript Document

	$(document).ready(function() {

		// get current rating
		
	

		getRating();

		// get rating function

		function getRating(){
			
			var bid = $("#bus_id").val();

			$.ajax({
				

				
				type: "GET",

				url: "http://payperanking.com/locksmith/star_rating/update.php",

				data: "do=getrate"+"&bid=" + bid, 

				cache: false,

				async: false,

				success: function(result) {

					// apply star rating to element
					//alert(result);
					
					$("#current-rating").css({ width: "" + result + "%" });

				},

				error: function(result) {
					//alert(result);

					//alert("some error occured, please try again later");

				}

			});

		}
		
		
		
		function userrating(){
			
			
			
			
			var strno = $("#strno").val();
			$.ajax({
				
				
				type: "GET",
				url: "http://payperanking.com/locksmith/star_rating/update.php",
				
				//data: "rating="+$(this).text()+"&do=userrate"+"&bid="+bid,
				data: "do=userrate"+"&strno=" + strno, 
				
				cache: false,
				async: false,
				success: function(result) {
					// apply star rating to element
					//alert(result);
					$("#user-rating").css({ width: "" + result + "%" });
					$("#star_message").show();
				},
				error: function(result) {
					//alert("some error occured, please try again later");
				}
			});
		}

		

		// link handler

		$('#ratelinks li a').click(function(){
		var bid = $("#bus_id").val();
		$("#strno").val($(this).text());
		//alert(bid);

			$.ajax({

				type: "GET",

				url: "http://payperanking.com/locksmith/star_rating/update.php",

				data: "rating="+$(this).text()+"&do=rate"+"&bid="+bid,

				cache: false,

				async: false,

				success: function(result) {
					
					// remove #ratelinks element to prevent another rate
					
					$("#ratelinks").remove();
					
					userrating();			
					// get rating after click
					//alert('Your rating has been updated. Please add your review also. The admin will verify and display your rating and review');	
					//userrating();
					

				},

				error: function(result) {

					//alert("some error occured, please try again later");

				}

			});

			

		});
		
		
		
		
		

	});

