/*
一些用法
  弹出自适应窗口(加在事件中调用)
  O.type="winopen"               //可选默认为winopen
  var url = "http://localhost"
  O.show(url,"wo")  //wo可选
  O.img(imgSrc)     //弹出单个图窗口
  
  框架自适应高宽
  O.type="iframe";
  O.resize("iframeId")
*/
function Js_Window()
{
	this.type = "winopen";   //区分弹出窗口与框架
	_this = this;
	this.show = function(url,mode)   //mode区分模式窗口与window.open
    {
	  var width = 30;
	  var height = 30;
	  if(mode==undefined){mode="wo"}	
	  if(mode=="wo"){
	    var left = (window.screen.width-width)/2
        var top  = 40
		var winOpenObj;
        winOpenObj = window.open(url,'name','width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=yes');
		_this.resize(winOpenObj);
		return winOpenObj;
	  }else{
	    return false;    //存放showmodelessDialog代码
      }
    }
	
	this.img = function(imgSrc)
	{
       foto1= new Image();
       foto1.src=(imgSrc);
       _this.Controlla(imgSrc);
    }
	
    this.Controlla = function(imgSrc){
      if((foto1.width!=0)&&(foto1.height!=0)){
        _this.viewFoto(imgSrc);
      }
      else{
        funzione="_this.Controlla('"+imgSrc+"')";
        intervallo=setTimeout(funzione,20);
      }
    }

this.viewFoto = function(imgSrc){
  largh=foto1.width+40;
  altez=foto1.height+40;
  stringa="width="+largh+",height="+altez;
  finestra=window.open(imgSrc,"",stringa);
  finestra.moveTo(5,5);
}

/*
跟据指定图片的长宽度制定弹出窗口的的长宽度
O.img1('aa.jpg','yy.asp')
*/

	this.img1 = function(imgSrc,fileUrl)
	{
       foto1= new Image();
       foto1.src=(imgSrc);
       _this.Controlla1(imgSrc,fileUrl);
    }
    this.Controlla1 = function(imgSrc,fileUrl){
      if((foto1.width!=0)&&(foto1.height!=0)){
        _this.viewFoto1(imgSrc,fileUrl);
      }
      else{
        funzione="_this.Controlla1('"+imgSrc+"','"+fileUrl+"')";
        intervallo=setTimeout(funzione,20);
      }
    }
	
this.viewFoto1 = function(imgSrc,fileUrl){
  largh=foto1.width+60;
  altez=foto1.height+20+80;
  stringa="width="+largh+",height="+altez+",scrollbars=auto";
  finestra=window.open(fileUrl,"",stringa);
  finestra.moveTo(5,5);
}

	
	/*
	resize用法
	1.包含文件
	2.在文档后面加入(不用在事件里加)
	  O.type = "iframe";
	  O.resize("objId")
	*/
	this.resize = function(ele)
	{
	   if(_this.type=="iframe"){
		    var frmright=$(ele);
			frmright.attachEvent("onload",function(){_this.iframeOnload(frmright)});
			_this.type = "";                //清空属性以免影响其它方法的调用
	   }else if(_this.type=="winopen"){
		   //图片
		   var imgWin = $(ele);
		   //alert(imgWin)
		   imgWin.attachEvent("onload",function(){_this.WinOnload(imgWin)});
		   
	   }
	}
////////////次调函数////////////////////////////////////
  this.iframeOnload = function(ele){     //框架自适应高宽
	 var frmright=$(ele);
     if (document.getElementById)
     {
        if (frmright && !window.opera)
        {
           if(frmright.contentDocument && frmright.contentDocument.body.offsetHeight)
		   { 
              frmright.height = frmright.contentDocument.body.offsetHeight; 
	          frmright.width = frmright.contentDocument.body.offsetWidth;
           }else if(frmright.Document && frmright.Document.body.scrollHeight){
              frmright.height = frmright.Document.body.scrollHeight;
	          frmright.width = frmright.Document.body.scrollWidth;
	       }
         }
      }
  }
  
   this.WinOnload = function(ele){
     var imgWin = ele  //ele窗口对象
	 var img = imgWin.document.getElementsByTagName("body");
	 img = img[0]
	 var winWidth = img.scrollWidth;
	 var winHeight = img.scrollHeight;
	 //if(winWidth>750) winWidth = 750;
	 //if(winHeight>600) winHeight = 550;
     var b=screen.width;
     var c=screen.height;
     b=(b-winWidth)/2;
     c=(c-winHeight)/2;
     imgWin.resizeTo(winWidth+30,winHeight+60);
     imgWin.moveTo(b,c);
     imgWin.focus();
  }
/*
   this.imgWinOnload = function(ele){
     var imgWin = ele  //$(ele)
	 var img = imgWin.document.getElementsByTagName("img");
	 img = img[0]
	 var winWidth = img.width;
	 var winHeight = img.height;
     var b=screen.width;
     var c=screen.height;
     b=(b-winWidth)/2;
     c=(c-winHeight)/2;
     imgWin.resizeTo(winWidth+27,winHeight+55);
     imgWin.moveTo(b,c);
     imgWin.focus();
  }
 */
 
 
}
var O = new Js_Window;
