////////////////////////////////////////////////////////////////
//
// 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 = '@hbh-kliniken.de';

////////////////////////////////////////////////////////////////
//
// 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(printUrl){  

  var url = location.href;
  if(printUrl != ''){
    url = printUrl;
  }
  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);
}


function wOpenPopupVideo(src, width, height){
  var name = '';

  if(width == '' || width == ' '){
    width = 786;
  }
  if(height == '' || height == ' '){
    height = 677;
  }
  var src       = src.replace(/&amp;/g, '&');
  var srcFrame  = '/hbh/wGlobal/content/areas/popup.area.php';
  var url       = srcFrame+'?vid='+src;
  
  //alert (url);
  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/grid5/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';
  location.href = 'mailto:' + name + mailPostfix;
}

////////////////////////////////////////////////////////////////
//
// 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: Generiert Spam-sichere Email mit frei definierbarer Domain.
// eingesetzt im Modul Mitarbeiterprofil
//
////////////////////////////////////////////////////////////////

function wSendMailNospam2(name, domain){

  location.href = 'mailto:' + name + '@' + domain;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Setzt die Sprachversion
//
////////////////////////////////////////////////////////////////

function wSetLanguageVersion(langVersion, redirectUrl){
  //var url = '/weblication/grid5/scripts/wSystem.php?action=setLanguageVersion&redirectUrl=' + escape(redirectUrl) + '&langVersion=' + langVersion;
  var url = '/weblication/grid5/scripts/wSystem.php?action=setLanguageVersion&redirectUrl=' + decodeURI(redirectUrl) + '&langVersion=' + langVersion;
  location.href = url;
}

function languageSelector(id) {
	if(document.getElementById(id)) {
		if(document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == '') {
			document.getElementById(id).style.display = 'block';
		} else {
			document.getElementById(id).style.display = 'none';
		}
	}
}


////////////////////////////////////////////////////////////////
//
// JQuery-Funktionen
//
////////////////////////////////////////////////////////////////

jQuery.noConflict();
     
 // Use jQuery via jQuery(...)
jQuery(document).ready(function($){
  jQuery("ul.toggle li h2").css('cursor', 'pointer');
  jQuery("ul.toggle li h2").click(function() { 
    
    var hiddenArea = jQuery(this).parent().find('.fadeIn');
    if (hiddenArea.is(":hidden")) {
      if(jQuery(this).parent().is(".first")){
        jQuery(this).parent().css('border-top', '1px solid #ffffff');
      }
      jQuery(this).parent().addClass('grey');
      hiddenArea.slideDown("slow");
    } else {
      if(jQuery(this).parent().is(".first")){
        jQuery(this).css('border-top', '0px none #ffffff');
      }
      hiddenArea.slideUp("slow");
      jQuery(this).parent().removeClass('grey');
    }
  });
  
  jQuery('a.druck').click(function(e) { 
    e.preventDefault();
    wShowPrintpreview(jQuery(this).attr('href'));
  });
  
  if(jQuery('#ecard').length > 0){
	  jQuery('#ecard').fancybox({
	    'padding': 20,
	    'hideOnContentClick': false,
	    'frameHeight': 285,
	    'overlayOpacity': true,
	    'overlayShow': true,    
	    'callbackOnShow': function(){   
		  sendECard();
	    },   
	    'overlayOpacity': 0.2    
	  });
  }
});

function sendECard(){
	  jQuery('#ecardForm').submit(function(e) {
	   e.preventDefault();

	  	/* Input Values sammeln */
	  	var emailto = jQuery('input#email-to').val();
	  	var emailtoName = jQuery('input#name-to').val();
	  	var emailfrom = jQuery('input#email-from').val();
	  	var emailfromName = jQuery('input#name-from').val();
	  	
	  	var emailtoError 	 = jQuery('input#email-to-error').val();
	  	var emailfromError = jQuery('input#email-from-error').val();
	  	var nametoError 	 = jQuery('input#name-to-error').val();
	  	var namefromError = jQuery('input#name-from-error').val();
	  	
	  	var messageOK = jQuery('input#empfehlen-message-ok').val();
	  	var messageNOK = jQuery('input#empfehlen-message-nok').val();
	  
	  	/* Validierung und Fehlermeldung */
	  	
	  	if (emailfrom === '' || isMail(emailfrom) == false) {
	  		jQuery("label#email-from-label")
	  			.text(emailfromError)
	  			.css({
	  				'color': '#F00',
	  				'font-weight': 'bold'
	  		});
	  		jQuery('input#email-from').focus();
	  		return false;
	  	}
	  	
	  	if (emailfromName === '') {
	  		jQuery("label#name-from-label")
	  			.text(namefromError)
	  			.css({
	  				'color': '#F00',
	  				'font-weight': 'bold'
	  		});
	  		jQuery('input#name-from').focus();
	  		return false;
	  	}
	  	
	  	if (emailto === '' || isMail(emailto) == false) {
	  		jQuery("label#email-to-label")
	  			.text(emailtoError)
	  			.css({
	  				'color': '#F00',
	  				'font-weight': 'bold'
	  		});
	  		jQuery('input#email-to').focus();
	  		return false;
	  	}
	  	if (emailtoName === '') {
	  		jQuery("label#name-to-label")
	  			.text(nametoError)
	  			.css({
	  				'color': '#F00',
	  				'font-weight': 'bold'
	  		});
	  		jQuery('input#name-to').focus();
	  		return false;
	  	}
	  	
	  	
	  	/* Form Submit mit AJAX */
	  	//var parameters 	= 'ajax=j&page='+window.location.pathname+'&email-to='+ emailto + '&email-from=' + emailfrom;
	  	/* alert (parameters); return false; */
	  	
	  	/* get URL */
	  	var pathname = "/hbh/wGlobal/scripts/php/actions.php?action=ecard&page="+window.location.pathname;
	  	
	    jQuery.ajax({
	      type: "POST",
	  		url: pathname,
	      data: jQuery(this).serialize(),
	      success: function(retCode) {
	      	retCode = trimStr(retCode);
	      	if(retCode == 1) {
	      		jQuery.fn.fancybox.close();   
	      	} else {
	      		alert(prepareAlert(messageNOK));
	      	}
	  
	  			/* Reset form nach Übermittlung */
	  			jQuery(':input','#ecardForm')
	  			 .not(':button, :submit, :reset, :hidden')
	  			 .val('')
	  			 .removeAttr('checked')
	  			 .removeAttr('selected');
	  			
	  			/* Verstecke DIV nach Übermittlung */ 
	  			//jQuery('#tellafriend').addClass('hidden');
	      }
	    });
	    return true;;
	  });
	}

	function trimStr(zeichenkette) {
	  // Erst führende, dann Abschließende Whitespaces entfernen
	  // und das Ergebnis dieser Operationen zurückliefern
	  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
	}

	function prepareAlert(s) {
		var sendBack = "";
		if(s.indexOf("LINEBREAK") > 0) {
			var sParts = s.split("LINEBREAK");
			for(i=0; i<sParts.length; i++) {
				if(i < (sParts.length-1)) {
					sendBack += sParts[i]+"\n";
				} else {
					sendBack += sParts[i];
				}
			}
		} else {
			sendBack= s;
		}
		return(sendBack);
	}

	function isMail(s){
		var a = false;
		var res = 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})$');
			res = (reg.test(s));
		} else {
			res = (s.search('@') >= 1 &&
			       s.lastIndexOf('.') > s.search('@') &&
			       s.lastIndexOf('.') >= s.length-5)
		}
		return(res);
	}

