/*

Script umfasst:


1) ZMS open functions
2) externalLinkNotification.js
3) activex.js
4) externalLinkNotification.js

*/


// #############################################################################

// ### open_function:

// #############################################################################

function open_function(url,width,height,options)

  {

    if ( height > screen.availHeight || width > screen.availWidth) {

      if ( options.indexOf( "scrollbars=") < 0) {

        if ( height > screen.availHeight)

          height = screen.availHeight;

        if ( width > screen.availWidth)

          width = screen.availWidth;

        options += ",scrollbars=yes";

      }

    }

    self.msgWindow = open(url, "Window", "width=" + width + ",height=" + height

      + ",screenX=" + (screen.width-width)/2

      + ",screenY=" + (screen.height-height)/2

      + ",dependent=yes"

      + ",left=" + (screen.width-width)/2

      + ",top=" + (screen.height-height)/2

      + options

      );

    if (self.msgWindow) {

      self.msgWindow.focus();

      if (self.msgWindow.opener == null) self.msgWindow.opener = self;

    }

  }

// #############################################################################

// ### get_url:

// #############################################################################

function get_url (url, k0 ,v0 ,k1 ,v1 ,k2 ,v2 ,k3 ,v3 ,k4 ,v4 ) 

{
  if (k0 && v0) url += "?" + k0 + "=" + escape(v0);
  if (k1 && v1) url += "&" + k1 + "=" + escape(v1);
  if (k2 && v2) url += "&" + k2 + "=" + escape(v2);
  if (k3 && v3) url += "&" + k3 + "=" + escape(v3);
  if (k4 && v4) url += "&" + k4 + "=" + escape(v4);
  return url;
}




/**
* xmachina external link modifier (popup pre-site)
* @version 0.3
* @package Abbott Humira
* @copyright 2008 xmachina Gmbh, cw.
* @license Alle Rechte vorbehalten. All rights reserved.
* Oficial website: http://www.xmachina.de
* -------------------------------------------
* Mofifies all external links to open a popup window, showing 
* a generell corporate statement about external links.
* Creator: cw
* Email: deus@xmachina.de
*/


// config ( all )

    // host
        var exceptionHosts = new Array( 'humira-prof.stage.xmachina.de','humira-2009.stage.xmachina.de','humira-2009.dev.xmachina.de', 'humira-dev.xmachina.de', 'humira-prof.dev.xmachina.de', 'humira-relaunch.xmachina.de', 'www.abbott.de', 'www.humira.de', 'www.abbott-care.de', 'psoriasisuncovered.xmachina.de', 'www.psoriasisuncovered.de' );

    // language
        var liabilityStatement = 'Sie haben einen externen Link gew&auml;hlt. Wenn Sie auf "Weiter" klicken, verlassen Sie die Homepage von Abbott GmbH & Co. KG. Bitte beachten Sie, dass die Abbott GmbH & Co. KG f&uuml;r den Inhalt der verlinkten Seite nicht verantwortlich ist.';
        // var langStatement = '';
        var confirmRequest = 'Wollen Sie die externe Seite betreten?';
        var no = 'nein';
        var yes = 'ja';
        var confirmTitle = 'Externer Link';
        
    // document locations
            // var stylesheetUrl = 'externalLinkNotification.css';
            // var scriptUrl = 'externalLinkNotification.js';


// config ( popup )

    // dimension
        // notice
        var winw = 300;
        var winh = 350;
    
        // target
        var targetWidth = 800;
        var targetHeight = 600;
            
    // position
        var screenw = screen.availWidth;
        var screenh = screen.availHeight;
        
        // notice
        var pre_posx = (screenw / 2) - (winw / 2);
        var pre_posy = (screenh / 2) - (winh / 2);
        
        // target
        var targetLeft = (screenw / 2) - (targetWidth / 2);
        var targetTop = (screenh / 2) - (targetHeight / 2);


// main function

    function main () {

        // process
            if ( document.links ) {

                for ( var i = 0; i < document.links.length; ++i ) {
                   
                    var current = document.links[i];
                    
                    // check for external href
                        var isExternal = true;
                        
                        for ( var j = 0; j < exceptionHosts.length; ++j ) {

                            if ( current.hostname == exceptionHosts[j] ) {
                                    isExternal = false;
                            }
                        }  
                    
                    // check for protocol (no mailto)
                        if ( current.protocol != 'http:' ) {
                                isExternal = false;
                        }
                    
                    // attach onclick event
                        if ( isExternal == true ) {
                        
                            current.addEventListener?current.addEventListener("click", showLinkNotification, false):current.attachEvent("onclick", showLinkNotification);
                        }
                }
            }
    }
    

// helper functions

    // popup function
        function showLinkNotification (e) {
        
            // prevent default (open href)
                e.preventDefault?(e.preventDefault()):(e.returnValue=false);
            
            // get crossbrowser event target element ( srcElement )
                var targ;
                if (!e) var e = window.event;
                if (e.target) targ = e.target;
                else if (e.srcElement) targ = e.srcElement;
                if (targ.nodeType == 3) // defeat Safari bug
                    targ = targ.parentNode;
            
            // fix linked images
                if ( targ.tagName == 'IMG' ) {
                    targ = targ.parentNode;
                }
            
            // get targetUrl
                var targetUrl = targ.href;

            // build popup
                    
                NotificationWin = window.open( '', 'NotificationWin', 'width='+winw+', height='+winh+', left='+pre_posx+', top='+pre_posy+', resizable=yes ' );
                NotificationWin.document.write('<html>');
                NotificationWin.document.write('    <head>');
                NotificationWin.document.write('          <link rel="stylesheet" href="'+ stylesheetUrl +'" type="text/css" />');
                NotificationWin.document.write('    </head>');
                NotificationWin.document.write('    <body>');
                NotificationWin.document.write('        <div class="linkNotification">');
                NotificationWin.document.write('            <p class="title">'+confirmTitle+'</p>');
                NotificationWin.document.write('            <p>'+liabilityStatement+'</p>');
                NotificationWin.document.write('            <p class="title_confirm">'+confirmRequest+'</p>');
                NotificationWin.document.write('            <p class="url">'+targetUrl+'</p>');
                NotificationWin.document.write('            <p class="confirm">[ <a onclick="window.open( \''+ targetUrl +'\', \'targetWin\', \'resizable=yes, scrollbars=yes , width='+targetWidth+', height='+targetHeight+', left='+targetLeft+', top='+targetTop+' \' ); self.close(); return false;" target="_blank" href="'+ targetUrl +'">'+ yes +'</a> ] [ <a class="maincontentlink" href="javascript:self.close()">'+ no +'</a> ]</p>');
                NotificationWin.document.write('        </div>');
                NotificationWin.document.write('    </body>');
                NotificationWin.document.write('</html>');
                NotificationWin.document.close();
                NotificationWin.focus();
        }
  
  
// start main function onload  
    window.addEventListener?window.addEventListener("load", main, false):window.attachEvent("onload", main);
    

// vormals activex.js

function activex() {
  if(document.all) {
    for(i=0; i<document.getElementsByTagName("object").length; i++) {
      if(document.getElementsByTagName("object")
[i].getAttribute("classid")) {
kopie = document.getElementsByTagName("object")[i];
        elemente = "<object classid=\"" + kopie.getAttribute("classid") + "\" codebase=\"" + kopie.getAttribute("codebase") + "\" width=\"" + kopie.getAttribute("width") +   "\" height=\"" + kopie.getAttribute("height") + "\">"
j = 0;
        while(kopie.childNodes[j]) {
          elemente = elemente + "<param name=\"" + kopie.childNodes[j].getAttribute("name") + "\" value=\"" + kopie.childNodes[j].getAttribute("value") +     "\" />";
          j++;
        }
 elemente = elemente + "</object>";
        document.getElementsByTagName("object")[i].outerHTML = elemente;
      }
    }
  }
}

// vormals simpleFontsizer.js

function setFontSize(sizename){
	var element = document.getElementById("maincontentdiv");
	if(element){

		var csize = 16;

		if (window.getComputedStyle) {
			var styledeclaration = window.getComputedStyle(element, null);
			csize = styledeclaration.getPropertyValue("font-size");
		} else if (element.currentStyle) {
			csize = element.currentStyle.fontSize;
		}
		csize=csize.replace(/px/g, "");
		csize=parseInt(csize);
		if(sizename=='') sizename=16;
		if(csize=='') csize=16;
		if(sizename=='up'){
			csize = csize +1;
		} else if(sizename=='down')  {
			csize = csize -1;
		} else {
			csize = sizename;
		}
	//	alert(csize);
		element.style.fontSize = csize +"px";
		setCookie( 'HUMIRAFONTSIZE', csize);
	}
	return false;
}

function initFontSize(){
	var FONTSIZE = getCookie( 'HUMIRAFONTSIZE' );
	if(FONTSIZE){
 		setFontSize(FONTSIZE);
	}
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : ';path=/' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
