﻿// JonScript 文件
//jon编写 2007 12 17
function _jonGet(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 JonWindow(name)
{    
    this.name=name;
    //标题
    this.titelName="wolpo";
    //取消按钮
    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()'>关闭</div></div>";
    //弹出框
    this.CasingTemplet =function (){return   "<div id='_"+this.name+"windowDiv' class='jonblue' style=' position:absolute; z-index:6 ;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' style='filter:alpha(opacity=60) blendTrans(duration=1); background:#f1f1f1; position:absolute;z-index:5;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='jon';
    
    this.Drawing=function ()
    {
         if(this.showDiv==null)
         {
            document.write(this.backGroundTemplet);
            document.write(this.CasingTemplet());  
            this.showDiv=_jonGet("_"+this.name+"showDiv");
            this.backGroundDiv=_jonGet("_"+this.name+"backGroundDiv");
            this.windowDiv=_jonGet("_"+this.name+"windowDiv");   
            this.titelNameDiv=_jonGet("_"+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=_jonGet("_"+this.name+"showDiv");
            this.backGroundDiv=_jonGet("_"+this.name+"backGroundDiv");
            this.windowDiv=_jonGet("_"+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="web";
        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(_jonGet("_"+this.name+"divCue")!=null)
            {
                 _jonGet("_"+this.name+"divCue").style.width="250px"; 
                 _jonGet("_"+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*25+75;
            x=600;
         }     
        var showGround= jon.showGround;
        var divClass=jon.divClass;
        this.Hidden();
        jon.showGround=showGround;
        jon.divClass=divClass;
        
        var hiddenStr=" "+this.name+".Hidden();"
        this.backGroundDiv.onclick=function (){ eval(hiddenStr); };
        var windowAlert="<div style='width:"+x+"px; padding:12px,0,12px,0;; text-align:center;'>"+content+"</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>请等待...</div>"+iframeTemplet;            
        this.windowIframe=_jonGet("_"+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";  
            _jonGet("_"+this.name+"divCue").style.padding=this.y/3+"px";            
            this.place();
          
        } else if(this.show=="to")
        {
             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.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";
                 _jonGet("_"+this.name+"divCue").style.padding=this.y/3+"px";
                this.windowDiv.filters.revealTrans.Transition=this.show; 
	            this.windowDiv.filters.revealTrans.apply();
                this.place(); 
	         }
                _jonGet("_"+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";
              _jonGet("_"+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+"px";
        this.windowDiv.style.width=this.x+"px";
        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 jon= new JonWindow("jon");
jon.Drawing();
function JonSetInterval()
{
    if(jon.Interval==null)
    {
        jon.window.Run();
        jon.Interval=setInterval(function (){ jon.changeSize();},100); 
    }
}

var Alert=function (a,showGround)
{
    JonSetInterval();
    
    if(showGround==undefined)
    {
        jon.showGround=null; 
        jon.divClass='jon';            
    
    }
    else
    { 
        jon.showGround=showGround;
        jon.divClass=showGround;
    }  
  
    jon.alert(a);
 }

function Open(a,x,y,titel,show,showGround,divClass)
{  
    JonSetInterval();
    if(titel==undefined)
    {
        jon.titelName="web";
    }else{jon.titelName=titel;}
    if(show==undefined)
    {
        jon.show=null;
    }else{ jon.show=show;}

    if(showGround==undefined)
    {
        jon.showGround=null;
    
    }else{ jon.showGround=showGround;}
    
    if(divClass==undefined)
    {
        jon.divClass="jon";        
    
    }else{ jon.divClass=divClass;}

    if(x==undefined){x=200;}
    if(y==undefined){y=150;}
    jon.openXy(x,y,a);
}

function jonChangeTitle(title)
{
    jon.titelName=title;
    jon.titelNameDiv.innerText=jon.titelName;
}

function jonClose()
{
    jon.Hidden();
}

function jonchageSize(x,y)
{
    jon.chageSize(x,y); 
}



