﻿// string functions
function Left(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0, n);
}
function Right(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
	{
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

// cookie functions
function set_cookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function get_cookie(name)
{
	var name_eq = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(name_eq) == 0) return c.substring(name_eq.length, c.length);
	}
	return null;
}

// Text Resize function
function resizeText(inc)
{
	var currentFontSize;

	if (get_cookie("currentFontSize") != null)
	{ currentFontSize = parseFloat(get_cookie("currentFontSize")); }
	else { currentFontSize = 8; }

	currentFontSize = currentFontSize + inc;
	if (currentFontSize >= 12) { currentFontSize = 12; }
	if (currentFontSize <= 6) { currentFontSize = 6; }

	document.body.style.fontSize = currentFontSize + "pt";
	set_cookie('currentFontSize', currentFontSize, '90');
}

function BlockStatChange(o)
{
	object = o.parentNode.parentNode.parentNode.childNodes;
	for (i = 0; i < object.length; i++)
	{
		if (object[i].className == 'sh_Contents')
		{
			if (object[i].style.display == 'none')
			{
				object[i].style.display = 'table-row';
				o.className = 'sh_CBSB sh_CBSBMin';
			} else
			{
				object[i].style.display = 'none';
				o.className = 'sh_CBSB sh_CBSBPlus';
			}
			return true;
		}
	}
}
function BlockStatChange2(o) // o = title td
{
	// oo = find minplus node
	object = o.childNodes; // object2 = all node in title
	var oo;
	for (i = 0; i < object.length; i++)
	{
		if (object[i].id == 'minplus')
			{ oo = object[i]; }
	}

	object = o.parentNode.parentNode.childNodes; // object = all tr in table

	for (i = 0; i < object.length; i++)
	{
		if (object[i].className == 'sh_Contents') // find middle table from all
		{
			if (object[i].style.display == 'none')
			{
				object[i].style.display = 'table-row';
				oo.className = 'sh_CBSB sh_CBSBMin';
			} else
			{
				object[i].style.display = 'none';
				oo.className = 'sh_CBSB sh_CBSBPlus';
			}
			return true;
		}
	}
}
