﻿function regular(){
    this.isEmpty=function(str){
        if (str!=undefined){
            if (str.length>0){return false;}
            else{return true;}
        }else{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}|15[0-9]{9}|18[0-9]{9}$/)!=-1){
            return true;
        }else{
            return false;
        }
    }
    this.isZip=function(str){
        if (str.search(/^[0-9]{6}/) != -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 flayer(){
    this.mask=true;
    this.fix=false;
    this.fltype="send";/*send or center**/
    
    this.bgindex=1;
    this.bgcolor="#eee";
    this.fgindex=2;
    this.fgcolor="#ccc";
    this.target="";
    this.twidth=0;
    this.sendtext="Loading&middot;&middot;&middot;";
    this.showcancel=true;
    this.showok=true;
    this.callback="";
    var gettype=function(){
        return "可以返回的";
    }
    flayer.closecenter=function(){$(".gk-target").append($("#gk-body .gk-center").html());$("#gk-body").empty();$("#gk-body").remove();$("#gk-maskbg").remove();}
    this.createsend=function(){
        $("body").append("<div id='gk-send'>"+this.sendtext+"</div>");
        $("#gk-send").css({"position":"absolute","z-index":this.fgindex,"top":$(document).scrollTop()+"px","right":"0","width":"120px","height":"25px","line-height":"25px","background-color":this.fgcolor,"text-indent":"5px","font-size":"12px"});
        if (!this.fix){
            $(window).scroll(function(){
                $("#gk-send").css("top",$(document).scrollTop()+"px");
            }); 
        }
    }
    this.closesend=function(){$("#gk-send").remove();$("#gk-maskbg").remove();}
    this.createcenter=function(){
        $("body").append("<div id='gk-body'><div class='gk-top'><div><a href='javascript:flayer.closecenter();'>关闭</a></div></div></div>");
        $("#gk-body").append("<div class='gk-center'>"+$(".gk-target").html()+"</div>");
        $(".gk-target").empty();
        if (this.showcancel||this.showok){
            $("#gk-body").append("<div class='gk-bottom'></div>");
        }
        if (this.showok){//onclick='flayer.closecenter();'
            if (this.callback.length==0){
                $("#gk-body .gk-bottom").append("<input id='gk-ok' type='button' onclick='flayer.closecenter();'  value='确定' />");
            }else{
                $("#gk-body .gk-bottom").append("<input id='gk-ok' type='button' onclick='"+this.callback+"'  value='确定' />");
            }
        }
        if (this.showcancel){
            $("#gk-body .gk-bottom").append("<input type='button' onclick='flayer.closecenter();' value='取消' />");
        }
        
        var top=($(window).height()-($("#gk-body .gk-center").height()+55))/2;
        if (this.twidth==0){
            this.twidth=400;
        }
        $("#gk-body").css({"z-index":this.fgindex,"top":top+"px","width":this.twidth+"px","margin-left":"-"+this.twidth/2+"px"}).show();
        if (!this.fix){
            $(window).scroll(function(){
                $("#gk-body").css("top",($(document).scrollTop()+top)+"px");
            }); 
        }        
    }    
    this.create=function(){
        var width=$(document).width();
        if ($.browser.msie){            
            if ($(document).height()>$(window).height()){
                if ($.browser.version=="8.0"||$.browser.version=="6.0"){
                    width-=16;
                } 
            }else{
                if ($.browser.version=="6.0"){
                    width-=16;
                } 
            }
        }
        var height=0;
        if ($(document).height()>$(window).height()){
            height=$(document).height();
        }else{
            height=$(window).height();
        }
        $("body").append("<div id='gk-maskbg'></div>");
        $("#gk-maskbg").css({"position":"absolute","top":"0","left":"0","width":width+"px","height":height+"px","z-index":this.bgindex,"background-color":this.bgcolor,"filter":"alpha(opacity=50)","opacity":"0.5"});
        if (this.fltype=="send"){this.createsend();}
        else if (this.fltype=="center"){this.createcenter();}
    } 
}
