﻿
/*standard*/
function winOpen(theURL,winName,features) 
{ 
winName = window.open(theURL,winName,features); 
if(winName == null || winName.closed){window.open(theURL,winName,features);} 
else{winName.location.href = theURL;} 
if (!winName.closed) 
winName.focus(); 
}

function Trim(str) {
  var x = 0;
  while(str.charAt(x) == ' ') ++x;
  return str.substring(x,str.length);
}

function GetCookie(Name) {
  var cookiefound = false;
  var start = 0;
  var end = 0;
  var cookiestring = document.cookie;
  var i = 0;
  var found = false;
  var n='';
  var v='';
  var t=''; 
  start = document.cookie;
  while (i <= document.cookie.length) {
    if((end = start.indexOf(";",i)) != -1) {
      t = start.substring(i,end);
      i = end+1;
      if((end = t.indexOf("=")) > -1) {
        n = Trim(t.substring(0,end));
        v = Trim(t.substring(end+1,t.length));
      } else {
        n = Trim(t);
        v = '';
      }
      if(n == Name) return v;				
    } else {
      if(i == document.cookie.length)
        break;
      t = start.substring(i,document.cookie.length);
      i = end+1;
      if((end = t.indexOf("=")) > -1) {
        n = Trim(t.substring(0,end));
        v = Trim(t.substring(end+1,t.length));
      } else {
        n = t;
        v = '';
      }
      i=document.cookie.length;
      if(n == Name) return v;
    }
  }
  return "";
}

/*showMovie*/
function showMovie(myId, DivId, Type, Width, Height, Preview)
{
  showMovie(myId, DivId, Type, Width, Height, Preview, '', '')
}

function showMovie(myId, DivId, Type, Width, Height, Preview, Image, Clicktag)
{
  var File = 'http://www.webvideo.bayer.com/service/downloads.aspx?id=' + myId;
  var ClicktagJS = "javascript:openPodcast('"+Clicktag+"');";
  if (Preview == true)
    File += "&action=vorschau";
 
  var Height = Height; 

  if (Type == "flv")
  {
    File = encodeURIComponent(File);
    Height += 20;
	
			var flashvars = {
				file:File,
				type:Type,
				image:Image,
				autostart:false,
                                                                                     //screencolor:'0x636363',
                                                                                     //frontcolor:'0x0078bc',
                                                                                     //lightcolor:'0x003959',
				width:Width,
				height:Height,
				clickTag:ClicktagJS,
				iszoomed:"false",
				showzoom:"true",
				autostart:"false"
			};
			var params = {
				//bgcolor : "#ffffff",
				wmode : "transparent",
				allowfullscreen : "true"
			};
			var attributes = {};
			swfobject.embedSWF("/swf/flvplayer.swf", DivId, Width, Height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);

  }
  else if (Type == "swf")
  {
  		var File = '/service/downloads.aspx?id=' + myId;
    //File = encodeURIComponent(File);
				if(myId == "13751"){
					var flashvars = {
						linkeurope:'/de/europa.aspx',
						linkasia:'/de/asien-pazifik.aspx',
						linkafrica:'/de/lateinamerika-afrika-nahost.aspx',
						linkamerica:'/de/nordamerika.aspx'
					};
				} else if(myId == "13754"){
					var flashvars = {
						linkeurope:'/en/europe.aspx',
						linkasia:'/en/asia-pacific.aspx',
						linkafrica:'/en/latin-america-africa-middle-east.aspx',
						linkamerica:'/en/north-america.aspx'
					};
				} else if(myId == "13755"){
					var flashvars = {lang:'en'};
				} else if(myId == "13880"){
					var flashvars = {lang:'en'};
				} else if(myId == "13756"){
					var flashvars = {lang:'de'};
				} else if(myId == "13879"){
					var flashvars = {lang:'de'};
				} else {
					var flashvars = {};
				}
			var params = {
				//bgcolor : "#ffffff",
				wmode : "transparent"
			};
			var attributes = {};


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() { 
swfobject.embedSWF(File, DivId, Width, Height, "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
});



  }
  else if (Type == "wmv" || Type == "mpg" || Type == "avi")
  {
    Height += 45;
    document.write('<object id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-80c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" width="' + Width + '" height="' + Height + '" type="application/x-mplayer2"><param name="FileName" value="' + File + '"><embed src="' + File + '" width="' + Width + '" height="' + Height + '" type="application/x-mplayer2" /></object>');
  }
  else if (Type == "mov")
  {
    Height += 16;
    document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' + Width + '" height="' + Height + '"><param name="src" value="' + File + '"><param name="autoplay" value="true"><param name="type" value="video/quicktime" width="' + Width + '" height="' + (Height + 16) + '"><embed src="' + File + '" width="' + Width + '" height="' + Height + '" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></object>');
  }
}

/*aktienticker*/
//JAVASCRIPT FOR AKTIENTICKER

function isRealBrowser() {
  return document.implementation && document.implementation.createDocument;
}


function createXMLDoc(xmlFile) {
  if (isRealBrowser()) {
    var myXMLHTTPRequest = new XMLHttpRequest();
    myXMLHTTPRequest.open("GET", xmlFile, false);
    myXMLHTTPRequest.send(null);
    xmlDoc = myXMLHTTPRequest.responseXML;
  }
  else {
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async = "false";
    xmlDoc.load(xmlFile);
  }
  return xmlDoc;
}

function replaceLastCharacter(variable, search, replace)
{
 lastIndex = variable.lastIndexOf(search);

 firstpart = variable.substring(0,lastIndex);
 secondpart = variable.substring(lastIndex).replace(search,replace);
 
 return firstpart+secondpart;
}

//JAVASCRIPT FOR AKTIENTICKER
/*alt*/
      function switchSite(dropDown)
      {
        if (dropDown != null)
        {
          var href = dropDown.value;
          if (href == '') {return;}
          
          if (href.indexOf("http://") <= 0)
          {
            document.location.href = href; 
          }
          else
          {
            window.open(dropDown.value,"","toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600");
          }
        }
      } 

/*printView*/
jQuery(function(){
   printView();
});

function printView() {
	var print = getParameterValue("print");
	
	if (print == "true") {
		window.print();
	}
}

function getParameterValue(parameter) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	
	for (i = 0; i < gy.length; i++) {
		var keyValuePair = gy[i].split("=");

		var key = keyValuePair[0];
		var value = keyValuePair[1];

		if (key == parameter) {
			return value;
		}
	}
}

function printIt() {
	var url = document.location.href;
	var pos = url.indexOf("?");
	var base = '';
	var location = '';
	
	if (pos == -1) {
		base = url.split("?");
		location = base[0] + "?print=true";
	} else {
		location = url + "&print=true";
	}
	
	window.open(location, "Drucken","width=775,height=750,scrollbars=yes");
}

function setBookmark(lang)
{
  bookmarkurl = location.href;
  if (document.all) {
     var text = document.title;
     text = text.replace(/:/ ,"");
     text = text.replace(/\*/ ,"");
     text = text.replace(/\?/ ,"");
     text = text.replace(/\\/ ,"");
     text = text.replace(/"/ ,"");
     text = text.replace(/</ ,"");
     text = text.replace(/>/ ,"");
     text = text.replace(/|/ ,"");
     window.external.AddFavorite(bookmarkurl,text);
  } else {
    alert('Your Browser does not support this feature!');
  }
}

function addTopicons() {
	jQuery("body").append('<div id="toparrows"></div>');
	jQuery("#toparrows").height(jQuery("#maincontent").height());
	for(var i = 1; i<(jQuery("#maincontent").height() / 448); i++){
		jQuery("#toparrows").append('<a href="#header">top</a>');
	}
}

/*zoom*/
function zoom(factor) {
    var size = "100%";
    var obj = document.getElementById("aspnetForm");
  if(obj!=null) {
    if (obj.style.fontSize != null && obj.style.fontSize != ""){ 
      size = obj.style.fontSize;
    }
    size = Number(String(size).substring(0, String(size).indexOf("%")))
    if (size > 20 && size < 200) size = size + factor;
    /*if (size == 100 && factor > 0) size = size + factor;*/
    if (factor == 0) size = 100;
    setPersFontSize(size + "%");
    loadZoom(size);

    if ((navigator.appName == "Netscape" && navigator.appCodeName != "Mozilla") || navigator.appName == "Opera") { location.reload(); }
}
}

function loadZoom(mysize) {
    var newSize = getPersFontSize();
    if (newSize == "100%" && mysize != undefined) { newSize = mysize + "%"; }

    var obj = document.getElementById("aspnetForm");
    if(obj!=null)
      obj.style.fontSize = newSize;
}

function setPersFontSize(fontSize) {
    document.cookie = "fontSize=" + fontSize + ";";
}

function getPersFontSize() {
    var fontSize = "100%";

    if (document.cookie) {
        var val = document.cookie
        var idxStart = val.indexOf("fontSize=")
        var idxEnd = val.indexOf(";", idxStart);

        if (idxEnd < 0) { idxEnd = val.length; }
        if (idxStart >= 0) { fontSize = val.substring(idxStart + "fontSize=".length, idxEnd); }
    }
    else {
        setPersFontSize(fontSize);
    }
    return fontSize;
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

var currentvalue= 10;
var intervalId = 0;

function countDown(){
  if(currentvalue > 0){
    currentvalue -= 1;
    $("#cntdwn").html(currentvalue);
  }
  if(currentvalue == 0){
    $("#cntdwn").html("0");
    clearInterval ( intervalId );
    if ( $("body").hasClass("de") ){
      window.location = "http://www.currenta.de/";
    } else {
      window.location = "http://www.currenta.com/";
    }
  }
}

$.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};
jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};
jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};
jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

// Checks the browser and adds classes to the body to reflect it.

jQuery(document).ready(function(){
    
    var userAgent = navigator.userAgent.toLowerCase();
    $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
    
    // Is this a version of IE?
    if($.browser.msie){
        $('body').addClass('browserIE');
        
        // Add the version number
        $('body').addClass('browserIE' + $.browser.version.substring(0,1));
    }
    
    
    // Is this a version of Chrome?
    if($.browser.chrome){
    
        $('body').addClass('browserChrome');
        
        //Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserChrome' + userAgent);
        
        // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
        $.browser.safari = false;
    }
    
    // Is this a version of Safari?
    if($.browser.safari){
        $('body').addClass('browserSafari');
        
        // Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserSafari' + userAgent);
    }
    
    // Is this a version of Mozilla?
    if($.browser.mozilla){
        
        //Is it Firefox?
        if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1){
            $('body').addClass('browserFirefox');
            
            // Add the version number
            userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
            userAgent = userAgent.substring(0,1);
            $('body').addClass('browserFirefox' + userAgent);
        }
        // If not then it must be another Mozilla
        else{
            $('body').addClass('browserMozilla');
        }
    }
    
    // Is this a version of Opera?
    if($.browser.opera){
        $('body').addClass('browserOpera');
    }
    
      $("div.zoomdiv > a > img").each(function(index) {
    
    var zdWidth = $(this).width();

    if (zdWidth == "140") {
      $(this).parent("a").parent("div.zoomdiv").css("width", "11.7em");
    }
  });

});

function onEnterSearch(e, input) {
    if (!e) var e = window.event;

    if (e.keyCode)
        code = e.keyCode;
    else if (e.which)
        code = e.which;

    if (code == 13) {
       return submitPageSearch(input);
    }
    return true;
}

function submitPageSearch(input)
{
    if (input.value.replace(' ','')!='' && input.value != 'Ihr Suchbegriff') {
        document.location.href = 'onpublix-search.aspx?searchvalue=' + encodeURI(input.value).replace(/\+/g, "%2b");
        return false;
    }
}

function openPodcast(theURL)
{
    winName = window.open(theURL,'Podcast','location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=938,height=756');
    if(winName == null || winName.closed){
    	window.open(theURL,winName,features);
    }
    else{winName.location.href = theURL;}
    if (!winName.closed)
    winName.focus();
}

/*mobile*/
//MOBILE
var showmobil = "";
var lang = "";

function setCookie(name, value, expires, path, domain, secure)
	{
		// set time (in Millisekunden)
		var today = new Date();
		today.setTime( today.getTime() );
	
		if (expires)
		{
			//expires = expires * sec  * min * h * days;
			expires = expires * 100 * 60 * 60 * 24;
			//expires = expires * 1000 * 60
		}
		var expires_date = new Date( today.getTime() + (expires) );
	
		var curCookie = name + "=" + escape(value) + "; path=/" + 
		((expires) ? "; expires=" + expires_date.toGMTString() : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}


	function getCookie(name)
	{
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1)
		{
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
		} 
		else 
		{
			begin += 2;
		}
		var end = document.cookie.indexOf(";", begin);
		if (end == -1)
		{
			end = dc.length;
		}
		return unescape(dc.substring(begin + prefix.length, end));
	}
	
	function deleteCookie(name, path, domain)
	{
		if (getCookie(name))
		{
			document.cookie = name + "=" + "; path=/" + 
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}


	function spIsMobileClient(userAgent) 
	{

           if(showmobil == "true") return true;	

		var spMobileClients=["midp","240x320","blackberry","netfront","nokia","panasonic","portalmmm", "sharp","sie-","sonyericsson","symbian","windows ce","benq","mda","mot-","opera mini","philips", "pocket pc","sagem","samsung","sda","sgh-","vodafone","xda","iphone","ipod","playstation","wap","windows ce","wm5 pie","iemobil","symbian","series60","series70","series80","series90","blackberry","android","midp","wml","brew","palm","xiino","blazer","pda","nitro","netfront","sonyericsson","ericsson","sec-sgh","docomo","kddi","vodafone"]; 
	
		try
		{
			var found = false;
			userAgent=userAgent.toLowerCase(); 
			for (var i=0; i < spMobileClients.length; i++) 
			{


				if (userAgent.indexOf(spMobileClients[i]) != -1) 
				{
					found = true;
					return true;
				}
				else
				{
					found = false;
				}
			}

			return found;
		} 
		catch (e) 
		{
			return false;
		} 
	}



	function spRedirectIfMobileClient()
	{
		try
		{

			if (spIsMobileClient(navigator.userAgent)) 
			{
                               document.close();
                               document.open();
			   //div mit text und Auswahl-Links in die Seite schreiben
                               var mobilhtml = '<style type="text/css">#header,#shdw,#kv,#content,#margi,#meta,#support,#shadow{display:none;}</style><div id="mobile" style="position:absolute; z-index:1000; border:1px solid #ccc; left:2%; top:2%; width:80%; padding:12px 12px 20px; background-color:#fff; font-size:1.4em;"><img src="/img/system/bayerlogo.gif" alt="Bayer AG" style="float:right;"/><h1 style="color:#06c; clear:both; font-size:1em;">Herzlich Willkommen bei der Bayer AG!</h1><p style="padding-bottom:16px;">Sie verwenden gerade ein mobiles Endger&auml;t zum Aufruf unserer Website. Da nicht alle mobilen Endger&auml;te Internetseiten richtig darstellen k&ouml;nnen, haben wir f&uuml;r diese ein spezielles Internetangebot erstellt. Bitte w&auml;hlen Sie nun, welche unserer Websites Sie aufrufen m&ouml;chten:<ul style="list-style-type:none; margin:0; padding:0;"><li style="padding-bottom:6px;"><a href="javascript:chooseMobile();">f&uuml;r mobile Endger&auml;te (Informationsumfang reduziert)</a></li><li><a href="javascript:chooseNormal();">HTML-Version</a></li></ul></p></div>';

                               if(lang == "en") mobilhtml = '<style type="text/css">#header,#shdw,#kv,#content,#margi,#meta,#support,#shadow{display:none;}</style><div id="mobile" style="position:absolute; z-index:1000; border:1px solid#ccc; left:2%; top:2%; width:80%; padding:12px 12px 20px; background-color:#fff; font-size:1.4em;"><img src="/img/system/bayerlogo.gif" alt="Bayer AG" style="float:right;"/><h1 style="color:#06c; clear:both; font-size:1em;">Welcome to Bayer AG!</h1><p style="padding-bottom:16px;">You are calling up our website from a mobile phone or other end device. As not all these devices can display web pages correctly, we have developed a special Internet format for them. Please choose now which of our websites you would like to access:<ul style="list-style-type:none; margin:0; padding:0;"><li style="padding-bottom:6px;"><a href="javascript:chooseMobile();">for mobile end devices (reduced coverage)</a></li><li><a href="javascript:chooseNormal();">HTML version</a></li></ul></p></div>';
			   document.write(mobilhtml);
                               clicktrack(1);
			}
		}
		catch (e) 
		{ // pssst.} 
			//alert(e);
			return false;
		}
	}


	function chooseMobile()
	{
                  clicktrack(3);
		window.location = "http://mobil.bayer.de";
	}
	
	
	function chooseNormal()
	{
                  clicktrack(2);
		setCookie('mobile', 'no', 1);
		document.getElementById("mobile").style.display = "none";
		document.getElementById("header").style.display = "block";
		document.getElementById("shdw").style.display = "block";
		document.getElementById("kv").style.display = "block";
		document.getElementById("content").style.display = "block";
		document.getElementById("margi").style.display = "block";
		document.getElementById("meta").style.display = "block";
		document.getElementById("support").style.display = "block";
		document.getElementById("shadow").style.display = "block";


	}
//MOBILE
