﻿function isBlank(c){return /^\s*$/.test(c);}
function isInt(obj){reg=/^[-+]?\d+$/; if(!reg.test(obj)) return false;else return true;}
function isFloat(obj){reg=/^[0-9]+([.]{1}[0-9]{1,2})?$/;if(!reg.test(obj)) return false;else return true;}
function isEmail(obj){reg=/^\w{3,}@\w+(\.\w+)+$/;if(!reg.test(obj)) return false;else return true;}
function isString(obj){reg=/^[a-z,A-Z]+$/;if(!reg.test(obj)) return false;else return true;}
function isTelephone(obj){reg=/^(\d{3,4}\-)?[1-9]\d{6,7}$/;if(!reg.test(obj)) return false;else return true;}
function isMobile(obj){reg=/^(\+\d{2,3}\-)?\d{11}$/;if(!reg.test(obj)) return false;else return true;}
function isUri(obj){reg=/^http:\/\/[a-zA-Z0-9]+\.[a-zA-Z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;if(!reg.test(obj)) return false;else return true;}
function inputNum(o){if(o){o.value=o.value.replace(/\D/g,'');}else if($('#'+o)){$('#'+o).val($('#'+o).val().replace(/\D/g,''));}else if($('.'+o)){$('.'+o).val($('.'+o).val().replace(/\D/g,''));}}

(function(a){
    a.user={
        state:function(){
            $.ajax({
                url: "../handler/user.ashx",
                type: "post",
                data: "action=state",
                async: false,
                success: function(result){
                    if(result!=''){$(".login").html(result);}
                    else{}
                }
            });
        },
        login:function(){
            var uname=$('#top_username').val(),pwd=$('#top_password').val();
            if(isBlank(uname) || isBlank(pwd)){
                alert('请输入用户名及登录密码');return;
            }else{
                $.ajax({
                    url: "../handler/user.ashx",
                    type: "post",
                    data: "action=login&username="+uname+"&password="+pwd,
                    async: false,
                    success: function(result){
                        if(result=='err'){alert('用户名或密码错误');}
                        else if(result!=''){$(".login").html(result);}
                        else{}
                    }
                });
            }
        },
        exit:function(){
            $.ajax({
                url: "../handler/user.ashx",
                type: "post",
                data: "action=exit",
                async: false,
                success: function(result){
                    if(result!=''){$(".login").html(result);}
                    else{}
                }
            });
        }
    }
})(jQuery);

