var starReset ;
function stars_deactivate() {
	starText = document.getElementById('star_text') ;
	starText.innerHTML = "&nbsp;Click to rate" ;
	for ( x = 1; x <= starLimit; x++ ) {
		thisStar = document.getElementById('star' + x) ;
		thisStar.src = "http://pictures.student.com/main/star_off.gif" ;
	}
}
function stars_rollover(star, limit) {
	starText = document.getElementById('star_text') ;
	if ( limit == 5 ) {
		switch (star) {
			case 1:
				newText = "Just bad" ;
				break ;
			case 2:
				newText = "It's OK" ;
				break ;
			case 3:
				newText = "Pretty good" ;
				break ;
			case 4:
				newText = "Really great" ;
				break ;
			case 5:
				newText = "Awesome video" ;
				break ;
			default:
				newText = "Click to rate" ;
				break ;
		}
		starText.innerHTML = "&nbsp;" + newText ;
	}
	clearTimeout(starReset) ;
	for ( x = 1; x <= limit; x++ ) {
		thisStar = document.getElementById('star' + x) ;
		if ( x <= star ) {
			thisStar.src = "http://pictures.student.com/main/star_red_on.gif" ;
		} else {
			thisStar.src = "http://pictures.student.com/main/star_red_off.gif" ;
		}
	}
}
function stars_rollout(limit) {
	starLimit = limit ;
	starReset = setTimeout('stars_deactivate()', 500) ;
}
function stars_rate(video_id, star, limit) {
	var rating = parseInt(star) ;
	if ( rating == 0 ) rating = 1 ;
	if ( rating > limit ) rating = limit ;
	var requestData = "vid=" + video_id + "&rating=" + rating + "&limit=" + limit ;
	if (!ajax_sendRequest("_video_rate", requestData, "stars_rate_success", "stars_rate_failure")) {
		alert('Please enable javascript on your browser to rate videos.') ;
	}
}
function stars_rate_success(thisResult) {
	result = thisResult.split("|");
	var rating = parseInt(result[1]) ;
	var limit = parseInt(result[2]) ;
	clearTimeout(starReset) ;
	for ( x = 1; x <= limit; x++ ) {
		thisCell = document.getElementById('starcell' + x) ;
		if ( x <= rating ) {
			starSrc = "http://pictures.student.com/main/star_on.gif" ;
		} else {
			starSrc = "http://pictures.student.com/main/star_off.gif" ;
		}
		thisCell.innerHTML = "<img src=\"" + starSrc + "\" border=\"0\" alt=\"\"/>" ;
	}
	starText = document.getElementById('star_text') ;
	starText.innerHTML = "&nbsp;Thanks for rating!" ;
}
function stars_rate_failure(thisResult) {
	result = thisResult.split("|") ;
	alert(result[1]) ;
	return;
}
function VideoShowComment() {
	comment_box = document.getElementById('video_comment_box') ;
	comment_box.style.display = "" ;
	comment_link = document.getElementById('video_comment_link') ;
	comment_link.style.display = "none" ;
}
function VideoDiscardComment() {
	comment_box = document.getElementById('video_comment_box') ;
	comment_box.style.display = "none" ;
	comment_textarea = document.getElementById('video_comment') ;
	comment_textarea.value = "" ;
	comment_link = document.getElementById('video_comment_link') ;
	comment_link.style.display = "" ;
}
function VideoPostComment() {
	var comment = document.getElementById('video_comment').value ;
	var video_id = document.getElementById('video_id').value ;
	if ( comment == "" ) {
		alert("Please enter a comment.") ;
		return ;
	}
	if ( !video_id ) {
		alert("SYSTEM ERROR: No video selected.") ;
		return ;
	}
	var requestData = "vid=" + video_id + "&comment=" + comment ;
	if (!ajax_sendRequest("_video_comment", requestData, "VideoPostComment_success", "VideoPostComment_failure")) {
		alert('Please enable javascript on your browser to comment on videos.') ;
	}
}
function VideoPostComment_success(thisResult) {
	var result = thisResult.split("|") ;
	var the_login_name = result[1] ;
	var date = result[2] ;
	var comment = result[3] ;

	my_comment = document.getElementById('my_comment') ;
	my_comment.innerHTML = "<a class=\"blue\" href=\"javascript:showProfileWindow('" + the_login_name + "')\">" + the_login_name + "</a>, " + date + "<br/>" + comment ;
	my_comment.style.display = "" ;

	comment_box = document.getElementById('video_comment_box') ;
	comment_box.style.display = "none" ;
	comment_box.innerHTML = "" ;
	comment_link = document.getElementById('video_comment_link') ;
	comment_link.style.display = "none" ;
	comment_link.innerHTML = "" ;

	no_comments = document.getElementById('video_no_comments') ;
	if ( no_comments && no_comments != undefined ) {
		no_comments.style.display = "none" ;
	}
	return;
}
function VideoPostComment_failure(thisResult) {
	result = thisResult.split("|") ;
	alert(result[1]) ;
	return;
}
function VideoDeleteComment(comment_id) {
	if ( confirm('Are you sure you want to delete this comment?') ) {
		var video_id = document.getElementById('video_id').value ;
		if ( !video_id ) {
			alert("SYSTEM ERROR: No video selected.") ;
			return ;
		}
		var requestData = "vid=" + video_id + "&comment_id=" + comment_id ;
		if (!ajax_sendRequest("_video_comment_delete", requestData, "VideoDeleteComment_success", "VideoDeleteComment_failure")) {
			alert('Please enable javascript on your browser to delete a comment.') ;
		}
	}
}
function VideoDeleteComment_success(thisResult) {
	result = thisResult.split("|") ;
	comment = document.getElementById('video_comment_' + result[1]) ;
	comment.style.display = "none" ;
}
function VideoDeleteComment_failure(thisResult) {
	result = thisResult.split("|") ;
	alert(result[1]) ;
	return;
}
