// Prototype on ladattu pohjille

var sFontSizeCookieName = 'fontSize';
var iFontSizeCookieExpiresDays = 3;
var sFontSizecookiePath = null;


// Huom! T&auml;m&auml; polku on suhteessa html-sivuun, ei siis t&auml;h&auml;n js-tiedostoon.
// includeScriptFile('jaetut/js/prototype-1.6.0.2.js');
	

function main() {
	var sFontSize = getCookie(sFontSizeCookieName);
	if (sFontSize != '') {
		setBodyFontSize(sFontSize);
	}
}
window.onload = main;




/* Funktiot */


// relative: setBodyFontSize(+6), setBodyFontSize(-6), modify current size by given amount
// absolute: setBodyFontSize('20px'), set size to absolute value
function setBodyFontSize(size) {
	var body = document.body;
	
	// relative size
	if ((size + '').search(/[+-]/) == 0) {
		var currentSize, sizeInt;
		currentSize = body.style.fontSize ? body.style.fontSize :
											(body.currentStyle ? body.currentStyle.fontSize : // IE
											(window.getComputedStyle ? window.getComputedStyle(body, "").fontSize : "12px")); // FireFox
		sizeInt = parseInt(currentSize);
		if (sizeInt == null) {
			return 0;
		}
		size = sizeInt + parseInt(size);
		// add units
		size = size + currentSize.replace(/\d+/g, '');
	}
	body.style.fontSize = size;
	setCookie(sFontSizeCookieName, size, iFontSizeCookieExpiresDays, sFontSizecookiePath);
}


// Adds a Google-search-formatted site-filter to the input sInputId
function addSiteToQuery(sInputId, sSite) {
	var eInput = document.getElementById(sInputId);
	if (eInput) {
		eInput.value += " site:" + sSite;
	}
	return true;
}


function getCookie(name)
{
	if (document.cookie.length > 0)
	{
		var nameStartPos = document.cookie.indexOf(name + "=");
		if (nameStartPos != -1)
		{
			var valueStartPos = nameStartPos + name.length + 1;
			var endPos = document.cookie.indexOf(";", valueStartPos);
			if (endPos == -1)
				endPos = document.cookie.length;
			return unescape(document.cookie.substring(valueStartPos, endPos));
		}
	}
	return "";
}


function setCookie(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime(today.getTime());
	if (expires)
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expirationDate = new Date(today.getTime() + expires);

	document.cookie =
		name + "=" + escape(value) +
		((expires) ? "; expires=" + expirationDate.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}


function includeScriptFile(source) {
	var head, eScript;
	head = document.getElementsByTagName('head');
	if (head.length == 0) {
		throw new Error(0x8009000,'Include: No <head> tag exists. Scripts not loaded.');
	}
	eScript = document.createElement('script');
	eScript.setAttribute('src',source);
	head[0].appendChild(eScript);
}

