
//var a_info = new Array("?","&iquest;");
//var a_anno = new Array("!","&iexcl;");

//var a_info = new Array("?","&#191;");
//var a_anno = new Array("!","&#161;");

//var a_info = new Array("?",String.fromCharCode(191));
//var a_anno = new Array("!",String.fromCharCode(161));

var a_info = new Array(String.fromCharCode(191),"?");
var a_anno = new Array(String.fromCharCode(161),"!");

function set_info_anno() {
	var cookie_tsi = getCookie('tsi');
	var el_tsi = document.getElementById('tree_show_info');
	if(cookie_tsi != null) {
		var status = cookie_tsi != '0'? true:false;
		if(!status) {
			node_set_bool(el_tsi,status,a_info);
			_show_info(status);
		}
	}
	var cookie_tsa = getCookie('tsa');
	var el_tsa = document.getElementById('tree_show_anno');
	if(cookie_tsa == null) {
		cookie_tsa = '0';
	}
	if(cookie_tsa != null) {
		var status = cookie_tsa != '0'? true:false;
		if(!status) {
			node_set_bool(el_tsa,status,a_anno);
			var mode_tsa = status? 'block':'none';
			_show_anno(mode_tsa);
		}
	}
}

function toggle_node(sn,a) {
	var n = document.getElementById(sn);
	var b = node_get_bool(n,a);
	var nb = b? false:true;
	node_set_bool(n,nb,a);
	return nb;
}

function toggle_info() {
	var b = toggle_node('tree_show_info',a_info);
//	var mode = b? 'inline':'none';
	var cookie= b? '1':'0';
// alert('toggle_info='+mode+' cookie='+cookie);
	setCookie('tsi',cookie,'','/');
	return _show_info(b);
}

function toggle_anno(o) {
	var b = toggle_node('tree_show_anno',a_anno);
	var mode = b? 'block':'none';
	var cookie= b? '1':'0';
	setCookie('tsa',cookie,'','/');
	return _show_anno(mode);
}



function show_info(o) {
	var mode = o.checked? 'inline':'none';
	var cookie= o.checked? '1':'0';
	setCookie('tsi',cookie,'','/');
	return _show_info(mode);
	return true;
}

function _show_info(b) {
	var i = b? 'inline':'none';
	var c = b? 'block':'none';
	set_mode_for_class('info',i);
	set_mode_for_class('course_info',c);
	return true;
}


function show_anno(o) {
	var mode = o.checked? 'block':'none';
	var cookie= o.checked? '1':'0';
	setCookie('tsa',cookie,'','/');
	return _show_anno(mode);
}

function _show_anno(mode) {
	set_mode_for_class('descr',mode);
	return true;
}


function hide_info_anno() {
	var mode = 'none';
	set_mode_for_class('info',mode);
	set_mode_for_class('course_info',mode);
	set_mode_for_class('descr',mode);
}


function set_mode_for_class(cl,mode) {
	var classElements = new Array();
	var node = document;
	var tag = 'div';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( els[i].className ==  cl) {
			els[i].style.display = mode;
		}
	}
}


function getCookie( name ) {
	var start = document.cookie.indexOf( name + '=' );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +
			//expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function node_get_text(n)
{
	return n.firstChild.nodeValue
}

function node_set_text(n,s)
{
	n.firstChild.nodeValue = s
}

function node_get_bool(n,a)
{
	var t = node_get_text(n);
	return t == a[0]? true:false;
}

function node_set_bool(n,bl,a)
{
	var t = bl? a[0]:a[1];
	node_set_text(n,t);
}

