/*
Dialog scripts
Copyright (C) 2005 Aptus s.c.
All rights reserved
*/

function ss(t)
{
	window.status=t;
	return true;
}

function sc()
{
	window.status='';
	return true;
}

function fs(f)
{
	document.forms[f].submit();
}

function rd(u)
{
	setTimeout('document.location.href="'+u+'"',1);
}

var dlg_tttext='';
var dlg_tthandler=null;
var dlg_mousex;
var dlg_mousey;
var dlg_ttvisible=false;

var dlg_win_num=0;
var dlg_win_max=new Array();
var dlg_dragx, dlg_dragy, dlg_winx, dlg_winy, dlg_dragid;
var dlg_dragged=false;
var dlg_zorder=1;
var dlg_win_opened=0;

function hs(t)
{
	var e=document.getElementById('dlg_tooltip');
	if(t!=dlg_tttext) {
		e.innerHTML=t;
		dlg_tttext=t;
	}
	dlg_ttvisible=true;
	e.style.left=dlg_mousex;
	e.style.top=dlg_mousey;
	dlg_tthandler=setTimeout("document.getElementById('dlg_tooltip').style.visibility='visible';document.getElementById('dlg_tooltip').style.display=''",750);
	return true;
}

function hc()
{
	if(dlg_tthandler!=null) {
		clearTimeout(dlg_tthandler);
		dlg_tthandler=null;
	}
	dlg_ttvisible=false;
	document.getElementById('dlg_tooltip').style.visibility='hidden';
	document.getElementById('dlg_tooltip').style.display='none';
	return true;
}

function dlg_mousemove(e)
{
	dlg_mousex=(e ? e.pageX : event.x+document.body.scrollLeft);
	dlg_mousey=(e ? e.pageY : event.y+document.body.scrollTop);
	if(dlg_ttvisible) {
		var t=document.getElementById('dlg_tooltip').style;
		t.left=dlg_mousex+5;
		t.top=dlg_mousey+5;
	}
	if(dlg_dragged) {
		document.getElementById(dlg_dragid).style.left=(dlg_winx+dlg_mousex-dlg_dragx)+'px';
		document.getElementById(dlg_dragid).style.top=(dlg_winy+dlg_mousey-dlg_dragy)+'px';
	}
}

function ttinit()
{
	document.body.onmousemove=dlg_mousemove;
	dlg_dtable_init();
}

function dbl(t)
{
	if(t.dlg_clicked)
		return false;
	t.dlg_clicked=true;
	return true;
}

function dlg_hex(val)
{
	var hd=new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
	var h=Math.floor(val/16);
	var l=val-16*h;
	if(h<0 || h>15 || l<0) {
		h=0;
		l=0;
	}
	return hd[h]+hd[l];
}

function render_tree(i)
{
	var s;
	if (this.dynamic_tree) {
		var e=document.getElementById('tree2_'+this.n+'_'+i);
		dlg_get(this.referer+'?ajax=1&n='+this.n+'&i='+i+'&ids='+(i==0 ? 'null' : i)+'&dontshow='+(this.dontshow ? this.dontshow : 'null'), function(d,p){
			if (p==null)
				document.getElementById('cats_tree').innerHTML=d;
			else
				p.innerHTML=d;
		},e);
	}
	else {
		s='<table cellspacing=0 cellpadding=0 id="tree3_'+this.n+'_'+i+'">';
		var j;
		var itn=0;
		for(j=0; j<this.tree[i].length; j++) {
			var it=this.tree[i][j];
			if(it==null) {
				s+='<tr><td style="height:0px;padding:0px 0px 0px 16px;background-image:url('+doc_root+'di/dt.gif);background-repeat:repeat-y;" id="ar_'+this.n+'_'+i+'_'+itn+'">'+(this.tree[i].length==1 ? '<a href="javascript:exp_click('+i+','+itn+',-1);void(0);"><img src="'+doc_root+'di/ins.gif" border=0></a>' : '')+'</td></tr>';
				itn++;
			}
			else {
				var overout;
				if(it.length>2 && it[2]!='')
					overout='onmouseover="return hs(\''+it[2]+'\');" onmouseout="return hc();"';
				else
					overout='';
				if(it.length>1 && it[1]!=null) {
					s+='<tr><td class="tree"><a href="javascript:dlg_trees['+this.n+'].toggle_tree('+it[1]+');"><img src="'+doc_root+'di/pl.gif" width=16 height=16 border=0 align="absmiddle" name="tree1_'+this.n+'_'+it[1]+'"></a><span class="treei" '+overout+' onclick="dlg_trees['+this.n+'].click(event,'+i+','+j+');" ondblclick="dlg_trees['+this.n+'].dblclick('+i+','+j+');" id="tree4_'+this.n+'_'+i+'_'+j+'">'+it[0]+'</span></td></tr>';
					s+='<tr><td id="tree2_'+this.n+'_'+it[1]+'" style="height:0px;padding-left:16px;background-image:url('+doc_root+'di/dt.gif);background-repeat:repeat-y;"></td></tr>';
				}
				else {
					s+='<tr><td class="tree" style="padding:1px 0px 1px 16px;background-image:url('+doc_root+'di/dt.gif);background-repeat:repeat-y;"><span class="treei" '+overout+' onclick="dlg_trees['+this.n+'].click(event,'+i+','+j+');" ondblclick="dlg_trees['+this.n+'].dblclick('+i+','+j+');" id="tree4_'+this.n+'_'+i+'_'+j+'">'+it[0]+'</span></td></tr>';
				}
			}
		}
		s+='</table>';
		return s;
	}
}

var dlg_trees=new Array();

function toggle_tree(i)
{
	var e=document.getElementById('tree2_'+this.n+'_'+i);
	if(e.innerHTML=='') {
		if (!this.dynamic_tree)
			e.innerHTML=this.render_tree(i);
		else
			this.render_tree(i);
		document.images['tree1_'+this.n+'_'+i].src=doc_root+'di/mi.gif';
	}
	else {
		e=document.getElementById('tree3_'+this.n+'_'+i);
		if(e.style.display=='none') {
			e.style.display='block';
			document.images['tree1_'+this.n+'_'+i].src=doc_root+'di/mi.gif';
		}
		else {
			e.style.display='none';
			document.images['tree1_'+this.n+'_'+i].src=doc_root+'di/pl.gif';
		}
	}
}

function dlg_tree(t,i)
{
	if (arguments.length>2) {
		this.dynamic_tree=arguments[3];
		this.dontshow=arguments[4];
		this.referer=arguments[2]
	}
	else
		this.dynamic_tree=false;
	this.n=dlg_trees.length;
	dlg_trees[this.n]=this;
	this.tree=t;
	this.render_tree=render_tree;
	this.toggle_tree=toggle_tree;
	this.click=click;
	this.dblclick=dblclick;
	this.preselect=preselect;
	this.selectable=false;
	this.selected_tree=null;
	this.selected_items=[];
	if(t.length>0 && !this.dynamic_tree)
		document.write(this.render_tree(i));
	else if(this.dynamic_tree)
		this.render_tree(i);
}

function preselect(i,j)
{
	var item_id='tree3_'+this.n+'_'+i;
	var open_array=new Array();
	if(!document.getElementById(item_id)) {
		var k,l;
		var s=i;
		var f;
		open_array[0]=s;
		do {
			f=false;
			for(k=0; k<this.tree.length && !f; k++)
				for(l=0; l<this.tree[k].length; l++)
					if(this.tree[k][l]!=null)
						if(this.tree[k][l].length>1 && this.tree[k][l][1]!=null)
							if(this.tree[k][l][1]==s) {
								f=true;
								open_array[open_array.length]=k;
								s=k;
								break;
							}
		} while(f);
	}
	var o;
	for(o=open_array.length-1; o>=0; o--) {
		var e=document.getElementById('tree2_'+this.n+'_'+open_array[o]);
		if(e) {
			if(e.innerHTML=='')
				this.toggle_tree(open_array[o]);
			else {
				e=document.getElementById('tree3_'+this.n+'_'+open_array[o]);
				if(e.style.display=='none')
					this.toggle_tree(open_array[o]);
			}
		}
	}
	if(j!=null)
		this.click(null,i,j);
}

function click(ev,i,j)
{
	var e;
	if(ev!=null)
		if(!ev.ctrlKey || !this.selectable || i!=this.selected_tree) {
			var k;
			for(k=0; k<this.selected_items.length; k++) {
				e=document.getElementById('tree4_'+this.n+'_'+this.selected_tree+'_'+this.selected_items[k]);
				e.style.borderWidth='0px';
			}
			this.selected_items=[];
		}
	var del=false;
	if(ev!=null)
		if(ev.ctrlKey) {
			var si=[];
			var k;
			for(k=0; k<this.selected_items.length; k++)
				if(this.selected_items[k]!=j)
					si[si.length]=this.selected_items[k];
				else
					if(this.selected_items.length>1) {
						document.getElementById('tree4_'+this.n+'_'+i+'_'+this.selected_items[k]).style.borderWidth='0px';
						del=true;
					}
			this.selected_items=si;
		}
	this.selected_tree=i;
	if(!del) {
		this.selected_items[this.selected_items.length]=j;
		e=document.getElementById('tree4_'+this.n+'_'+i+'_'+j);
		e.style.borderWidth='1px';
		e.style.borderColor='#000000';
		e.style.borderStyle='dotted';
	}
	if(this.onclick)
		this.onclick(i,this.selected_items[this.selected_items.length-1]);
}

function dblclick(i,j)
{
	if(document.selection)
		document.selection.empty();
	if(this.ondblclick)
		this.ondblclick(i,j);
}

var dlg_dialog=new Object();

function dlg_focus()
{
	if (dlg_dialog.win && !dlg_dialog.win.closed)
		dlg_dialog.win.focus()
}

function dlg_modal(url, width, height, returnFunc, args) {
	if (!dlg_dialog.win || (dlg_dialog.win && dlg_dialog.win.closed)) {
		dlg_dialog.returnFunc = returnFunc;
		dlg_dialog.name = (new Date()).getSeconds().toString();
		var attr="left="+((screen.width-width)/2)+",top="+((screen.height-height)/2)+",resizable=no,width="+width+",height="+height;
		dlg_dialog.win=window.open(url, dlg_dialog.name, attr);
		dlg_dialog.win.args=args;
		dlg_dialog.win.focus();
	}
	else
		dlg_dialog.win.focus();
}

function dlg_lock(w)
{
	if(w) {
		w.parent.frames['menu'].blockEvents();
		w.blockEvents();
	}
}

function dlg_unlock(w)
{
	if(w) {
		w.parent.frames['menu'].unblockEvents();
		w.unblockEvents();
	}
}

function dlg_parse_date(s)
{
	var d=s.value;
	var p='';
	var i;
	for(i=0; i<d.length; i++) {
		var c=d.substr(i,1);
		if(c>='0' && c<='9')
			p+='n';
		else if(c=='-' || c=='.' || c=='/')
			p+='-';
		else
			p+=' ';
	}
	var r=d;
	if(p=='nn-nn-nnnn' || p=='n-nn-nnnn' || p=='nn-n-nnnn' || p=='n-n-nnnn' || p=='nn-nn-nn' || p=='n-nn-nn' || p=='nn-n-nn' || p=='n-n-nn') {
		var s1=p.indexOf('-');
		var s2=p.indexOf('-',s1+1);
		var dd=d.substr(0,s1);
		var mm=d.substr(s1+1,s2-s1-1);
		var yy=d.substr(s2+1);
		if(yy.length==2) {
			if(parseInt(yy)>=50)
				yy='19'+yy;
			else
				yy='20'+yy;
		}
		r=(dd.length==1 ? '0' : '')+dd+'-'+(mm.length==1 ? '0' : '')+mm+'-'+yy;
	}
	else if(p=='nn-nn' || p=='n-nn' || p=='nn-n' || p=='n-n') {
		var s1=p.indexOf('-');
		var dd=d.substr(0,s1);
		var mm=d.substr(s1+1);
		var now=new Date();
		var yy=now.getFullYear();
		r=(dd.length==1 ? '0' : '')+dd+'-'+(mm.length==1 ? '0' : '')+mm+'-'+yy;
	}
	else if(p=='nnnnnnnn' || p=='nnnnnn' || p=='nnnn') {
		var yy=d.substr(4);
		if(yy.length==0) {
			var now=new Date();
			yy=now.getFullYear();
		}
		else if(yy.length==2) {
			if(parseInt(yy)>=50)
				yy='19'+yy;
			else
				yy='20'+yy;
		}
		r=d.substr(0,2)+'-'+d.substr(2,2)+'-'+yy;
	}
	else if(p=='nn' || p=='n') {
		var now=new Date();
		var mm=(now.getMonth()+1).toString();
		var yy=now.getFullYear();
		r=(d.length==1 ? '0' : '')+d+'-'+(mm.length==1 ? '0' : '')+mm+'-'+yy;
	}
	s.value=r;
}

var dlg_it_hdr=new Array();
var dlg_it_cols=new Array();
var dlg_it_data=new Array();
var dlg_it_sort=new Array();
var dlg_it_sort_col;
var dlg_it_sort_desc;

function dlg_itable_sortfunc(a,b)
{
	if(a[dlg_it_sort_col][1]<b[dlg_it_sort_col][1])
		return dlg_it_sort_desc ? 1 : -1;
	else if(a[dlg_it_sort_col][1]>b[dlg_it_sort_col][1])
		return dlg_it_sort_desc ? -1 : 1;
	return 0;
}

function dlg_itable_checkbox(n,i,j)
{
	dlg_it_data[n][i][j][3]=dlg_it_data[n][i][j][3]>0 ? 0 : 1;
}

function dlg_itable_fill(n)
{
	if(dlg_it_sort[n]!=null) {
		dlg_it_sort_col=dlg_it_sort[n]>0 ? dlg_it_sort[n]-1 : -dlg_it_sort[n]-1;
		dlg_it_sort_desc=dlg_it_sort[n]>0 ? false : true;
		dlg_it_data[n].sort(dlg_itable_sortfunc);
	}
	var s=new Array();
	s[0]=dlg_it_hdr[n];
	s[0]+='<tr>';
	var i;
	for(i=0; i<dlg_it_cols[n].length; i++)
		s[0]+='<td class=\"th\" width="'+dlg_it_cols[n][i][1]+'%">'+(dlg_it_sort[n]!=null ? ('<a href=\"javascript:dlg_itable_sort('+n+','+(dlg_it_sort_col==i ? (dlg_it_sort_desc ? i+1 : -(i+1)) : i+1)+');void(0);\" onmouseover=\"return ss(\''+dlg_it_cols[n][i][0]+'&nbsp;'+(dlg_it_sort_col==i ? (dlg_it_sort_desc ? '-&gt;' : '&lt;-') : '-&gt;')+'\');\" onmouseout=\"return sc();\" class=\"tha\">') : '')+dlg_it_cols[n][i][0]+(dlg_it_sort[n]!=null ? ('</a>'+(i==dlg_it_sort_col ? '&nbsp;'+(dlg_it_sort_desc ? '&uarr;' : '&darr;') : '')) : '')+'</td>';
	s[0]+='</tr>';
	for(i=0; i<dlg_it_data[n].length; i++) {
		s[i+1]='<tr>';
		var j;
		for(j=0; j<dlg_it_data[n][i].length; j++)
			if(dlg_it_cols[n][j][2]!='')
				s[i+1]+='<td class=\"t'+dlg_it_cols[n][j][2]+(i%2 ? '1' : '2')+'\">'+dlg_it_data[n][i][j][0]+'</td>';
			else {
				if(dlg_it_data[n][i][j].length>0) {
					if(dlg_it_data[n][i][j][0]=='') {
						var itype=dlg_it_data[n][i][j][1];
						if(itype=='c')
							s[i+1]+='<td class=\"tc'+(i%2 ? '1' : '2')+'\"><input type=\"checkbox\" name=\"'+dlg_it_data[n][i][j][2]+'\"'+(dlg_it_data[n][i][j][3]>0 ? ' checked' : '')+' value=\"'+(dlg_it_data[n][i][j].length>4 ? dlg_it_data[n][i][j][4] : '1')+'\" onclick=\"dlg_itable_checkbox('+n+','+i+','+j+');\"></td>';
					}
					else
						s[i+1]+='<td class=\"tc'+(i%2 ? '1' : '2')+'\"><table cellpadding=0 cellspacing=0 style="display:inline;"><tr><td><img src="'+doc_root+'di/sbtn1.gif"></td><td class="sbtn"><a '+(dlg_it_data[n][i][j].length>3 ? 'onclick=\"'+dlg_it_data[n][i][j][3]+'\" ' : '')+((dlg_it_data[n][i][j].length>2 && dlg_it_data[n][i][j][2]!='') ? 'target=\"'+dlg_it_data[n][i][j][2]+'\" ' : '')+'href=\"'+dlg_it_data[n][i][j][1]+'\" >'+dlg_it_data[n][i][j][0]+'</a></td><td><img src="'+doc_root+'di/sbtn3.gif"></td></tr></table></td>';
				}
				else
					s[i+1]+='<td class=\"tc'+(i%2 ? '1' : '2')+'\">&nbsp;</td>';
			}
		s[i+1]+='</tr>';
	}
	s[i+1]='</table><table class="tclose" cellspacing=0 cellpadding=0 style="width:<? echo($width) ?>%;" align="center"><tr><td><img src="'+doc_root+'di/tclose1.gif" width=4 height=5></td><td width="100%"></td><td><img src="'+doc_root+'di/tclose2.gif" width=4 height=5></td></tr></table>';
	document.getElementById('dlg_itable_'+n).innerHTML=s.join('');
}

function dlg_itable_sort(n,s)
{
	dlg_it_sort[n]=s;
	dlg_itable_fill(n);
}

function dlg_tab_sel(i,n,t,v,f,frm,frmid,foc)
{
	var j;
	for(j=0; j<n; j++) {
		document.getElementById('dlgtab_l'+t+'_'+j).className='tab_l'+(i==j ? 's' : '');
		document.getElementById('dlgtab_r'+t+'_'+j).className='tab_r'+(i==j ? 's' : '');
		document.getElementById('dlgtab_'+t+'_'+j).className='tab'+(i==j ? 's' : '');
		document.getElementById('dlgtabbody_'+t+'_'+j).style.display=(i==j ? 'inline' : 'none');
	}
	document.forms[frm][f].value=v;
	if(foc.length>0)
		document.forms[frm][foc].focus();
	if(frmid.length>0)
		window.parent.document.getElementById(frmid).style.height=document.body.scrollHeight+5;
}

function dlg_quote(s)
{
	var i;
	var r='';
	for(i=0; i<s.length; i++) {
		var c=s.charAt(i);
		if(c=='&')
			r+='&amp;';
		else if(c=='<')
			r+='&lt;';
		else if(c=='>')
			r+='&gt;';
		else if(c=='"')
			r+='&quot;';
		else
			r+=c;
	}
	return r;
}

function dlg_winopen(t,w,h,u,m,c)
{
	u=dlg_url(u);
	if(typeof(m)=='undefined')
		m=true;
	if(typeof(c)=='undefined')
		c=m;
	var e=document.createElement('div');
	e.setAttribute('id','dlg_win_div_'+dlg_win_num);
	var s='';
	if(m) {
		s='<img src="'+doc_root+'di/bl.gif" onclick="dlg_winfocus('+dlg_win_num+');" style="z-index:'+dlg_zorder+';position:absolute;left:0px;top:0px;width:'+document.body.scrollWidth+'px;height:'+document.body.scrollHeight+'px;"></div>';
		dlg_zorder++;
	}
	var mx=document.body.scrollLeft;
	var my=document.body.scrollTop;
	var cx=document.body.clientWidth;
	var cy=document.body.clientHeight;
	if(typeof(w)=='boolean' && w)
		w=cx-10;
	if(typeof(h)=='boolean' && h)
		h=cy-10;
	var x=dlg_mousex;
	var y=dlg_mousey;
	if(c) {
		x=Math.floor(cx/2-w/2)+mx;
		y=Math.floor(cy/2-h/2)+my;
		if(y<0)y=0;
	}
	else {
		if(x+w>mx+cx)
			x=mx+cx-w;
		if(y+h>my+cy)
			y=my+cy-h;
		if(x<mx)
			x=mx;
		if(y<my)
			y=my;
	}
	s+='<table class="wit" style="z-index:'+dlg_zorder+';position:absolute;left:'+x+'px;top:'+y+'px;width:'+w+'px;height:'+h+'px;" id="dlg_win_'+dlg_win_num+'" border=0 cellspacing=0 cellpadding=0><tr><td width="100%" colspan=2><table cellspacing=0 cellpadding=0 width="100%"><tr><td><img src="'+doc_root+'di/wix2.png" width=14 height=24 alt=""></td><td onmousedown="dlg_windrag('+dlg_win_num+');" onmouseup="dlg_windrop('+dlg_win_num+');" ondblclick="dlg_winmax('+dlg_win_num+');" class="wic" nowrap width="100%">'+dlg_quote(t)+'</td><td><a href="javascript:dlg_winmax('+dlg_win_num+');void(0);"><img src="'+doc_root+'di/wixup.png" width=29 height=24 alt=""></a></td><td><a href="javascript:dlg_winclose('+dlg_win_num+');void(0);"><img src="'+doc_root+'di/wixx.png" width=28 height=24 alt=""></a></td><td><img src="'+doc_root+'di/wix1.png" width=23 height=24 alt=""></td></tr></table></td></tr><tr><td height="100%" class="wii"><iframe id="dlg_wini_'+dlg_win_num+'" name="'+dlg_win_num+'" width="100%" height="100%" src="'+u+'" frameborder=0 scrolling="auto"></iframe></td><td class="wii2" nowrap><div style="width:7px;"></div></td></tr><tr><td colspan=2><table cellspacing=0 cellpadding=0 width="100%"><tr><td><img src="'+doc_root+'di/wixf1.png" width=140 height=12 alt=""></td><td class="wixf"></td><td><img src="'+doc_root+'di/wixf2.png" width=13 height=12 alt=""></td></tr></table></td></tr></table><div id="dlg_win_div_'+(dlg_win_num+1)+'"></div>';
	e.innerHTML=s;
	document.getElementById('dlg_win').appendChild(e);
	dlg_win_max[dlg_win_num]=false;
	dlg_zorder++;
	dlg_win_num++;





}

function dlg_winfocus(i)
{
	var mx=document.body.scrollLeft;
	var my=document.body.scrollTop;
	var cx=document.body.clientWidth;
	var cy=document.body.clientHeight;
	var e=document.getElementById('dlg_win_'+i);
	var wx=parseInt(e.style.left);
	var wy=parseInt(e.style.top);
	var ww=parseInt(e.style.width);
	var wh=parseInt(e.style.height);
	if(wx+ww>mx+cx)
		document.body.scrollLeft=wx-(cx-ww);
	if(wx<mx)
		document.body.scrollLeft=wx;
	if(wy+wh>my+cy)
		document.body.scrollTop=wy-(cy-wh);
	if(wy<my)
		document.body.scrollTop=wy;
	var bcol=e.style.borderColor;
	if(bcol=='') {
		e.style.borderColor='#ff0000';
		setTimeout('dlg_winborder('+i+',"'+bcol+'");',200);
	}
}

function dlg_winborder(i,col)
{
	var e=document.getElementById('dlg_win_'+i);
	if(e)
		e.style.borderColor=col;
}

function dlg_winmax(i)
{
	var e=document.getElementById('dlg_win_'+i).style;
	if(dlg_win_max[i]==false) {
		dlg_win_max[i]=new Array(parseInt(e.left),parseInt(e.top),parseInt(e.width),parseInt(e.height));
		e.left=document.body.scrollLeft+5;
		e.top=document.body.scrollTop+5;
		e.width=document.body.clientWidth-10;
		e.height=document.body.clientHeight-10;
	}
	else {
		e.left=dlg_win_max[i][0]+'px';
		e.top=dlg_win_max[i][1]+'px';
		e.width=dlg_win_max[i][2];
		e.height=dlg_win_max[i][3];
		dlg_win_max[i]=false;
	}
}

function dlg_winclose(i,a)
{
	if(typeof(a)=='undefined')
		a=true;
	if(a) {
		var e=document.getElementById('dlg_wini_'+i);
		if(typeof(e.contentWindow.dlg_onwinclose)=='function')
			if(!e.contentWindow.dlg_onwinclose())
				return false;
	}
	var j;
	var e=document.getElementById('dlg_win');
	for(j=0; j<e.childNodes.length; j++)
		if(e.childNodes[j].id=='dlg_win_div_'+i) {
			e.removeChild(e.childNodes[j]);
			break;
		}
	return true;
}

function dlg_winselfclose()
{
	window.parent.dlg_winclose(window.name,false);
}

function dlg_windrag(e)
{
	if(dlg_win_max[e]==false) {
		dlg_dragid='dlg_win_'+e;
		document.getElementById('dlg_wini_'+e).style.visibility='hidden';
		var el=document.getElementById(dlg_dragid);
		dlg_dragx=dlg_mousex;
		dlg_dragy=dlg_mousey;
		dlg_dragged=true;
		dlg_winx=parseInt(el.style.left);
		dlg_winy=parseInt(el.style.top);
		if(el.style.zIndex!=dlg_zorder) {
			el.style.zIndex=dlg_zorder+1;
			dlg_zorder++;
		}
	}
}

function dlg_windrop(e)
{
	dlg_dragged=false;
	document.getElementById('dlg_wini_'+e).style.visibility='visible';
}

function dlg_url(u)
{
	if(typeof(u)=='object') {
		var s=u[0];
		if(typeof(u[1])=='object') {
			var k;
			var sp='?';
			for (k in u[1]) {
				s+=sp+encodeURIComponent(k)+'='+encodeURIComponent(u[1][k]);
				sp='&';
			}
		}
		if(typeof(u[2])!='undefined')
			s+='#'+u[2];
		return s;
	}
	return u;
}


function dlg_get(u,cb,cbp)
{
	return dlg_xmlhttprequest(u,'GET','','',cb,cbp);
}


function dlg_xmlhttprequest(u,m,d,c,cb,cbp)
{
	u=dlg_url(u);
	var r=false;
    if(window.XMLHttpRequest) {
    	try {
			r=new XMLHttpRequest();
        }
		catch(e) {
			r=false;
        }
    }
	else if(window.ActiveXObject) {
       	try {
        	r=new ActiveXObject("Msxml2.XMLHTTP");
      	}
		catch(e) {
        	try {
          		r=new ActiveXObject("Microsoft.XMLHTTP");
        	}
			catch(e) {
          		r=false;
        	}
		}
    }

	if(r) {
		r.onreadystatechange=function() {
			if(r.readyState==4) {
				if(r.status==200)
					cb(r.responseText,cbp);
			}
		};
		r.open(m,u);
		if(c!='')
			r.setRequestHeader('Content-Type',c);
		r.send(d);
		return true;
	}
	return false;
}

function dlg_showhint(t)
{
	var e=document.getElementById('dlg_hint');
	e.innerHTML=t;
	e.style.top=dlg_mousey;
	e.style.left=dlg_mousex;
	e.style.display='block';
}

function dlg_hidehint()
{
	var e=document.getElementById('dlg_hint');
	if(e)
		e.style.display='none'
}

function dlg_dtable_init()
{
	var i=0;
	var e;
	while(e=document.getElementById('dlg_dt_'+i)) {
		if(e.getAttribute('dlg_load')>0)
			dlg_dtpage(i,0);
		i++;
	}
}

function dlg_dturl(n,u)
{
	var e=document.getElementById('dlg_dt_'+n);
	var ou=e.getAttribute('dlg_url');
	if(typeof(u)!='undefined')
		e.setAttribute('dlg_url',dlg_url(u));
	return ou;
}

function dlg_dtpage(n,p,s,sd)
{
	var e=document.getElementById('dlg_dt_'+n);
	var p=typeof(p)=='undefined' ? e.getAttribute('dlg_page') : p;
	var s=typeof(s)=='undefined' ? e.getAttribute('dlg_sort') : s;
	var sd=typeof(sd)=='undefined' ? e.getAttribute('dlg_sortdir') : sd;
	e.style.cursor='wait';
	dlg_xmlhttprequest(e.getAttribute('dlg_url'),'POST','dlg_dtnum='+n+'&dlg_dtpage='+p+'&dlg_dtsort='+encodeURIComponent(s)+'&dlg_dtsortdir='+encodeURIComponent(sd),'application/x-www-form-urlencoded',function(c) {
		e.innerHTML=c;
		e.style.cursor='';
		e.setAttribute('dlg_page',p);
		e.setAttribute('dlg_sort',s);
		e.setAttribute('dlg_sortdir',sd);
	});
}

function dlg_show_menu_pos(pos) {
	var item = document.getElementById(pos);
	if (item.style.display=='none')
		item.style.display='inline';
	else
		item.style.display='none';
}
