﻿function regular(){
    this.isEmpty=function(str){
        if (str!=undefined){
            if (str.length>0){return false;}
            else{return true;}
        }else{return true;}
    }
    this.isString=function(s){
        var patrn = /^[a-z]{5,19}$/;
        if (!patrn.exec(s))
            return false;
        return true;
    }
    this.isEmail=function(str){
        if (str=="undefined"||str.length==0){
            return false;
        }else{
            if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
                return true;
            }else{
                return false;
            }            
        }
    }
    this.isMobile=function(str){
        if (str.search(/^13[0,1,3,5,6,7,8,9][0-9]{8}|150[0-9]{8}|18[0-9]{9}$/)!=-1){
            return true;
        }else{
            return false;
        }
    }
    this.isZipcode=function(str){
        if (str.search(/^[0-9]{6}/) != -1){
            return true;
        }else{
            return false;
        }
    }
    this.isNumber=function(str){
        if (str.search(/^[0-9]/) != -1){
            return true;
        }else{
            return false;
        }
    }
    this.isBirthday=function(str){
        if (str.search(/^(19[0-9]{2})|200[0-9]-(0[0-9])|(1[1,2])-([0,1,2][0-9])|(0[0,1])$/)!=-1){
            return true;
        }else{
            return false;
        }
    }
}
function lib_pager(){
    this.pagelistidid;      //draw object
    this.recordcount;
    this.currentindex;
    this.pagecount;
    this.pagesize=10;
    this.showlimit=10;
    this.showfirstlast=false;
    this.showprewnext=false;
    this.firstchar="&lt;&lt;";
    this.prewchar="&lt;";
    this.nextchar="&gt;";
    this.lastchar="&gt;&gt;";
    this.postback;
    this.setpagecount=function(){
        var mod=this.recordcount%this.pagesize;
        if (mod==0){
            this.pagecount=this.recordcount/this.pagesize;
        }else{
            this.pagecount=(this.recordcount-mod)/this.pagesize+1;
        }
    };
    this.writepage=function(start,stop){//循环输出
        $("#"+this.pagelistid).empty();
        if (this.showfirstlast){
            if (this.currentindex==start){
                $("#"+this.pagelistid).append("<span class='current'><a>"+this.firstchar+"</a></span>");
            }else{
                $("#"+this.pagelistid).append("<span class='other'><a href='javascript:"+this.postback+"(1)'>"+this.firstchar+"</a></span>");
            }
        }
        if (this.showprewnext){
            if (this.currentindex==start){
                $("#"+this.pagelistid).append("<span class='current'><a>"+this.prewchar+"</a></span>");
            }else{
                $("#"+this.pagelistid).append("<span class='other'><a href='javascript:"+this.postback+"("+(this.currentindex-1)+")'>"+this.prewchar+"</a></span>");
            }
        }
        for (start;start<=stop;start++){
            if (this.currentindex==start){
                $("#"+this.pagelistid).append("<span class='current'><a>"+start+"</a></span>");
            }else{
                $("#"+this.pagelistid).append("<span class='other'><a href='javascript:"+this.postback+"("+start+")'>"+start+"</a></span>");
            }            
        }
        if (this.showprewnext){
            if (this.currentindex==stop){
                $("#"+this.pagelistid).append("<span class='current'><a>"+this.nextchar+"</a></span>");
            }else{
                $("#"+this.pagelistid).append("<span class='other'><a href='javascript:"+this.postback+"("+(this.currentindex+1)+")'>"+this.nextchar+"</a></span>");
            }
        }
        if (this.showfirstlast){
            if (this.currentindex==stop){
                $("#"+this.pagelistid).append("<span class='current'><a>"+this.lastchar+"</a></span>");
            }else{
                $("#"+this.pagelistid).append("<span class='other'><a href='javascript:"+this.postback+"("+this.pagecount+")'>"+this.lastchar+"</a></span>");
            }
        }
    }
    this.create=function(){
        if (this.pagecount<this.showlimit){
            this.writepage(1,this.pagecount);
        }else{
            if (this.currentindex<(this.showlimit/2)){
                this.writepage(1,this.showlimit-2);
            }else if (this.currentindex>(this.pagecount-(this.showlimit/2))){
                this.writepage(this.pagecount-this.showlimit+2,this.pagecount);
            }else{
                this.writepage(this.currentindex-(this.showlimit/2)+2,this.currentindex+(this.showlimit/2));
            }
        }
    }　
}
//get the param
function request(ss){
    var str=(window.location.search);
    str=str.substr(1);
    var arr = str.split("&");
    var obj = new Object();
    for(var j=0;j<arr.length;j++){
        a=arr[j].split("=");
        obj[a[0]]=a[1];
        //alert('a[0]='+a[0]+'\na[1]='+a[1]);
    }
    return(obj[ss]);
}   
