// Collapse/Expand Categories
// IPB2 funcs
// modified by Nick Pavlov

var ipb_var_cookieid = "";
var ipb_var_cookie_domain = "";
var ipb_var_cookie_path   = "/";

function togglecat(id)
{
	if (tmp = my_getcookie('collapseprefs') )
	{
		var saved = new Array();
		var newprefs = new Array();
		var flag = 0;
		saved = tmp.split(",");
		for(var i=0; i<saved.length; i++)
		{
			if(saved[i]==id)
			{
				my_show(my_getbyid("cat_"+id));
				my_src(my_getbyid("img_"+id), "minus");
				flag = 1;
			}
			else
			{
				newprefs[newprefs.length] = saved[i];
			}
		}
		if(flag != 1)
		{
			my_hide(my_getbyid("cat_"+id));
			my_src(my_getbyid("img_"+id), "plus");
			newprefs[newprefs.length] = id;
		}
		my_setcookie('collapseprefs', newprefs.join(','), 1);
	}
	else
	{
		my_hide(my_getbyid("cat_"+id));
		my_src(my_getbyid("img_"+id), "plus");
		my_setcookie('collapseprefs', id, 1);
	}
}

function apply_toggle_prefs(id)
{
	var tmp;
	if (tmp = my_getcookie('collapseprefs') )
	{
		var saved = new Array();
		saved = tmp.split(",");
		for(var i=0; i<saved.length; i++)
			if(saved[i]==id)
			{
				my_hide(my_getbyid("cat_"+id));
				my_src(my_getbyid("img_"+id), "plus");
				return;
			}
	}
}

function my_getcookie(name)
{
	cname = ipb_var_cookieid + name + '=';
	cpos  = document.cookie.indexOf( cname );
	if ( cpos != -1 )
	{
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);
		if (cend == -1)
		{
			cend = document.cookie.length;
		}
		return unescape( document.cookie.substring(cstart, cend) );
	}
	return null;
}

function my_setcookie(name, value, sticky)
{
	expire = "";
	domain = "";
	path   = "/";
	if ( sticky )
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}
	if ( ipb_var_cookie_domain != "" )
	{
		domain = '; domain=' + ipb_var_cookie_domain;
	}
	if ( ipb_var_cookie_path != "" )
	{
		path = ipb_var_cookie_path;
	}
	document.cookie = ipb_var_cookieid + name + "=" + value + "; path=" + path + expire + domain + ';';
}

function my_hide(itm)
{
	if (itm) itm.style.display = "none";
}

function my_show(itm)
{
	if (itm) itm.style.display = "";
}

function my_src(itm, what)
{
	if (itm) itm.src = "style_images/IPB_%28Bul-465/exp_"+what+".gif";
}

function my_getbyid(id)
{
	itm = null;
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	return itm;
}