$(function() {
var qqInput=$("#qq");
var qqPholder=qqInput.attr("placeholder");
var pwdInput=$("#pwd");
var pwdPholder=pwdInput.attr("placeholder");
var setPlaceHolderAction= function(ele,def){
ele.focus(function(){
ele.attr("placeholder","");
if(ele.val().length<=0||ele.val()==def){
ele.val("");
}
});
ele.blur(function(){
if(ele.val().length<=0){
ele.attr("placeholder",def);
}
});
};
setPlaceHolderAction(qqInput,qqPholder);
setPlaceHolderAction(pwdInput,pwdPholder);
var info = {};
var msgBox = $("#msg_box"), verifyBox = $("#verify_box"), lockMash = $("#bg_shadow"), loadingBox = $("#loading_box");
var curBox = msgBox;
var w = $("body>div");
lockMash.width($(window).width());
lockMash.height($(document).height());
var timer;
var orientationChange = function() {
clearTimeout(timer);
timer = setTimeout(function () {
if(curBox.is(':visible')){
setCenter(curBox);
lockMash.width($(window).width());
lockMash.height($(document).height());
}
}, 500);
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", orientationChange, false);
var setCenter = function(box){
box.css({
top : (w.height() - box.height()) / 2 + "px",
left : (w.position().left + (w.width() - box.width()) / 2)
+ "px"
});
}
var showLoading = function() {
setCenter(loadingBox);
curBox.hide();
loadingBox.show();
curBox = loadingBox;
}
var showPrompt = function(str) {
$("#qq").attr("disabled",true);
$("#pwd").attr("disabled",true);
$("#mbox_txt").html(str);
setCenter(msgBox);
curBox.hide();
msgBox.show();
curBox = msgBox;
}
$("#mbox_cz_btn").click(function() {
$("#qq").attr("disabled",false);
$("#pwd").attr("disabled",false);
msgBox.hide();
lockMash.hide();
});
var checkUinPwd = function() {
var qq = $("#qq").val();
if (qq.length == 0 || qq < 10000) {
showPrompt("请输入正确的帐号!");
return false;
}
var pwd = $("#pwd").val();
if (pwd.length == 0) {
showPrompt("你还没有输入密码!");
return false;
}
var pmd5 = $.md5(pwd.substr(0, 16));
$("#pmd5").val(pmd5);
return true;
}
var dealSubmitResult = function(str) {
info = jQuery.parseJSON(str);
if (info.code == 0) {
if(info.goUrl){
curBox.hide();
lockMash.hide();
window.location.href = info.goUrl;
}else
showPrompt("参数错误!");
} else if (info.code == 40001) {
showVerify(info);
} else {
showPrompt(info.msg);
}
}
var doSubmit = function(verify) {
lockMash.show();
var veriParam = "";
if (verify) {
var code = $("#verify_code").val();
if (code.length == 0) {
$("#vbox_txt").html("验证码不能为空");
return;
}
var u_token = $("#u_token").val();
veriParam += "&r_sid=" + info.rsid + "&verify=" + code + "&u_token=" + u_token;
} else {
if (!checkUinPwd())
return;
}
showLoading();
$.ajax({
type : "POST",
url : "/login?act=json",
data : $("#log_from :input[name!='pwd']").serialize()
+ veriParam,
success : function(ret) {
dealSubmitResult(ret);
}
});
}
var showVerify = function() {
$("#qq").attr("disabled",true);
$("#pwd").attr("disabled",true);
$("#vbox_txt").html(info.msg?info.msg:"输入图中的字符,不区分大小写");
$("#verify_code").val("");
$("#verify_img").attr(
"src",
info.vurl + ".gif?" + Math.floor(Math.random() * 10000)
+ new Date().getTime());
$("#u_token").val(info.u_token?info.u_token:"-1010");
verifyBox.css("top", $("#title").height + "px");
setCenter(verifyBox);
curBox.hide();
verifyBox.show();
curBox = verifyBox;
}
$("#verify_img").click(
function() {
$("#verify_img").attr(
"src",
info.vurl + ".gif?" + Math.floor(Math.random() * 10000)
+ new Date().getTime());
});
$(".vbox_lg_btn").click(function() {
$("#qq").attr("disabled",false);
$("#pwd").attr("disabled",false);
doSubmit(true);
});
$('#pwd').keypress(function(e){
if(e.which == 13){
doSubmit(false);
}
});
$('#verify_code').keypress(function(e){
if(e.which == 13){
$("#qq").attr("disabled",false);
$("#pwd").attr("disabled",false);
doSubmit(true);
}
});
$(".vbox_cz_btn").click(function() {
$("#qq").attr("disabled",false);
$("#pwd").attr("disabled",false);
verifyBox.hide();
$("#verify_code").val("");
lockMash.hide();
});
$(".lb_lg_btn").click(function() {
doSubmit(false);
});
});