var hndl_stdWin = null;
var hndl_userWin = null;
var hndl_HistWin = null;
var hndl_ServiceWin = null;
var hndl_ProtocolWin = null;
var hndl_WLWin = null;
var hndl_piWin = null;
var hndl_AddrWin = null;
var hndl_ContWin = null;
var hndl_ARTblWin = null;

function toggleVisibility(containerName)
{
	var theDiv = document.getElementById(containerName);

	if (theDiv.style.display == 'none')
	{
		// Container sichtbar schalten
		theDiv.style.display = '';
	}
	else
	{
		theDiv.style.display = 'none';
	}
}

/**
* printContent()
*
* Inhalt des Content-Frames drucken.
*
* @access   public
*/
function printContent()
{
	parent.frames.content.focus();
	window.print();
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean   whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. 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;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... 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;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... 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);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


/**
* openStdWin()
*
* Standardfenster oeffnen. Die Funktion bietet die Moeglichkeit,
* optional die Fensterparameter (Name, Parameter, Groesse) festzulegen.
* Wurden keine Angaben dazu gemacht, so wird ein normales Browserfenster "_blank"
* mit beliebiger Groesse geoffnet.
*
* Beispiel:
*   openStdWin('newPage.php', 'myPagename', 'scrollbars=no,resizable=no,width=600,height=750', 600, 750)
*
* @param newURL URL der anzuzeigenden Seite
* @param winName (opt., default: _blank) Name des neuen Fensters
* @param winParams (opt.) Fensterparameter (z.B. 'scrollbars=no,resizable=no...')
* @param winWidth (opt.) Fensterbreite (nur zusammen mit winHeight)
* @param winHeight (opt.) Fensterhoehe (nur zusammen mit winWidth)
*/
function openStdWin(newURL, winName, winParams, winWidth, winHeight)
{
	var myWin=null;

	var wName = winName!=null ? winName : "_blank";
	var wParams = winParams!=null ? winParams : "scrollbars=yes,resizable=yes,menubar=yes,status=yes,toolbar=no";
	var wWidth = winWidth!=null ? winWidth : 0;
	var wHeight = winHeight!=null ? winHeight : 0;

	myWin=hndl_stdWin=open(newURL, wName, winParams);
	if (myWin!=null)
	{
		if (wWidth>0 && wHeight>0)
			myWin.resizeTo(winWidth, winHeight);
		myWin.window.focus();
	}
}

function openWin(newURL, name)
{
	var winName = name!=null ? name : "_blank";
	var myWin=null;
	myWin=hndl_userWin=open(newURL, winName, "width=680, height=755, left=20, top=10, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openARTblWin(newURL, name)
{
	var winName = name!=null ? name : "_blank";
	var myWin=null;
	myWin=hndl_ARTblWin=open(newURL, winName, "width=800, height=455, left=20, top=60, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openHistoryWin(newURL, name)
{
	var winName = name!=null ? name : "_blank";
	var myWin=null;
	myWin=hndl_HistWin=open(newURL, winName, "width=680, height=435, left=30, top=220, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openAddrWin(newURL, winname)
{
	var myWin=null;
	winname = winname==null ? '_blank' : winname;
	myWin=hndl_AddrWin=open(newURL,winname,"width=700, height=475, left=20, top=10, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openContactWin(newURL, name)
{
	var winName = name!=null ? name : "_blank";
	var myWin=null;
	myWin=hndl_ContWin=open(newURL, winName, "width=500, height=440, left=40, top=270, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openServiceWin(newURL) // Edit Service
{
	var myWin=null;
	myWin=hndl_ServiceWin=open(newURL,"_blank","width=700, height=270, left=20, top=10, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openProtocolWin(newURL) // Edit Protokolle
{
	var myWin=null;
	myWin=hndl_ProtocolWin=open(newURL,"_blank","width=700, height=270, left=20, top=10, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openWLWin(newURL) // Edit Whitelist
{
	var myWin=null;
	myWin=hndl_WLWin=open(newURL,"_blank","width=700, height=475, left=20, top=10, resizable=yes, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openBigWin(newURL)
{
	var myWin=null;
	myWin=hndl_userWin=open(newURL,"_blank","width=1000, height=655, left=20, top=10, resizable=yes, scrollbars=yes, menubar=yes, toolbar=yes");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function pi(port)
{
	var myWin=null;
	var newURL="port_info.php?p="+port;
	myWin=hndl_piWin=open(newURL,"winPI","width=440, height=460, left=50, top=50, resizable=no, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function pri(protocol)
{
	var myWin=null;
	var newURL="protocol_info.php?p="+protocol;
	myWin=hndl_piWin=open(newURL,"winPI","width=440, height=460, left=50, top=50, resizable=no, scrollbars=yes, menubar=no");
	if (myWin!=null)
	{
		myWin.window.focus();
	}
}

function openAdrWin(newURL){
	var myWin=null;
	myWin=hndl_AdrWin=open(newURL, "winAdr", "width=650, height=615, left=180, top=135, resizable=no, scrollbars=yes, menubar=no");
	if (myWin!=null){
		myWin.window.focus();
	}
}

function openSelectedAdr(frmField){
	var frmFieldID = document.getElementsByName(frmField);
	if (frmFieldID.length!=1){
		alert('Die Adresse kann nicht angezeigt werden!');
		return;
	}
	var adrID = frmFieldID[0][frmFieldID[0].selectedIndex].value;
	if (adrID=='-1'){
		alert('Es ist keine Adresse ausgew&auml;hlt!');
		return;
	}
	openAdrWin('adr_admin.php?func=SADR&atyp=A&aID=' + adrID);
}

function closeWins()
{
	if (hndl_stdWin) hndl_stdWin.close();
	if (hndl_userWin) hndl_userWin.close();
	if (hndl_HistWin) hndl_HistWin.close();
	if (hndl_ServiceWin) hndl_ServiceWin.close();
	if (hndl_ProtocolWin) hndl_ProtocolWin.close();
	if (hndl_WLWin) hndl_WLWin.close();
	if (hndl_piWin) hndl_piWin.close();
	if (hndl_ContWin) hndl_ContWin.close();
	if (hndl_AddrWin) hndl_AddrWin.close();
	if (hndl_ARTblWin) hndl_ARTblWin.close();
}

function delData(theQuestion, theURL){
	if (confirm(theQuestion)){
		self.location=theURL;
	}
}

function frmDelData(theQuestion, theFrm, theFunc, theField, theVal)
{
	if (confirm(theQuestion)){
		document[theFrm].func.value=theFunc;
		if (theField)
			document[theFrm][theField].value=theVal;
		document[theFrm].submit();
	}
}

