function nyi() { alert('Not yet implemented.'); }

function chart(url) {
	par1=document.getElementById('par_1');
	par2=document.getElementById('par_2');
	url+='&par_1='+encodeURIComponent(par1?par1.value:'')+'&par_2='+encodeURIComponent(par2?par2.value:'');
	document.location.href=url;
}

function search(url) {
	var prevfld='ZZZ';
	var sel='';
	searchtext=document.getElementById('searchtext');
	if (searchtext && searchtext.value!='') {
		sel += (sel!=''?',':'') + 's=' + searchtext.value;
	}
	tbl=document.getElementById('searchtable');
	if (tbl) {
		tags=tbl.getElementsByTagName('*');
		for (i=0; i<tags.length; i++) {
			if (tags[i].name && tags[i].name.substr(0,5)=='Srch_' && tags[i].value!='') {
				if (tags[i].name.substr(5,7)=='dat_fr_') {
					sel += (sel!=''?',':'') + 'fdf' + tags[i].name.substr(12) + '=' + tags[i].value;
				}
				else if (tags[i].name.substr(5,7)=='dat_to_') {
					sel += (sel!=''?',':'') + 'fdt' + tags[i].name.substr(12) + '=' + tags[i].value;
				}
				else if (tags[i].name.substr(5,4)=='lst_') {
					opts=tags[i].options;
					if (opts) {
						sel += (sel!=''?',':'') + 'fi' + tags[i].name.substr(9) + '=';
						for (j=0; j<opts.length; j++) {
							if (opts[j].selected) {
								sel+=opts[j].value+'/';
							}
						}
					}
					else {
						if (tags[i].checked) {
							if (tags[i].name.substr(9)!=prevfld) {
								sel += (sel!=''?',':'') + 'fi' + tags[i].name.substr(9) + '=';
							}
							sel += tags[i].value + '/';
							prevfld=tags[i].name.substr(9);
						}
					}
				}
			}
		}
	}
	url+='&Sel='+encodeURIComponent(sel);
	document.location.href=url;
}

function filter(e, url, sel) {
	if (e.srcElement) el=e.srcElement; else el=e.target;
	if (el && el.value!='') {
		sel += (sel!=''?',':'') + el.value;
	}
	url+='&Sel='+encodeURIComponent(sel);
	document.location.href=url;
}

function com(hlid, params) {
	wnd=window.open('comments.asp?hlid='+hlid+'&'+params, 'mbrainCom', 'width=300,height=400,directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=yes');
	wnd.focus();
}

function addfav(url, title) {
	if (window.external) {
		window.external.AddFavorite(url, title);
	}
}

function on_load(elnam) {
	if (document.getElementById('menu1')) {
		new ypSlideOutMenu("menu1", "down")
	}
	if (elnam) {
		el=document.getElementById(elnam);
		if (el && (document.activeElement==null || document.activeElement.tagName=='BODY')) {
			el.focus();
		}
	}
}

function loginsecure() {
	u='';
	p='';
	token='';
	if (el=document.getElementById('u_local')) u=el.value;
	if (el=document.getElementById('p_local')) p=el.value;
	if (el=document.getElementById('token')) token=el.value;
	hash=hex_md5(u+p+token);
	if (el=document.getElementById('u')) el.value=u;
	if (el=document.getElementById('hash')) el.value=hash;
	if (el=document.getElementById('loginform')) el.submit();
}

var PrStyle;
function ChStyle(obj, NwStyle, NrStyle)
{
	PrStyle = obj.className;
	obj.className = NwStyle;
	PrSelection = obj;
	return;
}

function showmedia(evt)
{
	if (!evt) evt=window.event;
	el=evt.srcElement || evt.target;
	if (!el) return (true);							// Follow the HREF link.

	curdiv=document.getElementById('MediaDiv');		// If the media frame is already displayed, remove it from view.
	if (curdiv) {
		curframe=curdiv.firstChild;
		prevsrc='';
		if (curframe) {
			prevsrc=curframe.src;
			curframe.src='';						// Must unload the IFRAME this way. Otherwise WMP leaves the video on the screen even after the IFRAME is destroyed!
		}
		curdiv.parentNode.removeChild(curdiv);
		if (prevsrc==el.href) return(false);		// If the same media was already displayed, just remove it. If the user clicked another movie, continue to display the new media.
	}

	for (div=el; div && div.tagName!='BR'; div=div.nextSibling);		// Find end of the line.
	if (!div) div=el.parentNode;										// If no BR was found, add the media div after the element that contained the A tag.

	d2=document.createElement('DIV');
	d2.id='MediaDiv';
	i2=document.createElement('IFRAME');
	i2.id='MediaFrame';
	i2.src=el.href;
	i2.frameBorder=0;
	i2.scrolling='no';
	d2.appendChild(i2);
	div.parentNode.insertBefore(d2, div.nextSibling);
//	div.insertAdjacentHTML('afterEnd', '<DIV ID="MediaDiv"><IFRAME ID="MediaFrame" SRC="'+el.href+'" FRAMEBORDER=0 SCROLLING=no></IFRAME></DIV>');

	// TODO: Check if the current headline (or the video IFRAME) got out of the view. If so, scroll the minimum possible amount to get the full headline visible.

	return (false);									// Cancel the A click because we just handled the functionality here.
}

function StartProgressBar()
{
	window.setTimeout('pbar(0)', 250);
}

function pbar(n)
{
	var div=document.getElementById('ProgBarDiv')
	if (!div) return;
	if (div.style && div.style.display=='none') return;
	
	var tds=div.getElementsByTagName('TD');
	if (tds && n<tds.length) {
		tds[n].style.backgroundColor='#879da9';
		window.setTimeout('pbar('+(n+1)+')', 500+n*100+(n>15?n*500:0));		// 1..15: 19.5 s, 16..19 more.
	}
}

function HideProgressBar()
{
	var div=document.getElementById('ProgBarDiv')
	if (div && div.style) {
		div.style.display='none';
	}
}
