/*======================================================================*\
|| #################################################################### ||
|| #  				  Imperial Bulletin Board v1.x                    # ||
|| # ---------------------------------------------------------------- # ||
|| #  For license, version and changelog questions or concerns,       # ||
|| #  navigate to the docs/ folder or visit the forums at the		  # ||
|| #  website, http://www.imperialbb.com/forums. with your questions. # ||
|| # ---------------------------------------------------------------- # ||
|| # Name: js_toggle.js                                               # ||
|| # ---------------------------------------------------------------- # ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) 
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
	var name = ( ( cookie_prefix != null ) ? cookie_prefix+name : name );
	var arg = name+"=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
    {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value)
{
	var name = ( ( cookie_prefix != null ) ? cookie_prefix+name : name );
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = ( argc > 2 ) ? argv[2] : null;
	var path 	= ( cookie_path ) ? cookie_path : null;
	var domain 	= ( cookie_domain ) ? cookie_domain : null;
	var secure 	= ( cookie_secure ) ? cookie_secure : false;
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) + 
	((domain == null) ? "" : ("; domain=" + domain)) + 
	((secure == true) ? "; secure" : "");
}

function collapseforum(id)
{
	div1 = IBB.general.fetch_obj ( 'cat_v'+id ).style;
	div2 = IBB.general.fetch_obj ( 'cat_h'+id ).style;
	div1.display = div1.display == "none"? "block":"none";
	div2.display = div2.display == "block"? "none":"block";
	pathname = location.pathname;
	myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var largeExpDate = new Date ();
	largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));
	SetCookie('cat'+id,div1.display,largeExpDate,myDomain);
}

function update_display(id, show)
{
	div1 = IBB.general.fetch_obj ( 'cat_v'+id ).style;
	div2 = IBB.general.fetch_obj ( 'cat_h'+id ).style;
	if(show)
    {
		div1.display = "block";
		div2.display = "none";
	}
    else
    {
		div1.display = "none";
		div2.display = "block";
	}
}

function update_toggle ( name )
{
	if ( GetCookie ( 'cat'+name ) == 'block' || GetCookie ( 'cat'+name ) == null )
	{
		update_display ( name, true );
	}
	else
	{
		update_display ( name, false );
	}
}

function usercp_toggle ( id )
{
	gallery_avatar = IBB.general.fetch_obj ( 'gallery_avatar' );
	upload_avatar = IBB.general.fetch_obj ( 'upload_avatar' );
	remote_avatar = IBB.general.fetch_obj ( 'remote_avatar' );
	gallery_avatar.style.display = 'none';
	upload_avatar.style.display = 'none';
	remote_avatar.style.display = 'none';
	if ( id == "gallery_avatar" )
	{
		gallery_avatar.style.display = 'block';
	}
	else if ( id == "upload_avatar" )
	{
		upload_avatar.style.display = 'block';
	}
	else if ( id == "remote_avatar" )
	{
		remote_avatar.style.display = 'block';
	}
}

/*======================================================================*\
|| #################################################################### ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| #################################################################### ||
\*======================================================================*/