//  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
function xBB_Ajax_Update(params, paramname, position)
{
	var target = '/include/functions/Ajax/UpdatePos.php';
	var _params = 'action=ajaxupdate&position='+position +'&paramname='+paramname+'&' + params;
//	alert("ajax:\n"+target+'\n'+_params);
	var myAjax = new Ajax.Request(target, {method: 'get', parameters: _params});
}
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 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);
}
// BEGIN Christian denominations and religions MOD by xapis
function checkDenominationSelect(DenomSelectBox, selDenom)
{
	if (selDenom == 1)
	{
		while (DenomSelectBox.options.length > 0) 
		{
			DenomSelectBox.options[0] = null;
		}
		setDenomOptionText(DenomSelectBox, selKNOWCHRIST);
	}
	else
	{
		while (DenomSelectBox.options.length > 0) 
		{
			DenomSelectBox.options[0] = null;
		}
		setDenomOptionText(DenomSelectBox, selNOCHRIST);
	}
}
function setDenomOptionText(DenomSelectBox, dsel_array)
{
  for (var z = 0; z < dsel_array.length; z++)
  {
		DenomSelectBox.options[z] = new Option(dsel_array[z], dsel_array[z]);
  }
  DenomSelectBox.selectedIndex = 0;
  document.denomination.src = './img/general/denominations/' + DenomSelectBox.value + '.png';
}
function activeChurchText(churchText, christianyn)
{
	if (christianyn == 1)
	{
		churchText.disabled = false;
	}
	else
	{
		churchText.disabled = true;
		churchText.value = "";
	}
}
// END MOD by xapis
// BEGIN STATES MOD by xapis
function checkStateSelect(selectBox, selCountry)
{
	if (selCountry != "United States" && selCountry != "Canada" && selCountry != "United Kingdom" && selCountry != "Australia" && selCountry != "Germany" && selCountry != "Netherlands" && selCountry != "France" && selCountry != "Italy" && selCountry != "Spain" && selCountry != "Belgium" && selCountry != "Poland" && selCountry != "Switzerland" && selCountry != "Austria" && selCountry != "Brazil" && selCountry != "Czech Republic" && selCountry != "Slovakia" && selCountry != "Russia" && selCountry != "Ukraine" && selCountry != "Belarus" && selCountry != "Estonia" && selCountry != "Croatia" && selCountry != "Malaysia")
	{
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		selectBox.options[0] = new Option("--", "--", true, true);
		document.statesetc_flag.src = './img/general/flags/statesetc/' + selectBox.value + '.png';
	}
	else if (selCountry == "United States")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selUS);
	}
	else if (selCountry == "Canada")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selCA);
	}
	else if (selCountry == "United Kingdom")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selUK);
	}
	else if (selCountry == "Australia")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selAU);
	}
	else if (selCountry == "Germany")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selDE);
	}
	else if (selCountry == "Netherlands")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selNL);
	}
	else if (selCountry == "France")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selFR);
	}
	else if (selCountry == "Italy")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selIT);
	}
	else if (selCountry == "Spain")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selES);
	}
	else if (selCountry == "Belgium")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selBE);
	}
	else if (selCountry == "Poland")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selPL);
	}
	else if (selCountry == "Switzerland")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selCH);
	}
	else if (selCountry == "Austria")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selAT);
	}
	else if (selCountry == "Brazil")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selBR);
	}
	else if (selCountry == "Czech Republic")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selCZ);
	}
	else if (selCountry == "Slovakia")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selSK);
	}
	else if (selCountry == "Russia")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selRU);
	}
	else if (selCountry == "Ukraine")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selUA);
	}
	else if (selCountry == "Belarus")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selBY);
	}
	else if (selCountry == "Estonia")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selEE);
	}
	else if (selCountry == "Croatia")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selHR);
	}
	else if (selCountry == "Malaysia")
	{
		selectBox.disabled = false;
		while (selectBox.options.length > 0) 
		{
			selectBox.options[0] = null;
		}
		setOptionText(selectBox, selMY);
	}
}
function setOptionText(selectBox, sel_array)
{
  for (var i = 0; i < sel_array.length; i++)
  {
		selectBox.options[i] = new Option(sel_array[i], sel_array[i]);
  }
  selectBox.selectedIndex = 0;
  document.statesetc_flag.src = './img/general/flags/statesetc/' + selectBox.value + '.png';
}
// END MOD by xapis