var FUN = {
    ShareNum : null,
    circle : null,
    dirty : function (condition,success) {
        if(FUN.circle){
            clearInterval(FUN.circle);
        }
        FUN.circle = setInterval(function(){
            var condi = condition();
            if(condi){
                success();
                clearInterval(FUN.circle);
            }
        },20);
    },
    Count : function(start,end,id){
        var number = setInterval(function(){
            start = start + 30;
            $("#"+id).text(start);
            if(start == end || start > end){
                $("#"+id).text(end);
                clearInterval(number);
            }
        },1);
        setTimeout(function(){
            $("#"+id).text(end);
            clearInterval(number);
        },3000);
    },
    PreLoading : function (doc) {
        //do nothing fanhuibin
    },
    GetQueryString:function(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  r[2];
    }
    ,
    reDrawImg : function(canvasId,singleTime){
        var c = document.getElementById(canvasId);
        var canvas = c.getContext("2d");
        var imgData=canvas.getImageData(0,0,c.width,c.height);

        var least = 0;
        var scan = setInterval(function(){
            least ++;
            var percent = imgData.data.length * (least/100);
            for (var i = 0;i < percent;i+=4)
            {
                if(imgData.data[i+3] != 0){
                    imgData.data[i]=254;
                    imgData.data[i+1]=0;
                    imgData.data[i+2]=0;
                    imgData.data[i+3]=255;
                }
            }
            canvas.putImageData(imgData,0,0);
            if(least == 100){
                clearInterval(scan);
            }
        },singleTime);
    },
    Separate : function(){
        var useragent = navigator.userAgent.toLowerCase();
        var match = useragent.search(/iphone/);
        if(match > -1){
            return "ios";
        }else{
            return "android";
        }
    },
    isWeiXin : function(){
        var ua = window.navigator.userAgent.toLowerCase();
        if(ua.search(/micromessenger/) > -1){
            return true;
        }else{
            return false;
        }
    }
};