﻿// JScript 文件

jQuery(function($) { 

$("#load").ajaxStart(function(){
     $(this).html('<img name="" src="../images/floading.gif"/>请稍等...');
       });
$("#load").ajaxStop(function(){
      $(this).html("");
       }); 
//showcity(调用id,下拉列表名称后的数字,默认选择id,下拉列表的名称)	   
showloginState();
});

// 得到登陆状态
function showloginState(){
$.ajax({
			type:"post",
			url:"../GetDataByAjax/LoginState.ashx",
			// timeout: 2000,
			data:"",
			cache:false, 
			success:function(html){
				$("#l").html(html);
			},
			error:function(){
				$("#lerr").html("服务器错误！"); 
				return false;
			}					
		});

}

// 登陆
function login(UserName, Pass){
$.ajax({
			type:"post",
			url:"../GetDataByAjax/LoginState.ashx",
			// timeout: 2000,
			data:"UserName="+UserName+"&Pass="+Pass,
			cache:false, 
			success:function(html){
			    
			 	if(html.toUpperCase() == "LOGINFALSE"){
			 	    alert("您输入的用户名和密码不匹配！");
			 	}
			 	showloginState();
			},
			error:function(){
				$("#ferr").html("服务器错误！"); 
				return false;
			}					
		});

} 


// 登陆
function loginRegister(UserName, Pass){
$.ajax({
			type:"post",
			url:"../GetDataByAjax/LoginState.ashx",
			// timeout: 2000,
			data:"UserName="+UserName+"&Pass="+Pass,
			cache:false, 
			success:function(html){
			    
			 	if(html.toUpperCase() == "LOGINFALSE"){
			 	    alert("您输入的用户名和密码不匹配！");
			 	}
			 	if (html.toUpperCase() == "LOGINTRUE"){
			 	    window.location.href='../Member/';
			 	}
			},
			error:function(){
				$("#ferr").html("服务器错误！"); 
				return false;
			}					
		});

} 



// 验证登陆
function CheckLogin()
{
    var txUser = document.getElementById("txUserName");
    var txPass = document.getElementById("txbPass");
    if (txUser.value.trim() == "")
    {
        alert("请输入您的用户名！");
        txUser.focus();
        return false;
    }
    
    if (txPass.value.trim() == "")
    {
        alert("请输入您的密码！");
        txPass.focus();
        return false;
    }
    
    login(txUser.value.trim(), txPass.value.trim());
}


function loginCheck()
    {    
        var txUser = document.getElementById("txU");
        var txPass = document.getElementById('txP');
        if (txUser.value.trim() == "")
        {
            alert("请输入用户名!");
            txUser.focus();
            return false;
        }
        
        if (txPass.value.trim() == "")
        {
            alert("请输入密码！");
            txPass.focus();
            return false;
        }
        
        loginRegister(txUser.value.trim(), txPass.value.trim());
    }

// 确定是否退出
function LoginOut()
{
    if (confirm("您确定要退出么？"))
        loginOutNow();
    else
        return false;
}



// 退出登陆
function loginOutNow(){
$.ajax({
			type:"post",
			url:"../GetDataByAjax/LoginOperate.ashx",
			// timeout: 2000,
			data:"Logout=1",
			cache:false, 
			success:function(html){			    
			 	if(html.toUpperCase() == "LOGOUTSUCCESS"){
			 	    alert("退出成功！");
			 	}
			 	showloginState();
			},
			error:function(){
				$("#ferr").html("服务器错误！"); 
				return false;
			}					
		});

} 



// 判断登陆状态
function JudgeLoginState(txUserName)
{        
    var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    var url = "../GetDataByAjax/LoginOperate.ashx?Judge=1";
    XmlHttp.Open("POST",url,false);
    XmlHttp.Send();  
    if (XmlHttp.status == 200)
    {        
        var result = XmlHttp.responseText;  
        
        if (result.toUpperCase() == "FALSE")
        {               
            alert("您还没有登陆或者登陆超时，请先登录！");
	 	    if (document.getElementById(txUserName))
	 	    {			 	    
	 	        document.getElementById(txUserName).focus();
	 	    }
	 	    return false;
        }
        
        else
            return true;
    }
}    

// 定义方法，根据对象ID号得到评论内容
function GetComments(objectID, pageindex, type)
{
    $.ajax({
		type:"GET",
	    url:"../GetDataByAjax/LoginOperate.ashx",
	    // timeout: 2000,
	    data:"PageIndex=" + pageindex + "&ObjectID=" + objectID + "&type=" + type,
	    cache:false, 
	    success:function(html){	
	        $("#CommentsList").html(html);
	        //document.write(html);
	    },
	    error:function(){
				    $("#cerr").html("服务器错误！");
				    return false;
		}	
	});
}

// 定义方法，提交评论内容
function SendComment(objectID, type)
{
    if (!document.getElementById("txUserName"))
    {           
        // 调用方法，处理提交评论
        DoComment(objectID, type);
    }
    
    else
    {
        alert("对不起，您还没有登陆，请登录之后再做评论！");
        document.getElementById("txUserName").focus();
    }
}

// 定义方法，处理提交信息并返回结果
function DoComment(objectID, type)
{    
    var $CommentTitle		=$('#txTitle').val();
	var $CommentContent		=$('#txContent').val();
	var $CommentCode	    =$('#txCode').val();
	
	if ($.trim($CommentTitle)=='')
	{
		alert('请您填写标题！');
		$('#txTitle').focus();
		return false;
	}
	if ($.trim($CommentContent)=='')
	{
		alert('请您填写内容！');
		$('#txContent').focus();
		return false;
	}
	if ($.trim($CommentContent).length < 5)
	{
		alert('内容必须大于5个字，请认真填写！');
		$('#txContent').focus();
		return false;
	}
	if ($.trim($CommentCode)=='')
	{
		alert('请您填写验证码！');
		$('#txCode').focus();
		return false;
	}
	if (JudgeValidateCode($CommentCode))
	{
	    StopButton('btn_Comments', 30);
        $.ajax({
			    type:"POST",
			    url:"../GetDataByAjax/LoginOperate.ashx",
			    // timeout: 2000,
			    data:"title=" + encodeURI($CommentTitle) + "&content=" + encodeURI($CommentContent) + "&ObjectID=" + objectID + "&type=" + type, // type
			    cache:false, 
			    success:function(html){			    
			 	    if(html.toUpperCase() == "SUCCESS"){
			 	    
			 	        GetComments(objectID, 1, type);
			 	        $("#txTitle").val("");
			 	        $("#txContent").val("");
			 	        $("#txCode").val("");			 	        
			 	        alert("发布成功！");
			 	        $("#xiangxi_comment_submit").hide();
			 	        $("#imgCode").click();
			 	        
			 	    }
			 	    else{
			 	    alert(html);
			 	    }
    			 	
			    },
			    error:function(){
				    $("#cerr").html("服务器错误！");
				    return 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]+")",1000);
	}
	if(arguments[1]<=0){
		document.getElementById(arguments[0]).value='提 交';
		document.getElementById(arguments[0]).disabled=false;
	}
}