function openRating(type, id){
	var starImages = "";
	if(type==1)
		k=11;	 //film icin 10 yildiz
	else
		k=6;
	for (i = 1; i < k; i++){ // 6 -> 11
		starImages += "<a style='cursor:pointer;' onclick='addPoint("+type+", "+id+", "+i+");'><img border=0 id=star_"+i+" onmouseout=clearStars("+i+"); onmouseover=highlightStars("+i+"); src=images/stars/star_down.gif></a>";
	}
	document.getElementById("openRating").innerHTML = starImages;
}


function highlightStars(iStarID){
	for (i = 1; i <= iStarID; i++){
		var starImage = document.getElementById("star_"+i);
		if (starImage != null){
			starImage.src = "images/stars/star_up.gif";
		}
	}
}

function clearStars(iStarID){
	for (i = iStarID; i > 0; i--){
		var starImage = document.getElementById("star_"+i);
		starImage.src = "images/stars/star_down.gif";
	}

}

function addPoint(type,id,point){

	addUserPoint(id,point,type);

	new Ajax.Request('ajax_common.php', { method: 'post',parameters:{ action:'Rate',type:type,id:id,point:point}
					 , onSuccess: function(transport) {
						var response = transport.responseText || "";
					
					 }
			 });

}

function addUserPoint(id,point,type){
	
	var starImages = "";
	
	if(type==1){
		k=10;
		myRate = "Benim Puaným : "+point+" / 10";
		if($('myPoint'))document.getElementById("myPoint").innerHTML = myRate;
	}
	else{ 
		k=5;
	}
	
	for (i = 0; i < point; i++){ 
		starImages += "<img border=0 src=images/stars/star_up.gif>";
	}
	for (i = point; i < k; i++){ 
		starImages += "<img border=0 src=images/stars/star_down.gif>";
	}
	
	document.getElementById("openRating").innerHTML = starImages;	
}


// comment

function openCommentRating(type, id ){
	var starImages = "";
	k=11;
	for (i = 1; i < k; i++){ 
		starImages += "<a title='"+i+"' style='cursor:pointer;'><img border=0 id=star"+id+"_"+i+" onclick='addCommentPoint("+type+", "+id+", "+i+");' onmouseout=clearCommentStars("+i+","+id+"); onmouseover=highlightCommentStars("+i+","+id+"); src=images/stars/star_down.gif></a>";
	}
	document.getElementById("openRating_"+id).innerHTML = starImages;
	
}

function highlightCommentStars(iStarID,id){
	for (i = 1; i <= iStarID; i++){
		var starImage = document.getElementById("star"+id+"_"+i);
		if (starImage != null){
			starImage.src = "images/stars/star_up.gif";
		}
	}
}

function clearCommentStars(iStarID,id){
	for (i = iStarID; i > 0; i--){
		var starImage = document.getElementById("star"+id+"_"+i);
		starImage.src = "images/stars/star_down.gif";
	}

}

function addCommentPoint(type,id,point){
	
	addUserCommentPoint(id,point);
	
	new Ajax.Request('ajax_common.php', { method: 'post',parameters:{ action:'RateComment',type:type, commentid:id,point:point}
					 , onSuccess: function(transport) {
						var response = transport.responseText || "";
						document.getElementById("comment_avg_"+id).innerHTML = response;
						
					 }
			 });

}

function addUserCommentPoint(id,point){
	
	var starImages = "";
	k=10;
	for (i = 0; i < point; i++){ 
		starImages += "<img border=0 src=images/stars/star_up.gif>";
	}
	for (i = point; i < k; i++){ 
		starImages += "<img border=0 src=images/stars/star_down.gif>";
	}
	myRate = "Benim Puaným : "+point+" / 10";
	document.getElementById("openRating_"+id).innerHTML = starImages;
	document.getElementById("myRating_"+id).innerHTML = myRate;
	
}
