﻿
function userlogin()
{
    var uname = $("#UserName").val();
    var pass = $("#UserPass").val();
    if(uname==""||pass==""){
        alert("用户名或者密码不能为空");
        return;
    }
    
    var qurl = "/Ajax/User.aspx?ran="+Math.random();
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{username:uname,password:pass,action:'login'},
			//timeout : 10000,
			error : function(resp) {
				alert("系统忙碌，请稍候重试！");
			},
			success : function(data) {
                if ("1" == data.status) {
                    alert("登录成功");
                    //location="/";
                    var html = '<li class="guide">您好！'+data.username+'</li>';
				    html += '<li class="guide">';
				    html += '  <a href="/User/Index.aspx">[用户中心]</a>';
				    html += '</li>';
				    html += '<li class="guide"><a href="/User/Logout.aspx">[安全退出]</a></li>';
				    html += '<li class="guide"><a href="/User/RegSel.aspx" title="注册" target="_blank">注册</a> | </li>';
				    html += '<li class="guide"><a href="#" title="找回密码" target="_blank">找回密码</a> | </li>';
                    $("#LoginArea").html(html);
                    //window.location.reload();
                    if($(".hwordenter").length>0)
                    {
                        var whtml = "我要留言: 在此给发布者留言(最多只能填写120个汉字)";
                        whtml += "<div><textarea cols=\"70\" rows=\"6\" id=\"Content\"></textarea></div>";
                        whtml += "<table><tr><td>验证码：<input type=\"text\" style=\"width:50px;\" id=\"vcode\" /></td><td><img id=\"vcodeimg\" style=\"cursor:hand;\" onclick=\"this.src='/common/VerifyCode.aspx?time="+Math.random()+"'\" title=\"点击刷新验证码\"  src=\"/Common/VerifyCode.aspx?time="+Math.random()+"\" alt=\"验证码\" /></td></tr></table>";
                        whtml += "<div><input type=\"button\" value=\"提交留言\" onclick=\"DoLeaveWord()\" id=\"BtnSubmit\"/></div>";
                        $(".hwordenter").html(whtml);
                    }
                }else if ("2" == data.status){
                    alert("对不起，用户名或者密码错误");
                }else if ("3" == data.status){
                    alert("您的账户正在审核中，请耐心等待！我们会在24小时内帮您处理");
                }
			}
			});
}

function loginstatus()
{
    var qurl = "/Ajax/User.aspx?ran="+Math.random;
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{action:'iflogin'},
			error : function(resp) {
				alert("系统忙碌，请稍候重试！");
			},
			success : function(data) {
                if ("0" != data.status) {
                    var html = '<li class="guide">您好！'+data.status+'</li>';
				    html += '<li class="guide">';
				    html += '  <a href="/User/Index.aspx">[用户中心]</a>';
				    html += '</li>';
				    html += '<li class="guide"><a href="/User/Logout.aspx">[安全退出]</a></li>';
				    html += '<li class="guide"><a href="/User/RegSel.aspx" title="注册" target="_blank">注册</a> | </li>';
				    html += '<li class="guide"><a href="#" title="找回密码" target="_blank">找回密码</a> | </li>';
                    $("#LoginArea").html(html);
                }
			}
			});
}


function olduserlogin()
{
    var uname = $("#OldUserName").val();
    var pass = $("#OldPassword").val();
    if(uname==""||pass==""){
        alert("用户名或者密码不能为空");
        return;
    }
    
    var qurl = "/Ajax/User.aspx?ran="+Math.random();
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{username:uname,password:pass,action:'login'},
			//timeout : 10000,
			error : function(resp) {
				alert("系统忙碌，请稍候重试！");
			},
			success : function(data) {
                if ("1" == data.status) {
                    alert("登录成功");
                    //location="/";
                    var html = '<li class="guide">您好！'+data.username+'</li>';
				    html += '<li class="guide">';
				    html += '  <a href="/User/Index.aspx">[用户中心]</a>';
				    html += '</li>';
				    html += '<li class="guide"><a href="/User/Logout.aspx">[安全退出]</a></li>';
				    html += '<li class="guide"><a href="/User/RegSel.aspx" title="注册" target="_blank">注册</a> | </li>';
				    html += '<li class="guide"><a href="#" title="找回密码" target="_blank">找回密码</a> | </li>';
                    $("#LoginArea").html(html);
                    //window.location.reload();
                    var html1="";//个人会员
                    if(data.usertype=="1"){
                        html1+="<div class=\"title\">个人会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Person/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Person/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon3\"></span><a href=\"/User/Person/TradeHouse_Add.aspx?CMD=Add\">我要出售</a></li>";
                        html1+="    <li><span class=\"houseicon4\"></span><a href=\"/User/Person/LeaseHouse_Add.aspx?CMD=Add\">我要出租</a></li>";
                        html1+="    <li><span class=\"houseicon5\"></span><a href=\"/User/Person/LeaseRequest_Add.aspx?CMD=Add\">我要求租</a></li>";
                        html1+="    <li><span class=\"houseicon6\"></span><a href=\"/User/Person/TradeRequest_Add.aspx?CMD=Add\">我要求购</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Person/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }else if(data.usertype=="2"){
                        html1+="<div class=\"title\">中介会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Person/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Person/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Person/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }else if(data.usertype=="3"){
                        html1+="<div class=\"title\">经纪人会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Person/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Person/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon3\"></span><a href=\"/User/Person/TradeHouse_Add.aspx?CMD=Add\">我要出售</a></li>";
                        html1+="    <li><span class=\"houseicon4\"></span><a href=\"/User/Person/LeaseHouse_Add.aspx?CMD=Add\">我要出租</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Person/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }else if(data.usertype=="4"){
                        html1+="<div class=\"title\">开发商会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Person/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Person/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Person/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }
                    var html2="会员中心 资料修改 密码修改"; //中介
                    var html3="会员中心 我要出售 我要出租 资料修改 密码修改";//经纪人
                    var html4="会员中心 发布新楼盘  资料修改 密码修改";//开发商
                    $(".oldlogin_content").html(html1);
                }else if ("2" == data.status){
                    alert("对不起，用户名或者密码错误");
                }else if ("3" == data.status){
                    alert("您的账户正在审核中，请耐心等待！我们会在24小时内帮您处理");
                }
			}
			});
}

function oldloginstatus()
{
    var qurl = "/Ajax/User.aspx?ran="+Math.random;
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{action:'iflogin'},
			error : function(resp) {
				alert("系统忙碌，请稍候重试！");
			},
			success : function(data) {
                if ("0" != data.status) {
                    var html = '<li class="guide">您好！'+data.status+'</li>';
				    html += '<li class="guide">';
				    html += '  <a href="/User/Index.aspx">[用户中心]</a>';
				    html += '</li>';
				    html += '<li class="guide"><a href="/User/Logout.aspx">[安全退出]</a></li>';
				    html += '<li class="guide"><a href="/User/RegSel.aspx" title="注册" target="_blank">注册</a> | </li>';
				    html += '<li class="guide"><a href="#" title="找回密码" target="_blank">找回密码</a> | </li>';
                    $("#LoginArea").html(html);
                    
                    var html1="";//个人会员
                    if(data.usertype=="1"){
                        html1+="<div class=\"title\">个人会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Person/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Person/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon3\"></span><a href=\"/User/Person/TradeHouse_Add.aspx?CMD=Add\">我要出售</a></li>";
                        html1+="    <li><span class=\"houseicon4\"></span><a href=\"/User/Person/LeaseHouse_Add.aspx?CMD=Add\">我要出租</a></li>";
                        html1+="    <li><span class=\"houseicon5\"></span><a href=\"/User/Person/LeaseRequest_Add.aspx?CMD=Add\">我要求租</a></li>";
                        html1+="    <li><span class=\"houseicon6\"></span><a href=\"/User/Person/TradeRequest_Add.aspx?CMD=Add\">我要求购</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Person/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }else if(data.usertype=="2"){
                        html1+="<div class=\"title\">中介会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Agency/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Agency/Broker_List.aspx\">管理经纪人</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Agency/TradeHouse_List.aspx\">管理出售信息</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Agency/LeaseHouse_List.aspx\">管理出租信息</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Agency/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Agency/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }else if(data.usertype=="3"){
                        html1+="<div class=\"title\">经纪人会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Broker/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Broker/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon3\"></span><a href=\"/User/Broker/TradeHouse_Add.aspx?CMD=Add\">我要出售</a></li>";
                        html1+="    <li><span class=\"houseicon4\"></span><a href=\"/User/Broker/LeaseHouse_Add.aspx?CMD=Add\">我要出租</a></li>";
                        html1+="    <li><span class=\"houseicon3\"></span><a href=\"/User/Broker/TradeHouse_List.aspx\">管理出售</a></li>";
                        html1+="    <li><span class=\"houseicon3\"></span><a href=\"/User/Broker/LeaseHouse_List.aspx\">管理出租</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Broker/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }else if(data.usertype=="4"){
                        html1+="<div class=\"title\">开发商会员登录</div>";
                        html1+="<ul class=\"oldlogin_login\">";
                        html1+="    <li><span class=\"houseicon1\"></span><a href=\"/User/Empolder/Default.aspx\" >会员中心</a></li>";
                        html1+="    <li><span class=\"houseicon2\"></span><a href=\"/User/Empolder/UserInfo_Modify.aspx\">资料修改</a></li>";
                        html1+="    <li><span class=\"houseicon7\"></span><a href=\"/User/Empolder/Pass_Modify.aspx\">密码修改</a></li>";
                        html1+="</ul>";
                    }
                    $(".oldlogin_content").html(html1);
                }
			}
			});
}

$(function() {
    loginstatus();
	$("#LoginNow").click( function() {
		userlogin();
	});
	var $UName = $('#UserName'); 
	var $UPass = $('#UserPass'); 
    $UName.bind('keydown',function (e) { 
        var key = e.which; 
        if (key == 13) { 
            e.preventDefault();
            $("#LoginNow").click(); 
        }
    });
    $UPass.bind('keydown',function (e) { 
        var key = e.which; 
        if (key == 13) { 
            e.preventDefault();
            $("#LoginNow").click(); 
        }
    });
});
