// 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) {
		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.";
	}
}

/* pop para link externo

function openExternalLink(href, target) {
  var newwin = window.open('/util/exit-notice.shtml?url=' + encodeURIComponent(href) + '&target=' + encodeURIComponent(target),'openlink','width=330,height=160,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 showOverlayer(){
	var size = getPageSize();
	var scroll = getPageScroll();

	var obg = document.getElementById('page-bg');
	obg.style.width = size[0]+'px';
	obg.style.height = size[1]+'px';
	
	var ovr = document.getElementById('overlayer');
	
	obg.style.display = 'block';
	ovr.style.display = 'block';
	
}

function hideOverlayer(){
	var obg = document.getElementById('page-bg');
	var ovr = document.getElementById('overlayer');

	obg.style.display = 'none';
	ovr.style.display = 'none';

}

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 == ''){
			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 = '';
		}
	}
}

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();
}


