function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
   if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isDigit( ch )
{
  if ( (ch >= '0') && (ch <= '9') )
    return true;
  else
    return false;
}


function isAlpha( ch )
{
  if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
    return true;
  else
    return false;
}


function isAlnum( ch )
{
  if ( isAlpha( ch ) || isDigit( ch ) )
    return true;
  else
    return false;
}


function notIn( str1, str2 )
{
  var i = 0;
  var j = str2.length;
  for( ; i<j; i++ )
  {
    var str3 =  str2.charAt(i);
    if( str1.indexOf( str3 ) != -1 )
      return false;
  }
  return true;
}


function checkUsername( username, mustBeQuoted )
{
  var i = 0;
  var j = username.length;
  if ( username.charAt(0) != '"' )
  {
    if ( (username.charAt(0) <  ' ') || (username.charAt(0) >  '~')
          || !notIn( mustBeQuoted, username.charAt(0) ) )
      return false;
    for( i=1; i<j; i++ )
    {
      if ( ( (username.charAt(i) < ' ') || (username.charAt(i) >  '~')
            || !notIn ( mustBeQuoted, username.charAt(i) ) )
           && ( username.charAt(i-1) != '\\' ) )
        return false;
    }
  }
  else
  {
    if ( username.charAt( j-1 ) != '"' )
      return false;
    for( i=1; i<j-1; i++ )
    {
      if ( ( (username.charAt(i) == '\n') || (username.charAt(i) == '\r')
            || (username.charAt(i) == '\"') )
          && (username.charAt(i-1) != '\\') )
        return false;
    }

  }
  return true;
}


function checkNr ( nr )
{
  var i=0;
  var j=nr.length;

  if( j < 1 )
    return false;

  for( ; i<j; i++ )
    if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
      return false;

  return true;
}


function checkIpnr( ipnr )
{
  var iL=0;
  var iC=0;
  var i=0;
  var sNr = "";

  for( ; i< ipnr.length; i++ )
  {
    if ( ipnr.charAt(i) == '.' )
    {
      if ( !iL || (iL> 3) || parseInt( sNr,10 ) > 255 )
        return false;
      iC++;
      iL = 0;
      sNr = "";
      continue;
    }
    if ( isDigit ( ipnr.charAt(i) ) )
    {
      iL++;
      sNr = sNr + ipnr.charAt(i);
      continue;
    }
    return false;
  }

  if ( parseInt( sNr,10 ) > 255 )
    return false;
  if ( ( (iC==3) && (iL>=1) && (iL<=3) ) || ( (iC==4) && (!iL) )  )
    return true;
  else
    return false;
}


function checkFqdn( fqdn )
{
  var iL=0;
  var iC=0;
  var i=fqdn.length-1;

  if ( (fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-') )
    return false;
  if ( fqdn.charAt(i) == '.' )
    i=i-1;

  for( ; i>=0; i-- )
  {
    if ( fqdn.charAt(i) == '.' )
    {
      if ( iL < 2 && iC < 2 )
        return false;
      if ( fqdn.charAt(i-1) == '-' )
        return false;
      iC++;
      iL = 0;
      continue;
    }
    if ( isAlnum ( fqdn.charAt(i) ) )
    {
      iL++;
      continue;
    }
    if ( fqdn.charAt(i) == '-' )
    {
      if ( !iL )
        return false;
      iL++;
      continue;
    }
    return false;
  }

  if ( !iC || ( iL == 1 && iC < 2 ) || ( !iL && iC==1 ) ) {
    return false;
  }

  return true;

}


function checkHostname( hostname )
{
  if ( hostname.charAt(0) == '[' )
  {
    if ( hostname.charAt(hostname.length-1) != ']' )
      return false;
    var ipnr = hostname.substring( 1, hostname.length -1 );
      return checkIpnr( ipnr );
  }

  if ( hostname.charAt(0) == '#' )
  {
    var nr = hostname.substring( 1, hostname.length );
      return checkNr( nr );
  }

  return checkFqdn( hostname );
}


function checkEmailAdr( address )
{
  var status = true;
  var username = "";
  var hostname = "";

  if ( address.length < 8 )
    return false;

  var seperate = address.lastIndexOf("@");
  if ( seperate == -1 )
    return false;

  username = address.substring(0, seperate );
  if ( ! checkUsername( username, "<>()[],;:@\" " ) )
    return false;

  hostname = address.substring(seperate+1, address.length );
  if ( ! checkHostname( hostname ) )
    return false;

  return true;
}


function checkEmail( email, allowFullname )
{
  var existFullname = false;
  var status = true;
  var fullname = "";
  var adress = "";
  if ( email.length < 8 )
    return false;
  var emailBegin = email.indexOf("<");
  var emailEnd = email.lastIndexOf(">");

  if ( (emailBegin == -1) && (emailEnd == -1) )
    return checkEmailAdr( email );

  if ( ( (emailBegin == -1) && (emailEnd != -1) )
      || ( (emailBegin != -1) && (emailEnd == -1) ) )
    return false;

  adress = email.substring( emailBegin+1, emailEnd );

  if ( ! checkEmailAdr( adress ) )
    return false;

  if ( email.length == adress.length + 2 )
    return true;
  else
    if ( ! allowFullname )
      return false;

  if ( emailEnd == email.length - 1 )
  {
    if ( emailBegin == 0 )
      return true;
    if ( email.charAt( emailBegin -1 ) != ' ' )
      return false;
    fullname = email.substring( 0, emailBegin-1 );
    return checkUsername ( fullname, "<>()[],;:@\"" );
  }

  return false ;

}


var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  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;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = 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;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = 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;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // 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

