
//----------邮箱检测
function checkemail(email){
    $.post("info.aspx", { cmd: "email", email: email }, email_result);
}
function email_result(r) {
    r = parseInt(r);
    var resultbox = $("#check_email");
    if (r == 1) {
        resultbox.html('<img src="/images/yesok.gif" align="absmiddle"/> '); //邮箱可用
        flag[1] = 1;
        check_data();
    }
    else if (r == -1) {
        resultbox.innerHTML = '<img src="/./images/yesno.gif" align="absmiddle"/> <font color=red>邮箱格式错误</font>';
        flag[0] = 0;
        check_data();
    }
    else {
        resultbox.html('<img src="/images/yesno.gif" align="absmiddle"/> <font color=red>该邮箱已经注册过</font>');
        flag[1] = 0;
        check_data();
    }
}

//---进行注册-----------------------------------------------------------------
function sendinfo() {
        if (!checkPost()) {
            $("#check_ok").html("<img src='/images/yesno.gif' align='absmiddle'/> <font color=red>用户信息输入不完整...</font>");
            return;
        }
    var $email = $('#email').val();
    var $username = $('#username').val();
    var $password1 = $('#password1').val();
    var $sex = $('#sex').attr("vi");
    var $age_me = $('#age_me').attr("vi");
    var $iheight_me = $('#iheight_me').attr("vi");
    var $weight_me = $('#weight_me').attr("vi");
    var $love = $('#love').attr("vi");
    var $edu_me = $('#edu_me').attr("vi");
    var $job_me = $('#job_me').attr("vi");
    var $performance = $('#performance').attr("vi");
    var $attitude = $('#attitude').attr("vi");
    var $bx = $("#biaoxian").attr("vi");
    var $area_b = $('#area_b').val();
    var $area_s = $('#area_s').val();
    var $area = $('#area').val();
    var $qq_me = $('#qq_me').val();
    var $msn_me = $('#msn_me').val();
    if ($msn_me == "选填") {
        $msn_me = "";
    }
    var $mobile = $('#mobile_me').val();
    if ($mobile == "选填") {
        $mobile = "";
    }
    var $odds = $('#odds').val();
    var $age_begin = $('#age_begin').val();
    var $age_end = $('#age_end').val();
    var $iheight_begin = $('#iheight_begin').val();
    var $iheight_end = $('#iheight_end').val();
    var $weight_begin = $('#weight_begin').val();
    var $weight_end = $('#weight_end').val();
    var $edu1 = $('#edu1').attr("vi");
    var $job1 = $('#job1').attr("vi");
    var $itlove = $('#itlove').attr("vi");
    var $t_else = $('#t_else').val();
    var ts = $("input:checked", $("#placePanel"));
    var $ps = '';
    for (var i = 0; i < ts.length; i++) {
        $ps += $(ts[i]).val() + ",";
    }
    var $imycode = $('#imycode').val();

    $.get("info.aspx",
    { cmd: "reg",
        email: escape($email),
        username: escape($username),
        password: escape($password1),
        sex: $sex,
        age_me: $age_me,
        iheight_me: escape($iheight_me),
        weight_me: escape($weight_me),
        love: escape($love),
        edu_me: escape($edu_me),
        job_me: escape($job_me),
        performance: escape($performance),
        attitude: escape($attitude),
        bx:$bx,
        area_b: escape($area_b),
        area_s: escape($area_s),
        area: escape($area),
        qq_me: escape($qq_me),
        msn_me: escape($msn_me),
        mobile: $mobile,
        odds: escape($odds),
        age_begin: escape($age_begin),
        age_end: escape($age_end),
        iheight_begin: escape($iheight_begin),
        iheight_end: escape($iheight_end),
        weight_begin: escape($weight_begin),
        weight_end: escape($weight_end),
        edu_ta: escape($edu1),
        job_ta: escape($job1),
        itlove: escape($itlove),
        t_else: escape($t_else),
        ps: escape($ps),
        imycode: escape($imycode)
    },
    function (result) {
        resultReg(result, $email,$password1, $sex, $username);
    },"json");
}
function resultReg(result, email, password, sex, username) {
    var id =parseInt(result.id);
    if (id < 0) {
        var target = result.target;
        var message = decodeURIComponent(result.tip);
        var tip = $("#check_" + target);
        $("#" + target).focus();
        tip.html("<img src='/images/yesno.gif' align='absmiddle'/><font color=red>" + message + "</font>");
        $("#check_ok").html("<img src='/images/yesno.gif' align='absmiddle'/><font color=red>" + message + "</font>");
    }
    else {
        $("#activeHand").bind("click", function () {
            sendemail(id, email, password, sex, username);
        });
        $("#loginLink").attr("href", "/members/login.aspx?cmd=register&account=" + email + "&password=" + password);
        show_regok(email);
    }
}


//---进行邮件发送-----------------------------------------------------------------
	
function sendemail(uid,email, password,sex, username) {
    $.get("info.aspx", { cmd: "active", uid: uid, email: email, password:password, sex: sex, name: username },
    function (r) {
        r = parseInt(r);
        if (r > 0) {
            $("#send_email").html("<img src='/images/yesok.gif' align='absmiddle'/> 邮件发送成功，请查收！");
        }
        else {
            $("#send_email").html("<img src='/images/yesno.gif' align='absmiddle'/> 邮件发送失败,请浅激活账号.");
        }
    });
}


//---进行登录验证-----------------------------------------------------------------
function checklogin(show) {
    var $Key_Username = $('#Key_Username').val();
    var $Key_Password = $('#Key_Password').val();
    if ($.trim($Key_Username) == '' || $.trim($Key_Username) == '请输入登录邮箱') {
        $("#check_login").html("<img src='/images/yesno.gif' align='absmiddle'/> <font color=red>请输入登录邮箱..</font>");
        $('#Key_Username').focus();
        return false;
    }

    if ($.trim($Key_Password) == '' || $.trim($Key_Password) == '密码') {
        $("#check_login").html("<img src='/images/yesno.gif' align='absmiddle'/> <font color=red>请输入密码..</font>");
        $('#Key_Password').focus();
        return false;
    }

    var rx = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (!rx.test($Key_Username)) {
        $("#check_login").html("<img src='/images/yesno.gif' align='absmiddle'/> <font color=red>请输入登录邮箱...</font>");
        return false;
    }
    $("#check_login").html("<img src='/images/floading.gif' align='absmiddle'/> 登录中,请稍后...");
    $.get("/members/login.aspx", { cmd: "default", account: $Key_Username, password: $Key_Password, r: Math.random() }, function (r) {
        var result = parseInt(r);
        if (result > 0) {
            if (show != null) {
                window.location.href = show;
            }
            else {
                window.location.href = "/members";
            }
        }
        else {
            if (result == -1) {
                $("#check_login").html('您输入的验证码错误，请重新输入');
            }
            else if (result == -2) {
                $("#check_login").html('用户名或密码错误，请重新输入');
            }
            else if (result == -3) {
                $("#check_login").html('账号格式错误，请输入您的登录账号');
            }
            else if (result == -4) {
                $("#check_login").html('您输入密码不足4位，请重新输入');
            }
            else if (result == -5) {
                $("#check_login").html('您输入的验证码错误，请重新输入');
            }
        }
    });
}

	
//---进行账号浅激活-----------------------------------------------------------------
function sendsmalltag(email,Recommended,sex,username){
	var xmlhttp;
	var resultsendsmalltag=document.getElementById("send_smalltag");
	try{
		xmlhttp=new XMLHttpRequest();
	}catch(e){
    		var a=['MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','MICROSOFT.XMLHTTP.1.0','MICROSOFT.XMLHTTP.1','MICROSOFT.XMLHTTP'];
    		for (var i=0;i<a.length;i++){
      			try{
        			xmlhttp = new ActiveXObject(a[i]);
        			break;
      			}catch(e){}
    		}
  	}
	xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4){
		if (xmlhttp.status==200){
			var data=xmlhttp.responseText;
			sendsmalltag_result(data);
			}
		else{
			resultsendsmalltag.innerHTML="<img src='/images/yesno.gif' align='absmiddle'/> <font color=red>传值错误.</font>";
			}
		}
	else{
		resultsendsmalltag.innerHTML="<img src='/images/floading.gif' align='absmiddle'/> 正在进行浅激活...";
		//document.getElementById("Reg_all").style.display = "none";
		}
	}
	xmlhttp.open("post", "Check_smalltag.asp", true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send("email="+escape(email)+"&Recommended="+escape(Recommended)+"&sex="+escape(sex)+"&username="+escape(username));
}
function sendsmalltag_result(data){
	var resultsendsmalltag=document.getElementById("send_smalltag");
	if(data==1){//注册后激活
		window.location.href="/notLogin/?tag=small"
		}
	else if(data==3){//登录后激活	
		window.location.href="/notLogin/?tag=small"
	}		
	else{
		resultsendsmalltag.innerHTML="<img src='/images/yesno.gif' align='absmiddle'/> 激活失败.请稍后重试......";
	}
	}
	

//////////////提交后按钮延时


	function StopButton1() {
	    document.getElementById(arguments[0]).disabled = true;
	    document.getElementById(arguments[0]).innerHTML = "<img src=\"/images/apply2.png\" alt=\"\" align=\"absmiddle\"/>请认真阅读以下协议(" + arguments[1] + ")";
	    if (--arguments[1] > 0) {
	        window.setTimeout("StopButton1('" + arguments[0] + "'," + arguments[1] + ")", 1000);
	    }
	    if (arguments[1] <= 0) {
	        document.getElementById(arguments[0]).innerHTML = '<img src="/images/apply2.png" alt="" align="absmiddle"/>我已阅读并同意以下协议';
	        document.getElementById(arguments[0]).disabled = false;
	    }
	}
	function StopButton2() {
	    document.getElementById(arguments[0]).disabled = true;
	    document.getElementById(arguments[0]).innerText = "提交注册信息(" + arguments[1] + ")";
	    if (--arguments[1] > 0) {
	        window.setTimeout("StopButton2('" + arguments[0] + "'," + arguments[1] + ")", 1000);
	    }
	    if (arguments[1] <= 0) {
	        document.getElementById(arguments[0]).innerText = '提交注册信息';
	        document.getElementById(arguments[0]).disabled = false;
	    }
	}
