// navigation functions

function navOn(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'nav-select') {
			document.getElementById(navName).style.background = '#a28f7f';
		}
	}
}

function navOff(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'nav-select') {
			document.getElementById(navName).style.background = '#73563f';
		}
	}
}
function dnavSelect(navName) {
	if (document.getElementById) {
		document.getElementById(navName).className = 'dnav-select';
	}
}

function dnavOn(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'dnav-select') {
			document.getElementById(navName).style.background = '#ede9e6';
		}
	}
}

function dnavOff(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'dnav-select') {
			document.getElementById(navName).style.background = '#ffffff';
		}
	}
}

function showMenu(divName) {
	if (document.getElementById) {
		if (divName != 'navtwo-nav-list') { //JUWI CODE
			document.getElementById(divName).style.display = 'block';
		}
	}
}

function hideMenu(divName) {
	if (document.getElementById) {
		document.getElementById(divName).style.display = 'none';
	}
}

// investor info change

function showInv1() {
	if (document.getElementById) {
		document.getElementById('inv-tab-l-a').style.color = '#000000';
		document.getElementById('inv-tab-r-a').style.color = '#cc3300';
		document.getElementById('inv-tab-l-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('inv-tab-r-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('inv-info1').style.display = 'block';
		document.getElementById('inv-info2').style.display = 'none';
	}
}

function showInv2() {
	if (document.getElementById) {
		document.getElementById('inv-tab-l-a').style.color = '#cc3300';
		document.getElementById('inv-tab-r-a').style.color = '#000000';
		document.getElementById('inv-tab-l-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('inv-tab-r-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('inv-info1').style.display = 'none';
		document.getElementById('inv-info2').style.display = 'block';
	}
}


// investor info callout change

function showInvCallout1() {
	if (document.getElementById) {
		document.getElementById('inv-call-tab-l-a').style.color = '#000000';
		document.getElementById('inv-call-tab-r-a').style.color = '#cc3300';
		document.getElementById('inv-call-info1').style.display = 'block';
		document.getElementById('inv-call-info2').style.display = 'none';
	}
}

function showInvCallout2() {
	if (document.getElementById) {
		document.getElementById('inv-call-tab-l-a').style.color = '#cc3300';
		document.getElementById('inv-call-tab-r-a').style.color = '#000000';
		document.getElementById('inv-call-info1').style.display = 'none';
		document.getElementById('inv-call-info2').style.display = 'block';
	}
}

// content tabs change

function showContent1() {
	if (document.getElementById) {
		document.getElementById('content-tab-l-a').style.color = '#000000';
		document.getElementById('content-tab-r-a').style.color = '#a28f7f';
		document.getElementById('content-tab-l').style.borderBottom = '1px solid #ffffff';
		document.getElementById('content-tab-l-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('content-tab-r').style.borderBottom = '1px solid #e4e2cf';
		document.getElementById('content-tab-r').style.background = '#F8F6F5';
		document.getElementById('content-tab-l').style.background = '#FFFFFF';
		document.getElementById('content-tab-r-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('content-info1').style.display = 'block';
		document.getElementById('content-info2').style.display = 'none';
	}
}

function showContent2() {
	if (document.getElementById) {
		document.getElementById('content-tab-l-a').style.color = '#a28f7f';
		document.getElementById('content-tab-r-a').style.color = '#000000';
		document.getElementById('content-tab-l').style.borderBottom = '1px solid #e4e2cf';
		document.getElementById('content-tab-l-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('content-tab-r').style.borderBottom = '1px solid #ffffff';
		document.getElementById('content-tab-r-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('content-info1').style.display = 'none';
		document.getElementById('content-info2').style.display = 'block';
		document.getElementById('content-tab-r').style.background = '#FFFFFF';
		document.getElementById('content-tab-l').style.background = '#F8F6F5';
	}
}

// dropdown select location change
function sel(Url) {
	if (Url) {
  	window.open(Url,"_blank");
  }
}

// open a popup window
function openwin(url,w,h,s) {
  var scrl;
	if (s) { scrl="scrollbars=yes,"; w = w+16; }
	else { scrl="scrollbars=no,"; }

	if (!w) w = 640;
	if (!h) h = 480;

	fenster = window.open(url,"_blank",scrl+"resizable=yes,width="+w+",height="+h+",screenX=50,screenY=50");
	fenster.focus();
}

// font change functions

var fontsizeup_on = new Image();
fontsizeup_on.src = '/images/_common/icon-text-plus.jpg';
var fontsizeup_off = new Image();
fontsizeup_off.src = '/images/_common/icon-text-plus-inactive.jpg';
var fontsizeup_hover = new Image();
fontsizeup_hover.src = '/images/_common/icon-text-plus-hover.jpg';

var fontsizedown_on = new Image();
fontsizedown_on.src = '/images/_common/icon-text-minus.jpg';
var fontsizedown_off = new Image();
fontsizedown_off.src = '/images/_common/icon-text-minus-inactive.jpg';
var fontsizedown_hover = new Image();
fontsizedown_hover.src = '/images/_common/icon-text-minus-hover.jpg';

function fontsizeup() {
  active = getActiveStyleSheet();
  setActiveStyleSheet('large');
}

function fontsizedown() {
  active = getActiveStyleSheet();
  setActiveStyleSheet('reg');
}

function fontsizeOverOut(img_name, img_over, anchor_name){
	img = document.getElementById(img_name);
	a = document.getElementById(anchor_name);

	if(a.getAttribute('href')){
		img.src = img_over.src;
	}
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  
  imgdown = document.getElementById('font-size-down-img');
  imgup = document.getElementById('font-size-up-img');

  adown = document.getElementById('font-size-down-a');
  aup = document.getElementById('font-size-up-a');

  if(imgdown && imgup){
	  if(title == 'large'){
		  imgdown.src = fontsizedown_on.src;
		  imgup.src = fontsizeup_off.src;
		  aup.removeAttribute('href');
		  adown.setAttribute('href','javascript:void(0)');
	  }else{
  		  imgdown.src = fontsizedown_off.src;
		  imgup.src = fontsizeup_on.src;
		  aup.setAttribute('href','javascript:void(0)');
		  adown.removeAttribute('href');
	  }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('reg');
}

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;
}

function styleSheetOnLoad() {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

function styleSheetOnUnload() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);


//hide/show lang dropdown when onmouseover/onmouseout on main navigation
function showHideLang(){
  if (document.getElementById){
    lang_container = document.getElementById('lang-container');
    if (lang_container) {
      if (lang_container.style.visibility == 'hidden'){
        lang_container.style.visibility = 'visible';
      } else {
        lang_container.style.visibility = 'hidden';
      }
    }
  }
}

// JavaScript Server Side Includes - XML Requests

function funcClientSideInclude(id, url){
	var req = false;

	// Safari, Firefox, and other non-MS browsers
	if (window.XMLHttpRequest){
		try {
			req = new XMLHttpRequest();
		}
		catch(err){
			req = false;
		}
	}
	else if (window.ActiveXObject) {
		// For Internet Explorer on Windows
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(err){
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(err){
				req = false;
			}
		}
	}

	var element = document.getElementById(id);
	if(!element){
		alert("ID error: " + id + " passed to clientSideInclude. You need a div or span element with this id in your page.");
		return;
	}

	if(req){
		// Synchronous request
		req.open('GET', url, false);
		req.send(null);
		element.innerHTML = req.responseText;
	}
	else {
	element.innerHTML =
	"Sorry, your browser does not support XMLHTTPRequest objects. This page requires Internet Explorer 5 or better for Windows, or Firefox for any system, or Safari. Other compatible browsers may also exist.";
	}
}

function openExternalLink(href, target) {
  var newwin = window.open('/util/exit-notice.shtml?url=' + encodeURIComponent(href) + '&target=' + encodeURIComponent(target),'openlink','width=350,height=190,screenX=100,screenY=100,top=100,left=100,resizable=yes,toolbar=no,scrollbars=no')
  newwin.focus();
}

function setupExternalLinks() {
  var links = document.getElementsByTagName('a');
  for (var i = links.length; i != 0; i--) {
    var a = links[i-1];
    if (!a.href) continue;

    if (a.href.indexOf('http') != -1 &&
            a.href.indexOf(window.location.hostname) == -1 &&
            !excludeUrl(a.href)) {
                a.onclick = function() {
                openExternalLink(this.href, this.target);
                return false;
            }

    }
  }
}

var excludeUrls = Array();
function excludeUrl(url){
  re = /www./gi;
  for(var l = 0; l < excludeUrls.length; l++){
    if(url.indexOf(excludeUrls[l]) == 0 || url.indexOf(excludeUrls[l].replace(re, "")) == 0){
      return true;
    }
  }
  return false;
}

function init() {
  styleSheetOnLoad();
}

function uninit() {
  styleSheetOnUnload();
}

function initCustom() {
}

function uninitCustom() {
}


/* Overlayer functions */

function getPageScroll(){
     var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;   
     var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;   
	
	var arrayScroll = new Array(scrollx, scrolly);
	return arrayScroll;	
}

function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


function playSWF(flash, width, height) {
  var src="";
  src="<object width='"+width+"' height='"+height+"' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' style='z-index:10000;'>";
  src+="<param value='"+width+"' name='width' \/>";
  src+="<param value='"+height+"' name='height' \/>";
  src+="<param value='"+flash+"' name='src' \/>";
  src+="<param name='wmode' value='opaque'>";
  src+="<embed width='"+width+"' height='"+height+"' src='"+flash+"' type='application/x-shockwave-flash' \/>";
  src+="<\/object>";
  var tw=width+20;
  var th=height+20;
  Dialog.info(src,
              { className:"novartis",
                recenterAuto:false, 
                draggable:false, 
                closable:false, 
                width: tw, 
                height:th, 
                top:80,
                onShow:function()  { $('main-nav').hide(); },
                onClose:function() { $('main-nav').show(); }
              });
}

function showPIC(srcpic, width, height, titel) {
  var src="";
  src="<img src='"+srcpic+"' width='"+width+"' height='"+height+"' titel='"+titel+"' alt='"+titel+"'/>";
  var tw=width+14;
  var th=height+5;
  Dialog.info(src,
              { className:"novartis",
                recenterAuto:false, 
                draggable:false, 
                closable:true, 
                width: tw, 
                height:th, 
                top:80,
                onShow:function()  { $('main-nav').hide(); },
                onClose:function() { $('main-nav').show(); }
              });
}  

function openContact(url,name,width,height) {
  var src="<iframe src='"+url+"' width='"+width+"'px height='"+height+"'px frameborder=0></iframe>";
  var tw=width+20;
  var th=height+10;
  Dialog.info(src,
              { className:"novartis",
                recenterAuto:false, 
                draggable:false, 
                closable:true, 
                width: tw, 
                height: th, 
                top: 20,
                onShow:function()  { $('main-nav').hide(); },
                onClose:function() { $('main-nav').show(); }
              });
}  


function openBrWindow(url,name,width,height){
  window.open (url,name,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+width+",height="+height)
}



function openVideo(url) {
  var src="<iframe src='"+url+"' width=500px height=340px frameborder=0></iframe>";
  Dialog.info(src,
              { className:"novartis",
                recenterAuto:false, 
                draggable:false, 
                closable:true, 
                width: 500, 
                height: 340, 
                top: 74,
                onShow:function()  { $('main-nav').hide(); },
                onClose:function() { $('main-nav').show(); }
              });
} 


function showOverlayer(){
}

function hideOverlayer(){
  Dialog.closeInfo();
}





function openVPM(url) {
  var src="<iframe src='"+url+"' width=355px height=400px frameborder=0></iframe>";
  Dialog.info(src,
              { className:"novartis",
       			iframescroll:"no",
                recenterAuto:false, 
                draggable:false, 
                closable:true, 
                width: 355, 
                height: 406, 
                top: 20,
                onShow:function()  { $('main-nav').hide(); },
                onClose:function() { $('main-nav').show(); }
              });
}  
function _openVPM(url) {
  winVPM = new Window({ className:"novartis",
                      iframescroll:"no",
                      title:"",
                      minimizable:false,
                      maximizable:false,
                      resizable:false,
                      draggable:true,
                      recenterAuto:false,
                      destroyOnClose:true,
                      top:20,
                      width: 345,
                      height:400
                    });
  winVPM.setURL(url);
  winVPM.setZIndex(1500);
	winVPM.showCenter();
}

var icon_print_hover = new Image();
icon_print_hover.src = '/images/_common/icon_print_hover.jpg';

function imgChangeSrc(img_name, src){
	if(document.getElementById){
		document.getElementById(img_name).src = src;
	}
}

function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function showHide(name, clsname_hide, clsname_show){
	if(document.getElementById){
		r = document.getElementById(name);
		if(r.style.display == 'block'){
			if(clsname_hide && clsname_show){
				t = document.getElementById(name+'-td');
				t.className = 'nopad';
			}
			r.style.display = 'none';
		}else{
			if(clsname_hide && clsname_show){
				t = document.getElementById(name+'-td');
				t.className = clsname_show;
			}
			r.style.display = 'block';
		}
	}
}

var imgMinus = new Image();
imgMinus.src = '/images/_common/minus.gif';


function setPlusMinus(name, plus_src, minus_src){
	if(document.getElementById){
		if(!plus_src){
			plus_src = '/images/_common/plus.gif';
		}
		if(!minus_src){
			minus_src = '/images/_common/minus.gif';
		}
		i = document.getElementById(name);
		if(i.src.indexOf('plus') != -1){
			i.src = minus_src;
		}else{
			i.src = plus_src;
		}
	}
}

if(window.enable_ie_select_fix){
	var SKB = {

	  require: function(libraryName) {
	    // inserting via DOM fails in Safari 2.0, so brute force approach
	    document.write('<script type="text/javascript" src="' + libraryName + '"></script>');
	  },

	  load: function() {
	    this.require("/js/prototype/prototype.js");
	    this.require("/js/scriptaculous/builder.js");
	    this.require("/js/firebug/firebug.js");
	    this.require("/js/skb-util.js");
	    this.require("/js/fix-ie-select-zindex-bug.js");

	    this.require("/js/comunicati-stampa.js");
	  }
	};

	SKB.load();
}



