////////////////  GLOBAL TOOPTIP CONFIGURATION  /////////////////////
var ttBgColor      = "#FFFFFF";
var ttBgImg        = "";           // path to background image;
var ttBorderColor  = "#4D4D4D";
var ttBorderWidth  = 1;
var ttDelay        = 50;          // time span until tooltip shows up [milliseconds]
var ttFontColor    = "#000066";
var ttFontFace     = "arial,helvetica,sans-serif";
var ttFontSize     = "11px";
var ttFontWeight   = "normal";     // alternative is "bold";
var ttOffsetX      = 12;            // horizontal offset of left-top corner from mousepointer
var ttOffsetY      = 15;           // vertical offset                   "
var ttOpacity      = 100;          // opacity of tooltip in percent (must be integer between 0 and 100)
var ttPadding      = 3;            // spacing between border and content
var ttShadowColor  = "";
var ttShadowWidth  = 0;
var ttTemp         = 0;            // time span after which the tooltip disappears; 0 (zero) means "infinite timespan"
var ttTextAlign    = "left";
var ttTitleColor   = "#ffffff";    // color of caption text
var ttWidth        = 200;
////////////////////  END OF TOOLTIP CONFIG  ////////////////////////

function getDateTime(){
  var date=new Date();
  var dd=date.getDate();
  var mm=date.getMonth() + 1;
  var yyyy=date.getFullYear();
  var HH=date.getHours();
  var MM=date.getMinutes();
  var SS=date.getSeconds();
  if(dd<10)dd="0"+dd;
  if(mm<10)mm="0"+mm;
  if(HH<10)HH="0"+HH;
  if(MM<10)MM="0"+MM;
  if(SS<10)SS="0"+SS;
	return dd+"."+mm+"."+yyyy+" "+HH+":"+MM+":"+SS;
}	
	
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;
var click_row = null;
var click_rownum = 0;

function Mod(a, b) {
    return a - Math.floor(a / b) * b;
}

function Div(a, b) {
    return Math.floor(a / b);
}
/**
 * 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, theDefaultColorUG, theDefaultColorG, thePointerColor, theMarkColor)
{
    var theCells = null;
    var theDefaultColor;
    
    if(Mod(theRowNum+1,2) == 0){
      theDefaultColor = theDefaultColorG;
    } else {
      theDefaultColor = theDefaultColorUG;
    }

    // 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;
    }

    // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
    // if (theAction == "over" || theAction == "click") {
    //     theRow.style.cursor='pointer';
    // } else {
    //     theRow.style.cursor='default';
    // }

    // 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].bgcolor) != 'undefined') {
        currentColor = theCells[0].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 != '') {
	        if(click_row!=null&&click_row!=theCells){
			    // clear last marked row
		        var c = null;
            if(Mod(click_rownum+1,2) == 0){
              selectedDefaultColor = theDefaultColorG;
            } else {
              selectedDefaultColor = theDefaultColorUG;
            }
            
		        // with DOM compatible browsers except Opera
		        if (domDetect) {
		            for (c = 0; c < rowCellsCnt; c++) {
		                click_row[c].setAttribute('bgcolor', selectedDefaultColor, 0);
		            } // end for
		        }
		        // 5.2 ... with other browsers
		        else {
		            for (c = 0; c < rowCellsCnt; c++) {
		                click_row[c].style.backgroundColor = selectedDefaultColor;
		            }
		        }
            
 			      marked_row[click_rownum] = false;

            if(click_row == theCells){
	  	        click_row = null;
		  	      click_rownum = null;
              newColor = null;
            } else {
              marked_row[theRowNum] = true;
              click_row = theCells;
              click_rownum = theRowNum;
              newColor = theMarkColor;
  			    }
          } else {
            marked_row[theRowNum] = true;
            click_row = theCells;
            click_rownum = theRowNum;
            newColor = theMarkColor;
          }
        }
    }
    // 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 != '') {
	        if(click_row!=null&&click_row!=theCells){
			    // clear last marked row
		        var c = null;
            if(Mod(click_rownum+1,2) == 0){
              selectedDefaultColor = theDefaultColorG;
            } else {
              selectedDefaultColor = theDefaultColorUG;
            }

		        // with DOM compatible browsers except Opera
		        if (domDetect) {
		            for (c = 0; c < rowCellsCnt; c++) {
		                click_row[c].setAttribute('bgcolor', selectedDefaultColor, 0);
		            } // end for
		        }
		        // 5.2 ... with other browsers
		        else {
		            for (c = 0; c < rowCellsCnt; c++) {
		                click_row[c].style.backgroundColor = selectedDefaultColor;
		            }
		        }

 			      marked_row[click_rownum] = false;

            if(click_row == theCells){
	  	        click_row = null;
		  	      click_rownum = null;
              newColor = null;
            } else {
              marked_row[theRowNum] = true;
              click_row = theCells;
              click_rownum = theRowNum;
              newColor = theMarkColor;
  			    }
          } else {
            marked_row[theRowNum] = true;
            click_row = theCells;
            click_rownum = theRowNum;
            newColor = theMarkColor;
			    }
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        // deselect of a marked row is deaktivated to prevent flickering
        // when selecting and deselecting a checkbox
        if (theAction == 'click'&&false) {
          if(thePointerColor != ''){
            newColor = thePointerColor;
          } else {
            newColor = theDefaultColor;
          }
          if(typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]){
            marked_row[theRowNum] = true;
          } else {
            marked_row[theRowNum] = false;
  	        click_row = null;
	  	      click_rownum = 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


 function istEmail(elm) {
     if (elm.value.indexOf("@") != "-1" &&
         elm.value.indexOf(".") != "-1") {
         return true;
     }
     else {
         return false;
     }
 }

function ShowDeleteFile(id){
	fileInput = document.getElementById(id);
	fileDelete = document.getElementById(id+'_delete');
	fileDeleteLbl = document.getElementById(id+'_delete_label');
	if(fileInput&&fileDelete&&fileDeleteLbl){
		fileInput.style.display = 'none';
		fileDeleteLbl.style.display = 'inline';
		fileDelete.checked = true;
	}
}

function ShowInputFile(id){
	fileInput = document.getElementById(id);
	fileDelete = document.getElementById(id+'_delete');
	fileDeleteLbl = document.getElementById(id+'_delete_label');
	if(fileInput&&fileDelete&&fileDeleteLbl){
		if(fileDelete.checked==false){
		  fileInput.style.display = 'inline';
		  fileDeleteLbl.style.display = 'none';
		}
	}
}

function ImagePreloader(images,callback)
{
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;

	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ ) 
		this.preload(images[i]);
}
ImagePreloader.prototype.preload = function(image)
{
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);
	
	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	
	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;
	
	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}
ImagePreloader.prototype.onload = function()
{
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}

var popup_image;
var popup_sanduhr;
var maxWidth = 675;
var maxHeight = 350;
 
function setPopupImage(aImages){
  if(aImages[0].height){
    if(aImages[0].height>maxHeight){
      popup_image.height = maxHeight;
      popup_image.width = aImages[0].width*(maxHeight/aImages[0].height);
    } else {
      popup_image.height = aImages[0].height;
    }
    
    if((aImages[0].height<=maxHeight)&&(aImages[0].width>maxWidth)){
      popup_image.width = maxWidth;
      popup_image.height = aImages[0].height*(maxWidth/aImages[0].width);
    } else if(aImages[0].height<=maxHeight){
      popup_image.width = aImages[0].width;
    }

    popup_image.src = aImages[0].src;
    
    if(popup_sanduhr){
      popup_sanduhr.style.display = 'none';      
    }
  } else {
    popup_image.src = aImages[0].src;
  }    
} 
 
function ShowImagePopup(id,imgSource,w,h){
	popup = document.getElementById(id);
	popup_image = document.getElementById(id+'_image');
  popup_sanduhr = document.getElementById(id+'_sanduhr');
  if(popup&&popup_image){
    if(popup_sanduhr){
      popup_sanduhr.style.display = 'block';      
    }
    TogglePopupFormElements('hide');
    popup.style.display = 'block';
    if(!(h&&w)){
      popup_image.src = imgSource;
      img = new ImagePreloader([imgSource], setPopupImage);
    } else {
      popup_image.height = h;
      popup_image.width = w;
      popup_image.src = imgSource;
      if(popup_sanduhr){
        popup_sanduhr.style.display = 'none';      
      }
    }
  }
}

function ShowImagePopupMax(id,imgSource,w,h){
  maxWidth = w;
  maxHeight = h;
	popup = document.getElementById(id);
	popup_image = document.getElementById(id+'_image');
  popup_sanduhr = document.getElementById(id+'_sanduhr');
  if(popup&&popup_image){
    if(popup_sanduhr){
      popup_sanduhr.style.display = 'block';      
    }
    TogglePopupFormElements('hide');
    popup.style.display = 'block';
    popup_image.src = imgSource;
    img = new ImagePreloader([imgSource], setPopupImage);
  }
}

function HideImagePopup(id){
	popup = document.getElementById(id);
	popup_image = document.getElementById(id+'_image');
  if(popup&&popup_image){
    popup.style.display = 'none';
    TogglePopupFormElements('show');
    popup_image.src = '/images/inv.gif';
    popup_image.height = 350;
    popup_image.width = 675;
  }
}

function ShowPopup(id){
	popup = document.getElementById(id);
  if(popup){
    TogglePopupFormElements('hide');
    popup.style.display = 'block';
  }
}

function HidePopup(id){
	popup = document.getElementById(id);
  if(popup){
    TogglePopupFormElements('show');
    popup.style.display = 'none';
  }
}

function TogglePopupFormElements(v){
  for (var i = 1; i <= 5; i++){
  	obj = document.getElementById('popup_invisible'+i);
    if(obj){
      if(v=='hide'){
        obj.style.visibility = 'hidden';
      } else {
        obj.style.visibility = 'visible';
      }
    } else {
      break;
    }
  }
}

// www.web-toolbox.net , W. Jansen
// Übergabeparameter: bildquelle,breite,höhe,bildtitel
// hand over parameters: imagesource,width,height,title
// Angepasst zum automatischen Drucken von Manuel Gurski
function PrintPopupImage(id)
{
var eigenschaften,sbreite,shoehe,fenster,b,h,bildurl,bildtitel;

// stellt die Bildschirmabmessungen fest
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);

popup_image = document.getElementById(id+'_image');
if(popup_image){
	bildurl = popup_image.src;
	b = popup_image.width;
	h = popup_image.height;
	bildtitel = 'Drucken';
}

if(ns6||ns4) {
sbreite = innerWidth;
shoehe = innerHeight;
}
else if(ie4) {
sbreite = document.body.clientWidth;
shoehe = document.body.clientHeight;
}

x = (sbreite-b)/2;
y = (shoehe-h)/2;

eigenschaften="left="+x+",top="+y+",screenX="+x+",screenY="+y+",width="+b+",height="+h+",menubar=no,toolbar=no,statusbar=0";

fenster=window.open("","",eigenschaften);
fenster.focus();
fenster.document.open();
with (fenster) {
  document.write('<html><head>');
  // geändert 2004 für Mozilla
  document.write('<scr' + 'ipt type="text/javascr' + 'ipt" language="JavaScr' + 'ipt">');
  document.write("function click() { window.close(); } ");  // bei click  schliessen
  document.write("document.onmousedown=click ");
  // geändert 2004 für Mozilla
  document.write('</scr' + 'ipt>');
  document.write('<title>'+ bildtitel +'</title></head>');
  // Zeile geändert Aug 2003 (Dreamweaver machte Probleme)
  document.write('<' + 'body onload="print();" onblur="window.close();" ');// bei Focusverlust schliessen
  document.write('marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">');
  document.write('<center>');
  document.write('<img src="'+ bildurl +'" width="'+b+'" height="'+h+'" border="0">');
  document.write('</center>');
  document.write('</body></html>');
  fenster.document.close();
}
}

function table_hover(tr, InOut){
  if(InOut=='in'){
	  tr.style.backgroundColor='#D2D2D2';
	} else if(InOut=='out'){
		if(tr.className=='ug'){
		  tr.style.backgroundColor='#FFFFFF';
		} else {
		  tr.style.backgroundColor='#E4E4E4';
		}	
	}
}

function table_fav_hover(tr, InOut){
  if(InOut=='in'){
	  tr.style.backgroundColor='#FFFFFF';
	  tr.style.color='#444444';
	} else if(InOut=='out'){
	  tr.style.backgroundColor='#F4F9FC';
	  tr.style.color='#444444';
	}
}

