/*
一些用法
  弹出自适应窗口(加在事件中调用)
  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=auto');
		_this.resize(winOpenObj);
		return winOpenObj;
	  }else{
	    return false;    //存放showmodelessDialog代码
      }
    }
	
	this.img = function(imgSrc)
	{
	  var width = 200;
	  var height = 200;
	  var left = (window.screen.width-width)/2
      var top  = 40
	  var winOpenObj;
	  var winWidth;
      winOpenObj = window.open('','name','width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=no');
	  winOpenObj.document.write("<html>");
	  winOpenObj.document.write("<head>");
	  winOpenObj.document.write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />");
	  winOpenObj.document.write("<title>弹出窗口</title>");
	  winOpenObj.document.write("</head>");
	  //winOpenObj.document.write("<img id='img_pic' style='display:none' src='"+imgSrc+"'>");
	  winOpenObj.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
	  winOpenObj.document.write("<img id='img_pic' src='"+imgSrc+"'>");
	  winOpenObj.document.write("</body>");
	  winOpenObj.document.write("</html>");
	  //winOpenObj.document.close()
	  //_this.resize(winOpenObj);
	  var img = winOpenObj.document.getElementsByTagName("body")[0]   //窗口对象
	  var picObj = winOpenObj.document.getElementById("img_pic")      //图片对象
	  //alert(picObj.width)
	 // var a = window.setTimeout(abc(),1000)
	  //clearTimeout(a)
	  
	  
	  //setTimeout(_this.reImg(picObj,winOpenObj),10000)
	  
	  
	  
	  var sume = 1     //延迟1000000
	  for(var i_i = 0;i_i<=1500000;i_i++){
		  sume = sume + i_i
	  }
	  
	  if(picObj.width>700) {    //针对21JD不能弹出宽500的窗口(使弹出窗口宽为500,并固定图片显示500)
		  winWidth = 700;
		  picObj.width=700;
	  }else{
		  winWidth = picObj.width;   
	  }
	  
	  //var winWidth = img.scrollWidth;
	  var winHeight = picObj.height;
	  //if(winHeight>600) winHeight = 550;
      var b=screen.width;
      var c=screen.height;
      b=(b-winWidth)/2;
      c=(c-winHeight)/2;
	  //alert(winWidth+25)
      winOpenObj.resizeTo(winWidth+10,winHeight+60);
      winOpenObj.moveTo(b,c);
      winOpenObj.focus();
	  return winOpenObj;
	  
	  
	  
    }
	/*
	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+15,winHeight+60);
     imgWin.moveTo(b,c);
     imgWin.focus();
  }
  
  this.reImg = function(picObj,winOpenObj){
	  if(picObj.width>700) {    //针对21JD不能弹出宽500的窗口(使弹出窗口宽为500,并固定图片显示500)
		  winWidth = 700;
		  picObj.width=700;
	  }else{
		  winWidth = picObj.width;   
	  }
	  
	  //var winWidth = img.scrollWidth;
	  var winHeight = picObj.height;
	  //if(winHeight>600) winHeight = 550;
      var b=screen.width;
      var c=screen.height;
      b=(b-winWidth)/2;
      c=(c-winHeight)/2;
	  //alert(winWidth+25)
      winOpenObj.resizeTo(winWidth+10,winHeight+60);
      winOpenObj.moveTo(b,c);
      winOpenObj.focus();
	  return winOpenObj;
	  
}
/*
   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;
