function script_param(file, param)
{
	var item;
	var p = '';

	for(item in document.getElementsByTagName('script'))
	{
		with(document.getElementsByTagName('script')[item])
		{
			if(typeof src == 'string')
			{
				if(src.indexOf(file + '.js') != -1)
				{
					var q = src.split('?', 2)[1];
					var n = q.indexOf(param + '=', 0);
					var e = q.indexOf('&', n);

					p = q.substring(n + param.length + 1, (e != -1) ? e : q.length);
				}
			}
		}
	}

	return p;
}

var base = script_param('global', 'base');
var color = script_param('global', 'color');
var frame = script_param('global', 'frame');
var kase = script_param('global', 'case');
var js = script_param('global', 'js');

function $ID(id)
{
	if(!document.getElementById)
		return false;

	return document.getElementById(id) || null;
}

function show(_)
{
	var e = null;

	if(typeof _ == 'string')
	{
		e = $ID(_);
	}
	else e = _;

	if(!e)
		return;

	e.style.visibility = 'visible';
	e.style.display = arguments[1] || 'block';
}

function hide(_)
{
	var e = null;

	if(typeof _ == 'string')
	{
		e = $ID(_);
	}
	else e = _;

	if(!e)
		return;

	e.style.visibility = 'hidden';
	e.style.display = arguments[1] || 'none';
}

function change(_, content)
{
	var e = null;

	if(typeof _ == 'string')
	{
		e = $ID(_);
	}
	else e = _;

	if(!e)
		return;

	e.innerHTML = content || '';
}

function switchTo(id, cat)
{
	var cook;
	var cid = (arguments.length > 2) ? arguments[2] : '';

	switch(cat)
	{
		case 'frame':
		cook = frame;
		break;

		case 'case':
		cook = kase;
		break;

		default:
		return;
	}

	if(read_cookie(cook) != id)
	{
		create_cookie(cook, id);

		if(js == 'false')
		{
			window.location.reload();
		}
		else
		{
			if(cat == 'case' && $ID(id).innerHTML.replace(/\s*/g, '') != '')
			{
				adminCase(cid);
			}
			else
			{
				ajaxReq('index.php', {
					urlMethod: 'get',
					queryString: 'file=Admin&nude&admin=' + cat + 's&admin_' + cat + '=' + id,
					onReady: function(objReq)
					{
						if(objReq.responseText.substring(0, 2) == '<!')
						{
							window.location.reload();
						}
						else
						{
							if(cat == 'case')
							{
								$ID(id).innerHTML = objReq.responseText;
								adminCase(cid);
							}
							else
							{
								$ID(cat).innerHTML = objReq.responseText;
								adminFrame(id);
							}
						}
					}
				});
			}
		}
	}
}

try
{
	Node.prototype.siblingElement = function(direction)
	{
		var i = 0;
		var node = this || null;

		var dir   = direction.toLowerCase();
		var times = arguments[1] || 1;

		while(i < times && !!node)
		{
			node = node[dir + 'Sibling'] || null;

			if(!!node && node.nodeType == 1)
			{
				i++;
			}
		}

		return node;
	}
}
catch(e){}

function adminCase(id)
{
	var i;

	for(i = 0; i < document.getElementsByTagName('div').length; i++)
	{
		var klass = document.getElementsByTagName('div')[i].className || null;
		var node  = document.getElementsByTagName('div')[i];

		if(klass != null && klass.indexOf('case') == 0)
		{
			if(klass.split(' ')[1] == id)
			{
				show(node);

				try
				{
					if(node.siblingElement('previous').className)
					{
						node.siblingElement('previous').className += '_on';
					}
				}
				catch(e){}
			}
			else
			{
				hide(node);

				try
				{
					if(node.siblingElement('previous').className)
					{
						node.siblingElement('previous').className = node.siblingElement('previous').className.replace(/_on$/, '');
					}
				}
				catch(e){}
			}
		}
	}
}

function adminFrame(id)
{
	var goto_theme = $ID('goto_theme');
	var goto_nk = $ID('goto_nk');
	var goto_nkdeus = $ID('goto_nkdeus');
	var goto_nkdeus_ = $ID('goto_nkdeus').parentNode.parentNode.parentNode.parentNode.parentNode;

	switch(id)
	{
		case 'theme':
			goto_theme.className += '_on';
			goto_nk.className = goto_nk.className.replace('_on', '');
			off(goto_nkdeus);
			goto_nkdeus_.className = goto_nkdeus_.className.replace('_on', '');
		break;

		case 'nk':
			goto_nk.className += '_on';
			off(goto_nkdeus);
			goto_nkdeus_.className = goto_nkdeus_.className.replace('_on', '');
			goto_theme.className = goto_theme.className.replace('_on', '');
		break;

		case 'nkdeus':
			on(goto_nkdeus);
			goto_nkdeus_.className += '_on';
			goto_theme.className = goto_theme.className.replace('_on', '');
			goto_nk.className = goto_nk.className.replace('_on', '');
		break;

		default:
		break;
	}
}

function aliasNum(version)
{
	ajaxReq('index.php', {
		urlMethod: 'get',
		queryString: 'file=Admin&nude&case=Setting&op=num_alias&version=' + version,
		onReady: function(objReq)
		{
			var alias = parseInt(objReq.responseText);
			var select = $ID('alias');

			select.options[0] = new Option('1', '1');
			select.selectedIndex = 0;

			if(alias > 1)
			{
				for(i = 1; i < alias; i++)
				{
					select.options[i] = new Option((i + 1), (i + 1));
				}

				show(select, 'inline');
			}
			else hide(select);
		}
	});
}

function headerFlash(kolor, version, alias)
{
	$ID('header').style.backgroundImage = 'url(' + base + 'images/' + kolor + '/header/' + version + '/header_' + alias + '.jpg)';
	$ID('header').innerHTML = '';

	new objFlash(519, 141, base + 'flash/' + kolor + '/header/header_' + version + '_' + alias, {flashvars: flashvars}).goArea('header');
}

function on(e)
{
	e.src = e.src.replace(/off.([a-z]{3})$/, 'on.$1');
}

function off(e)
{
	e.src = e.src.replace(/on.([a-z]{3})$/, 'off.$1');
}

function choose_type_url(type, count)
{
	$ID(type + count).style.display = 'block';
	$ID(type + '_url' + count).name = 'url' + count;

	if(type == 'self')
	{
		$ID('blank' + count).style.display = 'none';
		$ID('mailto' + count).style.display = 'none';

		$ID('blank_url' + count).name = '';
		$ID('mailto_url' + count).name = '';
	}
	else if(type == 'blank')
	{
		$ID('self' + count).style.display = 'none';
		$ID('mailto' + count).style.display = 'none';

		$ID('self_url' + count).name = '';
		$ID('mailto_url' + count).name = '';
	}
	else
	{
		$ID('self' + count).style.display = 'none';
		$ID('blank' + count).style.display = 'none';

		$ID('self_url' + count).name = '';
		$ID('blank_url' + count).name = '';
	}
}

function create_cookie(name, value, days)
{
	var expires = '';

	if(days)
	{
		var date = new Date();
		    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

		expires = '; expires=' + date.toGMTString();
	}

	document.cookie = name + '=' + value + expires + '; path=/';
}

function read_cookie(name)
{
	var cookie = document.cookie;

	name += '=';
	var place = cookie.indexOf(name, 0);

	if(place == -1)
	{
		return 0;
	}
	else
	{
		var end = cookie.indexOf(";", place);

		if(end == -1)
		{
			return unescape(cookie.substring(place + name.length, cookie.length));
		}
		else
		{
			return unescape(cookie.substring(place + name.length, end));
		}
	}
}