||define||DLG_WIDTH||400||

function dge(a) { return document.getElementById(a); }
var mydlg_cb = null;
var dialog_open = false;

function modal_dialog()
{
	return dialog_open;
}
function dlg_init(cb,opt)
{
	if(!opt) opt={};
	var dlg=document.getElementById('dlg_win');
#	if(dlg&&dlg.custom) {
	if(dlg){	// Switch to always resetting it...
		dlg_reset();
		dlg=U;
	}
	var nopad=(opt && opt.nopad?'nopad':'')
	
	if (!dlg){
		var x=document.createElement("div");
		x.id='dlg_ovrl';
		x.style.display='none';
		x.innerHTML='<div onkeyup="stopEvent(event)" oncontextmenu="return false;" onkeydown="stopEvent(event);" style="width:100%;height:100%" tabindex="20"></div>'
		document.body.appendChild(x);
		dlg=document.createElement("div");
		dlg.id='dlg_win';
		dlg.style.display='none';
		dlg.innerHTML=
		    '<div id="dlg_t"></div>'+
		    '<div id="dlg_w" class="'+nopad+'" onkeydown="dlg_onkeydown(event)" onkeyup="dlg_onkeyup(event)"><div id="dlg_icon"></div><div id="dlg_prompt"></div><div id="dlg_custom" class="'+nopad+'"></div>'+
		      '<div id="dlg_x"><br /><input type="text" id="dlg_text"></div>'+
		      '<div class="buttons">'+
		  	   '<input type="button" id="dlg_ok" style="width:90px;" onclick="dlg_clk(1);" value="$$st_cmd_ok$$">'+
		       '<input type="button" class="ml" id="dlg_cancel" style="width:90px;" onclick="dlg_clk(0);" value="$$st_cmd_cancel$$">'+
		      '</div>'+
		    '</div>';
		document.body.appendChild(dlg);
		dlg.onkeydown=stopBubble;
		dlg.onkeyup=stopBubble;
		shadofy(dlg);
	}
	if (!dlg.init){
		dlg.hdr=document.getElementById('dlg_t');
		dlg.bdy=document.getElementById('dlg_w');
		dlg.txt=document.getElementById('dlg_prompt');
		panelise_roundtop(dlg.hdr,enHdr,true);
		panelise_square(dlg.bdy,enBody,true);
		Drag.init(dlg.hdr, dlg);
		dlg.init=true;
	}

	dlg.style.left=px(ClientWidth()/2-||DLG_WIDTH||/2);
	dlg.style.top=px(ClientHeight()*0.27);
	dlg.cb=cb;
	dialog_open = true;
	return dlg;
}

function x_alert(txt,cb,opt) {
	if(!opt) opt={};
	var dlg=dlg_init(cb);
	dlg.hdr.innerHTML = document.domain + ' - $$st_dlg_alert$$';
	dlg.txt.innerHTML = txt;
	dge('dlg_custom').innerHTML ='';
	dge('dlg_ovrl').style.display =	dlg.style.display = '';
	dlg_opt(opt);
	class_set(dlg,'alert');
	dge('dlg_ok').focus();
}

function x_confirm(q, cb, noshow,opt) {
	if(!opt) opt={};
	if(noshow) return cb(true);
	var dlg=dlg_init(cb);
	dge('dlg_t').innerHTML = document.domain+' - '+(opt.title?opt.title:'$$st_dlg_confirm$$') ;
	var el = dge('dlg_prompt');
	if(opt.view_init){
		el.innerHTML = '<div class="dlg_align"></div>';
		opt.view_init(el.firstChild);
	}else{
		el.innerHTML = '<div class="dlg_align">'+q+'</div>';
	}
	dge('dlg_custom').innerHTML ='';
	dge('dlg_ovrl').style.display =	dge('dlg_win').style.display = '';
	class_set(dlg,'confirm');
	dge('dlg_ok').focus();
}
function x_prompt(q, a, cb) {
	x_prompt2(q,a,cb,null);
}
function x_prompt2(q, a, cb, opt) {
	if(!opt) opt={};
	var dlg=dlg_init(cb);
	dge('dlg_t').innerHTML = document.domain+' - '+(opt.title?opt.title:'question:');
	dge('dlg_prompt').innerHTML = q;
	dge('dlg_custom').innerHTML ='';
	dge('dlg_text').value = a;
	dge('dlg_ovrl').style.display =	dge('dlg_win').style.display = '';
	class_set(dlg,'prompt');
	dlg_opt(opt);
	if(!opt.nofocus) dge('dlg_text').focus();
	if(!opt.noselect) dge('dlg_text').select();
}

function x_custom_dlg(txt,custom,cb,cb_init,opt)
{
	if(!opt) opt={};
	var dlg=dlg_init(cb);
	dlg.custom=true;
	dlg.hdr.innerHTML = document.domain + ' - $$st_dlg_alert$$';
	dge('dlg_prompt').innerHTML = txt;
	dge('dlg_custom').innerHTML = custom;
	dge('dlg_ovrl').style.display =	dge('dlg_win').style.display = '';
	dlg_opt(opt);
	class_set(dlg,'custom');
	if (cb_init) cb_init();
}
function x_custom_dlg2(txt,custom,cb,cb_init,opt)
{
	if(!opt) opt={};
	var dlg=dlg_init(cb,opt);
	dlg.custom=true;
	dlg.hdr.innerHTML = document.domain + ' - ' + txt;
	dge('dlg_custom').innerHTML = custom;
	dge('dlg_ovrl').style.display =	dge('dlg_win').style.display = '';

	dge('dlg_x').style.display = dge('dlg_ok').style.display = dge('dlg_prompt').style.display = dge('dlg_icon').style.display = 'none';	
	dge('dlg_cancel').value='$$st_cmd_close$$';
	dge('dlg_custom').style.marginLeft = '0';

	dlg_opt(opt);
	class_set(dlg,'custom');
	if (cb_init) cb_init();
}
function x_custom_dlg2_body(html)
{
#	var ch=ClientHeight();
#	var cw=ClientWidth();
#	var o=dge('dlg_win').style;
#	o.left=px(0.5*cw-200);
#	o.top=px(0.5*ch-200);
#	o.width = px(400);	

	var xdoc=dge("dlg_iframe").contentWindow.document;
	xdoc.open();
	xdoc.write(html);
	xdoc.close();			
}
function dlg_opt(opt)
{
	if(!opt)return;
	var ch=ClientHeight();
	var cw=ClientWidth();
	var o=dge('dlg_win').style;
	if(opt.tall){
		o.top=px(0.05*ch);
	}
	if(opt.width){
		if(opt.width<1){
			o.left=px(((1-opt.width)/2)*cw);
			o.width = px(opt.width*cw);
		}else{
			o.left=px((cw-opt.width)/2);
			o.width = px(opt.width);
		}
	}
	if(opt.nobtns){
		dge('dlg_cancel').parentNode.style.display='none';
	}
	if(opt.nocancel){
		dge('dlg_cancel').style.display='none';
	}
}

function dlg_clk(m) {
	dialog_open = false;
	var hide=true;
	var dlg=document.getElementById('dlg_win');
	switch(dlg.className){
		case 'alert':
			if (dlg.cb) dlg.cb();
			break;
		case 'confirm':
			hide=dlg.cb(m);
			break;
		case 'prompt':
			if (!m)
				dlg.cb(null);
			else
				dlg.cb(dge('dlg_text').value);
			break;
		case 'custom':
			hide=dlg.cb(m);
			break;

	}
	if (hide!=false){
		var o=dge('dlg_ovrl'); 
		if(o) o.style.display = 'none';
		remove_node(o);
		o=dge('dlg_win');
		if(o) o.style.display = 'none';
		remove_node(o);
	}
}
function dlg_size(sz)
{
	var extra=90;
	sz+=extra;
	var ch=ClientHeight();
	if(ch>600 && sz>ch-100) sz=ch-100;
	var dlg=document.getElementById('dlg_iframe');
	dlg.style.height=px(sz);	
	var dlg=document.getElementById('dlg_win');
	dlg.style.top=px((ch-sz)/2);		
	return sz-extra;
}
function x_dlg_hide()
{
	dialog_open = false;
	dge('dlg_ovrl').style.display =	dge('dlg_win').style.display = 'none';
	dge('dlg_custom').innerHTML ='';
}

function dlg_reset()
{
	var o=dge('dlg_win');
	o.parentNode.removeChild(o);
	var o=dge('dlg_ovrl');
	o.parentNode.removeChild(o);
}

function dlg_onkeyup(e)
{
	if(!e) e=window.event;
	dbg('dlg_onkeyup: '+e.keyCode)
	if((e.keyCode==10)||(e.keyCode==13)) dlg_clk(1); 
	if (e.keyCode==27) dlg_clk(0);
#	stopEvent(e);
}
function dlg_onkeydown(e)
{
#	stopEvent(e);
}