function set_cookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function get_cookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

function delete_cookie(name, path, domain) {
    if (getCookie(name))     {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function mytoggle(id) {
	if ($(id).style.display == 'none') {
		$(id + '_lnk').addClassName('open');
		$(id).show();
	} else {
		$(id + '_lnk').removeClassName('open');
		$(id).hide();
	}
}

function cinemascope_switch(id, nr) {
	var as = $(id).getElementsByClassName('cinemascope');
	for (var a=0; a<as.length; a++) 
		as[a].className = 'cinemascope';
	if (as[nr-1])
		as[nr-1].className = 'cinemascope active';
	var divs = $(id).getElementsByClassName('pane');
	for (var d=0; d<divs.length; d++) {
		if (d != nr-1 && divs[d].style.display != 'none') {
			divs[d].hide();
		}
	}
	divs[nr-1].show();
}
function init_cinemascope() {
	var cinemascopes = document.getElementsByClassName('cinemascope');
	for (var i=0; i<cinemascopes.length; i++) {
		if (cinemascopes[i].id)
			cinemascope_switch(cinemascopes[i].id, 1);
	}
}


function show_figure(pubid, figid, nr) {
	var w = 850;
	var h = 760;
	var l = (screen.availWidth - w) / 2;
	var t = (screen.availHeight - h) / 2;
	var figwindow = window.open('../eurorad/view_figure.php?pubid=' + pubid + '&figid=' + figid + '&nr=' + nr, 'figure', 'width=' + w + ',height=' + h + ',top=' + t + ',left=' + l + ',scrollbars=yes,dependent=yes,menubar=no,status=yes,toolbar=no');
}

function modal(w, h) {
	Control.Modal.open(false, {
		contents: '<p style="text-align:center">Loading ...</p>',
		width: w,
		height: h
	});
	var h1 = Control.Modal.getWindowHeight() + 20;
	var h2 = document.body.scrollHeight + 20;
	$('modal_overlay').style.height = new String(h1 > h2 ? h1 : h2) + 'px';
	$('modal_overlay').style.position = 'absolute';
}

function select_all(modus, name) {
	if (name == 'undefined') name = "ids[]";
	var el = document.getElementsByName(name);
	for (var i=0; i<el.length; i++) {
		if (!el[i].disabled) 
			el[i].checked = modus;
	}
}	