﻿var login =
{
    method: "",
    CheckForm: function() {
        var email = $("#email_text").val();
        var pwd = $("#pwd_text").val();
        var vcode = $("#login_code").val();
        var auto_login = true;
        if ($("#auto_login:checked").length < 1) {
            auto_login = false;
        }
        if (!login.IsEmail(email)) {
            $("#login_t").html("请正确输入你的邮箱").show();
            return;
        } else {
            $("#login_t").hide();
        }
        if (pwd.length < 6 || pwd.length > 18) {
            $("#login_t").html("密码长度应该在6-18位之间！").show();
            return;
        } else {
            $("#login_t").hide();
        }
        if (vcode.length < 1) {
            $("#login_t").html("验证码不能为空").show();
            return
        } else {
            $("#login_t").hide();
        }
        $.post('/useraction.ashx?type=2&useremail=' + email + '&userpwd=' + pwd + '&vcode=' + vcode + '&flag=' + auto_login, function(data) {
            if (data.tips) {
                switch (data.code) {
                    case "003":
                        window.location.reload();
                        break;
                    case "004":
                        $("#login_t").html("你的邮箱或密码有误").show();
                        $("#img_a").click();
                        break;
                    case "019":
                        $("#login_t").html("你的验证码输入有误").show();
                        $("#img_a").click();
                        break;
                    default:
                        break;

                }
            } else {
                return;
            }
        }, "json");
    },
    IsEmail: function(emailStr) {
        var re = /^[\w-]+(\.*[\w-]+)*@([0-9a-z]+(([0-9a-z]*)|([0-9a-z-]*[0-9a-z]))+\.)+[a-z]{2,3}$/i;
        if (re.test(emailStr))
            return true;
        else
            return false;
    },
    open: function() {
        var str = '<div class="float2010" id="login" style="width:324px;height:250px">'
					+ '<div class="bd-float floatnew-content">'
						+ '<div class="float-close" onclick="login.close()">关闭窗口</div>'
						+ '<h2 style="width:313px">登录有货：</h2>'
						+ '<div class="float-wrap">'
							+ '<form action="" method="" id="" class="form2010">'
								+ '<fieldset class="register">'
									+ '<legend>注册表单:</legend>'
									+ '<label class="inputbox useremail" style="width:250px"><b>邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</b><input style="ime-mode:disabled"  id="email_text" type="text" /></label>'
									+ '<label class="inputbox userpw" style="width:250px"><b>密&nbsp;&nbsp;&nbsp;&nbsp;码:</b><input id="pwd_text" type="password" /></label>'
									+ '<label class="inputbox usercheck"><b>验证码:</b><input id="login_code" type="text" /></label><img id="img_a" alt="看不清" src="/verifynum.ashx" onclick="this.src=\'/verifynum.ashx?\'+Math.random();" style="cursor:pointer;" />'
									+ '<label class="btn2010 btn-blacksmall" onclick="login.CheckForm()"><input type="button" value="登&nbsp;&nbsp;录" /></label>'
									+ '<p class="error red" id="login_t" style="display:none"></p>'
									+ '<div class="clear"></div>'
									+ '<label class="regyoho"><input id="auto_login" type="checkbox" checked="checked" />下次自动登录</label>'
									+ '<p class="reg-login" >还没有有货账号？<a href="javascript:void(0)" onclick="quick_reg.open()"><b>立即注册</b></a></p>'
								+ '</fieldset>'
							+ '</form>'
						+ '</div>'
					+ '</div>'
				+ '</div>';
        divShow(str);
		$("#login input").keyup(function(e){
			if(e.keyCode==13){
				login.CheckForm();
			}
        });
    },
    close: function() {
        $(".float-close").bind(
	   {
	       click: function() {
	           divShowClose();
	       }
	   });
        $(".float-close").click();
    }
}
var quick_reg =
{
    CheckForm: function() {
        var email = $("#email_text_r").val();
        var pwd = $("#pwd_text_r").val();
        var username = $("#username_text").val();
        var vcode = $("#reg_code").val();
        var reg_che = $("yohochkbox").val();
        if (!login.IsEmail(email)) {
            $("#reg_t").html("请正确输入你的邮箱").show();
            return;
        } else {
            $("#reg_t").hide();
        }
        if (pwd.length < 6 || pwd.length > 18) {
            $("#reg_t").html("密码长度应该在6-18位之间！").show();
            return;
        }
        if (vcode.length < 1) {
            $("#reg_t").html("验证码不能为空").show();
            return;
        } else {
            $("#reg_t").hide();
        }
        if (!username) {
            $("#reg_t").html("昵称不能为空").show();
            return;
        } else {
            $("#reg_t").hide();
        }
        if ($("#yohochkbox:checked").length < 1) {
            $("#reg_t").html("请阅读yoho.cn服务条款").show();
            return;
        } else {
            $("#reg_t").hide();
        }
        $.post('/useraction.ashx?type=1&useremail=' + email + '&userpwd=' + pwd + '&username=' + username + '&vcode=' + vcode, function(data) {
            if (data.tips) {
                switch (data.code) {
                    case "005":
                        window.location.reload();
                        break;
                    case "006":
                        $("#reg_t").html("你的邮箱已被注册").show();
                        $("#img_b").click();
                        break;
                    case "019":
                        $("#reg_t").html("你的验证码输入有误").show();
                        $("#img_b").click();
                        break;
                    default:
                        break;
                }
            } else {
                return;
            }
        }, "json");
    },
    open: function() {
        var str = '<div class="float2010" id="quick_reg" style="width:324px;height:250px">'
					+ '<div class="bd-float floatnew-content">'
						+ '<div class="float-close" onclick="quick_reg.close()">关闭窗口</div>'
						+ '<h2 style="width:313px">快速注册：</h2>'
						+ '<div class="float-wrap">'
							+ '<form action="" method="" id="" class="form2010">'
								+ '<fieldset class="register">'
									+ '<legend>注册表单:</legend>'
									+ '<label class="inputbox useremail" style="width:250px"><b>邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</b><input id="email_text_r" style="ime-mode:disabled" type="text" /></label>'
									+ '<label class="inputbox userpw" style="width:250px"><b>密&nbsp;&nbsp;&nbsp;&nbsp;码:</b><input id="pwd_text_r" type="password" /></label>'
									+ '<label class="inputbox username" style="width:250px"><b>昵&nbsp;&nbsp;&nbsp;&nbsp;称:</b><input id="username_text" type="text" /></label>'
									+ '<label class="inputbox usercheck"><b>验证码:</b><input id="reg_code" type="text" /></label><img id="img_b" alt="看不清" src="/verifynum.ashx" onclick="this.src=\'/verifynum.ashx?\'+Math.random();" style="cursor:pointer;" />'
									+ '<label class="btn2010 btn-redsmall" onclick="quick_reg.CheckForm()"><input type="button" value="快速注册" /></label>'
									+ '<p class="error red" id="reg_t" style="display:none"></p>'
									+ '<div class="clear"></div>'
									+ '<label class="regyoho"><input type="checkbox" checked="checked" id="yohochkbox" />我已阅读并同意遵守<a target="_blank" href="http://www.yoho.cn/About/aboutTerms.shtml" class="green">yoho.cn服务条款</a></label>'
									+ '<p class="reg-login" >已有账号？<a href="javascript:void(0)" onclick="login.open()"><b>登录</b></a></p>'
								+ '</fieldset>'
							+ '</form>'
						+ '</div>'
					+ '</div>'
				+ '</div>';
        divShow(str);
		$("#quick_reg input").keyup(function(e){
			if(e.keyCode==13){
				quick_reg.CheckForm();
			}
        });
    },
    close: function() {
        $(".float-close").bind({
            click: function() {
                divShowClose();
            }
        });
        $(".float-close").click();
    }
}
var active = {
    open: function() {
        var str = '<div class="float2010" style="height:500px">'
		  + '<div class="bd-float floatnew-content">'
		  + '<div class="float-close" onclick="active.close()">关闭窗口</div>'
		  + '<h2>激活账号：</h2>'
		  + '<div class="float-wrap">'
		  + '<h3 class="alertbig"><img src="http://pics.yoho.cn/yohobuy/floatlayer/alertbig.gif" />你的账号还未激活</h3>'
		  + '<div class="center"><span class="btn2010 btn-redsmall"><a href="http://i.yoho.cn/Manage/EditBasicInfo.aspx" target="_blank">立即激活</a></span></div>'
		  + '<br />'
		  + '<hr />'
		  + '<h4 class="alertpart"><img src="http://pics.yoho.cn/yohobuy/floatlayer/alertsmall.gif" />为什么要激活？</h4>'
		  + '<p class="alertpart">1,  新用户开通帐户后将会获得<a href="http://www.yoho.cn/help/helpinfo_01.html#point" class="red"     target="_blank">积分</a>。积分可用于兑换<a href="http://buy.yoho.cn/help0905/help_biz02.html#help_b02yohocoin" class="red" target="_blank">YOHO币</a>进行线上购物，参加各种站内活动等。</p>'
		  + '<p class="alertpart">2,  开通帐户后在<a href="http://buy.yoho.cn" target="_blank" class="red">有货</a>线上购物会返还你相应的现金YOHO币。</p>'
		  + '<h4 class="alertpart"><img src="http://pics.yoho.cn/yohobuy/floatlayer/alertsmall.gif" />收不到邮件？</h4>'
		  + '<p class="alertpart">1,&nbsp;&nbsp;确认你的邮箱可以正常接收邮件；</p>'
		  + '<p class="alertpart">2,&nbsp;&nbsp;可以到你邮箱的垃圾邮件目录里找找；</p>'
		  + '<p class="alertpart">3,&nbsp;&nbsp;请点击<a href="http://www.yoho.cn/YohoGuestBook/GuestBook.aspx" target="_blank" class="red">这里</a>给我们留言，或联系<a href="http://buy.yoho.cn/chat/onlineservies.aspx" class="red" target="_blank">客服</a>。</p>'
		  + '</div>'
		  + '</div>'
		  + '</div>';
        divShow(str);
    },
    close: function() {
        $(".float-close").bind({
            click: function() {
                divShowClose();
            }
        });
        $(".float-close").click();
    }
};
