﻿// JScript 文件
var temp;
temp=window.location.protocol+"//"+window.location.host;

function HiddenDivLogin()
{
    var Control=document.getElementById("CheckLogin");
    var divlogin=document.getElementById("divLogin");
    if(Control.checked==true)
    {
       divlogin.style.display='none';
    }
    else
    {
       if(document.getElementById("hidennUID").getAttribute("value")=='')
       {
           divlogin.style.display='block';
       }
       else
       {
           divlogin.style.display='none';
       }
    }
}
//登陆验证******************************************
//文本框onkeypress事件
function doClick(linkId, e){    
        if(e.keyCode != 13){
        
            return;
        }
        var fireOnThis = document.getElementById(linkId)
          if (document.createEvent)
          {
            var evObj = document.createEvent('MouseEvents')
            evObj.initEvent( 'click', true, false )
            fireOnThis.dispatchEvent(evObj)
          }
          else if (document.createEventObject)
          {
               fireOnThis.fireEvent('onclick')
          }
}

function GetComment($ID,$Page,$Type){
	$.ajax({
		url:temp+"/AjaxComments/Comment1.aspx?action=ajax_getcomment&id="+$ID+"&types="+$Type+"&page="+$Page+"&time"+new Date().toString()+"&db=true",
		type:'GET',
		success:function(){
			$('#comment').html(arguments[0]);
		}
	});
}

//Ajax评论******************************************************
function SendComment(){	
		var $CommentParentID	=document.getElementById("hidennID").getAttribute("value");
		var $CommentUserID		=document.getElementById("hidennUID").getAttribute("value");
		var $Types=document.getElementById("hideTID").getAttribute("value");

		if($.trim($CommentUserID)=='')
		{
		    $CommentUserID       ='00000';
		}
       var $CommentUser       =$('#CommentUser').val();
		var $CommentText		=$('#CommentText').val();
		var $CommentValidate	=$('#CommentValidate').val();
		if ($.trim($CommentUser)=='')
		{
			alert('请您填写昵称！');
			$('#CommentUser').focus();
			return false;
		}
		if ($.trim($CommentText)=='')
		{
			alert('请您填写评论内容！');
			$('#CommentText').focus();
			return false;
		}
		if ($.trim($CommentValidate)=='')
		{
			alert('请您填写验证码！');
			$('#CommentValidate').focus();
			return false;
		}		
		if ($CommentText.length<5||$CommentText.length>200)
		{
			alert('内容必须在5-200字之间！');		
			return false;
		}
		var $Username=$('#username').val();
       var $UserPwd=$('#userpwd').val();
       
		StopButton('CommentSubmit',3);
		//执行至此处
	$.ajax({
		url:temp+"/AjaxComments/Comment1.aspx?action=ajax_sendcomment&User="+$CommentUserID+"&commentparentid="+$CommentParentID+"&commentuser="+escape($CommentUser)+"&commenttext="+escape($CommentText)+"&commentvalidate="+escape($CommentValidate)+"&time="+new Date().toString()+"&db=true&types="+$Types+"&callback=?",
		type:'get',
		datatype:'jsonp',
		jsonp:'callback',
		data:'',
		success:function(){
			if (arguments[0]=='ERROR')
			{
				alert('验证码出错！');
			}else{
			       if($.trim($Username)!=''&&$.trim($UserPwd)!='')
		            {
		                $('#Button2').click();
		            }
				GetComment($CommentParentID,1,$Types);
				alert(arguments[0]);
				$("#CommentText").val("");
					//验证成功时，刷新验证码图片
				$("#CommentValidateImages").attr("src",temp+"/AjaxComments/VerifyCode.aspx?s="+Math.random());
			}
			$("#CommentValidate").val("");
			$('#username').val("");
            $('#userpwd').val("");
			$("#divLogin").visible='false';
		}
	});
}
//***************************************************************************************************
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]+")",300);
	}
	
	if(arguments[1]<=0){
		document.getElementById(arguments[0]).value='提交评论';
		document.getElementById(arguments[0]).disabled=false;
	}
}
//**********************************************ADConsult****************************************************
function GetComment_ADConsult($ID,$Page){
	$.ajax({
		url:temp+"/AjaxComments/Comment1.aspx?action=ajax_getcomment&id="+$ID+"&page="+$Page+"&time"+new Date().toString()+"&db=false&types=0",
		type:'GET',
		success:function(){
			$('#comment').html(arguments[0]);
		}
	});
}

//Ajax评论******************************************************
function SendComment_ADConsult(){	
		var $CommentParentID	=document.getElementById("hidennID").getAttribute("value");//'6607';//
		var $CommentUserID		=document.getElementById("hidennUID").getAttribute("value");//'84046';//
		if($.trim($CommentUserID)=='')
		{
		    $CommentUserID       ='00000';
		}
       var $CommentUser       =$('#CommentUser').val();
		var $CommentText		=$('#CommentText').val();
		var $CommentValidate	=$('#CommentValidate').val();
		if ($.trim($CommentUser)=='')
		{
			alert('请您填写昵称！');
			$('#CommentUser').focus();
			return false;
		}
		if ($.trim($CommentText)=='')
		{
			alert('请您填写评论内容！');
			$('#CommentText').focus();
			return false;
		}
		if ($.trim($CommentValidate)=='')
		{
			alert('请您填写验证码！');
			$('#CommentValidate').focus();
			return false;
		}		
		if ($CommentText.length<5||$CommentText.length>200)
		{
			alert('内容必须在5-200字之间！');		
			return false;
		}
		var $Username=$('#username').val();
        var $UserPwd=$('#userpwd').val();
		StopButton('CommentSubmit',3);
        //执行至此处
	$.ajax({
		url:temp+"/AjaxComments/Comment1.aspx?action=ajax_sendcomment&User="+$CommentUserID+"&commentparentid="+$CommentParentID+"&commentuser="+escape($CommentUser)+"&commenttext="+escape($CommentText)+"&commentvalidate="+escape($CommentValidate)+"&time="+new Date().toString()+"&db=false&types=0&callback=?",
		type:'get',
		datatype:'jsonp',
		jsonp:'callback',
		data:'',
		success:function(){
			if (arguments[0]=='ERROR')
			{
				alert('验证码出错！');
			}else{
			    if($.trim($Username)!=''&&$.trim($UserPwd)!='')
		            {
		                $('#Button2').click();
		            }
				GetComment_ADConsult($CommentParentID,1);
				alert(arguments[0]);
				$("#CommentText").val("");
					//验证成功时，刷新验证码图片
				$("#CommentValidateImages").attr("src",temp+"/AjaxComments/VerifyCode.aspx?s="+Math.random());
			}
			$("#CommentValidate").val("");
			$('#username').val("");
            $('#userpwd').val("");
			$("#divLogin").visible='false';
		}
	});
}
