/*
 模拟windows模态对话框。
 Author: HxyMan
 Thanks: Laomi,Fssunwin
 Update: 2008-1-20
*/
var MSWnd={
	$:function(d){return document.getElementById(d)},
	move:0,
	eventStartX:0,
	eventStartY:0,
	wndStartX:0,
	wndStartY:0,
	d:{a:'MSWnd',b:'MSWndtitle',c:'MSWndchild',d:'MSWndstatus',e:'MSWndiframe',g:'MSWndcanvas',w:'MSWnd'},
	e:null,
	x:function(){return MSWnd.e.clientX;},
	y:function(){return MSWnd.e.clientY;},
	drag_start:function(e){
		MSWnd.e=e;
		MSWnd.move=1;
		MSWnd.eventStartX=MSWnd.x();
		MSWnd.eventStartY=MSWnd.y();
		MSWnd.wndStartX=MSWnd.$(MSWnd.d.a).offsetLeft;
		MSWnd.wndStartY=MSWnd.$(MSWnd.d.a).offsetTop;
	},
	drag_stop:function(e){
		MSWnd.e=e;
		MSWnd.move=0;
	},
	drag:function(e){
		MSWnd.e=e;
		if(MSWnd.move){
			MSWnd.$(this.d.a).style.left=MSWnd.wndStartX+(MSWnd.x()-MSWnd.eventStartX)+'px';
			MSWnd.$(this.d.a).style.top=MSWnd.wndStartY+(MSWnd.y()-MSWnd.eventStartY)+'px';
			try{document.selection.empty();}catch(er){}
		}
	},
	close:function(){
		MSWnd.$(MSWnd.d.a).style.display='none';MSWnd.$(MSWnd.d.g).style.display='none';
		var a=document.body;a.removeChild(MSWnd.$(MSWnd.d.a));//a.removeChild(MSWnd.$(MSWnd.d.g));
	},
	onfocus:function(){
		MSWnd.flash(2);
	},
	flash:function(n){
		MSWnd.$(MSWnd.d.b).className='MSWndfocus';
		setTimeout(function(){MSWnd.$(MSWnd.d.b).className='MSWndtitle';},50);
		if(n>1){setTimeout(function(){MSWnd.flash(n-1);},100);}
	},
	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){	 // Explorer 6 Strict
			var st=de.scrollTop;
		} else if (document.body) {// all other Explorers
			var st=document.body.scrollTop;
		}
		if (window.innerHeight && window.scrollMaxY) {	
			var sh=window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			var sh=document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			var sh=document.body.offsetHeight;
		}
		var a=arguments;
		MSWnd.title=a[0]||'信息窗口';
		MSWnd.para=a[1];//网址或者要显示的内容
		MSWnd.width=a[2]||300;
		MSWnd.height=a[3]||200;
		MSWnd.type=null==a[4]?1:a[4];//1-框架,2-直接显示内容
		MSWnd.canvas=a[5]||{bgc:'#fff',opa:0.1};
		MSWnd.left=a[6]||(w-MSWnd.width)/2+'px';
		MSWnd.top=a[7]||(ch-(MSWnd.height||200))/2+st+'px';
		var dc=document,s='';
		var o=dc.createElement("div");
		o.id=MSWnd.d.a;
		o.className='MSWnd';
		o.style.width=MSWnd.width+'px';
		o.style.height=MSWnd.height+'px';
		o.style.left=MSWnd.left;
		o.style.top=MSWnd.top;
		s+='<div id="'+MSWnd.d.b+'" class="MSWndtitle" onmousedown="'+MSWnd.d.w+'.drag_start(event)" onmouseup="'+MSWnd.d.w+'.drag_stop(event)" onmousemove="'+MSWnd.d.w+'.drag(event)">';
		s+='<span style="float:right"><a href="javascript:'+MSWnd.d.w+'.close();" class="MSWndclose">×</a></span>'+MSWnd.title;
		s+='</div>';
		s+='<div id="'+MSWnd.d.c+'" class="MSWndchild">';
		s+=1==MSWnd.type?('<iframe id="'+MSWnd.d.e+'" name="'+MSWnd.d.e+'" src="about:blank"  style="width:100%;height:'+(MSWnd.height-40)+'px;" frameborder="0" hspace="0"></iframe>'):('<div style="padding:10px;">'+MSWnd.para+'</div>');
		s+='</div>';
		o.innerHTML=s;
		dc.body.appendChild(o);
		var f=0;
		o=MSWnd.$(MSWnd.d.g);
		if(!o){f=1;o=dc.createElement("div");}
		o.id=MSWnd.d.g;
		o.className='MSWndcanvas';
		o.style.height=(sh>ch?sh:ch)+'px';
		o.style.width=w+'px';
		s=MSWnd.canvas;
		o.style.backgroundColor=s.bgc;
		o.style.filter='alpha(opacity='+(s.opa*100)+')';
		o.style.display='block';
		if(f){o.onclick=function(){MSWnd.onfocus()};dc.body.appendChild(o)};
		if(1==MSWnd.type){MSWnd.$(MSWnd.d.e).src=MSWnd.para;}
	}
}