/* DBAG JavaScript Library */
var ns4 = (document.layers)?1:0;
var dom = (document.getElementById && !document.all);
var ie4 = (document.all)?1:0;
var opr = navigator.userAgent.indexOf("Opera");
var moz = navigator.appName=="Netscape" && navigator.appCodeName=="Mozilla" && !document.all;
var mac = navigator.userAgent.indexOf("Mac")!= -1;

window.status = "DB Carsharing"; // writes Javascript default message in browser status bar

// calculate the height of a layer
function getDivsHeight() {
  var iDivsHeight = 0;
  for(var i=0; i < arguments.length; i++) {
    if (document.getElementById(arguments[i]))
      iDivsHeight += document.getElementById(arguments[i]).offsetHeight;
  }
    // iDivsHeight = iDivsHeight+150;
    return iDivsHeight;
}

// set the height of the back main layer in order to move the footer
function setDivContentMinHeight() {
  var oDivcontent, iWinInnerHeight, tmpHeight;
  var mozCorrection = moz ? -1 : 0;
    oDivcontent = document.getElementById(arguments[0]); //assumes first passed object as name for the content area layer
  oStopperDiv = document.getElementById(arguments[1]); // retrieve stopper div object
  
  iWinInnerHeight = document.body.clientHeight; // store window height of the inner browser area temporarily
    //alert('iWinInnerHeight: '+iWinInnerHeight+' - ');
  if (arguments.length == 4) {
    tmpHeight = getDivsHeight(arguments[2], arguments[3]);
  }
  else if (arguments.length == 3) {
    tmpHeight = getDivsHeight(arguments[2]);
  } // calculate the height of the page elements except the content area; using the getDivsHeight function
  
  if(oStopperDiv) {
      if (iWinInnerHeight > (tmpHeight + oStopperDiv.offsetTop + oStopperDiv.offsetHeight)) {
        oDivcontent.style.height = iWinInnerHeight - tmpHeight + mozCorrection;
      } else {
        oDivcontent.style.height = oStopperDiv.offsetTop + oStopperDiv.offsetHeight + mozCorrection;
      }
  }
    //if there is more space on the page than the header and footer height, than the main layer is set to a new height
}

// Wrapper function to apply the changes to the footer / main layers if DOM browser detected
// loadEvent triggers a bugfix for MSIE 5.0 and footer bar placement, "true" is for function calls in onLoad events,
// "false" is default and for onResize events

function init(loadEvent) {
  /* haben wir ein Logo unten links, müssen wir schauen, wie's reinpasst
     und ggf. den Inhalt etwas aufziehen
  */
  navEndObj = document.getElementById('navBorder');
  contObj = document.getElementById('content');

  if(navEndObj.offsetHeight >= (contObj.offsetHeight-5) && document.getElementById('navlogo'))
    {
      contObj.style.height = navEndObj.offsetHeight+50+'px';
    }

  if (!ns4) {
    setDivContentMinHeight('main', 'stopper', 'header', 'footer');
    footero=document.getElementById('footer');
    if (footero)
      footero.style.visibility='visible';
  }
  if (loadEvent && ie4 && !ns4 && ((navigator.appVersion.indexOf("MSIE 5.0")!= -1) || (mac))) {
    window.resizeBy(1,1);
    window.resizeBy(-1,-1);
  }
  if (loadEvent)
    initImages(); // preload all portalnavigation images
}

// Wrapper function to apply the changes to the footer on the startpage
// only used in startpage because of different div-container structure
function initStart(loadEvent) {
  if (!ns4) {
    setDivContentMinHeight('content', 'stopper', 'header', 'footer');
    footero=document.getElementById('footer');
    footero.style.visibility='visible';
  }
  if (loadEvent && ie4 && !ns4 && ((navigator.appVersion.indexOf("MSIE 5.0")!= -1) || (mac))) {
    window.resizeBy(1,1);
    window.resizeBy(-1,-1);
  }
}

// onMouseOvers for the PortalNavigation
var initSet = false;

function initImages() {
  if (numPortalImages && imgInactNames && imgActNames) {
    for (var i=0; i< numPortalImages; i++) {
      var tempImage = new Image();
      tempImage.src = imgInactNames[i];
      tempImage.src = imgActNames[i];
    }
  }
}

function actImg(obj, num) {
  if (document.images && !ns4 && imgActNames) {
    document.getElementById(obj.id).src = imgActNames[num];
  }
}

function inActImg(obj, num) {
  if (document.images && !ns4 && imgInactNames) {
    document.getElementById(obj.id).src = imgInactNames[num];
  }
}

// popup window opener service function for standard content pages and large view on pictures
var marginWidth = 50;
var marginHeight = 300;
var top = 60;
var left = 80;
var picLarge;

function picLrgOpn(src, width, height) {
  var winWidth = width + marginWidth;
  var winHeight = height + marginHeight;
    
  if (picLarge!=null && !picLarge.closed) {
    picLarge.resizeTo(winWidth, winHeight);
    picLarge.location.href=src;
    picLarge.focus();
  } else {
    eval('picLarge = window.open(src, "_blank", "width=' + winWidth + ',height=' + winHeight + ',top=' + top + ',left=' + left + ',toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");');	
    picLarge.resizeTo(winWidth, winHeight);
    picLarge.focus();
  }
}

// print view opener
var printPopup;
var printPopupHeight=510;
var printPopupWidth=603;

function printOpen(src) {
  if (printPopup!=null && !printPopup.closed) {
    printPopup.location.href=src;
    printPopup.focus();
  } else {
    eval('printPopup = window.open(src, "_blank", "width=' + printPopupWidth + ',height=' + printPopupHeight + ',top=' + top + ',left=' + left + ',toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");');
    printPopup.focus();
  }	
}

// recommend view opener
var recommendPopup;
var recommendPopupHeight=510;
var recommendPopupWidth=401;

function recommendOpen(src) {
  if (recommendPopup!=null && !recommendPopup.closed) {
    recommendPopup.location.href=src;
    recommendPopup.focus();
  } else {
    eval('recommendPopup = window.open(src, "_blank", "width=' + recommendPopupWidth + ',height=' + recommendPopupHeight + ',top=' + top + ',left=' + left + ',toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");');
    recommendPopup.focus();
  }
}
  
// switch Element to visible when javascript is enabled, example: button bar in popup
function showElement(elemName) {
    if (!ns4) {
        elem=document.getElementById(elemName);
        if (elem != null)
          elem.style.visibility='visible';
    }
}
// Set time and date as default for the ticketinfo-form on startpage
// Examples for 'strFormatDate':
// + dd.mm.yy --> 01.03.03 and 12.10.03
// + d.m.yyyy --> 1.3.2003 and 12.10.2003
// + yyyy/mm/dd --> 2003/03/01 and 2003/10/12
// ddd -- > dd , mmm --> mm, y --> yy, yyy --> yyyy 
// Examples for 'strFormatTime':
// + hh:mm --> 06:09 and 13:32
// + h:m --> 6:09 and 13:32
function setTimeAndDate(strFormatDate,strFormatTime,strFormName,strElementNameDate,strElementNameTime)
{
  var oToday = new Date();
  var day = oToday.getDate();
  var month = oToday.getMonth()+1;
  var year = oToday.getFullYear()+"";
  var hours = oToday.getHours();
  var minutes = oToday.getMinutes();

  strFormatDate = strFormatDate.toLowerCase();
  strFormatTime = strFormatTime.toLowerCase();
  
  regTemp = strFormatDate.match(/d/g);
  if(regTemp.length>=2)if(day<10)day="0"+day;
  strFormatDate = strFormatDate.replace(/d+/,day);
  
  regTemp = strFormatDate.match(/m/g);
  if(regTemp.length>=2)if(month<10)month="0"+month;
  strFormatDate = strFormatDate.replace(/m+/,month);

  regTemp = strFormatDate.match(/y/g);
  if(regTemp.length<3)year= year.slice(2);
  strFormatDate = strFormatDate.replace(/y+/,year);
  
  regTemp = strFormatTime.match(/h/g);
  if(regTemp.length>=2)if(hours<10)hours="0"+hours;
  strFormatTime = strFormatTime.replace(/h+/,hours);

  if(minutes<10)minutes="0"+minutes;
  strFormatTime = strFormatTime.replace(/m+/,minutes);

  if(dom)
  {
    oFormElementDate = document.getElementById(strElementNameDate);
    oFormElementTime = document.getElementById(strElementNameTime);
    oFormElementDate.value = strFormatDate;
    oFormElementTime.value = strFormatTime;
  }
  else
  {
    document.forms[strFormName].elements[strElementNameDate].value=strFormatDate;
    document.forms[strFormName].elements[strElementNameTime].value=strFormatTime;
  }
}
/* Waitscreen anzeigen delay ist erstmal nicht implementiert */
function showWaitScreen(formname, show) {  
    if(document.forms[formname]) {     
        document.forms[formname].submit();
    }
    if(show > 0) {
        showWaitScreen2();
    }
}
        
function showWaitScreen2()
{   
    document.getElementsByTagName("html")[0].style.margin = "0";
    document.getElementsByTagName("html")[0].style.minHeight = "100%";
    document.getElementsByTagName("html")[0].style.height = "100%";
    document.getElementsByTagName("body")[0].style.margin = "0";
    document.getElementsByTagName("body")[0].style.minHeight = "100%";
    document.getElementsByTagName("body")[0].style.height = "100%";
    document.getElementById("doc").style.height = "100%";
    var x = '<table height="100%" valign="middle" align="center" class="content">'
        +'<tbody><tr><td valign="middle" align="center">'
        +'<div><img border="0" src="/kundenbuchung/templates/3/layout/bilder/logo_mnl.png" alt=""><\/div>'
        +'<div>Ihre Daten werden verarbeitet<\/div>'
        +'<div><img src="/kundenbuchung/templates/3/layout/bilder/wait.gif" width="300" height="8" border="0"><\/div>'
        +'<div>Bitte haben Sie etwas Geduld.<\/div>'
        +'<\/td><\/tr><\/tbody><\/table>';  
    document.getElementById("doc").innerHTML=x;
}
