
function resetOnFocus(ele, pText) {
	if(pText !=  "dummy" && ele.value == pText) {
		ele.value = "";
	}
}

function resetOnBlur(ele, pText) {
	if(pText !=  "dummy" && ele.value == '') {
		ele.value = pText;
	}
}


function checkSearchTerm(pDefaultText) {
  ele = document.getElementById('searchfield');
  if (ele) {
    sText = ele.value;
    if (ele.value == pDefaultText || ele.value == '') {
      alert("Bitte geben Sie einen Suchbegriff ein.");
      ele.focus();
      return false;
    }
    if (sText.length < 2) {
      alert("Bitte geben Sie mindestens 2 Zeichen als Suchbegriff ein.");
      ele.focus();
      return false;
    }
  }
  return true;
}

function changeCounterValue(sElement, iStep, iMinimum, iMaximum) {
  var obj = document.getElementById(sElement);
  var val = (parseInt(obj.value) ? parseInt(obj.value) : 0);
  val = parseInt(val + iStep);
  if (val < iMinimum) val = iMinimum
  if (val > iMaximum) val = iMaximum
  obj.value = val;
}

function getWindowWidth() {
  var windowWidth = 0;
  if (typeof(window.innerWidth) == "number") {
    windowWidth=window.innerWidth;
  } else {
    if (document.documentElement && document.documentElement.clientWidth) {
      windowWidth = document.documentElement.clientWidth;
    } else {
      if (document.body && document.body.clientWidth) {
        windowWidth=document.body.clientWidth;
      }
    }
  }
  return windowWidth;
}

function getWindowHeight() {
  var windowHeight = 0;
  if (typeof(window.innerHeight) == "number") {
    windowHeight=window.innerHeight;
  } else {
    if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
    } else {
      if (document.body && document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

function getScrollWidth() {
  var scrollWidth = 0;
  if (parseInt(document.body.scrollWidth)) scrollWidth = document.body.scrollWidth;
  if (scrollWidth < getWindowWidth()) scrollWidth = getWindowWidth();
  return scrollWidth;
}

function getScrollHeight() {
  var scrollHeight = 0;
  if (parseInt(document.body.scrollHeight)) scrollHeight = document.body.scrollHeight;
  if (scrollHeight < getWindowHeight()) scrollHeight = getWindowHeight();
  return scrollHeight;
}

function setRowClass(oRow, sEvent, sClass) {
 if (typeof(oRow) == "undefined") {
   return false;
 }
 if (sEvent == "over") {
   sCurrentClass = new String(oRow.className);
   if (sCurrentClass.indexOf(sClass) >= 0) {
     // Neue Klasse ist bereits zugewiesen
   } else {
     lastClass = oRow.className;
   }
 }
 if (sEvent == "out") {
   sNewClass = lastClass + ' ' + sClass;
 } else {
   sNewClass = sClass;
 }
 oRow.className = sNewClass;
}

function getPosition(element) {
  
  var elem=element,tagname="",x=0,y=0;
    
  while ((elem != null)&&(typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined")) {
    y+=elem.offsetTop;
    x+=elem.offsetLeft;
    tagname=elem.tagName.toUpperCase();
    if (tagname=="BODY") elem=0;
    if (typeof(elem)=="object" && typeof(elem.offsetParent)=="object") elem=elem.offsetParent;
  }
  
  position=new Object();
  position.x=x;
  position.y=y;
  return position;
} 

// usage: format_zahl( number [, number]  [, bool]  )
function formatZahl(zahl, k, fix)
{
    if(!k) k = 0;
    var neu = '';
    // Runden
    var f = Math.pow(10, k);
    zahl = '' + parseInt( zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;
    // Komma ermittlen
    var idx = zahl.indexOf('.');
    // fehlende Nullen einfügen
    if(fix)
    {
         zahl += (idx == -1 ? '.' : '' )
         + f.toString().substring(1);
    }
    // Nachkommastellen ermittlen
    idx = zahl.indexOf('.');
    if( idx == -1) idx = zahl.length;
    else neu = ',' + zahl.substr(idx + 1, k);

    // Tausendertrennzeichen
    while(idx > 0)
    {
        if(idx - 3 > 0)
        neu = '.' + zahl.substring( idx - 3, idx) + neu;
        else
        neu = zahl.substring(0, idx) + neu;
        idx -= 3;
    }

    return neu;
}

function openCentered(win, name, url, w, h, l, t) {
  if ((!l || (l == -1)) && (l != 0)) {
    var l = Math.round(0.5 * (screen.width - w));
  }
  if ((!t || (t == -1)) && (t != 0)) {
    var t = Math.round(screen.height * (1.0 - 0.618034) - 0.5 * h);
    if (t < 0.0) t = 0.0;
  }
  if (win && !win.closed) win.close();
  win = window.open(url, name,
              "left=" + l + ",top=" + t + ",width=" + w + ",height=" + h + ",toolbar=no,scrollbars=yes,resizable=yes"
  );
  return win;
}

function openWindow(sName, sUrl, iWidth, iHeight, bToolbar, bResizable, bScrollbars) {
  
  // Calculate window's left and top position
  var iLeft   = parseInt((screen.width / 2) - (iWidth / 2));
  var iTop    = parseInt((screen.height / 2) - (iHeight / 2) - 50);
  if (iTop < 0) iTop = 0;
  
  // Check if window should have a toolbar, be resizable or have scrollbars
  var sToolbar    = (bToolbar    ? "yes" : "no");
  var sResizable  = (bResizable  ? "yes" : "no");
  var sScrollbars = (bScrollbars ? "yes" : "no");
  
  // Open window and focus it
  var oWindow = window.open(sUrl, sName, "width=" + iWidth + ",height=" + iHeight + ",top=" + iTop + ",left=" + iLeft + ",toolbar=" + sToolbar + ",resizable=" + sResizable + ",scrollbars=" + sScrollbars);
  oWindow.focus();
  
  return oWindow;
  
}

