function OpenWin(url, name, width, height, style) {
	var hgap=40;
	var vgap=40;
	if (width>screen.availWidth-hgap||height>screen.availHeight-vgap)
		style += ((style?",":"")+"scrollbars=yes");
	if (width>screen.availWidth-hgap)
		width = screen.availWidth-hgap;
	if (height>screen.availHeight-vgap)
		height = screen.availHeight-vgap;

	var left = (screen.availWidth-width)/2;
	var top = (screen.availHeight-height)/2;
	var win = window.open(url, name, s="left="+left+",top="+top+",width="+width.toString()+",height="+height.toString()+","+style);
	//win.moveTo(left, top);
	win.focus();
	return win;
}

if (window.dialogArguments) {
	window.dialogArguments.ModalWin = self;
}

var ModalWin=null;

function IgnoreEvents(e) {
	return false;
}
function HandleFocus() {
	if (ModalWin) {
		if (!ModalWin.closed) {
			ModalWin.focus();
		}
		else {
			window.top.releaseEvents(Event.CLICK|Event.FOCUS);
		}
	}
	return false;
}
function HandleFocusIE() {
	if (ModalWin && ModalWin.open && !ModalWin.closed)
		ModalWin.focus();
	return false;
}
var UnloadOriIE=null;
function HandleUnloadIE() {
	if (ModalWin && ModalWin.open && !ModalWin.closed)
		ModalWin.close();
	if (UnloadOriIE)
		UnloadOriIE();
	return false;
}
function OpenModalWin(url, name, width, height, style) {
	var hgap=40;
	var vgap=40;
	if (width>screen.availWidth-hgap||height>screen.availHeight-vgap)
		style += ((style?",":"")+"scrollbars=yes");
	if (width>screen.availWidth-hgap)
		width = screen.availWidth-hgap;
	if (height>screen.availHeight-vgap)
		height = screen.availHeight-vgap;

	var left = (screen.availWidth-width)/2;
	var top = (screen.availHeight-height)/2;
	if (window.showModalDialog) {
		if (name) {
			if (window.attachEvent) {
				window.attachEvent("onfocus", HandleFocusIE);
				window.attachEvent("onunload", HandleUnloadIE);
			} else {
				window.onfocus = HandleFocusIE;
				UnloadOriIE = window.onunload;
				window.onunload = HandleUnloadIE;
			}
			ModalWin = window.open(url, name, "width="+width.toString()+",height="+height.toString()+(style?","+style:""));
			ModalWin.moveTo(left, top);
			ModalWin.focus();
		} else {
			if (style)
				style = style.replace(/,/g, ";");
			window.showModalDialog(url, self, "dialogWidth="+width.toString()+"px;dialogHeight="+height.toString()+"px"+(style?";"+style:""));
		}
	} else if (NS4) {
		window.top.captureEvents(Event.CLICK|Event.FOCUS);
		window.top.onClick = IgnoreEvents;
		window.top.onFocus = HandleFocus;
		ModalWin = window.open(url, name?name:"_blank", "dependent=yes,width="+width.toString()+",height="+height.toString()+(style?","+style:""));
		ModalWin.moveTo(left, top);
		ModalWin.focus();
	} else {
		if (name) {
			window.top.captureEvents(Event.CLICK|Event.FOCUS);
			window.top.onClick = IgnoreEvents;
			window.top.onFocus = HandleFocus;
			ModalWin = window.open(url, name, "dependent=yes,width="+width.toString()+",height="+height.toString()+(style?","+style:""));
			ModalWin.moveTo(left, top);
			ModalWin.focus();
		} else {
			window.open(url, "_blank", "modal=yes,width="+width.toString()+",height="+height.toString()+(style?","+style:""));
		}
	}
}

function Close_() {
	if (ModalWin && ModalWin.open && !ModalWin.closed)
		ModalWin.close();
	close();
	return false;
}
function Location_(url) {
	if (ModalWin && ModalWin.open && !ModalWin.closed)
		ModalWin.close();
	self.location.href = url;
}

