function getCookies() {
	var hash = new Array;
	if ( document.cookie ) {
		var cookies = document.cookie.split( '; ' );
		for ( var i = 0; i < cookies.length; i++ ) {
			var namevaluePairs = cookies[i].split( '=' );
			hash[namevaluePairs[0]] = unescape( namevaluePairs[1] ) || null;
		}
	}
	return hash;
}

function parseCookieData( cookieDataString ) {
	var cookieValues = new Object();
	var separatePairs = cookieDataString.split( '&' );
	for ( var i = 0; i < separatePairs.length; i++  ) {
		var separateValues = separatePairs[i].split( ':' );
		cookieValues[separateValues[0]] = separateValues[1] || null;
	}
	return cookieValues;
}

function setCookie( name, value, hours, path, domain, secure ) {
		var numHours = 0;

		if ( hours) {
			if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
				numHours = hours;
			} else if ( typeof(hours) == 'number' ) { // calculate Date from number of hours
				numHours = ( new Date((new Date()).getTime() + hours*3600000) ).toGMTString();
			}
		}

		document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
}


function killCookie( name, path, domain ) {
	var allCookies = getCookies();

	var theValue = allCookies[ name ] || null; // We need the value to kill the cookie
	if ( theValue ) {
		document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
	}
}

function setActiveStyleSheet(CSS_TITLE) {
  var i, a;
  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") == CSS_TITLE) a.disabled = false;
      var img = document.getElementById('textsize_'+CSS_TITLE);
    }	
  }
  $$('div.ArticleTools img.textsize').each( function(img)
  {
	var title = img.id.substr(9);
    img.src = PUB_PATH+'img/'+title+(title == CSS_TITLE ? '_ccc' : '')+'.gif';
  });
}

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;
}


/*	mediabar	*/
function showLinks(show, i) {
	if(show == 'true') {
		$('dpi-layer-'+i).style.display = "block";
	} else {
		$('dpi-layer-'+i).style.display = "none";
	}	
}

Event.observe(window, 'unload', function(e) {
  if (getActiveStyleSheet() != null) {
  	if (getActiveStyleSheet() != FONT_COOKIE) {
	  	setCookie( FONT_COOKIE_NAME, getActiveStyleSheet(), 24*31, FONT_COOKIE_PATH, FONT_COOKIE_DOMAIN, '');
	}
  } else {
  	killCookie( FONT_COOKIE_NAME, FONT_COOKIE_PATH, FONT_COOKIE_DOMAIN );
  }
});

Event.onDOMReady(function(){ 
	setActiveStyleSheet(CSS_TITLE);
	
	/*	because of nonscript, show ArticleTools by JS (F&I, TopicArticle)	*/
	$$("div[class^='ArticleTools']").each(function(elem) {
			$(elem).setStyle({display:'block'});
	});
});

var allCookies = getCookies();
var DomainArray = location.hostname.split( '.' );
var CurrDomain = ( DomainArray.length > 1 ) ? '.' + DomainArray[DomainArray.length-2] + '.' + DomainArray[DomainArray.length-1] : '';
          
var FONT_COOKIE_NAME = "siemensInnoFont";
var FONT_COOKIE_PATH = "/";
var FONT_COOKIE_DOMAIN = CurrDomain;
var FONT_COOKIE = allCookies[ FONT_COOKIE_NAME ] || null;
var CSS_TITLE = FONT_COOKIE ? FONT_COOKIE : 'minus';