var ie4 = false;
if(document.all) {
        ie4 = true;
}
function setContent(name, value) {
    var d;
    if (ie4)
    {
        d = document.all[name];
    }
    else
    {
    	d = document.getElementById(name);
    }

    d.innerHTML = value;
}

function getContent(name) {
    var d;
    if (ie4)
    {
        d = document.all[name];
    }
    else
    {
    	d = document.getElementById(name);
    }

    return d.innerHTML;
}

function setColor(name, value, active) {
        var d;
        var div;
        if (ie4) {
                d = document.all[name];
        } else {
                d = document.getElementById(name);
        }
        d.style.color = value;

		if (active)
			d.style.fontSize = '18px';
		else
			d.style.fontSize = '16px';
}

function getColor(name) {
    var d;
    if (ie4) {
            d = document.all[name];
    } else {
            d = document.getElementById(name);
    }
    return d.style.color;
}

function animate(name, col) {
    /*
    var value = getContent(name);
    if (value.indexOf('<span') >= 0) { return; }
    var length = 0;
            var str = '';
    var ch;
    var token = '';
    var htmltag = false;
    for (i = 0; i < value.length; i++)
    {
        ch = value.substring(i, i+1);
        if (i < value.length - 1) { nextch = value.substring(i+1, i+2); } else { nextch = ' '; }
        token += ch;
        if (ch == '<' && '/aAbBpPhHiIoOuUlLtT'.indexOf(nextch) >= 0) { htmltag = true; }
        if (ch == '>' && htmltag) { htmltag = false; }
        if (!htmltag && ch.charCodeAt(0) > 30 && ch != ' ' && ch != '\n') {
                        str += '<span id="' + name + '_' + length + '">' + token + '</span>';
            token = '';
            length++;
        }
	}
	*/

    var value = getContent(name);
	var str = "";
	var SP = 0;
	var EP = 0;
    var ch;
    var token = '';
    var cn = 0;

    for (i = 0; i < value.length; i++)
    {
        ch = value.substring(i, i + 1);

		if (ch == ' ' || ch == ',' || i == value.length - 1)
		{
			if (i == value.length - 1)
				EP = i + 1;
			else
				EP = i;

			if (value.substring(SP, EP) != ",")
			{
				str += '<span id="' + name + '_' + cn + '" normalText="' + value.substring(SP, EP) + '">' + value.substring(SP, EP) + '</span>';
				cn++;
			}
			else
				str += value.substring(SP, EP);

			SP = EP;
		}
	}

	cn--;

    setContent(name, str);
    command = 'animateloop(\'' + name + '\', ' + cn + ', 0, 1, \'' + col + '\')';
    setTimeout(command, 500);
}

var Counter = 0;

function animateloop(name, length, ind, delta, col)
{
	var next = ind + delta;

	if (next >= length)
		Counter++;

	if (next >= length)
	{
		delta = delta * -1;
		next = 1;
	}
	else if (next < (Counter < 3 ? 1 : 0))
	{
		delta = delta * -1;
		next = ind + delta;
	}

    setColor(name + '_' + ind, getColor(name + '_' + next), 0);
    setColor(name + '_' + next, col, 1);
    command = 'animateloop(\'' + name + '\', ' + length + ', ' + next + ', ' + delta + ', \'' + col + '\')';

    if (!(Counter >= 3 && next == 1))
    	setTimeout(command, 500);
    else
    {
    	setColor(name + '_' + next, getColor(name + '_' + (next + 1)), 0);
    }
}

function playVideo(video, autoPlay, id)
{
	window.open("video.php?f=" + video + (autoPlay==0 ? "&noAutoPlay=1" : "") + "&id=" + id ,"gh","height=363,width=640,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,copyhistory=0");
}

function openCalc()
{
window.open("spendenrechner.php","hww","height=585,width=480,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,copyhistory=0");
}

function showImage(id, image)
{
    var theImage = null;

    if (document.all)
        theImage = document.all[id];
    else
        theImage = document.getElementById(id);

    if (theImage != null && theImage != 'undefinded')
        theImage.src = image;
}

function showVideo(vid, divid)
{
    var so = new SWFObject('flvplayer.swf','player','272','220','7');
    so.addParam("allowfullscreen","true");
    so.addParam("allowscriptaccess","always");
    so.addVariable("autostart", "true");

    so.addVariable('width','272');
    so.addVariable('height','220');
    so.addVariable('file', vid);
    so.write(divid);
}

function showVideoVorstand(vid, divid)
{
    var so = new SWFObject('flvplayer.swf','player','196','196','7');
    so.addParam("allowfullscreen","true");
    so.addParam("allowscriptaccess","always");
    so.addVariable("autostart", "false");

    so.addVariable('width','196');
    so.addVariable('height','196');
    so.addVariable('file', vid);
    so.write(divid);
}

function showVideoHWWH(vid, divid)
{
    var so = new SWFObject('flvplayer.swf','player','196','196','7');
    so.addParam("allowfullscreen","true");
    so.addParam("allowscriptaccess","always");
    so.addVariable("autostart", "true");

    so.addVariable('width','196');
    so.addVariable('height','196');
    so.addVariable('file', vid);
    so.write(divid);
}

function showVideoHWWHNAS(vid, divid)
{
    var so = new SWFObject('flvplayer.swf','player','196','196','7');
    so.addParam("allowfullscreen","true");
    so.addParam("allowscriptaccess","always");
    so.addVariable("autostart", "false");

    so.addVariable('width','196');
    so.addVariable('height','196');
    so.addVariable('file', vid);
    so.write(divid);
}

function getCat(text)
{
    var iPos = text.toLowerCase().indexOf('<br>');

    if (iPos > -1)
        text = text.substring(iPos + 4);

    text = 'Zu \'' + text + '\' existiert noch keine Seite.';

    alert(text);
}
