﻿<!--
function submitComment() {
	if (!hasLogin()) {
		login();
	} else {
		var comment = trimCharacter(jQuery('#commentInput').val());
	    var topicid = jQuery('#topicid').val();
	    if("" == comment || "请填写留言" == comment) {
	    	alert("对不起！不能用空值或者默认内容进行留言。");
		    jQuery('#commentInput').trigger('focus');
		    return;	   	
	    }
		if (comment.length > 2000) {
	    	alert("对不起！留言最多2000字。");
	    	jQuery('#commentInput').trigger('focus');
	    	return;	
		}
		displayCommentStep('upload');
		comment = encodeURIComponent(comment);
		var param = "topicid="+topicid+"&content="+comment;
	    var url = "interface/reply.php";
	    new AjaxRequest('POST',url,param,getCommentResult);	
	}
}

function getCommentResult(jsonStr) {
    if (null != jsonStr && "" != jsonStr) {
		var myJSON = eval("(" + jsonStr +")");
		if (0 == myJSON.exitcode) {						
			jQuery('#comment_upload_word').css('background','#50D2FF');
			jQuery('#comment_upload_word').html('留言成功，等待审核');			
		} else {
			jQuery('#comment_upload_word').css('background','#FFB400');
			jQuery('#comment_upload_word').html('系统错误，请重新留言');	
		}
		window.setTimeout("displayCommentStep('result')", 3000);			
	}
}

function displayCommentStep(step) {
	if ( 'upload' == step) {
		jQuery('#comment_upload_word').css('background','#50D2FF');
		jQuery('#comment_upload_word').html('留言正在提交...');
		jQuery('#comment_upload_word').show();	
		jQuery('#comment_upload_img').hide();
	} else {
		jQuery('#comment_upload_img').show();
		jQuery('#comment_upload_word').hide();	
	}	
}

function comment() {
	var defaultTxt = "请先登录后再留言";
    var txt = "请填写留言";
    if (!hasLogin()) {
    	jQuery('#commentInput').val(defaultTxt);	
    	jQuery('#commentInput').attr('disabled',true);
    } else {
    	jQuery('#commentInput').val(txt);	
    	jQuery('#commentInput').attr('disabled',false);
    }  
    jQuery('#commentInput').focus(function(){
    	if (jQuery(this).val() == defaultTxt || jQuery(this).val() == txt) {
    		jQuery(this).val('');
    	}
    });
    jQuery('#preCommentBtn').attr('src','image/previousPage_d.gif')	
}

function openBlog(url) {
	window.open(url);
}

function prePageComment() {
	var compageObj = jQuery('#compage');
	var currenPage = compageObj.val();
	if (parseInt(currenPage) > 1) {
		compageObj.val(parseInt(currenPage) - 1);	
		showCommentList();
		jQuery('#nextCommentBtn').attr('src','image/nextPage.gif');
		jQuery('#nextCommentBtn').css('cursor','pointer');
		// first page
		if (parseInt(currenPage) == 1) {
			jQuery('#preCommentBtn').attr('src','image/previousPage_d.gif');
			jQuery('#preCommentBtn').css('cursor','auto');
		}
	}
}

function nextPageComment() {
	var compageObj = jQuery('#compage');
	var currenPage = compageObj.val();
	var maxPage = jQuery('#maxpage').val();
	if ( parseInt(currenPage) < parseInt(maxPage)) {
		compageObj.val(parseInt(currenPage) + 1);	
		showCommentList();
		var preCommentBtn = jQuery('#preCommentBtn');
		jQuery('#preCommentBtn').attr('src','image/previousPage.giff');
		jQuery('#preCommentBtn').css('cursor','pointer');
		
		if (parseInt(currenPage) == (parseInt(maxPage) - 1)) {
			jQuery('#nextCommentBtn').attr('src','image/nextPage_d.gif');
			jQuery('#nextCommentBtn').css('cursor','auto');
		}
	}
}

function showCommentList() {
    var topicid = jQuery('#topicid').val();
    var page = jQuery('#compage').val();
    var param = "topicid="+topicid+"&page="+page;
    var url = "interface/comList.php";
    new AjaxRequest('POST',url,param,getCommentInfo);
}

function getCommentInfo(jsonStr) {
	if (null != jsonStr && "" != jsonStr) {
		var myJSON = eval("(" + jsonStr +")");
		if(0 == myJSON.exitcode){
			insertCommentInfo(myJSON);
		} else {
			alert(myJSON.desc);
		}
	}
}

function insertCommentInfo(myJSON) {
	var myCommentDiv = jQuery("#commentListTable");
	var mycommentbody = jQuery("<div></div>");
	mycommentbody.attr('id','commentBody');
	//delete old comment data
	deleteCommentList();
	for (var index = 0; index < myJSON.detail.length; index++) {
		var content = myJSON.detail[index].content;
				var date = myJSON.detail[index].date;
				var author = myJSON.detail[index].author;		
				//create comment list
				var comCell = jQuery("<div></div>");
				comCell.attr('className','commentCell');
				
				var comAuthor = jQuery("<div></div>");
				comAuthor.attr('className','commentAuthor');
				comAuthor.append(author + "(" + date + "):").appendTo(comCell);

				var comContent = jQuery("<div></div>");
				comContent.attr('className','commentContent');
				comContent.append(jQuery("<pre></pre>").append(content)).appendTo(comCell);	
								 
				mycommentbody.append(comCell);
	}
	myCommentDiv.append(mycommentbody);
	addScrollBar('commentListTable');
}

function deleteCommentList() {
	jQuery('#commentListTable').empty();
}

function judgePrePageBtn(state) {
	var currenPage = jQuery('#compage').val();
	if ('over' == state) {
      	 if (parseInt(currenPage) > 1) {
      	 	jQuery('#preCommentBtn').attr('src','image/previousPage_a.gif');
      	 }   	 
    } else {
        if (parseInt(currenPage) > 1) {
      	 	jQuery('#preCommentBtn').attr('src','image/previousPage.gif');
      	 }
	}
}

function judgeNextPageBtn(state) {
	var currenPage = jQuery('#compage').val();
	var maxPage = jQuery('#maxpage').val();
	if ('over' == state) {
      	 if(parseInt(currenPage) < parseInt(maxPage)){
      	 	jQuery('#nextCommentBtn').attr('src','image/nextPage_a.gif');
      	 }   	 
    } else {
        if(parseInt(currenPage) <  parseInt(maxPage)){
      	 	jQuery('#nextCommentBtn').attr('src','image/nextPage.gif');
      	 }
	}
}
// 
function returnListPage(frmid,action) {
    jQuery('#'+frmid).attr('action',action);
    jQuery('#'+frmid).trigger('submit');
}
//-->