﻿var urlpath = "";
var loadtype = "";
var objyx;
function showlog(obj) {
    //弹出层,若要登录转到登录页

    var dbhtml = "<div id='reg_quly'><div style='display:inline;margin-left:30px;width:225px;display:inline; float:left;margin-top:20px; margin-left:20px;'><div style='height:40px;'><div class='commloginDiv'></div><div style='float:left; margin:2px 0 0 5px; color:#666; font-weight:bold;'>您必须登录以继续操作</div></div><div class='Clear'></div><table id='table'><tr style='height:45px'><td class='td1width'>用户名：</td><td><input class='logininput'  id='yp_userName' type='text' maxlength='50' /></td>";
    dbhtml += "</tr><tr><td class='td1width'>密码：</td><td><input id='yp_userPwd' class='logininput' type='password'  value='' maxlength='18' /></td></tr><tr><td></td> <td><input checked='checked' type='checkbox' id='forgetLogin' style='float:left;padding-bottom:10px' /><div style=' margin-top:0px;*margin-top:3px; float:left' ><label for='forgetLogin' style='color:#666666;' >保持登入状态</label></div></td></tr><tr><td style='height:25px'></td><td style='height:25px'> <div id='logdiv' style=' float:left;'><div style='background:url(/images/smallLogin.jpg) no-repeat scroll -26px 2px transparent;width:13px;height:15px;float:left; margin-top:2px'></div><div style='float:left; margin-left:5px'>用户名或密码错误</div></div></td></tr><tr><td></td><td><input type='button' id='clicklog' /><span class='Commona'><a href='/Forgotpwd.html' style='text-decoration:underline'>忘记密码</a></span></td>";
        dbhtml += "</tr></table></div><div style='float:left; display:inline;margin-left:30px;margin-top:15px;'><img src=\"/images/logline.jpg\"  title=''/></div><div style='float:left; display:inline; margin-top:21px; margin-left:20px;' id='logininfo'><div id='lgon2' ></div><ul><li><span class='lgtd_1'>电子邮件：</span><span class='lgtd_2'><input type='text' id='reg_email'/></span><span class='lgtd_3'></span><div id='reg_email_1'></div></li><li><span class='lgtd_1'>用户名：</span><span class='lgtd_2'><input type='text' id='reg_user'/></span><span class='lgtd_4'></span><div id='reg_user_1'></div></li><li><span class='lgtd_1'>密码：</span><span class='lgtd_2'><input type='password' id='reg_pwd'/></span><div id='reg_pwd_1'></div></li><li class='reviewcontenta '><span class='lgtd_1'></span><input type='checkbox' id='cbServbox' checked='true' />接受<a href='/support/aboutUS#tk'>易评网服务条款</a></li>";
        dbhtml += "<li><span class='lgtd_1'></span><input  id='btnsubmitreg' type='button' /></li></ul></div></div>";
        dbhtml += " <div id='acitveReg'><div id='acitveReg_0'><img  src='/images/wait.gif'/></div><div id='acitveReg_2'>已向&nbsp;&nbsp;<span id='acitveReg_2_1'></span>&nbsp;&nbsp;发送了一封激活邮件,请点击邮件里的链接完成注册</div><div id='acitveReg_3'></div>";
        dbhtml += "<div id='acitveReg_4'>没有收到邮件？</div><div id='acitveReg_5'>它可能归类在您的<span class='acitveReg_4_1'>垃圾邮件</span>中。如果超过十分钟仍然没有收到，请点击此处<span class='acitveReg_4_2'>重新发送邮件激活</span></div></div>";
      
        showWindow('', dbhtml, '用户登录', '', '550', '330', 'tgrz');
        
        var reg_email = $("#reg_email"); //邮箱注册
        var reg_user = $("#reg_user"); //用户名注册
        var reg_pwd = $("#reg_pwd"); //用户密码
        var issub = false;
        var emailFous = function checkEmail() {//验证email
            var regd = /^[\w\.]+([-]\w+)*@[A-Za-z0-9-_]+[\.][A-Za-z0-9-_]/;
            if (!regd.test(reg_email.val()))
            { $("#reg_email_1").html("邮箱格式不正确"); issub = false;  }
            else {

                ///查看是否已注册
                $.get('/WebServe/userHand.ashx?userEmail=' + reg_email.val() + "&usertype=3" + "&round=" + (new Date).getSeconds(), function(data) {
                    if (data == 0)
                    { $("#reg_email_1").html(""); issub = true; $(".lgtd_3").css("display", "inline-block") }
                    else
                    { $("#reg_email_1").html("此邮箱已注册"); issub = false; $(".lgtd_3").css("display", "none") }
                })
            }
        }

        var userNameFous = function userNameFous() {//验证用户名
            var regd = /^[A-Za-z0-9\u4E00-\u9FFF]+$/;
            if (getstringlength($.trim(reg_user.val())) < 3 || getstringlength($.trim(reg_user.val())) > 20)
            { $("#reg_user_1").html("用户名由3到20个字符组成"); issub = false; }
            else {
                ///查看是否已注册
                $.get("/WebServe/userHand.ashx?userName=" + reg_user.val() + "&usertype=4" + "&round=" + (new Date).getSeconds(), function(data) {
                    if (data == 0)
                    { $("#reg_user_1").html(""); issub = true; $(".lgtd_4").css("display", "inline-block") }
                    else
                    { $("#reg_user_1").html("此用户名已注册"); issub = false;$(".lgtd_4").css("display", "none") }
                })
            }
        }
        
        var userpwdreg = function userpwdFous() { //验证密码
        var regd = /^[A-Za-z0-9\u4E00-\u9FFF]+$/;
        if (getstringlength($.trim(reg_pwd.val())) < 6 || getstringlength($.trim(reg_pwd.val())) > 16)
        { $("#reg_pwd_1").html("密码由6到16个字符组成"); issub = false; }
        else
        { $("#reg_pwd_1").html(""); issub = true;  }
        }

        //
       
        //重发激活码
        $(".acitveReg_4_2").click(function() {
         
            $("#acitveReg_2").html("邮件发送中。。。");
            $.get("/WebServe/userHand.ashx?usertype=9&useremailnew=" + emails + "&uName=" + reguserNames + "&t=" + new Date().getSeconds(), function(data) {
                if (data != "no-regin") {
                    $("#acitveReg_2").html("已发送成功，请再次确认，完成激活邮件");
                }
                else { $("#acitveReg_2").html("邮件发送失败，请与我们客服联系，或重新注册"); }
            })

        })
        var pwdEvent = function pwdEventfoucs(event) {//获取焦点
        
            if (event.which == 13) {
                $("#btnsubmitreg").click();
            }
        }
       //
        reg_email.bind("blur", emailFous);
        reg_user.bind("blur", userNameFous);
        reg_pwd.bind("blur", userpwdreg);
        reg_pwd.bind("keydown", pwdEvent);
        var emails;
        var reguserNames;
        //stare--------------注册------------------------------
        $("#btnsubmitreg").click(function() {
            reg_email.blur()
            reg_user.blur();
            reg_pwd.blur();
            if (!$("#cbServbox").attr("checked"))
                return false;
            if (issub == true) {
                $("#btnsubmitreg").hide();
                $("#btnsubmitreg").after("<span>数据加载中...<span>");
                $.get("/WebServe/userHand.ashx?yp_email=" + reg_email.val() + "&yp_userName=" + escape(reg_user.val()) + "&yp_pwd=" + reg_pwd.val() + "&usertype=14" + "&r=" + new Date().getSeconds(), function(data) {
                    if (data != "") {
                        var pwd = reg_pwd.val();
                        emails = reg_email.val();
                        reguserNames = reg_user.val();
                        $("#acitveReg").show();
                        $("#reg_quly").hide();
                        $("#acitveReg_3").html("<a target='_blank' href='" + data.split(',')[0] + "'>去" + data.split(',')[1].split('.')[0] + "邮箱</a>");
                        $("#acitveReg_2_1").html(reg_email.val());
                        var l = setInterval(function() {
                            $.get("/WebServe/userHand.ashx?userName=" + emails + "&usertype=1" + "&r=" + new Date().getSeconds() + "&pwd=" + pwd + "&cblogin=true", function(data) {
                                if (data != "") {
                                    if (data.split(',')[1] == 1) {
                                        dUserid = data.split(',')[0];
                                        clearInterval(l);
                                        Senderobj(obj);
                                    }
                                }
                            })

                        }, 5000)
                    }
                    else {
                        $("#btnsubmitreg").show();
                        $("#btnsubmitreg").next().hide();
                    }
                })
            }

        })
      
     
        //end
        $("#clicklog").click(function() {
            var tipinfo = $("#logdiv"); //提示信息
            var ypwd = $.trim($("#yp_userPwd").val()); //密码
            var userName = $.trim($("#yp_userName").val()); //用户名
            if (getstringlength(userName) < 3) {
                tipinfo.show();
                return false;
            }
            if (ypwd.length < 6 || ypwd.length > 20) {
                tipinfo.show(); //显示
                return false;
            }
            var cblogin = $('#forgetLogin').attr('checked'); //是否长久登入
            $.get("/WebServe/userHand.ashx?usertype=1&userName=" + escape(userName) + "&pwd=" + ypwd + "&r=" + (new Date()).getSeconds() + "&cblogin=" + cblogin, function(data) {

                if (data != "")//登录成功
                {
                    var datasplit = data.split(',');
                    if (datasplit[1] == "1") {//已激活
                        dUserid = datasplit[0];
                        dUserName = userName;
                        $("#lg").hide();
                        $("#lg1").show();
                        $("#lg2").text(userName);
                        Senderobj(obj);
                        //
                    } else {
                        window.location.href = "/reg_new2.aspx?isAction=true";
                    }
                }
                else {
                    tipinfo.show();
                }
            })


        })

    function getstringlength(str) {
        return str.replace(/[^\x00-\xff]/ig, "aa").length;
    }
   
    $("#loading").bind("ajaxStart", function() {
        $(this).show();
        $("#clicklog").hide();

    })
    $("#loading").bind("ajaxStop", function() {
        $(this).hide();
        $("#clicklog").show();
    })

    $("#yp_userPwd").keyup(function(event) {
        if (event.which == 13) {
            $("#clicklog").click();
        }
    })

   
}
function gotoReg() {
    window.location.href = '/reg_new1.aspx';
}

function pathul() {
    if (urlpath != "") {
        closeWindow("tgrz");
        window.location.reload(true);
    }

}
function getstringlength(str) {
    return str.replace(/[^\x00-\xff]/ig, "aa").length;
}


function Senderobj(obj) {
    //
    if (obj == "followuser") { //关注此评论人
        urlpath = window.location.href;
        $("#guanzuta").click();
    }
    else if (loadtype == "dafen") {//打分
        urlpath = window.location.href + "&temp=temp#dafen";
        obj.click();
    }
    else if (obj == "gcp") {//关注此产品
        urlpath = window.location.href;
        $("#followproc").click();
    }
    else if (obj == "yx") {//评印象
        urlpath = window.location.href;
        $("#impressub").click();
    }
    else if (obj == "ryx") {//重新加载印象
        urlpath = window.location.href;
        objyx.click();
    }
    else if (obj == "reply")//回复
    {
        urlpath = window.location.href;
        $("#btnsave").click();
    }
    else if (loadtype == "gz")//关注guanzhu.aspx|fensi.aspx
    {
        urlpath = window.location.href;
        obj.click();
    }
    else if (loadtype == "gzqx") { //取消关注guanzhu.aspx|fensi.aspx
        urlpath = window.location.href;
        obj.click();
    }
    else if (loadtype == "hdlogin") { //活动页面
        urlpath = window.location.href;
        obj.click();
    }
    else if (loadtype == "searchlogin") { //搜索页面
        urlpath = window.location.href;
        bindclick(obj);
    }
    else if (loadtype == "Factorites") { //收藏
        urlpath = window.location.href;
        obj.click();
    }
    else if (loadtype == "shparReview") { //分享
        urlpath = window.location.href;
        obj.click();
    }
    else if (loadtype == "tasklv") {
        urlpath = window.location.href;
        obj.click();
    }
    else if (loadtype == "jianPing") {
        urlpath = window.location.href;
        window.location.href = urlpath;
    }
    else if (loadtype == "myTask") {
        urlpath = window.location.href;
        window.location.href = urlpath;
    }
    else if (loadtype == "hdYq") {
        urlpath = window.location.href;
        window.location.href = urlpath.replace("?t=dhq", "").replace("?t=yq", "") + "?t=yq";
    }
    else if (loadtype == "hdDhq") {
        urlpath = window.location.href;
        window.location.href = urlpath.replace("?t=yq", "").replace("?t=dhq", "") + "?t=dhq";
    }
   //


}
