//  Copyright (C) 2005-2006  Xenno Group group.xennobb.com.
//  Visit XennoBB at www.xennobb.com.
//
//  XennoBB is free software; you can redistribute it and/or modify it
//  under the terms of the GNU General Public License as published
//  by the Free Software Foundation; either version 2 of the License,
//  or (at your option) any later version.
//
//  XennoBB is distributed in the hope that it will be useful, but
//  WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//  MA 02110-1301 USA
var var_cookieid = "";
var var_cookie_domain = "";
var var_cookie_path   = "/";
function xBB_Get_Cookie(name)
{
	cname = 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 xBB_Set_Cookie(name, value, sticky)
{
	expire = "";
	domain = "";
	path   = "/";
	if (sticky)
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}
	if (var_cookie_domain != "")
	{
		domain = '; domain=' + var_cookie_domain;
	}
	if (var_cookie_path != "")
	{
		path = var_cookie_path;
	}
	document.cookie = var_cookieid + name + "=" + value + "; path = " + path + expire + domain + ';';
}
function xBB_Get_By_ID(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;
}
function xBB_Hide_Div(itm)
{
	if (!itm) return;
	itm.style.display = "none";
}
function xBB_Show_Div(itm)
{
	if (!itm) return;
	itm.style.display = "";
}
function xBB_Toggle_Category(fid, add)
{
	saved = new Array();
	clean = new Array();
	if (tmp = xBB_Get_Cookie('collapseprefs'))
	{
		saved = tmp.split(",");
	}
	for(i = 0 ; i < saved.length; i++)
	{
		if (saved[i] != fid && saved[i] != "")
		{
			clean[clean.length] = saved[i];
		}
	}
	if (add)
	{
		clean[ clean.length ] = fid;
		xBB_Show_Div(xBB_Get_By_ID('ido'+fid));
		xBB_Hide_Div(xBB_Get_By_ID('idx'+fid));
	}
	else
	{
		xBB_Show_Div(xBB_Get_By_ID( 'idx'+fid));
		xBB_Hide_Div(xBB_Get_By_ID( 'ido'+fid));
	}
	xBB_Set_Cookie('collapseprefs', clean.join(','), 1);
}
var ie  = document.all  ? 1 : 0;
var ns4 = document.layers ? 1 : 0;
function SelectCbox(cb)
{
	if (ie)
	{
		while (cb.tagName != "TR")
		{
			cb = cb.parentElement;
		}
	}
	else
	{
		while (cb.tagName != "TD")
		{
			cb = cb.parentNode;
		}
	}
	cb.className = 'tcmod_sel';
}
function cca(cb)
{
	if (cb.checked)
	{
		SelectCbox(cb);
	}
	else
	{
		DeselectCbox(cb);
	}
}
function DeselectCbox(cb)
{
	if (ie)
	{
		while (cb.tagName != "TR")
		{
			cb = cb.parentElement;
		}
	}
	else
	{
		while (cb.tagName != "TD")
		{
			cb = cb.parentNode;
		}
	}
	cb.className = 'tcmod';
}
function InboxCheckAll(cb)
{
	var fmobj = document.multiselect;
	for (var i=0;i<fmobj.elements.length;i++)
	{
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled))
		{
			e.checked = fmobj.allbox.checked;
			if (fmobj.allbox.checked)
			{
				SelectCbox(e);
			}
			else
			{
				DeselectCbox(e);
			}
		}
	}
}
function xBB_Mail_To(s)
{
	var n = 0;
	var r = "";
	for (var i = 0; i < s.length; i++)
	{
		n = s.charCodeAt(i);
		if (n>= 8364) n = 128;
		r += String.fromCharCode(n-(2));
	}
	location.href = "mailto:"+r;
}
function OpenWindow(url,w,h)
{
	window.open(url,"Admin Control Panel","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width="+w+", height="+h);
}
function Expand_QP(e, v)
{
	rows_val = parseFloat(document.getElementById(e).getAttribute('rows'));
	if (rows_val < v) { rows_val = rows_val + 5 }
	document.getElementById(e).setAttribute('rows', rows_val);
}
function Collapse_QP(e, v)
{
	rows_val = parseFloat(document.getElementById(e).getAttribute('rows'));
	if (rows_val > v) { rows_val = rows_val - 5 } 
	document.getElementById(e).setAttribute('rows', rows_val);
}
