// JavaScript Document
function StopButton(){
	document.getElementById(arguments[0]).disabled=true;
	document.getElementById(arguments[0]).value="提交("+arguments[1]+")";
	if(--arguments[1]>0){
		window.setTimeout("StopButton('"+arguments[0]+"',"+arguments[1]+")",1000);
	}
	if(arguments[1]<=0){
		document.getElementById(arguments[0]).value='提交';
		document.getElementById(arguments[0]).disabled=false;
	}
}
function GetComment($ID,$Page){
	$.ajax({
		url:"book/Comment.asp?action=ajax_getcomment&id="+$ID+"&page="+$Page+"&time"+new Date().toString(),
		type:'GET',
		success:function(){
			$('#comment').html(arguments[0]);
		}
	});
}
function SendComment(){	
		var $CommentParentID	=arguments[0];
		var $CommentUser		=$('#CommentUser').val();
		
		var $Company			=$('#Company').val();
		var $Address			=$('#Address').val();
		var $Telephone			=$('#Telephone').val();
		var $Email				=$('#Email').val();
		
		var $CommentText		=$('#CommentText').val();
		var $CommentValidate	=$('#CommentValidate').val();
		if ($.trim($CommentUser)=='')
		{
			alert('请您填写昵称');
			$('#CommentUser').focus();
			return false;
		}
		
		
		if ($.trim($Company)=='')
		{
			alert('请您填写单位');
			$('#Company').focus();
			return false;
		}
		if ($.trim($Address)=='')
		{
			alert('请您填写地址');
			$('#Address').focus();
			return false;
		}
		if ($.trim($Telephone)=='')
		{
			alert('请您填写电话');
			$('#Telephone').focus();
			return false;
		}
		if (!$.trim($Email).match(/^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/))
		{
			alert('请您正确填写mail');
			$('#Email').focus();
			return false;
		}
		
		
		if ($.trim($CommentValidate)!='www.yodsn.com')
		{
			alert('请您正确填写我们的网址');
			$('#CommentValidate').focus();
			return false;
		}	
		
		if ($.trim($CommentText)=='')
		{
			alert('请您填写内容');
			$('#CommentText').focus();
			return false;
		}
		if ($CommentText.length<5||$CommentText.length>2000)
		{
			alert('内容必须在5-2000字之间！');		
			return false;
		}
		StopButton('CommentSubmit',10);
	$.ajax({
		url:"book/Comment.asp?action=ajax_sendcomment&commentparentid="+$CommentParentID+"&commentuser="+escape($CommentUser)+"&Company="+escape($Company)+"&Address="+escape($Address)+"&Telephone="+escape($Telephone)+"&Email="+escape($Email)+"&commenttext="+escape($CommentText)+"&commentvalidate="+escape($CommentValidate)+"&time="+new Date().toString(),
		type:'GET',
		success:function(){

				GetComment($CommentParentID,0);
				alert(arguments[0]);
				$("#CommentText").val("");
					//验证成功时，刷新验证码图片
				$("#CommentValidateImages").attr("src","book/Code.asp?s="+Math.random());

			$("#CommentValidate").val("");
		}
	});
//SetCookie("CommentUser",$CommentUser,3);
}
