﻿if(lan){var closetext="关闭";}else{var closetext="Close";}
var DvWnd={
	$:function(id){return document.getElementById(id)},
	move:0,
	eventStartX:0,
	eventStartY:0,
	wndStartX:0,
	wndStartY:0,
	c:{fun:'DvWnd',id:'dvwnd',title:'dvwndtitle',body:'dvwndbody',i:'dvwndiframe',bgs:'dvwndbgs',bgs2:'dvwndbgs_ifr',c:'dvwndclose'},
	e:null,
	x:function(){return this.e.clientX;},
	y:function(){return this.e.clientY;},
	start:function(e){
		this.e=e;
		this.move=1;
		this.eventStartX=this.x();
		this.eventStartY=this.y();
		this.wndStartX=this.$(this.c.id).offsetLeft;
		this.wndStartY=this.$(this.c.id).offsetTop;
	},
	stop:function(e){
		this.e=e;
		this.move=0;
	},
	drag:function(e){
		this.e=e;
		if(this.move){
			this.$(this.c.id).style.left=this.wndStartX+(this.x()-this.eventStartX)+'px';
			this.$(this.c.id).style.top=this.wndStartY+(this.y()-this.eventStartY)+'px';
			try{noright(this.$(this.c.title));}catch(e){}
		}
	},
	close:function(){
		document.body.removeChild(this.$(this.c.id));
		document.body.removeChild(this.$(this.c.bgs));
	},
	noright:function(obj)
	{
		obj.oncontextmenu = function(){return false;}
		obj.ondragstart = function(){return false;}
		obj.onselectstart = function(){return false;}
		obj.onselect = function(){obj.selection.empty();}
		obj.oncopy = function(){obj.selection.empty();}
		obj.onbeforecopy = function(){return false;}
	},
	autoIframe:function(obj)
	{
		if(!!this.autoh)
		{
			var oldH=obj.clientHeight;
			try{
				var bHeight=obj.contentWindow.document.body.scrollHeight;
				var dHeight=obj.contentWindow.document.documentElement.scrollHeight;
				var height=Math.max(bHeight,dHeight);
				obj.style.height=height+"px";
			}catch(e){}
			var ca=height-oldH;
			var nTop=parseInt(this.$(this.c.id).style.top)-ca;
			if(nTop<0)nTop=0;
			this.$(this.c.id).style.top=nTop+"px";
			this.$(this.c.id).style.height="auto";
		}
		else
			return;
	},
	open:function(){		
		var de=document.documentElement;
		var w=window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var ch=window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
		if (self.pageYOffset){
			var st=self.pageYOffset;
		} else if (de&&de.scrollTop){
			var st=de.scrollTop;
		} else if (document.body){
			var st=document.body.scrollTop;
		}
		if (window.innerHeight && window.scrollMaxY){	
			var sh=window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			var sh=document.body.scrollHeight;
		} else {
			var sh=document.body.offsetHeight;
		}
		
		//DvWnd.open('title','url',0,500,100,1,{bgc:'#ffffff',opa:0.5});
		var a=arguments,s='';
		this.title=a[0]||'信息窗口';							//title
		this.para=a[1];											//网址或者要显示的内容
		this.autoh=a[2]||0;										//1自适应高度
		this.width=a[3]||800;									//宽
		this.height=a[4]||500;									//高
		this.type=null==a[5]?1:a[5];							//1-框架,2-直接显示内容
		this.canvas=a[6]||{bgc:'#ffffff',opa:0.5,full:0};		//背景色和透明度
		this.none=a[7]||0;										//简单界面
		this.left=a[8]||(w-this.width)/2+'px';					//X位置
		this.top=a[9]+st||(ch-(this.height||200))/2+st+'px';	//Y位置
		if(this.$(this.c.id))this.close();
		var o=document.createElement("div");
		o.id=this.c.id;
		o.style.width=this.width+'px';
		o.style.height=this.height+'px';
		o.style.left=this.left;
		o.style.top=this.top;
		s+='<div id="'+this.c.title+'" onmousedown="'+this.c.fun+'.start(event)" onmouseup="'+this.c.fun+'.stop(event)" onmousemove="'+this.c.fun+'.drag(event)">';
		s+='<a href="javascript:'+this.c.fun+'.close();" class="'+this.c.c+'" title="'+closetext+'"></a>'+this.title+'</div>';
		s+='<div id="'+this.c.body+'">';
		s+=this.type==1?('<iframe id="'+this.c.i+'" name="'+this.c.i+'" onload="DvWnd.autoIframe(this);" src="'+this.para+'" allowTransparency="true" style="width:100%;height:'+(this.height-26)+'px;" frameborder="0"></iframe>'):('<div style="margin:10px;">'+this.para+'</div>');
		s+='</div>';
		o.innerHTML=s;
		document.body.appendChild(o);
		if(this.none)
		{
			o.className="none";
			this.$(this.c.i).style.height=o.style.height;
		}
		var nbg=0,fullstr,rollbarw=0;
		s=this.canvas;
		if(!!s.full)
			fullstr="<style>html,body{overflow:hidden;}<style>",rollbarw=30;
		else
			fullstr="<style>html,body{overflow-x:hidden;}<style>",rollbarw=0;
		o=this.$(this.c.bgs);
		if(!o){nbg=1;o=document.createElement("div");}
		o.id=this.c.bgs;
		o.style.width=(w+rollbarw)+'px';
		o.style.height=(sh>ch?sh:ch)+'px';		
		o.style.backgroundColor=s.bgc;
		o.style.filter='alpha(opacity='+(s.opa*100)+')';
		o.style.opacity=s.opa;
		o.style.display='block';		
		o.innerHTML='<iframe id="'+this.c.bgs2+'" src="about:blank" scrolling="no" frameborder="0" onclick="alert(0);"></iframe>'+fullstr;
		if(nbg){document.body.appendChild(o)};
		var o2=this.$(this.c.bgs2);
		if(o2){
			o2.style.width=w+'px';
			o2.style.height=(sh>ch?sh:ch)+'px';
		}
		if(this.type==1){this.$(this.c.i).src=this.para;}
	}
}
