function loadComment(pageID, userID ,movieID ) {
	var txtComment=document.getElementById("comment");
	if(txtComment){
		var args = "type=loadComment&page=" +pageID+"&movie=" + movieID+"&user="+userID;
		makePOSTRequest('/cgi2/manageMovies.pl',args, 'loadComment');
   }
}

function loadCommentHandler(reqObj){
	if (reqObj.readyState == 4){
   		if (reqObj.status==200 || window.location.href.indexOf("http")==-1){
			var data = eval('(' + reqObj.responseText + ')');
			if(data.status=="OK"){				
				document.getElementById("dispComment").innerHTML = data.html;
				document.getElementById("pagenav").innerHTML = data.nav;
				document.getElementById("commentcount").innerHTML = data.count;			
				document.getElementById("comment").value = '';
				counterUpdate('comment', 'countBody');
			}
		}
   	}
}

function submitComment() {
	var txtComment=document.getElementById("comment");	
	if(txtComment){
		var postStr = "type=comment&comment=" + encodeURI(txtComment.value) +"&movie=" + encodeURI( document.getElementById("movieID").value)+"&user=" +encodeURI( document.getElementById("memID").value) +"&visitor=" + encodeURI( document.getElementById("visitorID").value);
		makePOSTRequest('/cgi2/manageMovies.pl', postStr, 'addComment');
   }
}

function addCommentHandler(reqObj) {
   if (reqObj.readyState == 4){
   		if (reqObj.status==200 || window.location.href.indexOf("http")==-1){
			var data = eval('(' + reqObj.responseText + ')');
			if(data.status=="OK"){				
				loadComment(0,data.memid, data.movieid);
			}
			alert(data.alert);
		}else{
			alert(getErrorString());
		}
   	}
}

function rateMovie(rating) {
	var postStr = "type=rating&rating=" + rating +"&movie=" + encodeURI( document.getElementById("movieID").value)+"&user=" + encodeURI( document.getElementById("memID").value)+"&visitor=" + encodeURI( document.getElementById("visitorID").value);
	makePOSTRequest('/cgi2/manageMovies.pl', postStr, 'addRating');
}


function addRatingHandler(reqObj) {
   	if (reqObj.readyState == 4){
   		if (reqObj.status==200 || window.location.href.indexOf("http")==-1){
			var data = eval('(' + reqObj.responseText + ')');
			if(data.status=="OK"){				
				document.getElementById("1star").style.display="none";
				document.getElementById("2star").style.display="none";
				document.getElementById("3star").style.display="none";
				document.getElementById("4star").style.display="none";
				document.getElementById("5star").style.display="none";
				document.getElementById("current-rating").style.width=data.current;
				document.getElementById("ratingText").innerHTML=data.ratingStr;
				createCookie(data.movieid,data.rating,1);
			}
			alert(data.alert);		
		}else{
			document.getElementById("1star").style.display="";
			document.getElementById("2star").style.display="";
			document.getElementById("3star").style.display="";
			document.getElementById("4star").style.display="";
			document.getElementById("5star").style.display="";
			alert(getErrorString());
		}
   	}
	
}
