var PreloadFlag = false;
var expDays = 90;
var exp = new Date();
var tmp = '';
var tmp_counter = 0;
var tmp_open = 0;

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function SetCookie(name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

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 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;
}

/**
* Jump to page
*/
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
function jumpto() {
	var page = prompt(jump_page, on_page);

	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
		var seo_page = (page - 1) * per_page;
		var anchor = '';
		var anchor_parts = base_url.split('#');
		if ( anchor_parts[1] ) {
			base_url = anchor_parts[0];
			anchor = '#' + anchor_parts[1];
		}
		if ( seo_page > 0 ) {
			var phpEXtest = false;
			if ( base_url.indexOf('?') >= 0 || ( phpEXtest = base_url.match(/\.php$/i))) {
				document.location.href = base_url.replace(/&amp;/g, '&') + (phpEXtest ? '?' : '&') + 'start=' + seo_page + anchor;
			} else {
				var ext = base_url.match(/\.[a-z0-9]+$/i);
				if (ext) {
					// location.ext => location-xx.ext
					document.location.href = base_url.replace(/\.[a-z0-9]+$/i, '') + seo_delim_start + seo_page + ext + anchor;
				} else {
					// location and location/ to location/pagexx.html
					var slash = base_url.match(/\/$/) ? '' : '/';
					document.location.href = base_url + slash + seo_static_pagination + seo_page + seo_ext_pagination + anchor;
				}
			}
		} else {
			document.location.href = base_url + anchor;
		}
	}
}
// Open external links in new window in a XHTML 1.x compliant way.
/**
*  phpbb_seo_href()
*  Fixes href="#something" links with virtual directories
*  Optionally open external or marked with a css class links in a new window
*  in a XHTML 1.x compliant way.
*/
function phpbb_seo_href() {
	var current_domain = document.domain.toLowerCase();
	if (!current_domain || !document.getElementsByTagName) return;
	if (seo_external_sub && current_domain.indexOf('.') >= 0) {
		current_domain = current_domain.replace(new RegExp(/^[a-z0-9_-]+\.([a-z0-9_-]+\.([a-z]{2,6}|[a-z]{2,3}\.[a-z]{2,3}))$/i), '$1');
	}
	if (seo_ext_classes) {
		var extclass = new RegExp("(^|\s)(" + seo_ext_classes + ")(\s|$)");
	}
	if (seo_hashfix) {
		var basehref = document.getElementsByTagName('base')[0];
		if (basehref) {
			basehref = basehref.href;
			var hashtest = new RegExp("^(" + basehref + "|)#[a-z0-9_-]+$");
			var current_href = document.location.href.replace(/#[a-z0-9_-]+$/i, "");
		} else {
			seo_hashfix = false;
		}
	}
	var hrefels = document.getElementsByTagName("a");
	var hrefelslen = hrefels.length;
	for (var i = 0; i < hrefelslen; i++) {
		var el = hrefels[i];
		var hrefinner = el.innerHTML.toLowerCase();
		if (el.onclick || (el.href == '') || (el.href.indexOf('javascript') >=0 ) || (el.href.indexOf('mailto') >=0 ) || (hrefinner.indexOf('<a') >= 0) ) {
			continue;
		}
		if (seo_hashfix && el.hash && hashtest.test(el.href)) {
			el.href = current_href + el.hash;
		}
		if (seo_external) {
			if ((el.href.indexOf(current_domain) >= 0) && !(seo_ext_classes && extclass.test(el.className))) {
				continue;
			}
			el.onclick = function () { window.open(this.href); return false; };
		}
	}
}
if (seo_external || seo_hashfix) {
	onload_functions.push('phpbb_seo_href()');
}
// www.phpBB-SEO.com SEO TOOLKIT END

function ShowHide(id1, id2, id3)
{
	var res = expMenu(id1);
	if (id2 != '')
	{
		expMenu(id2);
	}
	if (id3 != '')
	{
		SetCookie(id3, res, exp);
	}
}

function expMenu(id)
{
	var 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];
	}
	if (!itm)
	{
		// do nothing
	}
	else if (itm.style)
	{
		if (itm.style.display == "none")
		{
			itm.style.display = "";
			return 1;
		}
		else
		{
			itm.style.display = "none";
			return 2;
		}
	}
	else
	{
		itm.visibility = "show";
		return 1;
	}
}

function showMenu(id)
{
	var 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];
	}
	if (!itm)
	{
		// do nothing
	}
	else if (itm.style)
	{
		if (itm.style.display == "none")
		{
			itm.style.display = "";
			return true;
		}
		else
		{
//			itm.style.display = "none";
			return true;
		}
	}
	else
	{
		itm.visibility = "show";
		return true;
	}
}

function hideMenu(id)
{
	var 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];
	}
	if (!itm)
	{
		// do nothing
	}
	else if (itm.style)
	{
		if (itm.style.display == "none")
		{
//			itm.style.display = "";
			return true;
		}
		else
		{
			itm.style.display = "none";
			return true;
		}
	}
	else
	{
		itm.visibility = "hide";
		return true;
	}
}

function IsIEMac()
{
	// Any better way to detect IEMac?
	var ua = String(navigator.userAgent).toLowerCase();
	if( document.all && ua.indexOf("mac") >= 0 )
	{
		return true;
	}
	return false;
}


function select_text(obj)
{
	var o = document.getElementById(obj)
	if( !o ) return;
	var r, s;
	if( document.selection && !IsIEMac() )
	{
		// Works on: IE5+
		// To be confirmed: IE4? / IEMac fails?
		r = document.body.createTextRange();
		r.moveToElementText(o);
		r.select();
	}
	else if( document.createRange && (document.getSelection || window.getSelection) )
	{
		// Works on: Netscape/Mozilla/Konqueror/Safari
		// To be confirmed: Konqueror/Safari use window.getSelection ?
		r = document.createRange();
		r.selectNodeContents(o);
		s = window.getSelection ? window.getSelection() : document.getSelection();
		s.removeAllRanges();
		s.addRange(r);
	}
}

