////////////////////////////////////////////////////////////////
//
// wScript.js 5.0.1
// erstellt durch Scholl Communications AG, 77694 Kehl, www.scholl.de
// erstellt mit Weblication Content Management Server, www.weblication.de
//
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//
// Anzupassende Variablen:
//
////////////////////////////////////////////////////////////////

var mailPostfix = '@domain.dd';

////////////////////////////////////////////////////////////////
//
// Beschreibung: Browsererkennung
//
////////////////////////////////////////////////////////////////

var ns  = (document.layers) ? 1 : 0;
var ie  = (document.all) ? 1 : 0;
var dom = (document.getElementById) ? 1 : 0;
var mac = (navigator.platform.indexOf("Mac") != -1) ? 1 : 0;
var gecko     = (navigator.userAgent.indexOf("Gecko") != -1) ? 1 : 0;
var geckoVers = parseFloat(navigator.userAgent.replace(/.*rv:(\d+\.\d+).*/, '$1'));
var ieVers    = navigator.appVersion.substring(navigator.appVersion.lastIndexOf("MSIE") + 4,navigator.appVersion.lastIndexOf("MSIE") + 8);

////////////////////////////////////////////////////////////////
//
// Beschreibung: Oeffnet ein Popup-Fenster
//
////////////////////////////////////////////////////////////////

function openPopup(url){

 if(debugMode == 1){
  alert(url);
 }

 window.open(url, "popup", optionsPopup);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Oeffnet ein Popup-Fenster vom Typ 1
//
////////////////////////////////////////////////////////////////

function openPopup1(url){

 if(debugMode == 1){
  alert(url);
 }

 window.open(url, "popup1", optionsPopup1);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Oeffnet ein Popup-Fenster vom Typ 2
//
////////////////////////////////////////////////////////////////

function openPopup2(url){

 if(debugMode == 1){
  alert(url);
 }

 window.open(url, "popup2", optionsPopup2);
}


////////////////////////////////////////////////////////////////
//
// Beschreibung: Zeigt die Druckansicht an
//
////////////////////////////////////////////////////////////////

function wShowPrintpreview(){  

  var url = location.href;
  var anchor = location.hash;

  url = url.replace(anchor, '');
  
  if(url.indexOf('?') >= 0){
    url += '&viewmode=print';
  }
  else{
    url += '?viewmode=print';    
  }
  
  openWindow(url, 'wPrintpreview', 'width=768,height=520,scrollbars=yes');
}

/*********************************************************************************/
//
// Öffnet ein Fenster
//
// @param string Url
//
// @param string Name des Fensters
//
// @param string Optionen
//
// @return window			
//
/*********************************************************************************/

function openWindow(url, name, options){

  var regWidth = /width=(\d+)/;
  regWidth.exec(options);
  width = RegExp.$1; 
  if(width == ''){   
    width = 640; 
  }

  var regHeight = /height=(\d+)/;
  regHeight.exec(options);
  height = RegExp.$1;       
  if(height == ''){   
    height = 480; 
  }    


  if(!name && !width && !height && !options){
    return window.open(url, name);
    return;
  }
  //Zusaetzliche Optionen angeben
  if(!options){
    options = ',resizable=no,scrollbars=no,status=no';
  }
  //Position zentriert festlegen
  
  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  //alert('top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);<<<
  return window.open(url, name, 'top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Druckt das aktuelle Dokument
//
////////////////////////////////////////////////////////////////

function printDocument(){  

  if(document.all && navigator.appVersion.substring(22,23)==4) {
    self.focus();
    var OLECMDID_PRINT = 6;
    var OLECMDEXECOPT_DONTPROMPTUSER = 2;
    var OLECMDEXECOPT_PROMPTUSER = 1;
    var WebBrowser = '<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
    document.body.insertAdjacentHTML('beforeEnd',WebBrowser);
    WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
    WebBrowser1.outerHTML = '';
  }
  else{
    window.print();  
  }
}

/*********************************************************************************/
//
// @description Ruft eine URL auf
//
// @parameter   String Aufzurufende Url
//
// @parameter   Function Nach der Anfrage aufzurufende Funktion
//
// @return      void
//
/*********************************************************************************/

function getUrl(url, functionResult){

  var requestObject = new wRequestObject(url, functionResult);
}

/*********************************************************************************/
//
// @description Ruft eine URL auf
//
// @parameter   String Aufzurufende Url
//
// @parameter   Function Nach der Anfrage aufzurufende Funktion
//
// @return      void
//
/*********************************************************************************/

function wRequestObject(url, functionResult){

  if(typeof functionResult == 'function'){
    var id              = resultFunctions.length;
    //alert(id);

    this.request        = null;

    if(document.all){
      this.request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
      this.request = new XMLHttpRequest();
    }

    resultFunctions.push(functionResult);
    //alert('push' +  requests.length);

    requests.push(this.request);
    this.request.open('GET', url, true);

    this.request.onreadystatechange = function(){
      var requestObject = requests[id];
      if(requestObject.readyState == 4){
        if(requestObject.status == '200'){
          resultFunctions[id](requestObject.responseText);
        }
      }
    }

    this.request.send('');
  }
}

/***************************************************
* @info  : Oeffnet eine URL in einem popUp         *
* @param : url   : Zu oeffnende URL                *
*          width : Breite des Fensters             *
*          height: Hoehe des Fensters              *
* @return: -                                       *
***************************************************/

function wOpenPopupURL(url, width, height){
  var name = '';
  
  if(width == '' || width == ' '){
    width = 786;
  }
  if(height == '' || height == ' '){
    height = 677;
  }
  url = url.replace(/&amp;/g, '&');
  options = ',location=no, menubar=no,toolbar=no,resizable=no,scrollbars=no,status=no';
  width   = parseInt(width);
  height  = parseInt(height);
  //Position zentriert festlegen
  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  window.open(url, name, 'top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);
}

/***************************************************
* @info  : Oeffnet ein Bild in einem popUp         *
* @param : url   : Zu oeffnende URL                *
* @return: -                                       *
***************************************************/

function wOpenImageAdaptSize(url){

  var name = '';
  var path = '/weblication/grid/scripts/wImage.php?action=getImageSize&path='+url;
  curImageUrl = url;
  getUrl(path, wOpenImageAdaptSizeResponse);
}

function wOpenImageAdaptSizeResponse(response){
  
  var name = '';
  var size = response;
  if(response == ''){
    size = 'width="800" height="600"';
  }
  
  var regex = /(?:")(\d+?)(?:").*(?:")(\d+?)(?:")/;
  var match = size.match(regex);d 
  
  if(match){
    width   = match[1];
    height  = match[2]; 
  }
  else{
    width   = 800;
    height  = 600;
  }
  
  curImageUrl = curImageUrl.replace(/&amp;/g, '&');
  options = ',location=no, menubar=no,toolbar=no,resizable=no,scrollbars=no,status=no';
  width   = parseInt(width);
  height  = parseInt(height);
  //Position zentriert festlegen
  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  window.open(curImageUrl, name, 'top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Generiert Spam-sichere Email
//
////////////////////////////////////////////////////////////////

function wWriteMail(name){
 location.href = 'mailto:' + name + '@scholl.de';
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Druckt das aktuelle Dokument
//
////////////////////////////////////////////////////////////////

function wPrintDocument(){

  if(document.all && navigator.appVersion.substring(22,23)==4) {
    self.focus();
    var OLECMDID_PRINT = 6;
    var OLECMDEXECOPT_DONTPROMPTUSER = 2;
    var OLECMDEXECOPT_PROMPTUSER = 1;
    var WebBrowser = '<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
    document.body.insertAdjacentHTML('beforeEnd',WebBrowser);
    WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
    WebBrowser1.outerHTML = '';
  }
  else{
    window.print();  
  }
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Generiert Spam-sichere Email
//
////////////////////////////////////////////////////////////////

function wSendMailNospam(name){

  location.href = 'mailto:' + name + mailPostfix;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Setzt die Sprachversion
//
////////////////////////////////////////////////////////////////

function wSetLanguageVersion(langVersion, redirectUrl){
  var url = '/weblication/grid/scripts/wSystem.php?action=setLanguageVersion&redirectUrl=' + decodeURI(redirectUrl) + '&langVersion=' + langVersion;
  location.href = url;
}

function toggleLanguageFinder(){
  var languageSwitchDiv = document.getElementById('languageSwitch');
  if (languageSwitchDiv.style.display != 'block'){
    languageSwitchDiv.style.display = 'block';
  } else {
    languageSwitchDiv.style.display = 'none';
  }
}

function hoverLanguage(langID){
  var curLangDiv = document.getElementById(langID);
  curLangDiv.className = 'languageVersionOver';
}

function outLanguage(langID){
  var curLangDiv = document.getElementById(langID);
  curLangDiv.className = 'languageVersion';
}


// function getElementStyle(elemID,styleID) {
//   var elem = document.getElementById(elemID);
//    if (elem.currentStyle){
//       return elem.currentStyle[styleID];
//     } else if (window.getComputedStyle) {
//       var compStyle = window.getComputedStyle(elem, "");
//       return compStyle.getPropertyValue(styleID);
//     }
//   return "";
// }


function getElementStyle(elemID,styleID) {
  var elem = document.getElementById(elemID);
  currentHeight = elem.offsetHeight;
  return currentHeight;
}


function setElementStyle(elemID,styleID,value) {
  var elem = document.getElementById(elemID);
  elem.style.height = value+'px';
}

function stripStyleString(styleValue){
  var pos = styleValue.lastIndexOf("px");
  if (pos != '-1'){
    var styleValueNum = parseInt(styleValue.substring(0,pos));
    return styleValueNum;
  } else {
    var styleValueNum = parseInt(styleValue);
    return styleValue;
  }
}

function apaptSizeWindows(){
  var minHeight = 400;
  if (ie){
    var customOffset = 32;
    var customOffsetLeft = 4;
  } else {
    var customOffset = 32;
    var customOffsetLeft = 4;
  }
  
  var windowLeft          = document.getElementById('blockLeftInner');
  var windowMiddle        = document.getElementById('blockContentInner');
  var windowLeftHeight    = getElementStyle('blockLeftInner','height');
  var windowMiddleHeight  = getElementStyle('blockContentInner','height');
  if (document.getElementById('blockContentTopInner')){
    var windowMiddleTopHeight  = getElementStyle('blockContentTopInner','height');
    middleHeightTotal = windowMiddleTopHeight+windowMiddleHeight+customOffset;
  } else {
    middleHeightTotal = windowMiddleHeight;
  }

  if (windowLeftHeight<middleHeightTotal){
    plusHeight = middleHeightTotal+customOffsetLeft;
    setElementStyle('blockLeftInner','height',plusHeight);
  } else if (windowLeftHeight>middleHeightTotal){
    diffHeight = windowLeftHeight-middleHeightTotal;
    plusHeight = windowMiddleHeight+diffHeight;
    setElementStyle('blockContentInner','height',plusHeight);
  } else {
  }
  
  finalLeftHeight = getElementStyle('blockLeftInner','height');
  finalContentHeight = getElementStyle('blockContentInner','height');
  if (document.getElementById('blockContentTopInner')){
    finalContentTopHeight = getElementStyle('blockContentTopInner','height');
    finalContentTotalHeight = finalContentHeight+finalContentTopHeight;
  } else {
    finalContentTotalHeight=finalContentHeight;
  }
  //alert ('links.'+finalLeftHeight+'\n'+'mitte.'+finalContentTotalHeight)
}

function tryResize(mode){
  window.setTimeout("apaptSizeWindows2('"+mode+"')",250);
  //window.setTimeout("apaptSizeWindows2()",500);
}

function apaptSizeWindows2(mode){

  if (ie){
    var customOffset = 10;
  } else {
    var customOffset = 0;
  }
  spaceHeight             = 26;
  var windowAllHeightSrc  = getElementStyle('blockLeftContentRight','height');
  var windowAllHeight     = windowAllHeightSrc - spaceHeight;
  var windowMiddleHeight  = getElementStyle('blockContent','height');
  diffMiddleMain          = windowAllHeight-windowMiddleHeight;
  var windowTopHeight     = 134;

  if (mode == 'start'){
    var windowRightHeight   = getElementStyle('blockRight','height');
    diffRightMain           = windowAllHeight-windowRightHeight;


    if (diffRightMain > 0){
      plusHeight = windowRightHeight+diffRightMain;
      setElementStyle('blockRight','height',plusHeight);
    } else if (diffMiddleMain > 0) {
      if (document.getElementById('blockContentTopInner')){
        plusHeight = windowMiddleHeight+diffMiddleMain-windowTopHeight-customOffset+20;
      } else {
        plusHeight = windowMiddleHeight+diffMiddleMain+10;
      }
      setElementStyle('blockContent','height',plusHeight);
    }

  } else {
    var windowLeftHeight    = getElementStyle('blockLeftInner','height');
    diffLeftMain            = windowAllHeight-windowLeftHeight;

    if (diffLeftMain > 0){
      plusHeight = windowLeftHeight+diffLeftMain;
      setElementStyle('blockLeftInner','height',plusHeight);
    } else if (diffMiddleMain > 0) {
      if (document.getElementById('blockContentTopInner')){
        plusHeight = windowMiddleHeight+diffMiddleMain-windowTopHeight-customOffset+20;
      } else {
        plusHeight = windowMiddleHeight+diffMiddleMain+20;
      }
      setElementStyle('blockContent','height',plusHeight);
    }

  }

  if (windowAllHeight < 400){
    var setDefault = 400;
  }


}

function openContactWindow(){
  windowToClose = document.getElementById('kontaktFormularNewsletter');
  windowToClose.style.display = 'block';
}

