// JavaScript Document
$(document).ready(function(){
	$.post(tentpath+'js/comments.php?action=main&S_ID='+S_ID+'&types='+types,function(R){
		 if (R=="close"){
			 $("#av_comment").html("<b>站长已经关闭评论！</b>");
			 }									
		 else if (R!=""){	
		  $("#av_comment").html(R);
		 }
	})	




})

function showlist(page,id){
	$("#Message").html("正在载入中,请稍等．．．");
	$.post(tentpath+'js/comments.php?action=main&S_ID='+S_ID+'&types='+types+'&pages='+page,function(R){
	    if (R=="close"){
			 $("#av_comment").html("&nbsp;<b>站长已经关闭评论!</b>");
			 $("#av_comment").css("display","none");
			 }									
		 else if (R!=""){									
		  $("#av_comment").html(R);
		 }									
		})
	}

function check_sub(){
			var content=$("#comment_content").val();
			var names=$("#syccom_user").val();
			var codes=$("#codes").val();
			var score= $('input[@name=score][@checked]').val();
			var id=$("#Syc_VID").val();
			var types=$("#types").val();
			if (names==""){$("#msg_syccms_connment").html("&nbsp;&nbsp;<b>请输入你的大名！</b>");return false;}
			if (content==""){$("#msg_syccms_connment").html("&nbsp;&nbsp;<b>请输入留言内容！</b>");return false;}
			if (codes==""){$("#msg_syccms_connment").html("&nbsp;&nbsp;<b>请输入验证码！</b>");return false;}
			$.post(tentpath+'js/comments.php',{action:"add",content:content,names:names,codes:codes,score:score,types:types,id:id},function(R){
				
				if(R=="timeerror"){
					$("#msg_syccms_connment").html("&nbsp;&nbsp;<b>兄台，不要着急嘛，15秒时间还没过呢！</b>");
				}
				else if(R=="namelenerr"){
					 $("#msg_syccms_connment").html("&nbsp;&nbsp;<b>用户名过长！</b>");
					 }
				 else if(R=="contentlenerr"){
					 $("#msg_syccms_connment").html("&nbsp;&nbsp;<b>留言内容过长！</b>");
					 }
				else if(R=="codeerr"){
					 $("#msg_syccms_connment").html("&nbsp;&nbsp;<b>验证码不正确！</b>");
					}	 
				 else{	
				 	
				 	if(R=="checkok"){alert('站长已经开启评论审核,审核将显示!');}
				 $.post(tentpath+'js/comments.php?action=main&S_ID='+id+'&types='+types,function(R){															
						$("#av_comment").html(R);
					
			})	
}
				 }) 

	}


function keywords_sub(){
			var content=$("#keywords").val();
			var id=$("#Chsh_VID").val();
			var types=$("#types1").val();
			if (content==""){$("#msg_key_connment").html("&nbsp;&nbsp;<font color=red><b>请输入内容！</b></font>");return false;}
			$.post(tentpath+'js/comments.php',{action:"keyadd",content:content,types:types,id:id},function(R){
				
				if(R=="keylenerr"){
					$("#msg_key_connment").html("&nbsp;&nbsp;<font color=red><b>最多只能输入5个字！</b></font>");
				} 
				if(R=="keyyes"){
					$("#msg_key_connment").html("&nbsp;&nbsp;<font color=red><b>该标签已经存在！</b></font>");
				} 
				 else{	
				 $.post(tentpath+'js/comments.php?action=main&S_ID='+id+'&types='+types,function(R){															
						$("#av_comment").html(R);
					
			})	
}
				 }) 

	}


function insertTags(tagOpen, tagClose, sampleText) {
    var txtarea = document.getElementById("comment_content");

	if(document.selection) {
		var theSelection = document.selection.createRange().text;
		if(!theSelection) { theSelection=sampleText;}
		txtarea.focus();
		if(theSelection.charAt(theSelection.length - 1) == " "){
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}
	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var myText = (txtarea.value).substring(startPos, endPos);
		if(!myText) { myText=sampleText;}
		if(myText.charAt(myText.length - 1) == " "){ 
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " "; 
		} else {
			subst = tagOpen + myText + tagClose; 
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;

	} else {
		tagOpen=tagOpen.replace(/\n/g,"");
		tagClose=tagClose.replace(/\n/g,"");
		document.infoform.infobox.value=tagOpen+sampleText+tagClose;
		txtarea.focus();
	}
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}