﻿var onsubwindowopen=null;
var onsubwindowclose=null;
function subwindow(url,caption,width,height,callclose,post,callopen) {
  var body=document.getElementsByTagName("BODY")[0];
  var doc = document.documentElement;
  var bg=document.createElement("div");
  bg.id="__background";
  bg.style.position="absolute";
  bg.style.lef="0px";
  bg.style.top="0px";
  bg.style.width=body.offsetWidth+"px";
  bg.style.height=Math.max(doc.scrollHeight,doc.clientHeight)+"px";
  bg.style.backgroundColor="#CCCCCC";
  bg.style.filter="alpha(opacity=10)";  // IE
  bg.style.opacity=0.10;  // Firefox,Google
  bg.style.zIndex=999;
  var out=document.createElement("div");
     out.id="__loaddialog";
	 out.className="modal-dialog";
	 out.style.left=((doc.clientWidth-width)/2)+"px";
	 out.style.top=(((doc.clientHeight<height?doc.scrollHeight:doc.clientHeight)-height)/2+Math.max(doc.scrollTop,body.scrollTop))+"px";
	 out.style.width=width+"px";
	 out.style.zIndex=1000;

  var inner=document.createElement("div");
  inner.className="modal-dialog-title";
  var title=document.createElement("span");
  title.className="modal-dialog-title-text";
  title.innerHTML="<b>"+caption+"</b>";
  var close=document.createElement("span");
  close.className="modal-dialog-title-close1";
  close.onclick=function() {
		turnoff(callclose);
	}
	
  var client2=document.createElement("div");
  client2.id="dialogouter";
  var client1=document.createElement("div");
  client1.id="dialoginner";
  client1.className="manage-sharing-contents";
  var client=document.createElement("div");
  client.className="dialog-section";  
  var client3=document.createElement("div");
  client3.className="dialog-tray";
  client3.innerHTML=""+""+"";
	if(post) {
		var sp=url.indexOf("?");
		var posturl=sp>0?url.substring(0,sp):url;
		var parameter=sp>0?url.substring(sp+1):null;
		ajaxpost(posturl,function(xmlHttp) {
			if (xmlHttp.readyState==4) {
				if (xmlHttp.status==200||xmlHttp.status==0) {
					client.innerHTML=xmlHttp.responseText;
					title.appendChild(close);
					inner.appendChild(title);
					client1.appendChild(client);
					client2.appendChild(client1);
					client2.appendChild(client3);
					out.appendChild(inner);
					out.appendChild(client2);
					body.appendChild(bg);
					body.appendChild(out);
					if(onsubwindowopen) {
						onsubwindowopen();
					}
					if(callopen) {
						callopen();
					}
				}
			}
		},parameter);
	}
	else {
		ajaxget(url,function(xmlHttp) {
			if (xmlHttp.readyState==4) {
				if (xmlHttp.status==200||xmlHttp.status==0) {
					client.innerHTML=xmlHttp.responseText;
					title.appendChild(close);
					inner.appendChild(title);
					client1.appendChild(client);
					client2.appendChild(client1);
					client2.appendChild(client3);
					out.appendChild(inner);
					out.appendChild(client2);
					body.appendChild(bg);
					body.appendChild(out);
					if(onsubwindowopen) {
						onsubwindowopen();
					}
					if(callopen) {
						callopen();
					}
				}
			}
		});
	}
	
}
function turnoff(callclose) {
  var bg=document.getElementById("__background");
  var out=document.getElementById("__loaddialog");
  var body=document.getElementsByTagName("BODY")[0];
  body.removeChild(bg);
  body.removeChild(out);
  
	if(callclose) {
		callclose();
	}
	if(onsubwindowclose) {
		onsubwindowclose();
	}
}