//var children = new Array();

function close_children() {
	for (var j=0; j<children.length; j++) {
		if (children[j] != null && !(children[j].closed)) { children[j].close(); children[j] = null; }
	}
	children = null;
	children = new Array();
}
function XY (o) { this.x = 0; this.y = 0;
	while (o != null) {
		this.x += o.offsetLeft; this.y += o.offsetTop; 
		o = o.offsetParent;
	}
}
function set_line_vert (i0_name, i1_name, ivert_name, ivert_s_name, line_weight) {
	var i0 = document.images[i0_name];
	var i1 = document.images[i1_name];
	var ivert = document.images[ivert_name];
	var ivert_s = document.images[ivert_s_name];
//alert('i0='+i0+'; i1='+i1+'; ivert='+ivert+'; ivert_s='+ivert_s);
	if (ivert_s != null && ivert != null && i0 != null && i1 != null) {
		var iact0_XY = new XY(i0);
		var top0 = iact0_XY.y + Math.round((i0.height-line_weight)/2);
		var iact1_XY = new XY(i1);
		var top1 = iact1_XY.y + Math.round((i1.height-line_weight)/2);
		ivert_s.height = Math.min(top0, top1);
		ivert.height = Math.abs(top0 - top1) + line_weight;
	}
}

function login(topic, uri, openfile, lang) {
	if (openfile == null) { openfile = 0; }
	var left = 0;
	var top = 0;
	var width = 860;
	var height = 700;
	var scrollable = 'yes';
	var url = '/login/index.dcc?lang=' + lang + '&topic=' + topic + '&uri=' + escape(uri);
	if (openfile != 0) { url = url + '&openfile=' + openfile; }
	children[children.length] = window.open (url, "login",  "top="+top+",left="+left+",width="+width+",height="+height+",toolbar=no,menubar=no,address=no,scrollbars="+scrollable+",resizable=yes");
}

function goto_url(url) {
	document.location=url;
}

/*
function img_resize() {
alert(children[children.length-1].document.images.length);
//alert(children.length-1);
}
*/

function popup(topic, params, left, top, width, height, scrollable, lang, status) {
	close_children();
	if (left == null) left = 0;
	if (top == null) top = 0;
	if (width == null) width = 700;
	if (height == null) height = 500;
	if (scrollable == null) { scrollable = 'no'; } else { scrollable = 'yes'; }
	if (status == null) { status = 'no'; } else { status = 'yes'; }
	var url = '/popup.dcc?lang=' + lang + '&topic=' + topic;
	if (params != null && params.length > 0) url += '&' + params;
	children[children.length] = window.open (url, "popup",  "top="+top+",left="+left+",width="+width+",height="+height+",toolbar=no,menubar=no,address=no,scrollbars="+scrollable+",resizable=yes,status="+status);
	var lastInd = children.length-1;
//	if (children[lastInd] != null) { children[lastInd].statusbar.visible = false } // && children[lastInd].statusbar != null && status == 'no'
	if (children[lastInd] != null) {
//alert(children[lastInd].document.images.length);
//		children[lastInd].document.onclick = img_resize;
		children[lastInd].focus();
	}
}


function change_param(o) {
	for(var j=0; j<document.anchors.length; j++) {
		if (document.anchors[j].id == 'aLetters') {
			var ipos = document.anchors[j].href.indexOf('&'+o.name+'=');
			if (ipos > 0) {
				var lstr = document.anchors[j].href.substr(0, ipos);
				ipos++;
				var rstr = document.anchors[j].href.substr(ipos);
				ipos = rstr.indexOf('&');
				if (ipos >= 0)
					rstr = rstr.substr(ipos);
				else
					rstr = '';
				document.anchors[j].href = lstr + '&' + o.name + '='+o.options[o.selectedIndex].value + rstr;
			}
			else {
				document.anchors[j].href = document.anchors[j].href + '&' + o.name + '='+o.options[o.selectedIndex].value;
			}
		}
	}
}

function trim(txt) {
	while(txt.substr(txt.length-1,1) == ' ') {
		txt = txt.substr(0,txt.length-1);
	}
	while(txt.substr(0,1) == ' ') {
		txt = txt.substr(1,txt.length-1);
	}
	return txt;
}

