// JavaScript Document
$.extend(Array.prototype,{
    each:function(fn){
        for(var i=0,l=this.length;i<l;i++)fn.call(this[i],i)
            },
    has:function(e){
        for(var i in this){
            if(this[i]===e)return true;
        }
        return false
        }
});
$.extend(String.prototype,{
    ltrim:function(){
        return this.replace(/^\s+/,'')
        },
    rtrim:function(){
        return this.replace(/\s+$/,'')
        },
    trim:function(){
        return this.ltrim().rtrim()
        }
    });
function G(o){
    return typeof o==='string'?document.getElementById(o):o
    };
var loads=[];
window.onload=function(){
    loads.each(function(){
        this()
        });
}//加载完成时执行
var com=function(){
    var t=this;
    t.tipType={
        1:'ok',
        2:'warming',
        3:'error'
    };
    t.msgBoxTimer=null;
    t.isIE=document.all?true:false;
    t.isIE6=t.isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1]==6);
};
com.prototype={
    //初始化基本事件
    init:function(){
        var t=this;
        $('#overlay').click(function(){
            t.hide()
            })
        document.onkeydown=function(e){
            e=e||window.event;
            var keyCode=e.keyCode||e.which;
            if(keyCode==27){
                t.hide();
            }
        }
    },
    //提示层[类型,信息,延迟消失时间]
    tips:function(type,msg,_time,layer){
        var t=this;
		clearTimeout(this.tipTimer);
        var _html='<div class="alertTips">\
				<table style="100%"><tr>\
				<td valign="top"><img src="/css/images/set_succeed_'+type+'.gif" /></td>\
				<td>'+ msg + '</td>\
				</tr></table></div>';
        layer&&$('#overlay').show();
        $('#tipBox').html(_html).show();
        this.center('tipBox');
        if(_time!=false){
            this.tipTimer = setTimeout(function(){
                t.hide()
                },(_time||3)*1000);
        }
    },
    //弹出层屏幕居中
    center:function(id){
        var a=typeof id==='string'?document.getElementById(id):id;
        if($(a).css('position')!='fixed')a.style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight/2)+'px';
        a.style.marginLeft = -(a.offsetWidth/2)+'px';
        a.style.marginTop = -(a.offsetHeight/2)+'px';
    },
    //ajax带转码
    post:function(o){
        var t=this;
        (o.type.toLowerCase()!='get')&&(o.data['ajax']='1');
        var _func=o.success;
        o.success=function(x){
            _func(x);
        };

        $.ajax(o)
        },
    //加载js
    loadJs:function(src,callback){
        var z=$('script');
        for(var i=z.length-1;i>-1;i--){
            if(z[i].src==src){
                typeof callback==='function' && callback();
                return;
            }
        }
    var e=document.createElement('script');
    e.src=src;
    e.type='text/javascript';
    if(typeof callback==='function'){
        e.onload=e.onreadystatechange=function(){
            if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')callback()
                }
            }
document.getElementsByTagName('head')[0].appendChild(e);
},
ePos:function(e){
    e=G(e);
    var l=0,t=0;
    do{
        l+=e.offsetLeft;
        t+=e.offsetTop;
    }while(e=e.offsetParent);
    return{
        x:l,
        y:t
    }
},
confirm:function(fn){},
alert:function(){},
hide:function(){
    $('#overlay').hide();
    $('#tipBox').hide();
},
msgBox:function(){
    var suid = $('#uid').val();
    if (suid) {
        this.msgBoxTimer=setInterval(function(){
            $.ajax({
                url:'/mycncn/feed',
                type:'post',
                data:{},
                success:function(x){
                    $('#box').html(x);
                }
            });
        },10000);
    }
},
focus:function(o){
    o.value==o.defaultValue&&(o.value='')
    },
blur:function(o){
    o.value==''&&(o.value=o.defaultValue)
    },
gotopage:function(){
    var cpg=parseInt(G('cpage').value),pct=parseInt(G('pcount').innerHTML);
    return cpg>pct?pct:cpg
    }
};

var com=new com;
loads.push(function(){
    com.init();
    com.msgBox();
    //com.loadJs('/css/js/com_init.js?a='+Math.random());
});
