function browserCheck()
{
	this.br = navigator.appName.toLowerCase();
	this.version = navigator.appVersion.toLowerCase();
	this.agent = navigator.userAgent.toLowerCase();
	this.platform = navigator.platform.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.is_safari = ( this.version.indexOf( 'safari' ) != -1 );
	this.is_opera = ( this.agent.indexOf( 'opera' ) != -1 );
	this.is_mozilla = ( this.agent.indexOf( 'gecko' ) != -1 );
	this.is_ns = ( this.br == 'netscape' && !this.is_opera );
	this.is_ie = ( this.br == 'microsoft internet explorer' && !this.is_opera );
	this.is_ns4 = ( this.is_ns && this.major == 4 && !this.is_opera );
	this.is_ns6 = ( this.is_ns && this.major == 5 && !this.is_opera );
	this.is_ie4 = ( this.version.indexOf( 'msie 4.0' ) != -1 && !this.is_opera );
	this.is_ie5 = ( this.version.indexOf( 'msie 5.0' ) != -1 && !this.is_opera );
	this.is_ie55 = ( this.version.indexOf( 'msie 5.5' ) != -1 && !this.is_opera );
	if( this.is_ie55 ) this.is_ie5 = true;
	this.is_ie6 = ( this.version.indexOf( 'msie 6.0' ) != -1 && !this.is_opera );
	if( !this.is_ie6 && this.version.indexOf( 'msie 7' ) != -1 && !this.is_opera )
	{
		this.is_ie6 = true; // fool the IE7 to think it's a 6
	}
	this.is_windows = ( this.platform.indexOf( 'win' ) != -1 );
	this.is_mac = ( this.agent.indexOf( 'mac' ) != -1 );
	this.is_linux = ( this.platform.indexOf( 'linux' ) != -1 || this.platform.indexOf( 'x11' ) != -1 ) ? true:false;
	this.is_dom = ( document.getElementById ) ? true:false;
}
br = new browserCheck();

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 expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getCookie( check_name ) 
{
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;

			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

// Oletusfonttikoko (2 = 100%)
var font_size = 2;
// yritetään hakea fonttikoko cookiesta
if( parseInt( getCookie( 'font_size' ) ) > 0 )
{
	font_size = parseInt( getCookie( 'font_size' ) );
}

function increaseFontSize()
{
	if( font_size < 5 )
	{
		font_size++;
		setFontSize();
		setMiddle();	
	}
}

function decreaseFontSize()
{
	if( font_size > 1 )
	{
		font_size--;
		setFontSize();
		setMiddle();
	}
}

function setFontSize()
{
	var size = 'small';
	if( document.getElementById('container') )
	{
		switch( font_size )
		{
			case 1: size = "100%"; break;
			case 2: size = "110%"; break;
			case 3: size = "150%"; break;
			case 4: size = "160%"; break;
			case 5: size = "180%"; break;
			default: size = "100%";
		}
		document.getElementById('container').style.fontSize = String(size);
		setCookie( 'font_size', font_size, 30, '/', '', '' );
	}
}

function setMiddle()
{
	if( document.getElementById('header') && document.getElementById('footer') && document.getElementById('middle') )
	{
		document.getElementById( 'middle' ).style.height = '';		
		var height = document.getElementById( 'footer' ).offsetTop - document.getElementById( 'header' ).offsetHeight;
		document.getElementById( 'middle' ).style.height = height + 'px';
	}
}
function popUp( url, name, params )
{
	if( url != "" )
	{
			window.open( url, name, params );
	}
}

function getDocumentHeight(d) 
{
    return Math.max(
        Math.max(d.body.scrollHeight, d.documentElement.scrollHeight),
        Math.max(d.body.offsetHeight, d.documentElement.offsetHeight),
        Math.max(d.body.clientHeight, d.documentElement.clientHeight)
    );
}

function adjustIframeHeight(frame)
{
	try{
		var d = br.is_ie ? frame.contentWindow.document : frame.contentDocument;
		frame.style.height = getDocumentHeight(d) + 'px';
	}
	catch(e)
	{
		alert(e.message);
	}
}
