﻿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:"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 $CommentCp		=$('#CommentCp').val();
		var $CommentCpadress		=$('#CommentCpadress').val();
		var $CommentTel		=$('#CommentTel').val();
		var $CommentEmail		=$('#CommentEmail').val();
		var $CommentText		=$('#CommentText').val();
		var $CommentValidate	=$('#CommentValidate').val();
		if ($.trim($CommentUser)=='')
		{
			$('#msg').html('联系人不能为空！');
			$('#CommentUser').focus();
			return false;
		}
				if (($.trim($CommentTel)=='')&&($.trim($CommentEmail)==''))
		{
			$('#msg').html('电话和邮箱地址至少有一个不能为空！');
			$('#CommentTel').focus();
			return false;
		}
		
	
		if($.trim($CommentEmail)!='')
		{
		var str=$CommentEmail
		var reg=/^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/
match=reg.test(str);
if (!match){
				$('#msg').html('邮箱格式不对。');
			$('#CommentEmail').focus();
			return false;
          }
			
		}
		
		if($.trim($CommentTel)!='')
		{
		var str=$CommentTel
		var reg=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/
match=reg.test(str);
if (!match){
				$('#msg').html('电话格式不对！电话格式为区号-电话号码，如0595-8888888');
			$('#CommentTel').focus();
			return false;
          }
			
		}
		
		if ($.trim($CommentValidate)=='')
		{
			$('#msg').html('请您填写验证码！');
			$('#CommentValidate').focus();
			return false;
		}		
		if ($.trim($CommentText)=='')
		{
			$('#msg').html('请您填写描述内容！');
			$('#CommentText').focus();
			return false;
		}
		if ($CommentText.length<5||$CommentText.length>200)
		{
			$('#msg').html('内容必须在5-200字之间！');		
			return false;
		}
		StopButton('CommentSubmit',10);
	$.ajax({
		url:"Comment.asp?action=ajax_sendcomment&commentparentid="+$CommentParentID+"&commentuser="+escape($CommentUser)+"&commentcp="+escape($CommentCp)+"&commentcpadress="+escape($CommentCpadress)+"&commenttel="+escape($CommentTel)+"&commentemail="+escape($CommentEmail)+"&commenttext="+escape($CommentText)+"&commentvalidate="+escape($CommentValidate)+"&time="+new Date().toString(),
		type:'GET',
		success:function(){
			if (arguments[0]=='ERROR')
			{
				$('#msg').html('验证码出错！');
			}else{
				GetComment($CommentParentID,0);
				$('#msg').html(arguments[0]);
				$("#CommentText").val("");
					//验证成功时，刷新验证码图片
				$("#CommentValidateImages").attr("src","Code.asp?s="+Math.random());
			}
			$("#CommentValidate").val("");
			$("#CommentUser").val("");
			$("#CommentCp").val("");
			$("#CommentCpadress").val("");
			$("#CommentTel").val("");
			$("#CommentEmail").val("");
			
		}
	});
//SetCookie("CommentUser",$CommentUser,3);
}
