var oPopup ;

function WindowClose2() {
    window.opener=null;
        window.open("","_self");
        window.close();
}
function Lcalert(id,pCaption,xMsg)
{ //debugger;
  if (oPopup==null) {
      var Alert1 = new AlertM(id, 200, 120, pCaption, xMsg);
   Alert1.rect(null, null, null, screen.height - 30);
   Alert1.speed = 10;
   Alert1.step = 5;
   Alert1.show();  
  }
  else
  {
   var oTabletxts = oPopup.document.getElementById("Tabletxts");  
   var otr0 = oPopup.document.getElementById("tr0");  

   var fr = otr0.cloneNode(true);

   fr.childNodes[0].innerHTML=GetHM();
   fr.childNodes[1].innerHTML="<DIV class='wrap' style='FONT-SIZE:12px'>"+xMsg+"</DIV>";

   oTabletxts.firstChild.insertBefore(fr,otr0);
  }

}
function DoNewWin(myUrl)
{alert(myUrl);
  window.location=myUrl;
  //window.open(unescape(myUrl));    
}

function GetHM()
{ var now = new Date();
        hour = now.getHours();
        min = now.getMinutes();
        if (hour <= 9) {
            hour = "0" + hour;
        }
        if (min <= 9) {
            min = "0" + min;
        }

        return hour + ':' + min;
}
function addcss()
{ 
 if(!oPopup.document.styleSheets) return;
   var cssStr = ".wrap {word-break:break-all;width:136px;}";
var style =  oPopup.document.createElement("style");
style.setAttribute("type", "text/css");
if(style.styleSheet){
style.styleSheet.cssText = cssStr;
} else {
var cssText = doc.createTextNode(cssStr);
style.appendChild(cssText);
}
oPopup.document.getElementsByTagName('head')[0].appendChild(style);
 
}

function AlertM(id,width,height,caption,message){  
    this.id     = id;  
    this.caption= caption;  
    this.message= message;  
  
    this.width    = width?width:200;  
    this.height = height?height:120;  
    this.timeout= 500;  //停留時間
    this.speed    = 20; 
    this.step    = 1; 
    this.right    = screen.width -1;  
    this.bottom = screen.height; 
    this.left    = this.right - this.width; 
    this.top    = this.bottom - this.height; 
    this.timer    = 0; 
    this.pause    = false;
    this.close    = false;
    this.autoHide    = false; //自動關閉
}  
  

AlertM.prototype.hide = function(){  
    if(this.onunload()){  

        var offset  = this.height>this.bottom-this.top?this.height:this.bottom-this.top; 
        var me  = this;  

        if(this.timer>0){   
            window.clearInterval(me.timer);  
        }  

        var fun = function(){  
            if(me.pause==false||me.close){
                var x  = me.left; 
                var y  = 0; 
                var width = me.width; 
                var height = 0; 
                if(me.offset>0){ 
                    height = me.offset; 
                } 
     
                y  = me.bottom - height; 
     
                if(y>=me.bottom){ 
                    window.clearInterval(me.timer);  
                    me.Pop.hide();  
                } else { 
                    me.offset = me.offset - me.step;  
                } 
                me.Pop.show(x,y,width,height);    
            }             
        }  

        this.timer = window.setInterval(fun,this.speed)      
    }  
}  
  

AlertM.prototype.onunload = function() {  
    return true;  
}  

AlertM.prototype.oncommand = function(){  
    //this.close = true;
   // this.hide();  

	window.open(document.URLUnencoded.substr(0,document.URLUnencoded.indexOf("&__RunObj")));
   
} 

AlertM.prototype.show = function(){  

    oPopup = window.createPopup(); //IE5.5+ 

    addcss();
    this.Pop = oPopup;  
 
    var w = this.width;  
    var h = this.height;  
  
    var str = "<DIV style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: " + w + "px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: " + h + "px; BACKGROUND-COLOR: #c9d3f3'>"  
        str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>"  
        str += "<TR>"  
        str += "<TD vAlign=center width='100%'>Message : <A href='javascript:void(0)' hidefocus=false id='btCommand'>" + this.caption + "</A></TD>"  
        str += "<TD vAlign=center align=right width=19>"  
        str += "<SPAN title=Close style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>"  
        str += "</TR><TR>" 
        str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=2 >"  
        str += "<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 1px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 1px; FONT-SIZE: 12px; PADDING-BOTTOM: 3px; BORDER-LEFT: #728eb8 1px solid; COLOR: #1f336b; PADDING-TOP: 3px; BORDER-BOTTOM: #b9c9ef 1px solid;width:190px;height:90px;overflow:auto '><table id='Tabletxts' cellspacing='1' cellpadding='1' border='0' bgcolor='#b9c9ef'><tr id='tr0' bgcolor= '#cfdef4'><td style='FONT-SIZE:12px'>"
        str += GetHM()+"</td><td><div class='wrap' style='FONT-SIZE:12px'>"+ this.message+"</td></tr>" 
        str += "</table></DIV>"
        str += "</TD></TR>"  
        str += "<TR ><TD colSpan=2  vAlign=top  height=5><img src='ClientBin/images/BotMsn.png' ></TD>" 
        str += "</TR>"  
        str += "</TABLE>"  
        str += "</DIV>"  
  
    oPopup.document.body.innerHTML = str; 
   
   
    this.offset  = 0; 
    var me  = this;  

    oPopup.document.body.onmouseover = function(){me.pause=true;}
    oPopup.document.body.onmouseout = function(){me.pause=false;}

    var fun = function(){  
        var x  = me.left; 
        var y  = 0; 
        var width    = me.width; 
        var height    = me.height; 

            if(me.offset>me.height){ 
                height = me.height; 
            } else { 
                height = me.offset; 
            } 

        y  = me.bottom - me.offset; 
        if(y<=me.top){ 
       //     me.timeout--; 
         //   if(me.timeout==0){ 
           //     window.clearInterval(me.timer);  
           //     if(me.autoHide){
             //       me.hide(); 
             //   }
    //        } 
        } else { 
            me.offset = me.offset + me.step; 
        } 
        me.Pop.show(x,y,width,height);    

    }  
  
    this.timer = window.setInterval(fun,this.speed)      
  
     
  
    var btClose = oPopup.document.getElementById("btSysClose");  
  
    btClose.onclick = function(){  
        me.close = true;
        me.hide();  
       oPopup=null;
    }  
  
    var btCommand = oPopup.document.getElementById("btCommand");  
    btCommand.onclick = function(){  
        me.oncommand();  
    }    
	
}  

AlertM.prototype.speed = function(s){ 
    var t = 20; 
    try { 
        t = praseInt(s); 
    } catch(e){} 
    this.speed = t; 
} 

AlertM.prototype.step = function(s){ 
    var t = 1; 
    try { 
        t = praseInt(s); 
    } catch(e){} 
    this.step = t; 
} 
  
AlertM.prototype.rect = function(left,right,top,bottom){ 
    try { 
        this.left        = left    !=null?left:this.right-this.width; 
        this.right        = right    !=null?right:this.left +this.width; 
        this.bottom        = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height; 
        this.top        = top    !=null?top:this.bottom - this.height; 
    } catch(e){} 
} 

function CopyToClip(cFid){

var ReList=cFid.split("[");
var cFid2=ReList[0];
var cFid3=ReList[1];

var img2 = document.getElementById('copythis2');
  img2.src="ClientBin/Gadget/"+cFid2+".png?re="+cFid3;
var div = document.getElementById('copythis');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}