/* Windowオブジェクト */

var DialogSystem = function (w, c, b, cl) {
	this.initialize(w, c, b, cl);
};
DialogSystem.prototype = {
	win: null,
	close_tab: null,
	win_back: null,
	on_close: null,
	parent_win: null,
	initialize: function(w, c, b, cl) {
		this.win       = xGetElementById(w);
		this.close_tab = xGetElementById(c);
		this.win_back  = xGetElementById(b);
		this.on_close  = cl;
		this.openWindow();
		if (this.close_tab) xAddEventListener(this.close_tab, 'click', this.onClick.bind(this), false);
		if (this.win_back)  xAddEventListener(this.win_back,  'click', this.onClick.bind(this), false);
	},
	onClick: function(event) {
		event = event || window.event;
		this.onClose();
	},
	onClose: function() {
		this.callClose();
		document.body.style.overflow = 'auto';
		if (this.win)        xDisplay(this.win, 'none');
		if (this.win_back)   xDisplay(this.win_back, 'none');
		if (this.parent_win) this.parent_win.openWindow();
		if (this.on_close)   this.on_close();
	},
	callClose: function() {
	},
	openWindow: function() {
		/* document.body.style.overflow = 'hidden'; */
		var ds = xDocSize();
		var x = xScrollLeft(null, true);
		var y = xScrollTop(null, true);
		xDisplay(this.win_back, 'block');
		xMoveTo(this.win_back, 0, 0);
		xResizeTo(this.win_back, ds.w, ds.h);
		xZIndex(this.win_back, 999);
		xDisplay(this.win, 'block');
		xZIndex(this.win, 1010);
		/* this.setCenter(); */
	},
	setCenter: function() {
		var x = xScrollLeft(null, true);
		var y = xScrollTop(null, true);
		var w = Math.round((xClientWidth() - xWidth(this.win)) / 2);
		var h = Math.round((xClientHeight() - xHeight(this.win)) / 2);
		xLeft(this.win, w + x);
		xTop(this.win, h + y);
	},
	setParent: function(p) {
		this.parent_win = p;
	},
	getParent: function() {
		return this.parent_win;
	}
};
