var pointer_row = -1;
var pointer_color = '';

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor, c2mId, name1, name2, datum1, datum2, bez2, buttonv){
    var theCells = null;
    var box = null;
    
    //document.getElementById('divdiv').innerHTML += theAction+'<br />';
    //Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    //Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    //Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    //... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    //... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    }

	//... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    //Defines the new color
    //Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            setOldColor(domDetect);
            newColor              = theMarkColor;
            pointer_row = theRowNum;
			pointer_color = theDefaultColor;

            //document.grid.opt[theRowNum -1].checked = true;
        }
    }

    //Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            setOldColor(domDetect);
            newColor              = theMarkColor;
            pointer_row = theRowNum;
			pointer_color = theDefaultColor;
			
			//adminbox
			if (document.getElementById('adminbox'+c2mId)){
				box = document.getElementById('adminbox'+c2mId);
				box.style.visibility = "visible";
				
				box = document.getElementById('bez1'+c2mId);
			   	box.innerHTML = "Autor";
			    box = document.getElementById('name1'+c2mId);
			   	box.innerHTML = name1;
			   	
			    box = document.getElementById('datum1'+c2mId);
			   	box.innerHTML = datum1;
			   	
			   	
			   	box = document.getElementById('bez2'+c2mId);
			   	box.innerHTML = bez2;
			   	box = document.getElementById('name2'+c2mId);
			   	box.innerHTML = name2;
			   	box = document.getElementById('datum2'+c2mId);
			   	box.innerHTML = datum2;
			}
			
			if (document.getElementById('buttonAccept')){
			   	box = document.getElementById('buttonAccept');
			   	if (buttonv == "1"){
				   	box.style.visibility = "visible";
			   	} else {
					box.style.visibility = "hidden";
			   	}
			}
        }
    }

    //Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
			newColor              = thePointerColor;
            pointer_row = -1;
			pointer_color = '';
			if (document.getElementById('adminbox')){
				box = document.getElementById('adminbox');
				box.style.visibility = "hidden";
			}
			
			if (document.getElementById('buttonAccept')){
				box = document.getElementById('buttonAccept');
				box.style.visibility = "hidden";
			}
        }
    }

    //Sets the new color...
    if (newColor) {
        var c = null;
        //... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        //... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }
   	
    return true;
}

function setOldColor(domDetect){
    var theCells2 = null;

    if (pointer_row != -1){
       newColor2 = pointer_color;
       theRow2 = document.getElementById('row'+pointer_row);

	   //Gets the current row and exits if the browser can't get it
	   if (typeof(document.getElementsByTagName) != 'undefined') {
	   	  theCells2 = theRow2.getElementsByTagName('td');
	   } else if (typeof(theRow2.cells) != 'undefined') {
	      theCells2 = theRow2.cells;
	   } else { return false; }

	   //Sets the new color...
	   if (newColor2) {
	        var d = null;
	        //... with DOM compatible browsers except Opera
	        if (domDetect) {
	            for (d = 0; d < theCells2.length; d++) {
	                theCells2[d].setAttribute('bgcolor', newColor2, 0);
	            } // end for
	        }
	        //... with other browsers
	        else {
	            for (d = 0; d < theCells2.length; d++) {
	                theCells2[d].style.backgroundColor = newColor2;
	            }
	        }
	    }
     }
}

function submitGridWithAction(naction, nformname, getId, getprefix){
	if (getId == 1){
		if (pointer_row > 0){
			document.getElementById(nformname).action = naction+'&'+getprefix+'Id='+pointer_row;
			document.getElementById(nformname).submit();
		}
	} else {
		document.getElementById(nformname).action = naction;
		document.getElementById(nformname).submit();
	}
}

function submitFormWithAction(naction, nformname){
	document.getElementById(nformname).action = naction;
	if (typeof document.getElementById(nformname).onsubmit == "function") {
		document.getElementById(nformname).onsubmit();
	}
	document.getElementById(nformname).submit();
}

function initdiv(){
	if(!document.all && document.getElementById('roottable')){
		var strHeight = new String(parseInt(window.innerHeight-divmainHeight)+'px');
		var strWidth = new String(parseInt(window.innerWidth-divmainWidth)+'px');
		document.getElementById('roottable').style.height = strHeight;
		document.getElementById('divmain').style.height = strHeight;
		document.getElementById('divmain').style.width = strWidth;
		
		document.getElementById('roottable').style.height = strHeight;
		var strHeight = new String(parseInt(window.innerHeight-divnaviHeight)+'px');
		var strWidth = new String(parseInt(200)+'px');
		document.getElementById('navitd').style.height = strHeight;

		scrollTo("navitd");
		window.onresize = function() { initdiv(); }
	}
}

function initdivTemp(){
	if(!document.all && document.getElementById('roottable')){
		/*var strHeight = new String(parseInt(window.innerHeight-divmainHeight)+'px');
		var strWidth = new String(parseInt(window.innerWidth-divmainWidth)+'px');
		document.getElementById('roottable').style.height = strHeight;
		document.getElementById('divmain').style.height = strHeight;
		document.getElementById('divmain').style.width = strWidth;
		
		document.getElementById('roottable').style.height = strHeight;*/
		var strHeight = new String(parseInt(window.innerHeight-divnaviHeight)+'px');
		var strWidth = new String(parseInt(200)+'px');
		document.getElementById('navitd').style.height = strHeight;

		scrollTo("navitd");
		window.onresize = function() { initdiv(); }
	}
}

function initdiv2(){
	if(!document.all){
		var strHeight = new String(parseInt(window.innerHeight-151)+'px');
		var strWidth = new String(parseInt(window.innerWidth-219)+'px');
		
		if (window.innerHeight > 300){
			document.getElementById('roottable').style.height = strHeight;
			document.getElementById('divmain').style.height = strHeight;
			document.getElementById('divmain').style.width = strWidth;		
			document.getElementById('navitd').style.height = strHeight;	
		}
		
		scrollTo("navitd");
		window.onresize = function() { initdiv2(); }
	}
}

function initdiv3(){
	if(!document.all){
		var strHeight = new String(parseInt(window.innerHeight-190)+'px');
		var strWidth = new String(parseInt(window.innerWidth-219)+'px');
		
		if (window.innerHeight > 300){
			document.getElementById('roottable').style.height = strHeight;
			document.getElementById('divmain').style.height = strHeight;
			document.getElementById('divmain').style.width = strWidth;		
			document.getElementById('navitd').style.height = strHeight;	
		}
		
		scrollTo("navitd");
		window.onresize = function() { initdiv3(); }
	}
}

function initdiv4(){
	if(!document.all){
		var strHeight = new String(parseInt(window.innerHeight-187)+'px');
		
		if (window.innerHeight > 300){
			document.getElementById('roottable').style.height = strHeight;
			document.getElementById('divmain').style.height = strHeight;
		}
		
		scrollTo("navitd");
		window.onresize = function() { initdiv4(); }
	}
}

function setScroll(what) {
	document.cookie = 'ScrollPosNavi='+document.getElementById(what).scrollTop;
}

function scrollTo(what) {
	var scrollpos = GetCookie('ScrollPosNavi');
	window.setTimeout('document.getElementById("navitd").scrollTop = ' + parseInt(scrollpos), 0);
	document.getElementById(what).onscroll = function() { setScroll("navitd"); }
}

function printMail(email){
	rmail = replace(email, "[at]", "@");
	rmail = replace(rmail, "[.]", ".");
	document.write("<a href=\"mailto:" + rmail + "\">" + rmail + "</a>");
}

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
