function doLogin() {
	window.location.href = ctx +"/jit.u";
}

function checkCommentText(action) {
	if (action == "focus") {
		if ($("#commentText").val() == "Post your comment here...")
			$("#commentText").val("");
	}
	if (action == "blur") {
		if ($.trim($("#commentText").val()) == "")
			$("#commentText").val("Post your comment here...");
	}
}

function limitText(limitField,limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
		$(limitField).scrollTo($(limitField).attr('scrollHeight'));
	}
}

function menuMouseOver(elementId) {
	$("#"+elementId).addClass("classMouseOver");
	if ($("#"+elementId).hasClass("classClick") || $("#"+elementId).hasClass("classMouseOver")) {
		//if (elementId == "menuOption02")
			//$("#img02").attr("src",ctx+"/images/module/classroom/toolbar/icon02_ov.png");
		if (elementId == "menuOption11")
			$("#img11").attr("src",ctx+"/images/module/classroom/toolbar/icon11_ov.png");
	}
}

function menuMouseOut(elementId) {
	$("#"+elementId).removeClass("classMouseOver");
	if ( !$("#"+elementId).hasClass("classClick") && !$("#"+elementId).hasClass("classMouseOver") ) {
		//if (elementId == "menuOption02")
			//$("#img02").attr("src",ctx+"/images/module/classroom/toolbar/icon02.png");
		if (elementId == "menuOption11")
			$("#img11").attr("src",ctx+"/images/module/classroom/toolbar/icon11.png");
	}
}

function menuClick(elementId) {
	switch (elementId)	{
	case 'menuOption01':
		showNoteList();
		break;
	case 'menuOption02':
		showHideAttachment();
		break;
	case 'menuOption03':
		scroll(0,700);
		showHideResponses("click");
		break;
	case 'menuOption04':
		showOfficeHour();
		break;
	case 'menuOption05':
		showEmailInstructor();
		break;
	case 'menuOption06':
		showEmailLesson();
		break;
	case 'menuOption07':
		showURL();
		break;
	case 'menuOption08':
		showRate();
		break;
	case 'menuOption09':
		showBookMark();
		break;
	case 'menuOption10':
		//$("#menuOption10").toggleClass("classClick");
		//$("#menuOption10").addClass("classClick");
		giftLesson($("#arg1").val(),$("#arg2").val(),$("#arg3").val());
		break;
	case 'menuOption11':
		showReport();
		break;
	case 'menuOption12':
		//$("#menuOption12").addClass("classClick");
		fbs_click();
		break;
	default:
		alert('error');
	}
}

function selectImg(imgNum){
	if(imgNum!=null) {
		if (imgNum > 9)
			$("#menuOption"+imgNum).addClass("classClick");
		else 
			$("#menuOption0"+imgNum).addClass("classClick");

		if (imgNum == 11)
			$("#img11").attr("src",ctx+"/images/module/classroom/toolbar/icon11_ov.png");
		
		if (imgNum != 1 || imgNum != 2){
			document.getElementById("file_swf_room").setIsPopupWindowFlg("select");
		}
	}
}

function unselectImg(imgNum){
	if(imgNum!=null) {
		if (imgNum > 9)
			$("#menuOption"+imgNum).removeClass("classClick");
		else
			$("#menuOption0"+imgNum).removeClass("classClick");

		if (imgNum == 11)
			$("#img11").attr("src",ctx+"/images/module/classroom/toolbar/icon11.png");
		
		if (imgNum != 1 || imgNum != 2){
			document.getElementById("file_swf_room").setIsPopupWindowFlg("unselect");
		}
	}
}

/*function disableImg(imgNum){
	if(imgNum!=null) {
		$("#img"+imgNum).attr("src",ctx+"/images/module/classroom/toolbar/icon"+imgNum+"_ds.png");
	}
}*/

function showNoteList() {
	//$("#menuOption01").toggleClass("classClick");
	document.getElementById("file_swf_room").showNoteList();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
} 

function showHideAttachment(){
	$("#menuOption02").toggleClass("classClick");
	
	if($("#menuOption02").hasClass("classClick"))
		$("#divAttachments").show();
	else
		$("#divAttachments").hide();
}

function showHideResponses(action){
	if (action!="" && action!=null) {
		if (action=="post")
			$("#menuOption03").addClass("classClick");
		else
			$("#menuOption03").toggleClass("classClick");
		
		if($("#menuOption03").hasClass("classClick")){
			$("#responseArrow").attr("src",ctx+"/images/module/classroom/arrow.png");
			$("#responseContent").css("height", "auto");
			$("#responseContent").show();
			$("#divComment").show();
		}
		else{
			$("#responseArrow").attr("src",ctx+"/images/module/classroom/arrow_right.png");
			$("#responseContent").hide();
			$("#divComment").hide();
		}
		
		if (action=="empty") {
			$("#divComment").hide();
			$("#responseTitle").hide();
			$("#responseContent").hide();
		}
	}
}

function showOfficeHour() {
	//$("#menuOption04").toggleClass("classClick");
	document.getElementById("file_swf_room").showOfficeHour();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

function showEmailInstructor() {
	//$("#menuOption05").toggleClass("classClick");
	document.getElementById("file_swf_room").showEmailInstructor();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

function showEmailLesson() {
	//$("#menuOption06").toggleClass("classClick");
	document.getElementById("file_swf_room").showEmailLesson();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

function showURL() {
	//$("#menuOption07").toggleClass("classClick");
	document.getElementById("file_swf_room").showURL();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

function showRate() { 
	//$("#menuOption08").toggleClass("classClick");
	document.getElementById("file_swf_room").showRelateLessonFlg = false;
	document.getElementById("file_swf_room").showRate(false);
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

function showBookMark() {
	//$("#menuOption09").toggleClass("classClick");
	document.getElementById("file_swf_room").showBookMark();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

function showReport() {
	//$("#menuOption11").toggleClass("classClick");
	document.getElementById("file_swf_room").showReport();
	document.getElementById("file_swf_room").setLessonShareObject();
	scroll(0,140);
}

/*
function showComments(page){
	document.getElementById("file_swf_room").showAddComment(false,"");
	document.getElementById("file_swf_room").showReportComment(false,"");
	document.getElementById("file_swf_room").setLessonShareObject();
	getComments("","","",page);
}
 */
function deleteCommentOk(commentId){
	//document.getElementById("file_swf_room").showAddComment(false,"");
	//document.getElementById("file_swf_room").showReportComment(false,"");
	document.getElementById("file_swf_room").setLessonShareObject();
	getComments("deletecomment",commentId,"","1");
}

function deleteComment(commentId){
	//document.getElementById("file_swf_room").deleteCommentMessage("Are you sure you want to delete this comment?",commentId);
	confirmMsg("Are you sure you want to delete this comment?",function(){deleteCommentOk(commentId);});
}

function showToolbar(lessonUserId,loginUserId){
/*	if(lessonUserId!=loginUserId){
		disableChat();
	} else {
		disableAbuse();
	}
*/
}
/*
function disableChat(){
	$("#img04").attr("src",ctx+"/images/module/classroom/toolbar/icon04_ds.png");
	$("#img04").attr("title","Chat");	
}

function disableAbuse(){
	$("#img11").attr("src",ctx+"/images/module/classroom/toolbar/icon11_ds.png");
	$("#img11").attr("title","Report Content Abuse");
}
*/
function hideToolbar(){		
	$('#footer_toolbar').hide();
	$('#footer_toolbar').html('');
	$('#footer_toolbar').remove();
}

function checkLogin(loginUserId) {
	if (loginUserId == '') {
		confirmLogin("Please log in to comment this Lesson.",function(){goLoginComment()});
		enableButton($("#postCommentBtn"));
		return false;
	}
	return true;
}

function postComment(commentId,loginUserId,type) {  
	disableButton($("#postCommentBtn"));
	checkLogin(loginUserId);
	var limitNum = 2000;
	var content;
	if (type=="post") {
		content = $.trim(document.getElementById("commentText").value.substring(0, limitNum));
		content = content.replace(/\'/g, "&#39;");
		content = content.replace(/\r\n/g, "<br>");
		content = content.replace(/\n/g, "<br>");
		content = content.replace(/\r/g, "<br>");
	}
	else if (type=="update") {
		content = $.trim(document.getElementById("commentEditText"+commentId).value.substring(0, limitNum));
		content = content.replace(/\'/g, "&#39;");
		content = content.replace(/\r\n/g, "<br>");
		content = content.replace(/\n/g, "<br>");
		content = content.replace(/\r/g, "<br>");
		document.getElementById("responseTextDiv"+commentId).value=content;
	}
	var conlen = content.length;
	if (conlen != 0 && content != "Post your comment here..."){ 
		getComments("savecomment",commentId,content,"1");
	}
	else {
		alertMessageWarning("Please enter your comment.",function(){});
		enableButton($("#postCommentBtn"));
	}
}

function editResponse(commentId,comment) {
	var content = comment.replace(/&#39;/g, "\'");
	content = content.replace(/<br>/g, "\n");
	//content = content.replace(/\r\n/g, "\n");
	
	$("#responseEditDiv"+commentId).show();
	$("#responseUpdateBtn"+commentId).show();
	$("#responseTextDiv"+commentId).hide();
	$("#responseEditBtn"+commentId).hide();

	$("#commentEditText"+commentId).autogrow();
	$("#commentEditText"+commentId).focus();
	$("#commentEditText"+commentId).val(content);
	
}

function cancelEditResponse(commentId) {
	$('#responseTextDiv'+commentId).show();
	$('#responseEditBtn'+commentId).show();
	$('#responseEditDiv'+commentId).hide();
	$('#responseUpdateBtn'+commentId).hide();	
}

/*function activateTextAreaExpand(txtAreaId) {
	$(txtAreaId).autogrow();
}*/

function showReportComment(url,windowId, width, commentId, loginUserId){
	//document.getElementById("file_swf_room").showReportComment(true,commentId);
	if (loginUserId == '') {
    	confirmLogin("Please log in to report inappropriate comment.",function(){goLoginReportComment(commentId)});
		return;
    }
    var window = $("#"+windowId);
    window.html(''//<div id="clarityDiv"></div>'
        + '<div id="window" style="width:' + width + 'px">'
        + '<div id="window_content">' + '</div>' + '</div>');
    var divId = $("#window");
    divId.css("top","15%").css("left",(document.body.clientWidth - divId.attr('clientWidth')) / 2+ document.body.scrollLeft + "px");
    //divId.css("left",(document.body.clientWidth - document.getElementById("window").clientWidth) / 2+ document.body.scrollLeft + "px");   
    //divId.css("top",document.getElementById("window").offsetTop - 200 +"px");   
    window.show();  
    getPage(url, 'window_content');
    scroll(0,700);
}

function closeReportComment(){
	$("#reportCommentDiv").html('');
}

function calculateCommentLength(){
    var commentLength = 2000 - $.trim($("#reportCommentText").val()).length;
	if (commentLength <= 0){
		$("#reportCommentText").val($.trim($("#reportCommentText").val()).substring(0, 2000));
		commentLength = 0;
	}
	$("#reportCommentCounter").html("* " + commentLength + " characters remaining");
    if (commentLength == 2000){
    	$("#reportCommentCounter").html("* 2000 characters maximum");
    } 
}

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+
			encodeURIComponent(u)+'&t='+encodeURIComponent(t),
			'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function checkReportComment() {
	if($.trim($("#reportCommentText").val())==""){
		  alertMessageWarning("Please explain why this comment is inappropriate.",function(){$("#reportCommentText").focus();});
		  return false;
	}
	return true;
}
//add by leo.gao for open 3 rows rating summary page when click rating in classromm
function ratingClick(){
	document.getElementById("file_swf_room").showRatingSummary3Rows();
	scroll(0,140);
}
//add by leo.gao for goto view rating summary page
function viewRatingSummary(lessonId){
	window.location.href = ctx + "/rating_summary.jsp?lessonId=" + lessonId;
}