var type = "%";
var defaultSize = 100;
var minSize = 80;
var maxSize = 140;
var css = null;
var contrast = false;
var fontsizer;
var lang = "";

var deGraphic = new Array("Textversion","Grafikversion");
var itGraphic = new Array("Versione testuale", "Versione grafica");
var deContrast = new Array("Normal", "Kontrast");
var itContrast = new Array("Normale", "Contrasto");
var deRest = new Array("Schrift verkleinern", "Schrift zurücksetzen", "Schrift vergrößern", "Hilfe");
var itRest = new Array("Diminuire scrittura", "Scrittura originale", "Ingrandire scrittura", "Aiuto");


//constructor
function sizerOfFont()
{
	this.setFont = setFont;
	this.resetFont = resetFont;
	this.setCSS = setCSS;
}


function setCSS(_cssType)
{
	var count = 0;
	var sheet;
    var title;
	
	if((_cssType != "graphic") && (_cssType != "contrast"))
	{
		//if setCSS() was called at the page load
		tmp = _cssType.split("|");
		css = tmp[0];
		(tmp[1] == "true") ? contrast = true : contrast = false;
	}
	else if(_cssType == "contrast")
	{
		//if setCSS() was called by the user (contrast)
		(contrast == true) ? contrast = false : contrast = true;
	}
	else
	{
		//if setCSS() was called by the user (graphic)	
		(css == "graphic") ? css = "text" : css = "graphic";
	}
	
	while(sheet = document.getElementsByTagName("link")[count])
	{
		title = sheet.getAttribute("title");
		if((sheet.getAttribute("rel").indexOf("style") != -1) && (title))
		{
			sheet.disabled = true;
			if((contrast == true) && (title == "contrast")) sheet.disabled = false;
			if(title == css) sheet.disabled = false;
		}
		count++;
	}

	//set graphic icon	
	if(tmpIcon = document.getElementById("iconGraphic"))
	{
		(lang == "it") ? tmpTitle = itGraphic  : tmpTitle = deGraphic;
		if(css == "graphic") 
		{
			tmpSrc = "icon_nographic.gif";
			tmpIcon.alt = tmpTitle[0] + " [ALT+8]";
		}
		else
		{
			tmpSrc = "icon_graphic.gif";
			tmpIcon.alt = tmpTitle[1] + " [ALT+8]";
		}
		tmpIcon.src = tmpSrc;
		//hide alternativ graphic icon
		if(tmpAltIcon = document.getElementById("iconGraphicAlt")) tmpAltIcon.style.display = "none";
	}
	
	//set contrast icon
	if(tmpIcon = document.getElementById("iconContrast"))
	{
		(lang == "it") ? tmpTitle = itContrast  : tmpTitle = deContrast;
		if(contrast == true)
		{
			src = "icon_normal.gif"
			tmpIcon.alt = tmpTitle[0] + " [ALT+9]";
		}
		else
		{
			src = "icon_contrast.gif";
			tmpIcon.alt = tmpTitle[1] + " [ALT+9]";
		}
		tmpIcon.src = src;	
		//hide alternative contrast icon
		if(tmpAltIcon = document.getElementById("iconContrastAlt")) tmpAltIcon.style.display = "none";	
	}	
	
	//set alternativ graphic icon	
	if(tmpIcon = document.getElementById("iconContrastAlt"))
	{
		(lang == "it") ? tmpTitle = deGraphic  : tmpTitle = itGraphic;
		(contrast == true) ? tmpIcon.alt = tmpTitle[0] + " [ALT+9]" : tmpIcon.alt = tmpTitle[1] + " [ALT+9]";
	}		
	
	//set graphic text intern pages	
	if(tmpLink = document.getElementById("internGraphicText"))
	{
		tmpLinkTxt = tmpLink.firstChild;
		((tmpLinkTxt.nodeValue==itGraphic[0])||(tmpLinkTxt.nodeValue==itGraphic[1])) ? 
			tmpLang = itGraphic : tmpLang = deGraphic;
		(css == "graphic") ? nodeVal = tmpLang[0] : nodeVal = tmpLang[1];
		tmpLink.title = nodeVal + " [ALT+8]";		
		tmpLinkTxt.nodeValue = nodeVal;
	}
	
	//set contrast text intern pages
	if(tmpLink = document.getElementById("internContrastText"))
	{
		tmpLinkTxt = tmpLink.firstChild;
		((tmpLinkTxt.nodeValue==itContrast[0])||(tmpLinkTxt.nodeValue==itContrast[1])) ?
			tmpLang = itContrast : tmpLang = deContrast;
		(contrast == true) ? nodeVal = tmpLang[0] : nodeVal = tmpLang[1];
		tmpLink.title = nodeVal + " [ALT+9]";
		tmpLinkTxt.nodeValue = nodeVal;
	}
	
	//if someone switched off JS this part of the link will not be shown (< = > etc.)
	if(tmpObj = document.getElementById("siteJsLink")) tmpObj.style.display = "inline";
	
	cookieTxt = css + "|" + contrast;
	if(cookieTxt != readCookie("cssKrebshilfe")) createCookie("cssKrebshilfe", cookieTxt, 365);
}


function createCookie(_cookieName, _value, _days) 
{
	var date = new Date();
	var expires = "";
	if(_days)
	{
		var expireDay = date.getTime() + (_days * 24 * 60 * 60 * 1000);
		date.setTime(expireDay);
		expires = date.toGMTString();
	}
	document.cookie = _cookieName + "=" + _value + "; expires=" + expires;
}


function readCookie(_cookieName) 
{
	var cookieName = _cookieName + "=";
	var cookieSplit = document.cookie.split(';');
	for(var count=0; count < cookieSplit.length; count++) 
	{
		var value = cookieSplit[count];
		while (value.charAt(0)==' ') 
		{
			value = value.substring(1, value.length);
		}
		if (value.indexOf(cookieName) == 0)
		{ 
			return value.substring(cookieName.length, value.length);
		}
	}
	return null;
}


function delCookie(_cookieName) 
{
	if (readCookie(_cookieName)) 
	{
		document.cookie = _cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


function setFont(inc)
{
	var size = parseFloat(document.body.style.fontSize);
	size += inc;
	
	if (inc > 0)
	{
		size = Math.min(size, maxSize);
	}
	else 
	{
		size = Math.max(size, minSize);
	}
	createCookie("sizeKrebshilfe", size, 365);
	document.body.style.fontSize = size + type;
}


function resetFont()
{
	size = defaultSize;
	document.body.style.fontSize = size + type;
	delCookie("sizeKrebshilfe");
}

function BrowserLang()
{
	if((navigator.appName=="Netscape")||(navigator.userAgent.indexOf('Opera')!=-1)) 
	{
		lang = navigator.language;
	} 
	else lang = navigator.browserLanguage;
 	if (navigator.userAgent.indexOf('Firefox')!=-1) lang = lang.substring(0,2);
}

function setAltTexts()
{
	(lang == "it") ? tmpTitle = itRest  : tmpTitle = deRest;
	//set font decrease icon
	if(tmpObj = document.getElementById("fontDecrease")) 
	{
		tmpObj.title = tmpTitle[0] + " [ALT+5]";
		if(tmpObjAlt = document.getElementById("fontDecreaseAlt")) tmpObjAlt.style.display = "none";
	}
	//set font reset icon
	if(tmpObj = document.getElementById("fontReset")) 
	{
		tmpObj.title = tmpTitle[1] + " [ALT+6]";
		if(tmpObjAlt = document.getElementById("fontResetAlt")) tmpObjAlt.style.display = "none";
	}
	//set font increase icon
	if(tmpObj = document.getElementById("fontIncrease")) 
	{
		tmpObj.title = tmpTitle[2] + " [ALT+7]";
		if(tmpObjAlt = document.getElementById("fontIncreaseAlt")) tmpObjAlt.style.display = "none";
	}	
	//set font increase icon
	if(tmpObj = document.getElementById("help")) 
	{
		(lang == "it") ? tmpObj.href = "aiuto.htm" : tmpObj.href = "hilfe.htm";
		tmpObj.title = tmpTitle[3] + " [ALT+0]";
		if(tmpObjAlt = document.getElementById("helpAlt")) tmpObjAlt.style.display = "none";
	}	
	//set logo alternative texts
	if(tmpObj = document.getElementById("indexLogo"))
	{
		if(lang == "it") tmpObj.alt = "Logo Assistenza Tumori Alto Adige";
	}	
	//set internLogo alternative texts
	if(tmpObj = document.getElementById("internLogo"))
	{
		(lang == "it") ? 
			tmpObj.alt = "Logo dell'Assistenza Tumori Alto Adige e link alla pagina iniziale [ALT+1]" : 
			tmpObj.alt = "Logo der Südtiroler Krebshilfe und Link zur Startseite [ALT+1]";
	}
}

function openImageWin(aLoca, aWinOpenTitle, aTitle, aWidth, aHeight)
{
	// alert(aWidth + "|" + aHeight);
	var aHtml = '<html><head><title>'+aTitle+'</title></head><body topmargin="0" marginheight="0" marginwidth="0" leftmargin="0"><img src="'+aLoca+'" width="'+aWidth+'" height="'+aHeight+'" border="0" alt="'+aTitle+'" /></body></html>\n'; 
	var aNewWin = window.open('', aWinOpenTitle, "width="+aWidth+",height="+aHeight+",menubar=no,scrollbars=no,resizable=no,status=no,location=no,toolbar=no");
	aNewWin.document.write(aHtml);
	aNewWin.document.close();
	aNewWin.focus();
}

window.onload = function(e) 
{
	if((!document.body) || (!document.getElementById)) return;
	
	//set all alternative text for multilingual pages
	if((document.getElementById("iconGraphic"))&&(document.getElementById("iconContrast")))
	{
		BrowserLang();
		setAltTexts();
	}

	this.fontsizer = new sizerOfFont();
	var tmpSize = readCookie("sizeKrebshilfe");
  	var size = isNaN(parseFloat(tmpSize)) ? this.defaultSize : parseFloat(tmpSize);
	if((size < this.minSize) || (size > this.maxSize)) 
	{
		size = this.defaultSize;
	}
	document.body.style.fontSize = size + this.type;

	var style = readCookie("cssKrebshilfe");
	var tmpCSS = (style) ? style : "graphic";
	setCSS(tmpCSS);
}

var style = readCookie("cssKrebshilfe");
var tmpCSS = (style) ? style : "graphic";
setCSS(tmpCSS);

