var items = new Array();
function hide(a,type)
{
	var e = document.getElementById(a);
	if(!e)
		return true;
	if(e.style.display == "none")
	{
		if(!type)
			type = "block";
		else if(type == 1)
			type = "inline";
		e.style.display=type;
	
	}
	else
		e.style.display="none";
	return true;
}

function countdown(text1, text2, timekey, outputc, refresh, change)
{
	if(typeof(refresh) == 'undefined')
		refresh = 1;
	if(!change)
		change = 0;
	timekey--;
	var timekey2 = timekey;
	var days = 0;
	var hours = 0;
	var minutes = 0;
	var seconds = 0;
	var output = new Array();
	if(timekey > 0)
	{
		if(timekey >= 60*60*24*365)
		{
			years = Math.floor(timekey/(60*60*24*365));
			timekey -= years*60*60*24*365;
			output.push(years+' Jahr'+((years > 1) ? 'e'+(change ? '' : 'n') : ''));
		}
		if(timekey >= 60*60*24*30)
		{
			months = Math.floor(timekey/(60*60*24*30));
			timekey -= months*60*60*24*30;
			output.push(months+' Monat'+((months > 1) ? 'e'+(change ? '' : 'n') : ''));
		}
		if(timekey >= 60*60*24)
		{			days = Math.floor(timekey/(60*60*24));
			timekey -= days*60*60*24;
			output.push(days+' Tag'+((days > 1) ? 'e'+(change ? '' : 'n') : ''));
		}
		if(timekey >= 60*60)
		{
			hours = Math.floor(timekey/(60*60));
			timekey -= hours*60*60;
			output.push(hours+' Stunde'+((hours > 1) ? 'n' : ''));
		}
		if(timekey >= 60)
		{
			minutes = Math.floor(timekey/(60));
			timekey -= minutes*60;
			output.push(minutes+' Minute'+((minutes > 1) ? 'n' : ''));
		}
		if(timekey > 0)
		{
			seconds = timekey;
			timekey = 0;
			output.push(seconds+' Sekunde'+((seconds > 1) ? 'n' : ''));
		}
		var outputtext = '';
		var ifor = output.length;
		if(ifor == 0)
			outputtext = '-';
		else
		{
			var sep = '';
			for(var i = 0; i < ifor; i++)
			{
				if(i < ifor-2)
					sep = ', ';
				else if(i == ifor-2)
					sep = ' und ';
				else
					sep = '';
				outputtext += output[i]+sep;
			}
		}
		window.setTimeout("countdown('"+text1+"','"+text2+"',"+timekey2+",'"+outputc+"', '"+refresh+"', "+change+");", 1000);
	}
	else
	{
		outputtext = '-';
		if(refresh == 1)
		{
			if(document.location.href.indexOf('?') == -1)
				window.setTimeout("document.location.href = document.location.href;", 1000);
			else
				window.setTimeout("document.location.href = document.location.href.substring(0, document.location.href.indexOf('?'));", 1000);
		}
		else if(refresh != 0)
		{
			window.setTimeout("document.location.href = '"+refresh+"';", 1000);
		}
	}
	document.getElementById(outputc).innerHTML = text1+outputtext+text2;
}

function checkField(field, len)
{
    return (field.value.length == 0 || field.value.length > len);
}

function isNumber(str)
{
	for(var position = 0; position < str.length; position++)
	{
		var chr = str.charAt(position);
		if(chr < 0 || chr > 9)
			return false;
	}
	return true;
}

function isNumeric(str)
{
	var ValidChars = "0123456789";
	for(var position = 0; position < str.length; position++)
	{
		var chr = str.charAt(position);
		if(ValidChars.indexOf(chr) == -1)
			return false;
	}
	return true;
}

function checkNumber(str, start, end)
{
	if(!end)
		end = 0;
	if(str.length == 0)
		return false;
	if(!isnumeric(str))
		return false;
	if(str < start)
		return false;
	if(str > end && end != 0)
		return false;
	return true;
}

function textLength(input, len, output)
{
	if(input.value.length <= len)
		output.innerHTML = 'Du hast bereits '+input.value.length+'/'+len+' Zeichen benutzt.';
	else
		output.innerHTML = 'Du hast bereits <font color=\'red\'>'+input.value.length+'/'+len+' Zeichen benutzt.';
}
function changeall(objs, state)
{
	var e = document.getElementsByName(objs);
	for(var i = 0; i < e.length; i++)
	{
		e[i].checked = state;
		if(document.getElementById('anz_'+e[i].value))
			document.getElementById('anz_'+e[i].value).value = state ? items[e[i].value] : 1;
	}
}

function changestyle(style)
{
	var style2 = (style.indexOf('http://') == -1 ? ('styles/'+style) : style)+'.css';
	parent.text.document.getElementsByTagName('link')[0].href = style2;
	parent.player.document.getElementsByTagName('link')[0].href = style2;
	parent.chat.document.getElementsByTagName('link')[0].href = style2;
	parent.chatsend.document.getElementsByTagName('link')[0].href = style2;
	parent.info.document.getElementsByTagName('link')[0].href = style2;
	parent.map.document.getElementsByTagName('link')[0].href = style2;
	parent.player.document.getElementsByTagName('link')[0].href = style2;
	parent.menu.document.getElementsByTagName('link')[0].href = style2;
}

function maxitemscheckbox(checkbox, sbox, counterid, costsid, count, coststype)
{
	var current = document.getElementById(counterid).innerHTML * 1;
	var costs = 15;
	if(!sbox.checked)
	{
		if(current > count)
		{
			sbox.checked = false;
			return false;
		}
		else
		{
			current++;
			if(current == count)
				costs = 0;
			if(coststype == 1)
			{
				for(var i = 1; i < count-current; i++)
				costs += i*5;
				document.getElementById(costsid).innerHTML = costs;
			}
			document.getElementById(counterid).innerHTML = current;
			return true;
		}
	}
	else
	{
		if(current > 0)
		{
			current--;
			if(coststype == 1)
			{
				for(var i = 1; i < count-current; i++)
					costs += i*5;
				document.getElementById(costsid).innerHTML = costs;
			}
			document.getElementById(counterid).innerHTML = current;
			return true;
		}
		else
		{
			sbox.checked = false;
			return false;
		}
	}
}

function popup(url, desc)
{
	fenster = window.open(url, desc, 'width=800,height=700,status=yes,scrollbars=yes,resizable=yes');
	fenster.focus();
}

function keyDown(a_oEvent)
{
	if (window.all || window.opera) {
		iKey = event.keyCode;
	} else if (navigator.appName == "Netscape") {
		iKey = a_oEvent.which;
	} else {
		return false;
	}

	/* Die gedrueckte Taste steht nun
	   in iKey und kann weiter bearbeitet
	   werden */
	  
	if(iKey == 110)
		parent.map.move('up');

	return true;
}
