var EXPLORER = "Explorer";
var NETSCAPE = "Netscape";
var OPERA = "Opera";

var derAppName = navigator.appName;

function isBrowser(browserName){
        return (derAppName.indexOf(browserName) > -1);
}

//------------------------------
function  setKlass(id, klass){
        if(document.getElementById(id) != null)
        {
                document.getElementById(id).className = klass;
        }
}

function getKlass(id){
        if(document.getElementById(id) != null)
        {
                return document.getElementById(id).className;
        }
        else
        {
                return "";
        }
}

function addTipText(text, breite){//
        breiteMin = 100;
        if(breite < breiteMin)
                breite = breiteMin;


        //alert(breite);
        Tip(text,TITLE, '', WIDTH, breite, BGCOLOR, '#dfdfdf', FONTCOLOR, '#000000', BORDERWIDTH, 1, ABOVE, true, OFFSETX, 10, OFFSETY, 1, FADEIN, 400, FADEOUT, 300);
       // Tip(text,TITLE, '', WIDTH, breite, BORDERWIDTH, 0, ABOVE, true, OFFSETX, 10, OFFSETY, 1, FADEIN, 400, FADEOUT, 300);
}

function  setAktiv(id, klass){
	if(document.getElementById(id) != null)
	{
		//alert(klass);
		document.getElementById(id).className = klass;
	}
}

function zeileMausHover(zeile){

    if(zeile != null && zeile.className != "zeile-Selected")
    	zeile.className = "zeile-Hover";
}
function zeileMausOut(zeile){

    if( zeile != null && zeile.className != "zeile-Selected")
    	zeile.className = "zeile-Out";
}

function zeileMausKlickRb(zeile, div1, div2, idBase, max){
	if(zeile==null)
    	return;

    zeile.className = "zeile-Selected";
	for(var i=0; i<max; i++)
    {
    	var zeileNext = document.getElementById(idBase+(i+1));

        if(zeile != zeileNext)
        {
        	zeileNext.className = "zeile-Out";
        }
    }
	//alert(1);
    if(tauscheDivInner(div1, div2))
    {
    	//alert(2);
    	var divAktu = document.getElementById(div1);
        //alert(divAktu.innerHTML);
        if(isBrowser(EXPLORER))
        {
        	innerAktu = divAktu.innerHTML.replace(/id=replace-/g, "id=replace-aktu-");// IE
        }
        else
        {
			innerAktu = divAktu.innerHTML.replace(/id='replace-/g, "id='replace-aktu-");
        	innerAktu = divAktu.innerHTML.replace(/id=\"replace-/g, "id=\"replace-aktu-");
        }
		divAktu.innerHTML = innerAktu;
        //alert(divAktu.innerHTML);

        text_replace_divId = div2;
    }

}

//---------------------------
function klickRb(div1, div2, idBase, klassBase, klasseNeu, nr, max){

        ind = nr-1;
        for(var i=0; i<max; i++)
        {
                if(i == ind)
                        setKlass(idBase+(i+1), klasseNeu);
                else
                        setKlass(idBase+(i+1), klassBase);
        }


        tauscheDivInner(div1, div2);
        scrolleNachOben();

        //tauscheDivInner(div1, null);
        //scrolleNachObenUndTauscheDIVs(div1, div2, 1);
}

function zuFrage(vonFrageNr, zuFrageNr){
        tauscheDivInner("rb-aktu", "rb-"+zuFrageNr);
        setKlass("a-rb-navi-"+vonFrageNr, "rb-navi");
        setKlass("a-rb-navi-"+zuFrageNr, "rb-navi-aktu");
        scrolleNachOben();
}


function tauscheDivInner(div1, div2){

        d1 = document.getElementById(div1);
        d2 = document.getElementById(div2);

        //alert(d1+"\n"+d2);

        if(d1 != null && d2 != null)
        {
        	//alert(div1+" not null "+div2);
        	d1.innerHTML = d2.innerHTML;
            //alert(d1+"\n"+d2);
            return true;
        }
        else if(d1 != null && d2 == null)
        {
        	//alert(div1+" null "+div2);
        	d1.innerHTML = "";
            //alert(d1+"\n"+d2);
            return true;
        }

        return false;
}

function scrolleNachOben () {
        var y = 0;
        if (window.pageYOffset)
        {
                y = window.pageYOffset;
        }
        else if (document.body && document.body.scrollTop)
        {
                y = document.body.scrollTop;
        }
        if (y > 0)
        {
                window.scrollBy(0, -20);
                setTimeout("scrolleNachOben()", 10);
        }
}

function scrolleNachObenUndTauscheDIVs (div1, div2, zaeler) {
        var y = 0;
        var step = 20;
        if (window.pageYOffset)
        {
                y = window.pageYOffset;
        }
        else if (document.body && document.body.scrollTop)
        {
                y = document.body.scrollTop;
        }

        tuot = 10;
        if(zaeler == 1 && y <= 0)
        {
                //alert("1: "+zaeler);
                y = step;
                tuot = 200;
        }
        else        if(y < step+10)
        {
                //alert("2: "+zaeler);
                tuot = 200;
        }

        zaeler ++;

        if (y > 0)
        {
                window.scrollBy(0, -step);
                setTimeout("scrolleNachObenUndTauscheDIVs('"+div1+"','"+ div2+"',"+zaeler+")", tuot);
        }
        else
        {
                tauscheDivInner(div1, div2);
        }
}

//---------------------------------

var text_replace_leuft = false;
var text_replace_divId = "";

function setBgColorDivAktuNachClass(divId, textIdMax){
	text_replace_divId = divId;
    setBgColorNachClassWarten(divId, 0, textIdMax);
}

//---------------------------------
function setBgColorInMenu(textIdMax){
	for(var i=0; i<textIdMax && false; i++)
    {
    	wortId = "replace-l-"+i;
		var wort = document.getElementById(wortId);
        if(wort != null)
        {
        	inner = wort.innerHTML;
            //alert(inner);
            anzBust = inner.length;
            if(inner.indexOf("<") > -1)
				anzBust = inner.indexOf("<");


            bgColor = "#"+wort.className;
			replaceBgColor("dawai-dawai", bgColor, wortId, inner, anzBust, 0);
            //window.setTimeout("void(0)", 1000);
        }
    }

}

//---------------------------------
function setBgColorNachClassWarten(divId, textIdAktu, textIdMax){
   //	alert(textIdAktu+"/"+textIdMax);
	if(textIdAktu >= textIdMax) return;

	/*
	if(text_replace_leuft)// abwarten bis ein wort markiert wird
    {
		window.setTimeout("setBgColorNachClassWarten('"+divId+"', "+textIdAktu+", "+textIdMax+")", 10);
    }
	else
    {*/
	   	wortId = "replace-aktu-"+textIdAktu;
        //alert(wortId);
		var wort = document.getElementById(wortId);
        if(wort != null)// wort markieren lassen
        {
        	inner = wort.innerHTML;
            //alert(inner);
            anzBust = inner.length;
            if(inner.indexOf("<") > -1)
				anzBust = inner.indexOf("<");


            bgColor = "#"+wort.className;
            text_replace_leuft = true;
			replaceBgColor(divId, bgColor, wortId, inner, anzBust, 0);
			textIdAktu++;
        	window.setTimeout("setBgColorNachClassWarten('"+divId+"', "+textIdAktu+", "+textIdMax+")", 10);
        }
        else// gehört nicht zu diesem Text
        {
			textIdAktu++;
        	window.setTimeout("setBgColorNachClassWarten('"+divId+"', "+textIdAktu+", "+textIdMax+")", 1);
        }
	//}
}

function replaceBgColor(divId, bgColor, wortId, inner, anzBust, anzAktu){

    //alert(wortId+"\n"+inner+"\n"+anzAktu+"/"+anzBust);

    if(divId != text_replace_divId && divId != "dawai-dawai")
    {
		text_replace_leuft = false;
        return true;
    }

    var wort = document.getElementById(wortId);
    if(wort != null)
    {

    	if(anzAktu > anzBust)
        {

			text_replace_leuft = false;
            return true;
        }

		innerAktu = "<span style='background-color:"+bgColor+"; color:black;' >"+
        				inner.substr(0,anzAktu)+
                    "</span>"+
                    inner.substr(anzAktu);
		wort.innerHTML = innerAktu;
        anzAktu ++;
        window.setTimeout("replaceBgColor('"+divId+"', '"+bgColor+"', '"+wortId+"', '"+inner+"', "+anzBust+", "+anzAktu+")", 50);
    }
	else
    {
    	 anzAktu ++;
		window.setTimeout("replaceBgColor('"+divId+"','"+bgColor+"', '"+wortId+"', '"+inner+"', "+anzBust+", "+anzAktu+")", 100);
    }

}
