$(function(){
$("#login_form").click(function(){
    

    
var login_user = $("#login_user").val();
var login_pass = $("#login_pass").val();

if(login_user==""){
    alert('请输入登录账号!');
    return false;
}
if(login_pass==""){
    alert('请输入登录密码!');
    return false;
}
$.post("login.php",{
    username:login_user,
    userpass:login_pass
},function(a,b){
if(a=="username_error"){
    alert('您输入的账号不存在!');
    return false;
}
if(a=="userpass_error"){
    alert('您输入的密码有误!');
    return false;
}
if(a=="0"){
    location.href='manage/manage.php';
    return false;
}
if(a=="1"){
    location.href='manage/guzhu.php';
    return false;
}

}); 
});

$(".reg").click(function(){
    
    var widthshu = $(window).width();
    var widths = parseInt((widthshu-550)/2);
    var heightshu = $(window).height();
    var heights = parseInt((heightshu-600)/2);
    $("#reg").css("left",widths + 'px');
    $("#reg").css("top",heights + 'px');
    
    
   $("#bg").show();
   $("#reg").show();
    $("#username").val('');
    $("#userpass1").val('');
    $("#userpass2").val('');
    $("#qq").val('');
    
});
$("#reg .close").click(function(){
   $("#bg").hide();
   $("#reg").hide();
});
$("#userpass2").keyup(function(){
    var userpass1 = $("#userpass1").val();
    var userpass2 = $(this).val();
   if(userpass1 != userpass2){
   $("#user_mm").html("<span style='color:red;'>两次密码输入不一致,请重新输入!</span>");
   return false;
   }else{
    $("#user_mm").html("<span style='color:green;'>输入正确!</span>");
   return false;
   }
});

$("#formreg").click(function(){
   var shenfen = $("#shenfen").val();
   var username = $("#username").val();
   var userpass1 = $("#userpass1").val();
   var userpass2 = $("#userpass2").val();
   var qq = $("#qq").val();
   var usernameif = username.replace(/[^\w\/]/ig,'');
   if(username != usernameif){
   $("#user_zh").html("<span style='color:red;'>账号不可包含中文字符</span>");
   return false;
   }
   if(username==""){
   $("#user_zh").html("<span style='color:red;'>请输入注册账号</span>");
    return false;
   }

   if(userpass1 != userpass2){
   $("#user_mm").html("<span style='color:red;'>两次密码输入不一致,请重新输入!</span>");
   return false;
   }
   
   if(qq.length < "5"){
   $("#user_qq").html("<span style='color:red;'>请正确输入您的QQ号码!</span>");
    return false;
   }
    $(this).attr("disabled",true);
    $(this).attr("value","请稍候……");
   $.post("reg.php",{
    shenfen:shenfen,
    username:username,
    userpass:userpass1,
    qq:qq
   },function(a,b){
    if(a=="0"){
        location.href='manage/manage.php';
        return false;
    }
    if(a=="1"){
        location.href='manage/guzhu.php';
        return false;
    }else{
        alert(a);
    }
   });
    
});
$("#username").keyup(function(){
    var username = $(this).val();
    var userleng = username.length;
    if(userleng > "5" && userleng < "19"){
    $.get("reg.php?username="+username+"&id="+ Math.random(),function(a,b){
    if(a=="ok"){
    $("#user_zh").html("<span style='color:green;'>输入正确,您输入的账号可注册!</span>");
    $("#formreg").attr("disabled",false);
    return false;
    }else{
    $("#user_zh").html("<span style='color:red;'>账号已被注册,请重新输入!</span>");
    $("#formreg").attr("disabled",true);
    return false;
    }
        });

    }else{
   $("#user_zh").html("<span style='color:red;'>账号长度只限于6-18个字符</span>");
    $("#formreg").attr("disabled",true);
    return false;
    }
});

$("#qq").keyup(function(){
    
    var qq = $(this).val();
    if(qq.length >= 5 && qq.length<=11){
    $("#user_qq").html("<span style='color:green;'>输入正确!</span>"); 
    }
    
});

});