////////////////////////////////////////////////////////////////
//
// 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 = '@rapp.ch';
//
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//
// Beschreibung: Browsererkennung
//
////////////////////////////////////////////////////////////////

var browser = new browserDetection();
function browserDetection(){
  /*
  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;
  */
  this.useragent       = navigator.userAgent.toLowerCase();

  this.browserName     = "undetected";
  this.browserVersion = "undetected";

  this.isMozilla       = false;
  this.isNetscape     = false;
  this.isNetscape6     = false;
  this.isNetscape7     = false;
  this.isIE           = false;
  this.isIE6           = false;
  this.isIE7           = false;
  this.isIE8           = false;
  this.isFF           = false;
  this.isFF2           = false;
  this.isFF3           = false;
  this.isFF35         = false;
  this.isChrome       = false;
  this.isOpera         = false;
  this.isSafari       = false;

  // Mozilla
  if(this.useragent.search(/mozilla/) != -1) {
    this.isMozilla       = true;
    this.browserName     = "Mozilla";
    this.browserVersion = parseFloat(/(mozilla[^\s]*)/.exec(this.useragent)[0].split("/")[1]);
  }

  // Netscape
  if(this.useragent.search(/netscape/) != -1) {
    this.browserName     = "Netscape";
    this.browserVersion = parseFloat(/(firefox[^\s]*)/.exec(this.useragent)[0].split("/")[1]);
    var browserVersionTest = ""+this.browserVersion;
    if(browserVersionTest.substring(0, 1) == 7) {
      this.isNetscape7   = true;
    } else if(browserVersionTest.substring(0, 1) == 6) {
      this.isNetscape6   = true;
    } else if(browserVersionTest.substring(0, 1) <= 5) {
      this.isNetscape   = true;
    }
  }

  // IE
  if(this.useragent.search(/msie/) != -1) {
    this.isIE           = true;
    this.browserName     = "IE";
    this.browserVersion = parseFloat(/(msie[^;]*)/.exec(this.useragent)[0].split(" ")[1]);
    var browserVersionTest = ""+this.browserVersion;
    if(browserVersionTest.substring(0, 1) == 8) {
      this.isIE8         = true;
    } else if(browserVersionTest.substring(0, 1) == 7) {
      this.isIE7         = true;
    } else if(browserVersionTest.substring(0, 1) <= 6) {
      this.isIE6         = true;
    }
  }

  // Firefox
  if(this.useragent.search(/firefox/) != -1) {
    this.isIE           = true;
    this.browserName     = "Firefox";
    this.browserVersion = parseFloat(/(firefox[^\s]*)/.exec(this.useragent)[0].split("/")[1]);
    var browserVersionTest = ""+this.browserVersion;
    if(browserVersionTest.substring(0, 3) == "3.5") {
      this.isFF35       = true;
    } else if(browserVersionTest.substring(0, 1) == 3) {
      this.isFF3         = true;
    } else if(browserVersionTest.substring(0, 1) <= 2) {
      this.isFF2         = true;
    }
  }

  // Chrome
  if(this.useragent.search(/chrome/) != -1) {
    this.isChrome       = true;
    this.browserName     = "Chrome";
    this.browserVersion = parseFloat(/(chrome[^\s]*)/.exec(this.useragent)[0].split("/")[1]);
  }

  // Opera
  if(this.useragent.search(/opera/) != -1) {
    this.isOpera         = true;
    this.browserName     = "Opera";
    this.browserVersion = parseFloat(/(opera[^\s]*)/.exec(this.useragent)[0].split("/")[1]);
  }

  // Safari
  if(this.useragent.search(/khtml/) != -1) {
    this.isSafari       = true;
    this.browserName     = "Safari (Win)";
    this.browserVersion = parseFloat(/(version[^\s]*)/.exec(this.useragent)[0].split("/")[1]);
  }
}



////////////////////////////////////////////////////////////////
//
// 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: Prüft, ob die Plichtfelder im Formular korrekt ausgefüllt worden sind.
//
////////////////////////////////////////////////////////////////////////////////////////

function checkForm(validatorsNameStr, validatorsTypeStr, validatorsIdentStr, validatorsMsgStr) {
  var checkEmail   = /.*\@.*\.\w+/i;

  var errorName       = new Array();

  var sendFormular     = true;
  var validatorsName   = validatorsNameStr.split("|");
  var validatorsType   = validatorsTypeStr.split("|");
  var validatorsIdent = validatorsIdentStr.split("|");
  var validatorsMsg    = validatorsMsgStr.split("|");

  if(validatorsName.length > 0) {
    for(i=0; i<validatorsName.length; i++) {
      jQuery('input#'+validatorsName[i]).removeClass('inputError');

      var value = jQuery('input#'+validatorsName[i]).val();
      if(validatorsType[i] == 'email') {
        if(checkEmail.test(value) == false) {
          errorName.push(validatorsName[i]);
        }
      } else if(validatorsType[i] == 'captcha' || validatorsType[i] == 'required') {
        if(value == '') {
          errorName.push(validatorsName[i]);
        }
      } else if(validatorsType[i] == '==') {
        var valueIdent = jQuery('input#'+validatorsIdent[i]).val();

        if(valueIdent == '' || value != valueIdent) {
          errorName.push(validatorsName[i]);
          errorName.push(validatorsIdent[i]);
        }
      }
    }
  }
  if(errorName.length > 0) {
    for(i=0; i<errorName.length; i++) {
      errorName[i] = trim(errorName[i]);
      if(errorName[i] != "" && jQuery('input#'+errorName[i])) {
        jQuery('input#'+errorName[i]).addClass('inputError');
        jQuery('input#'+errorName[i]).focus();
      }
    }
    sendFormular = false;
  }
  return sendFormular;
}

////////////////////////////////////////////////////////////////
//
// setzt im Zusammenhang mit einem Formular festgestellte Fehler
//
////////////////////////////////////////////////////////////////

function setFormErrors(errorNameStr) {
  var errorName   = errorNameStr.split("|");
  if(errorName.length > 0) {
    for(i=0; i<errorName.length; i++) {
      jQuery('input#'+errorName[i]).addClass('inputError');
      jQuery('input#'+errorName[i]).focus();
    }
  }
}

////////////////////////////////////////////////////////////////
//
// Zeichenkette trimmen
//
////////////////////////////////////////////////////////////////
function trim(zeichenkette) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

////////////////////////////////////////////////////////////////
//
// E-Mail auf Gültigkeit prüfen
//
////////////////////////////////////////////////////////////////
function checkEmail(email) {
  var sendBack = false;

  var a   = false;
  if(typeof(RegExp) == 'function') {
    var b = new RegExp('abc');
    if(b.test('abc') == true){
      a = true;
    }
  }

  if(a == true) {
    reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                     '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                     '(\\.)([a-zA-Z]{2,4})$');
    sendBack = (reg.test(email));
  } else {
    sendBack = (email.search('@') >= 1 && email.lastIndexOf('.') > email.search('@') && email.lastIndexOf('.') >= email.length-5);
  }
  //alert(email+"\n"+sendBack);
  return sendBack;
}


////////////////////////////////////////////////////////////////
//
// Öffnet ein Popup-Fenster
//
////////////////////////////////////////////////////////////////

function wOpenPopupURL(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: Generiert Spam-sichere Email
//
////////////////////////////////////////////////////////////////

function wSendMailNospam(name){
  location.href = 'mailto:' + name + mailPostfix;
}

////////////////////////////////////////////////////////////////
//
// jQuery - Bereich
//
////////////////////////////////////////////////////////////////

var $j = jQuery.noConflict();

jQuery(document).ready(function() {
  //Fancybox
  jQuery("a[rel=fancybox]").fancybox({
    'hideOnContentClick': true,
    //'hideOnOverlayClick': true,
    //'showCloseButton': true,
    'overlayShow':true,
    'overlayOpacity': 0.5,
    'centerOnScroll': false
  });

  jQuery(".elementPictureLupeButton").mouseover(function() {
    jQuery(this).css('background', 'transparent url(/wGlobal-de/wGlobal/layout/images/icons/but_lupe_r.gif) no-repeat scroll 0 0');

  });
  jQuery(".elementPictureLupeButton").mouseout(function() {
    jQuery(this).css('background', 'transparent url(/wGlobal-de/wGlobal/layout/images/icons/but_lupe_n.gif) no-repeat scroll 0 0');
  });

  //Druckvorschau
  jQuery("#printpreviewLink").click(function(e) {
    e.preventDefault();

    var anchor  = location.hash;
    var url     = location.href.replace(anchor, '');

    if(url.indexOf('?') >= 0) {
      url += '&viewmode=print';
    } else {
      url += '?viewmode=print';
    }

    wOpenPopupURL(url, 'wPrintpreview', 'width=730,height=520,scrollbars=yes');
  });

  //Seite empfehlen
  jQuery("#tellafriendLink").fancybox({
    'hideOnContentClick': false,
    'frameWidth': 320,
    'frameHeight': 300,
    'overlayShow':true,
    'overlayOpacity': 0.5,
    'centerOnScroll': false
  });
});
