﻿// LeoScript 文件
//leo编写 2007 12 17
function _leoGet(name)
{
    return  document.getElementById(name);
}


//窗口

function myWindow()
{
   this.de = document.documentElement;
   this.w =null;
   this.h =null;
   this.t=null;
   this.l=null;
   this.ch=null;
   this.cw=null;
   this.RunWindow=function ()
   {
       this.ch=document.documentElement.scrollHeight>document.body.scrollHeight?document.documentElement.scrollHeight:document.body.scrollHeight;
       this.cw=document.documentElement.scrollWidth>document.body.scrollWidth?document.documentElement.scrollWidth:document.body.scrollWidth;    
    }
   this.Run=function ()
   {
        this.w = window.innerWidth || self.innerWidth || (this.de&&this.de.clientWidth) || document.body.clientWidth;
        this.h = window.innerHeight || self.innerHeight || (this.de&&this.de.clientHeight) || document.body.clientHeight;
        this.t=this.T();
   } 
   this.T=function (){
	    var yScrolltop;
	    if (self.pageYOffset) {
		    yScrolltop = self.pageYOffset;
	    } else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		    yScrolltop = document.documentElement.scrollTop;
	    } else if (document.body) {// all other Explorers
		    yScrolltop = document.body.scrollTop;
	    }
	    return yScrolltop;
	}
}

function LeoWindow(name)
{    
    this.name=name;
    //标题
    this.titelName="ShangHailu";
    //取消按钮
    this.cancelButtonTemplet="<input type='button' style='background:#F0F0F0; margin:2px,10px,0px,0px;line-height:10px;float:right;width:15px; height:15px; text-align:center; border:0px;' onClick='"+this.name+".Hidden()' value='x'>";
    //标题框
   this.TitelTemplet ="<div class='lightwindow_top' ><div class='right'></div></div><div class='lightwindow_title_bar'><div class='titelName' id='_"+this.name+"titelNameDiv' >"+this.titelName+"</div><div class='button_close' onClick='"+this.name+".Hidden()'>close</div></div>";
 
    //弹出框
    this.CasingTemplet =function (){return   "<div id='_"+this.name+"windowDiv' class='leoblue' style=' position:absolute; z-index:9999 ;display:none;filter:revealTrans(duration=2,transition=23);' >"+this.TitelTemplet+"<div id='_"+this.name+"showDiv'  style='height:100%px;background:#fff;'></div><div class='lightwindow_bottom' ><div class='div'></div></div></div>";}
    //背景
    this.backGroundTemplet= "<div id='_"+this.name+"backGroundDiv' class='leobackGrounddiv' style= 'position:absolute;z-index:2000;display:none;top:0px;left:0px;' onclick='return false;'></div>";  
    
   
    
    
    
    this.window=new myWindow();
    this.showDiv=null;
    this.backGroundDiv=null;
    this.titelNameDiv=null;
    this.windowDiv=null;
    this.windowIframe=null;
    this.x=0;
    this.y=0;
    this.Interval=null;
    this.IntervalToSize=null;
    this.show=null;
    this.showGround=null;
    this.divClass='leo';
    
    this.Drawing=function ()
    {
         if(this.showDiv==null)
         {
            document.write(this.backGroundTemplet);
            document.write(this.CasingTemplet());  
            this.showDiv=_leoGet("_"+this.name+"showDiv");
            this.backGroundDiv=_leoGet("_"+this.name+"backGroundDiv");
            this.windowDiv=_leoGet("_"+this.name+"windowDiv");   
            this.titelNameDiv=_leoGet("_"+this.name+"titelNameDiv");         
          }     
    }
    
    //基础函数
    //用于调整窗口位置
    this.backGroundBase=function()
    {
        if(this.showGround==null)
        {
            this.backGroundDiv.style.width=this.window.cw+"px";
	        this.backGroundDiv.style.height=this.window.ch+"px";
	    }
    }
    
    this.changeSize=function()
    {
         if(this.backGroundDiv==null)
        {
            if ((this.window.ch==document.documentElement.scrollHeight)&&(this.window.cw==document.documentElement.scrollWidth)){return;} 
         
            if((""+this.backGroundDiv.style.display)=="none") {return;} 
         
             this.place();
             this.backGroundBase();	        
        }else
        {
            this.showDiv=_leoGet("_"+this.name+"showDiv");
            this.backGroundDiv=_leoGet("_"+this.name+"backGroundDiv");
            this.windowDiv=_leoGet("_"+this.name+"windowDiv");
        }
    }
    

    
    this.base=function(x,y)
    {
        this.x=x;
        this.y=y; 
     
		this.windowDiv.style.textAlign="left";
        this.titelNameDiv.innerText=this.titelName;
        this.windowDiv.style.display=""
      
        this.windowDiv.style.height=this.y+23+"px";
        this.windowDiv.style.width=this.x+"px"; 
        this.windowDiv.className=this.divClass;   
        this.place();
        if(this.showGround==null)
        {       
             this.backGroundDiv.style.display="";
             this.backGroundBase();         
        }
        this.hideAllSelect();
    }
    //调整消息框位置
    this.place=function ()
    {
        var y=Number(this.windowDiv.style.height.replace("px",""));
        var x=Number(this.windowDiv.style.width.replace("px",""));
        this.window.Run(); 
        var _top =this.window.h/2-y/2+this.window.t;
        var _left=this.window.w/2-x/2; 
      
        if(_top>0)
        {
            this.windowDiv.style.top=_top+"px";
        }else{ 
        this.windowDiv.style.top=this.window.t+"px";
        }
        if(_left>=0)
        {
            this.windowDiv.style.left=_left+"px";
        }else{ this.windowDiv.style.left=0;}            
         this.window.RunWindow(); 
    }
    
    //关闭窗口
    this.Hidden=function()
    {
        this.titelName="Shanghailu";
        this.show=null;
        this.showGround=null;
        this.showAllSelect();
        this.backGroundDiv.style.display="none";
        this.windowDiv.style.display="none";
        this.showDiv.innerHTML="";
        this.backGroundDiv.onclick=null;
        if(this.windowIframe!=null)
        {
            this.windowIframe.style.display="none";
            if(_leoGet("_"+this.name+"divCue")!=null)
            {
                 _leoGet("_"+this.name+"divCue").style.width="250px"; 
                 _leoGet("_"+this.name+"divCue").style.height="100px";    
             }           
        }
        this.y=100;
        this.w=250; 
        this.showDiv.style.height="100px";            
        this.showDiv.style.width="250px"; 
        this.windowDiv.style.height="100px";
        this.windowDiv.style.width="250px"; 
    }
    //出现提示筐 有大小的

    this.Show=function (x,y,content)
    {      
        this.base(x,y);          
        this.showDiv.innerHTML=content;        
    }
    //出现提示筐 默认大小的
    this.alert=function(content)
    {  
        var x=this.strLength(content)*5;      
        var y=100; 
        if(x<250)
        {
            x=250;
        }
        if(x>600)
        {            
            y=x/600*14+75;
            x=600;
         }     
        var showGround= leo.showGround;
        var divClass=leo.divClass;
        this.Hidden();
        leo.showGround=showGround;
        leo.divClass=divClass;
        
        var hiddenStr=" "+this.name+".Hidden();"
        this.backGroundDiv.onclick=function (){ eval(hiddenStr); };
        var windowAlert="<div style='width:"+x+"px;text-align:center;font-size:12px;'><div style=' padding:10px; '>"+content+"</div></div>"
        windowAlert+="<div align='center' style='width:100%; '><input type='button' style='line-height:20px;float:none;width:80px; height:22px;background:#fff; text-align:center; border:#ccc solid 1px;' onClick='"+this.name+".Hidden()' value='确定'></div><div stype='height:8px''></div>";
        this.Show(x,y,windowAlert);   
         this.showDiv.style.height=y+"px";            
          this.showDiv.style.width=x+"px"; 
          this.windowDiv.style.height=y+23+"px";
          this.windowDiv.style.width=x+"px";     
    }
    //弹出窗口
    this.openXy=function (x,y,content)
    { 
        var iframeTemplet="<iframe style='position:absolute;display:none;' scrolling='auto' height='1' width='1'  onload='"+this.name+".iframeOPenShow("+x+","+y+");'  allowTransparency='true' id='_"+this.name+"iframeOPen' frameborder=0 marginheight=0 src='about:blank' marginwidth=0 hspace=0 vspace=0 scrolling=no></iframe>"; 
        this.showDiv.innerHTML="<div id='_"+this.name+"divCue' style='text-align:center;padding-top:0px;'  ><div class='lodingImage'></div>wait please...</div>"+iframeTemplet;            
        this.windowIframe=_leoGet("_"+this.name+"iframeOPen"); 
        this.url=content;
        this.base(x,y+30);
   
       
        if(this.show==null)
        {
            if(this.url.split('?').length>1)
            {
            this.windowIframe.src=this.url+"&Math="+(Math.random()*100000);     
            } else{ this.windowIframe.src=this.url+"?Math="+(Math.random()*100000);   }
            this.showDiv.style.height=this.y+"px";            
            this.showDiv.style.width=this.x+"px"; 
            this.windowDiv.style.height=this.y+23+"px";
            this.windowDiv.style.width=this.x+"px";  
            _leoGet("_"+this.name+"divCue").style.padding=this.y/3+"px";            
            this.place();
          
        } else if(this.show=="to")
        {
               this.windowDiv.style.height="100px";
                this.windowDiv.style.width="100px"; 
             var changeWindow=""+this.name+".ToSize();";      
            this.IntervalToSize=setInterval(function (){ eval(changeWindow);},10);          
            
        }else{         
                if(this.windowIframe.src!=this.url)
                {
                    this.windowIframe.src=this.url;
                    
                     this.showDiv.style.height=this.y+"px";            
                    this.showDiv.style.width=this.x+"px"; 
                    this.windowDiv.style.height=this.y+23+"px";
                    this.windowDiv.style.width=this.x+"px";  
                    _leoGet("_"+this.name+"divCue").style.padding=this.y/3+"px";            
                    this.place();
                } 
             }
       
        this.windowIframe.close=this.Hidden;  
        this.windowIframe.opener=this.windowIframe.parent;
    }
    //显示弹出窗口内容 用于弹出新页面的
    this.iframeOPenShow=function (x,y)
    { 
        if(this.windowIframe.src!="about:blank"&&this.windowIframe.src!=""&&this.windowDiv.style.display!="none")
        {   
            if(this.show!=null&&this.show!="to")
            {
                this.showDiv.style.height=this.y+"px";            
                this.showDiv.style.width=this.x+"px"; 
                this.windowDiv.style.height=this.y+"px";
                this.windowDiv.style.width=this.x+"px";
                 _leoGet("_"+this.name+"divCue").style.padding=this.y/3+"px";
                this.windowDiv.filters.revealTrans.Transition=this.show; 
	            this.windowDiv.filters.revealTrans.apply();
                this.place(); 
	         }
                _leoGet("_"+this.name+"divCue").style.display="none"; 
                 this.windowIframe.style.display="";  
                this.windowIframe.close= this.Hidden;
                 this.windowIframe.width=this.x;
                 this.windowIframe.height=this.y;
                 if(this.show!=null&&this.show!="to")
                {
                 this.windowDiv.filters.revealTrans.play();
                 }
          }
    }
    
    this.ToSize=function()
    { 
        var y=Number(this.windowDiv.style.height.replace("px",""));
        var x=Number(this.windowDiv.style.width.replace("px",""));
        var xEnd=false;
        var yEnd=false;
       if(x<this.x)
        {       
            this.showDiv.style.width=(x+10)+"px";
            this.windowDiv.style.width=(x+10)+"px";
         }else{xEnd=true;}
        if(y<this.y&&xEnd)
        {       
            this.showDiv.style.height=(y+10)+"px";
            this.windowDiv.style.height=(y+10)+"px";
              _leoGet("_"+this.name+"divCue").style.padding=y/3+"px";
         }else{yEnd=true;}
         
     
      
         if(xEnd&&yEnd)
         { 
            this.windowIframe.src=this.url;
            clearInterval(this.IntervalToSize);             
          }
       
        this.place();
    }
    
    
    this.chageSize=  function (x,y,obj)
    {
        this.x=x;
        this.y=y;
        this.showDiv.style.height=this.y+"px";            
        this.showDiv.style.width=this.x+"px"; 
        this.windowDiv.style.height=this.y+25+"px";
        this.windowDiv.style.width=this.x+"px";
        if(this.windowIframe)
        {
            this.windowIframe.width=this.x;
            this.windowIframe.height=this.y;
        }
        this.place();
        this.backGroundBase();   
    }
    
    //计算字符串长度
    this.strLength= function ( sTargetStr ) {
        var sTmpStr, sTmpChar;
        var nOriginLen = 0;
        var nStrLength = 0;         
        sTmpStr = new String(sTargetStr);
        nOriginLen = sTmpStr.length;
        for ( var i=0 ; i < nOriginLen ; i++ ) {
                sTmpChar = sTmpStr.charAt(i);
                if (escape(sTmpChar).length > 4) {
                        nStrLength += 2;
                } else if (sTmpChar!='\r') {
                        nStrLength ++;
                }
        }        
        return nStrLength;         
    }

    
    
this.hideAllSelect=function(){
  var obj;
  obj=document.getElementsByTagName("SELECT");
  var i;
  for(i=0;i<obj.length;i++)
obj[i].style.visibility="hidden";
  }
/**//**
 * 显示所有的select
 */ 
  this.showAllSelect=function(){
  var obj;
  obj=document.getElementsByTagName("SELECT");
  var i;
  for(i=0;i<obj.length;i++)
obj[i].style.visibility="visible";
}
 
}





var leo= new LeoWindow("leo");

leo.Drawing();

function LeoSetInterval()
{
    if(leo.Interval==null)
    {
        leo.window.Run();
        leo.Interval=setInterval(function (){ leo.changeSize();},100); 
    }
}

var Alert=function (a,showGround)
{
    LeoSetInterval();
    if(showGround==undefined)
    {
        leo.showGround=null; 
        leo.divClass='leo';            
    
    }else{ 
     leo.showGround=showGround;
     leo.divClass=showGround;
     }
   
  
    leo.alert(a);
 }

function Open(a,x,y,titel,show,showGround,divClass)
{  
    LeoSetInterval();
    if(titel==undefined)
    {
        leo.titelName="";
    }else{leo.titelName=titel;}
    if(show==undefined)
    {
        leo.show=null;
    }else{ leo.show=show;}

    if(showGround==undefined)
    {
        leo.showGround=null;        
    
    }else{ leo.showGround=showGround;}
    
    if(divClass==undefined)
    {
        leo.divClass="leo";        
    
    }else{ leo.divClass=divClass;}

    if(x==undefined){x=200;}
    if(y==undefined){y=150;}
    leo.openXy(x,y,a);
}

function leoChangeTitle(title)
{
    leo.titelName=title;
    leo.titelNameDiv.innerText=leo.titelName;
}

function leoClose()
{
    leo.Hidden();
}

function leochageSize(x,y)
{
    leo.chageSize(x,y); 
}


