//var isIE=(navigator.appName.indexOf("Microsoft")!=-1);
var isIE=window.navigator.userAgent.indexOf("MSIE ")>=1;
var isIE5=window.navigator.userAgent.indexOf("MSIE 5")>=1;
var isIE6=window.navigator.userAgent.indexOf("MSIE 6")>=1;
var isIE7=window.navigator.userAgent.indexOf("MSIE 7")>=1;
var isIE8=window.navigator.userAgent.indexOf("MSIE 8")>=1;

//对象拖动
//cid:被移动容器对象的id
//oid:被拖动对象的id
function drag(c,o){
    try {
        o.firstChild.onmousedown=function(){return false; };
    } catch (e) {}

    o.onmousedown=function(a){
        var d=top.document;if(!a){a=top.window.event;}
        var x=a.layerX?a.layerX:a.offsetX,
        y=a.layerY?a.layerY:a.offsetY;
        if(o.setCapture){
            o.setCapture();
        }else if(window.captureEvents){
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
        }
        var theBody = top.document.documentElement;
        var scTop = parseInt(theBody.scrollTop,10);
        var scLeft = parseInt(theBody.scrollLeft,10);

        d.onmousemove=function(a){
            if(!a){a=top.window.event;}
            if(!a.pageX){a.pageX=a.clientX;}
            if(!a.pageY){a.pageY=a.clientY;}
            var tx=a.pageX-x;
            ty=a.pageY-y;
            if(isIE){
                c.style.left=tx+"px";
                c.style.top=ty+"px";
            }else{
                c.style.left=(tx-scLeft)+"px";
                c.style.top=(ty-scTop)+"px";
            }
            c.style.cursor="move";
        };
        d.onmouseup=function(){
            if(o.releaseCapture){
                o.releaseCapture();
            }else if(top.window.captureEvents){
                top.window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
            }
            c.style.cursor="default";
            d.onmousemove=null;
            d.onmouseup=null;
        };
    };
}

function readCookie(name){
    var cookieValue = "";
    var search = name + "=";
    if(document.cookie.length > 0)
    {
        var offset = document.cookie.indexOf(search);
		var end='';
        if (offset != -1)
        {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1){end = document.cookie.length;}
            cookieValue = unescape(document.cookie.substring(offset, end));
        }
    }
    return cookieValue;
}

//popup 语言
var popup_lang = new Object();


popup_lang.locale="zh-cn";
popup_lang.lang=function(){
    this.locale=readCookie('locale');
};

popup_lang.lang.prototype={
    initLang : function(){
        if(this.locale.toLocaleLowerCase()=='en-us'){
            this.str1='Loading...';
            this.str2=' O K ';
            this.str3='Cancel';
        }else{
            this.str1='正在读取数据...';
            this.str2='确定';
            this.str3='取消';
        }
    }
};

var _PL_= new popup_lang.lang();
_PL_.initLang();
//弹出层
var popup	= {
    sFrame:	"_popup_iframeShow",
    sWin:"_popup_win",
    _iWidth:0,
    _iHeight:0,
    clickx:0,
    clicky:0,
    moved:0,
    useropen:0,

    loding:	'<div style="text-align:center;font-size:12px;">'+_PL_.str1+'</div>',
    $:		function(_sID){
        return top.document.getElementById(_sID);
    },
    $$:		function(_sID){
        return top.document.frames ? top.document.frames[_sID] : this.$(_sID).contentWindow;
    },
    set:	function(_sID){
        var cThis	= this.$(_sID);
        this.$(this.sWin).style.width	= cThis.style.width;
        this.$(this.sWin).style.height	= cThis.style.height;
    },
    self:	function(_sID){
        var sHTML	= this.$(_sID).innerHTML;
        this.$$(this.sFrame).document.open("text/html","replace");
        this.$$(this.sFrame).document.write(sHTML);
        this.$$(this.sFrame).document.close();
    },
    writeObj:	function(str,o){
        if(o==null){o=this.sFrame;}
        this.$$(o).document.open("text/html","replace");
        this.$$(o).document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><style>body{background:#FFFFFF;font-size:9pt}div.buttonwidth {width:80px;}div.button {background:transparent url(/images/button.gif) repeat-x scroll 0 0;border:1px solid #D1D4D1;cursor:pointer;height:22px;line-height:22px;text-align:center;width:100%;}a,a:visited,a:link,a:hover{text-decoration:none;color:#000000}</style></head><body>');
        this.$$(o).document.write(str);
        this.$$(o).document.write('</body></html>');
        this.$$(o).document.close();
    },

    setSize:	function(_iWidth,_iHeight){
        this.$(this.sWin).style.width	= _iWidth;
        this.$(this.sFrame).style.width	= _iWidth;
        this.$(this.sWin).style.height	=_iHeight;
        this.$(this.sFrame).style.height	=_iHeight;
        this.$(this.sWin).style.display	= "block";

    },
    alert:function(title,str,_width,_height){
        if(!_width){_width=350;}
        if(!_height){_height=180;}
        this.win(title,_width,_height);
        this.writeObj('<br><div style="text-align:left;line-heigh:130%">'+str+'</div><div style="clear:both;text-align: center;margin:10px 0;height:1px;font-size:1px;"></div><div style="text-align:center"><div class="buttonwidth button" style="width:80px;float:right"><a href="#" onclick="parent.popup.close();return false;" style="display:block"> &nbsp;'+_PL_.str2+'&nbsp; </a></div></div><div style="clear:both;height:0px"></div>');
    },
    alert2:function(title,str,_width,_height,callback){
        if(!_width){_width=350;}
        if(!_height){_height=180;}
        this.win(title,_width,_height);
        this.writeObj('<br><div style="text-align:left;line-heigh:130%">'+str+'</div><div style="clear:both;text-align: center;margin:10px 0;height:1px"></div><div style="text-align:center"><div class="buttonwidth button" style="width:80px;float:right;margin-right:30px"><a href="#" onclick="parent.popup.close();'+callback+';return false;" style="display:block"> &nbsp;'+_PL_.str2+'&nbsp; </a></div></div><div style="clear:both;height:0px"></div>');
    },
    confirm:function(title,str,_width,_height,callback,close_self){

        if(!_width){_width=350;}
        if(!_height){_height=180;}
        this.win(title,_width,_height);
        if(!close_self||close_self.toLowerCase()!='off'){close_self='on';}

        if(close_self.toLowerCase()=='off'){
            this.writeObj('<br><div style="text-align:left;line-heigh:130%">'+str+'</div><div style="clear:both;text-align: center;margin:0;height:35px"></div><div style="text-align:center;clear:both"><div class="buttonwidth button" style="margin:0 20px 0 5px;width:80px;float:right"><a href="#" onclick="parent.popup.close();return false;" style="display:block"> &nbsp;'+_PL_.str3+'&nbsp; </a></div>  <div class="buttonwidth button" style="width:80px;float:right"><a href="#" onclick="parent.'+callback+';return false;" style="display:block"> &nbsp;'+_PL_.str2+'&nbsp; </a></div></div><div style="clear:both;height:0px"></div>');
        }
        if(close_self.toLowerCase()=='on'){
            this.writeObj('<br><div style="text-align:left;line-heigh:130%">'+str+'</div><div style="clear:both;text-align: center;margin:0;height:35px"></div><div style="text-align:center;clear:both"><div class="buttonwidth button" style="margin:0 20px 0 5px;width:80px;float:right"><a href="#" onclick="parent.popup.close();return false;" style="display:block"> &nbsp;'+_PL_.str3+'&nbsp; </a></div>  <div class="buttonwidth button" style="width:80px;float:right"><a href="#" onclick="parent.popup.close();parent.'+callback+';return false;" style="display:block"> &nbsp;'+_PL_.str2+'&nbsp; </a></div></div><div style="clear:both;height:0px"></div>');}

    },
    loading:function(_iWidth, _iHeight){
        if(!_iWidth){_iWidth=300;}
        if(!_iHeight){_iHeight=150;}
        var pop=this.getWin(this.sWin);
        pop.style.border = '0px';
        pop.style.background = 'transparent';
        pop.innerHTML='<div><iframe class="data" allowtransparency="true" style="background-color:transparent;" id="'+this.sFrame+'" frameborder="0" scrolling="no"></iframe></div>';
        this.$(this.sWin).style.display	= "block";

        try{
            this.$$(this.sFrame).document.open("text/html","replace");
            this.$$(this.sFrame).document.write(this.loding);
            this.$$(this.sFrame).document.close();
        }catch(e){}
        //drag(this.$(this.sWin),this.$("popupHeader"));
        this.showShadow();
        if(_iWidth){
            var w=parseInt(_iWidth,10);
            this.$(this.sWin).style.width	= w +"px";
            this.$(this.sFrame).style.width = w+w.toString().substring(w.toString().length,10)+"px";
        }
        if(_iHeight){
            var h=parseInt(_iHeight,10);
            this.$(this.sWin).style.height	= h+"px";
            this.$(this.sFrame).style.height	= (h-30)+"px";
        }

        this.setPos(this.sWin);

        this.writeLoadingObj('<p style="text-align:center; color:#fff; padding-bottom:5px;font-weight:bold;"> LOADING...</p>'+
                    '<div style="width:230px; margin:0px auto; text-align:ceneter;">'+
	                '<p><img alt="" src="/img/loading.gif"></p></div>');
    },
    writeLoadingObj:function(str,o){
        if(o==null){o=this.sFrame;}
        this.$$(o).document.open("text/html","replace");
        this.$$(o).document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><style>body{background:transparent;font-size:9pt}div.buttonwidth {width:80px;}div.button {background:transparent url(/images/button.gif) repeat-x scroll 0 0;border:1px solid #D1D4D1;cursor:pointer;height:22px;line-height:22px;text-align:center;width:100%;}a,a:visited,a:link,a:hover{text-decoration:none;color:#000000}</style></head><body>');
        this.$$(o).document.write(str);
        this.$$(o).document.write('</body></html>');
        this.$$(o).document.close();
    },
    callback:function(){},
    win:	function(_sTitle , _iWidth, _iHeight, _sUrl,cache){
        var pop=this.getWin(this.sWin);
        pop.innerHTML='<table border=0 cellpadding="0" cellspacing="0" class="head" align="center" width="100%"><tr style="height:30px; line-height:30px; background:#999"><td id="popupHeader" align="left" valign="middle" style="padding-left:0px; font-size:15px;">&nbsp;&nbsp;'+_sTitle+'</td><td width="45" nowrap><a id="closeBtnX" href="#" onClick="popup.close();return false;">X</a></td></tr></table><div><iframe class="data" id="'+this.sFrame+'" frameborder="0" scrolling="no"></iframe></div>';
        this.$(this.sWin).style.display			= "block";

        try{
            this.$$(this.sFrame).document.open("text/html","replace");
            this.$$(this.sFrame).document.write(this.loding);
            this.$$(this.sFrame).document.close();
        }catch(e){}

        if(_sUrl){
            if(cache!="cache" && cache!="yes" && cache!="1"){
                // 加随机数防止缓存
                if (_sUrl.indexOf("?") > 0)
                {
                    _sUrl += "&randnum=" + Math.random();
                }
                else
                {
                    _sUrl += "?randnum=" + Math.random();
                }
            }
            this.$(this.sFrame).src = _sUrl;
        }
        drag(this.$(this.sWin),this.$("popupHeader"));
        this.showShadow();
        if(_iWidth){
            var w=parseInt(_iWidth,10);
            this.$(this.sWin).style.width	= w +"px";
            this.$(this.sFrame).style.width = w+w.toString().substring(w.toString().length,10)+"px";
        }
        if(_iHeight){
            var h=parseInt(_iHeight,10);
            this.$(this.sWin).style.height	= h+"px";
            this.$(this.sFrame).style.height	= (h-30)+"px";
        }


        this.setPos(this.sWin);
    },
    msgWin:function(_sTitle , _iWidth, _iHeight, _sUrl,cache){
        var pop=this.getWin('msgWin');
        pop.innerHTML='<table border=0 cellpadding="0" cellspacing="0" class="head" align="center" width="100%"><tr><td id="popupMsgHeader" align="left" onmoseover="this.style.cursor=move" onclick="popup.moved=1">&nbsp;'+_sTitle+'</td><td width="60" align="right" nowrap><a href="#" onclick="popup.closeMsgWin();return false;">__</a> <a href="#" onclick="popup.useropen=1;popup.openMsgWin();return false;">口</a> <a href="#" onClick="popup.hideMsgWin();return false;">X</a>&nbsp;</td></tr></table><div><iframe class="data" id="iframeMsgShow" frameborder="0" scrolling="no"></iframe></div>';

        pop.style.display			= "block";
        pop.style.height			='25px';

        try{
            this.$$("iframeMsgShow").document.open("text/html","replace");
            this.$$("iframeMsgShow").document.write(this.loding);
            this.$$("iframeMsgShow").document.close();
        }catch(e){}
        if(_sUrl){
            if(cache!="cache" && cache!="yes" && cache!="1"){
                // 加随机数防止缓存
                if (_sUrl.indexOf("?") > 0)
                {
                    _sUrl += "&randnum=" + Math.random();
                }
                else
                {
                    _sUrl += "?randnum=" + Math.random();
                }
            }
            this.$("iframeMsgShow").src= _sUrl;
        }
        if(_iWidth){
            pop.style.width	= _iWidth +"px";
            var w=parseInt(_iWidth,10);
            this.$("iframeMsgShow").style.width = (w-2)+_iWidth.substring(parseInt(_iWidth).toString().length,10)+"px";
        }
        if(_iHeight){
            pop.style.height	= _iHeight+"px";
            this.$("iframeMsgShow").style.height	= _iHeight-25+"px";
        }
        this.$("iframeMsgShow").style.height			='0px';
        pop.style.right='0px';
        pop.style.bottom='0px';
        this.openMsgWin();
        drag(this.$("msgWin"),this.$("popupMsgHeader"));
    },

    setPos:function(objId){
        var _width = this.$(objId).offsetWidth;
        var _height = this.$(objId).offsetHeight;

        var fullHeight = getViewportHeight();
        var fullWidth = getViewportWidth();
        //        alert(document.documentElement.scrollTop+"--"+fullHeight+"----"+_height);
        if(isIE){

            //this.$(objId).style.top="300px";
            if(isIE8){
                this.$(objId).style.top=((fullHeight-_height)/2)+"px";
            }
            this.$(objId).style.left=((fullWidth-_width)/2)+"px";

        }else{
            this.$(objId).style.top=((fullHeight-_height)/2)+"px";
            this.$(objId).style.left=((fullWidth-_width)/2)+"px";
        }

    },
    getWin:function (objID){
        var pop=this.getObj(objID);
        pop.setAttribute("class","popup");
        pop.setAttribute("className","popup");
        pop.style.display="none";
        return pop;
    },
    hide:	function(_oThis, _sMake){
        var mark	= this.$(this.sWin).getAttribute("ctrl");
        if(this.$(this.sWin).style.display == "block" && mark == _sMake){
            this.$(this.sWin).style.display = "none";
            return false;
        }
        this.hideShadow();
        return true;
    },

    close:	function(){
        try{
            if(isIE){
                //

                this.$(this.sWin).parentNode.firstChild.removeNode(true);
                setTimeout("popup.close();",100);
            }else{
                this.$(this.sWin).style.display	= "none";
            }
            this.hideShadow();
            return true;

        }catch(e){}

    },
    openMsgWinTimer:null,
    closeMsgWinTimer:null,
    openMsgWin:function(){
        window.clearInterval(popup.closeMsgWinTimer);
        var pop=popup.$("msgWin");
        if(parseInt(pop.style.right,10)==0 || isNaN(parseInt(pop.style.right,10))){
            popup.openMsgWinTimer=window.setInterval(function(){
                if(parseInt(pop.style.height,10)=='150' && parseInt(popup.$("iframeMsgShow").style.height,10)=='125'){
                    window.clearInterval(popup.openMsgWinTimer);
                }

                if(parseInt(pop.style.height,10)<150){
                    pop.style.height=(parseInt(pop.style.height,10)+5)+'px';
                }
                if(parseInt(popup.$("iframeMsgShow").style.height,10)<125){
                    popup.$("iframeMsgShow").style.height=(parseInt(popup.$("iframeMsgShow").style.height,10)+5)+'px';
                }
                var _width = pop.offsetWidth;
                var _height = pop.offsetHeight;

                var fullHeight = getViewportHeight();
                var fullWidth = getViewportWidth();

                pop.style.top=(fullHeight-_height)+"px";
                pop.style.left=(fullWidth-_width)+"px";
                pop.style.bottom=pop.style.right="0px";
            },50);
        }else{
            popup.openMsgWinTimer=window.setInterval(function(){
                if(parseInt(pop.style.height,10)==150 && parseInt(popup.$("iframeMsgShow").style.height,10)==125){
                    window.clearInterval(popup.openMsgWinTimer);
                }

                if(parseInt(pop.style.height,10)<150){
                    pop.style.height=(parseInt(pop.style.height,10)+5)+'px';
                }
                if(parseInt(popup.$("iframeMsgShow").style.height,10)<125){
                    popup.$("iframeMsgShow").style.height=(parseInt(popup.$("iframeMsgShow").style.height,10)+5)+'px';
                }
                var _width = pop.offsetWidth;
                var _height = pop.offsetHeight;

                var fullHeight = getViewportHeight();
                var fullWidth = getViewportWidth();
                pop.style.top=(fullHeight-_height)/2+"px";
                pop.style.left=(fullWidth-_width)/2+"px";

                //			pop.style.right='0px'
                //			pop.style.bottom='0px'
            },50);
        }
        if(popup.moved!=1 && popup.useropen!=1)setTimeout("popup.closeMsgWin()",15000);
    },
    closeMsgWin:function(){
        window.clearInterval(popup.openMsgWinTimer);
        var w=popup.$("msgWin");
        popup.closeMsgWinTimer=window.setInterval(function(){
            if(parseInt(popup.$("msgWin").style.height,10)==25 && parseInt(popup.$("iframeMsgShow").style.height,10)==0){
                window.clearInterval(popup.closeMsgWinTimer);
            }
            if(parseInt(popup.$("msgWin").style.height,10)>25){
                popup.$("msgWin").style.height=(parseInt(popup.$("msgWin").style.height,10)-5)+'px';
            }
            if(parseInt(popup.$("iframeMsgShow").style.height,10)>0){
                popup.$("iframeMsgShow").style.height=(parseInt(popup.$("iframeMsgShow").style.height,10)-5)+'px';
            }



            var _width = popup.$("msgWin").offsetWidth;
            var _height = popup.$("msgWin").offsetHeight;

            var fullHeight = getViewportHeight();
            var fullWidth = getViewportWidth();

            popup.$("msgWin").style.top=(fullHeight-_height)+"px";
            popup.$("msgWin").style.left=(fullWidth-_width)+"px";
            //popup.$("msgWin").style.right='0px'
            //popup.$("msgWin").style.bottom='0px'
        },50);
        popup.moved=0;
    },
    hideMsgWin:function(){
        popup.$('msgWin').style.display	= "none";
    },
    iframeResize:	function(sWidth,sHeight){
        var reFrame   = this.$$(this.sFrame);
        if (reFrame != null){
            if(!sWidth){var sWidth=reFrame.document.documentElement.clientWidth.toString();}
            if(!sHeight){var sHeight=reFrame.document.documentElement.clientHeight.toString();}

            if(sWidth != "0" && sHeight != "0"){
                this.$(this.sWin).style.width			= sWidth + "px";
                this.$(this.sWin).style.height			= (sHeight+50)+ "px";
                this.$(this.sFrame).style.width	= sWidth + "px";
                this.$(this.sFrame).style.height	= (sHeight+30) + "px";
            }
        }
        this.setPos(this.sWin);
    },
    getObj:function(name){
        var obj=this.$(name);
        if(obj==null){
            var obj=top.document.createElement("div");
            obj.id=name;
            var body=top.document.getElementsByTagName("BODY")[0];
            body.insertBefore(obj,body.firstChild);
        }
        return obj;
    },
    getFriendDialogShadow:function(){
        var o=this.getObj("friendDialogShadow");
        o.style.position= "absolute";
        o.style.display= "block";

        o.style.opacity= "0.4";
        o.style.filter= "alpha(opacity=40);-moz-opacity: 0.4; opacity:0.4;progid:DXImageTransform.Microsoft.Alpha(opacity=40)";
        o.style.background= "#000000";
        o.style.top= "0px";
        o.style.left= "0px";
        o.style.zIndex= "1000";
        return o;
    },
    showShadow:function ()
    {
        var objShadow=this.getFriendDialogShadow();
        var document_body;
        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            document_body = document.documentElement;
        } else if (document.body) { // other Explorers
            document_body = document.body;
        }
        var sClientWidth=0;
        var sClientHeight=0;
        var sScrollTop=0;
        var sScrollLeft=0;
        var myClientHeight=0;
        if(document.documentElement)
        {
            sClientWidth = parent ? parent.document.documentElement.scrollWidth : document.documentElement.scrollWidth;
            sClientHeight = parent ? parent.document.documentElement.scrollHeight : document.documentElement.scrollHeight;
            sScrollTop = parent ? parent.document.documentElement.scrollTop : document.documentElement.scrollTop;
            myClientHeight=parent ? parent.document.documentElement.clientHeight : document.documentElement.clientHeight;
        }
        else if(document.body)
        {
            sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
            sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
            sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
            myClientHeight=parent ? parent.document.body.clientHeight : document.body.clientHeight;

        }
        var shadowH=(sClientHeight>myClientHeight)?sClientHeight:myClientHeight;
        objShadow.style.width= "100%";
        objShadow.style.height= shadowH+ 'px';
    },
    hideShadow:function() {
        try{
            var objShadow=this.$('friendDialogShadow');
            objShadow.style.display= "none";
        }catch(e){}
    },
    addEvent:function (obj, evType, fn){
        if (obj.addEventListener){
            obj.addEventListener(evType, fn, false);
            return true;
        } else if (obj.attachEvent){
            var r = obj.attachEvent("on"+evType, fn);
            return r;
        } else {
            return false;
        }
    },
    removeEvent:function (obj, evType, fn, useCapture){
        if (obj.removeEventListener){
            obj.removeEventListener(evType, fn, useCapture);
            return true;
        } else if (obj.detachEvent){
            var r = obj.detachEvent("on"+evType, fn);
            return r;
        } else {
            return false;
        }
    }
};

function getViewportHeight() {
    var w=top.window,d=top.document;
    if (w.innerHeight!==w.undefined){ return w.innerHeight;}
    if (d.compatMode==="CSS1Compat") {return d.documentElement.clientHeight;}
    if (d.body) {return d.body.clientHeight; }
    return w.undefined;
}

function getViewportWidth() {
    var w=top.window,d=top.document;
    if (w.innerWidth!=w.undefined){ return w.innerWidth; }
    if (d.compatMode==="CSS1Compat"){ return d.documentElement.clientWidth; }
    if (d.body){ return d.body.clientWidth; }
    return w.undefined;
}
