var cssNames = [ "yellow", "blue", "red", "green", "orange", "lila", "light", "dark" ];

function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 )
	{
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();


		if ( strHref.indexOf("#") > -1 )
		{
			strQueryString = strQueryString.substring(0,strQueryString.indexOf("#"));
		}

		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
			{
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

var stylenumber = getURLParam("stylenumber");
if (stylenumber) {
createCookie("stylenumber", stylenumber, 7);
} else {
stylenumber = readCookie("stylenumber");
} 

document.write('<link rel="stylesheet" id="tcstyle" type="text/css" href="http://otaku.onlinehome.de/tcstyle_'+cssNames[stylenumber]+'.css"/>')


//'+cssNames[readCookie("stylenumber")]+'.css"/>');

function setFont(name){
createCookie("fontname", name, 7);
if (name == "times"){
document.body.style.fontSize = "11pt";
document.body.style.fontFamily = "times, 'Time New Roman'";
} else {
document.body.style.fontSize = "10pt";
document.body.style.fontFamily = "arial, helvetica, sans-serif";
}
setzeHintergrundHoehe();
}

function fontsmaller(){
document.body.style.fontSize -= 1;
}
function fontbigger(){
document.body.style.fontSize += 1;
}


function nofollow(n){ document.location.href=n; }

function linkaddstyle(ur,anchor)
{
	if (anchor) 
	{
		if (stylenumber != null && stylenumber != 0)
		{		
			document.location.href=ur+'?stylenumber='+stylenumber+anchor;
			} else {
			document.location.href=ur+anchor;
		}
	    } else {
		if (stylenumber != null && stylenumber != 0)
		{
			document.location.href=ur+'?stylenumber='+stylenumber;
			} else {
			document.location.href=ur;
		}
	}
}



/* wenn stil geändert wird*/

function stylechange(sn) {
        stylenumber = sn;
	createCookie("stylenumber", stylenumber, 7);
	document.getElementById( 'tcstyle' ).href = "http://otaku.onlinehome.de/tcstyle_"+cssNames[ stylenumber ]+".css";

	var loco = window.location.href;
	var anchor = "";
	if ( loco.indexOf("#") > -1 ) {
		anchor = loco.substr(loco.indexOf("#"));
	}
	if ( loco.indexOf("?") > -1 ) {
		loco = loco.substring(0,loco.indexOf("?"))+"?stylenumber="+stylenumber+anchor;
		window.location.href = loco;
	}
}

function setzeHintergrundHoehe()
{
if (document.height) {
    document.getElementById("pagebg").style.height = document.height+"px";
} else {
    document.getElementById("pagebg").style.height = document.body.scrollHeight+"px";
}
}

window.onresize = setzeHintergrundHoehe;

function neuAufbau() {
	var stylenumber = readCookie("stylenumber");
/*	document.getElementById( 'tcstyle' ).href = "http://otaku.onlinehome.de/"+cssNames[ stylenumber ]; */
	setzeHintergrundHoehe();
        document.getElementById("styleselect").selectedIndex = stylenumber;
	if (readCookie("fontname")) setFont(readCookie("fontname"));
}


// toggle tree float
function toggle( targetId ){
if (document.getElementById){
target = document.getElementById( targetId );
if (target.style.position == "static"){
target.style.position = "fixed";
} else {
target.style.position = "static";
}
}
}

function createCookie(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 readCookie(name) {
	var nameEQ = 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(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/*

function eraseCookie(name) {
	createCookie(name,"",-1);
}

*/
