var gotlayers = 0;
var IE = 0;
var NS = 0;
var N6 = 0;

if( document.all )
	IE = 1;
else if( document.layers )
	NS = 1;
else if( document.getElementById )
	N6 = 1;

function showBanner( banner, left, top )
	{
	if( self.innerWidth )
		{
		width = self.innerWidth;
		height = self.innerHeight;
		}
	else if( document.documentElement && document.documentElement.clientWidth )
		{
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
		}
	else if( document.body )
		{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
		}
	
	left = (width / 2) + left;

	if( IE )
		{
		document.getElementById(banner).style.left = left + "px";
		document.getElementById(banner).style.top = top + "px";
		document.getElementById(banner).style.visibility = 'visible';
		}
	else if( NS )
		{
		document.layers[banner].left = left;
		document.layers[banner].top = top;
		document.layers[banner].visibility = 'show';
		}
	else if( N6 )
		{
		document.getElementById(banner).style.left = left + "px";
		document.getElementById(banner).style.top = top + "px";
		document.getElementById(banner).style.visibility = 'visible';
		}
	}


function newPopup( url, name, width, height, directories, location, menubar, scrollbars, status, toolbar, resizable )
	{
	var features =
		'width='        + width +
		',height='      + height +
		',directories=' + directories +
		',location='    + location +
		',menubar='     + menubar +
		',scrollbars='  + scrollbars +
		',status='      + status +
		',toolbar='     + toolbar +
		',resizable='   + resizable;
	
	window.open(url, name, features);
	}


function printDocument()
	{
	if( window.print )
		window.print();
	}


function highlight( field )
	{
	field.focus();
	field.select();
	}


/* Haku kohdenumerolla */
function fetch_by_object_id( id )
	{
	if( id.value.length >= 7 && id.value.length <= 8 && !isNaN(id.value) )
		window.location.href = "http://www.toimitilat.fi/main_vapaat.php?cmd=view_object&id=" + id.value;
	else
		alert("Virheellinen kohdenumero!");
	}

/* Kohdenumeron tarkastus */
function objectNumber( number )
	{
	if( number.value.length >= 7 && number.value.length <= 8 && !isNaN(number.value) )
		return true;
	else
		{
		alert("Virheellinen kohdenumero!");
		return false;
		}
	}


function init()
{
if( NS || N6 )
	document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = handleMouseMove;
}


function handleMouseMove( evt )
{
mouseX = NS || N6 ? evt.pageX : window.event.clientX;
mouseY = NS || N6 ? evt.pageY : window.event.clientY;
}


function moveLayers( menuName )
{
if( gotlayers )
	{
	if( NS )
		{
		document.layers[menuName].left = mouseX + 15 + "px";
		document.layers[menuName].top = mouseY + "px";
		}
	if( IE )
		{
		document.getElementById(menuName).style.left = mouseX + 15 + "px";
		document.getElementById(menuName).style.top = mouseY + document.documentElement.scrollTop + "px";
		}
	if( N6 )
		{
		document.getElementById(menuName).style.left = mouseX + 15 + "px";
		document.getElementById(menuName).style.top = mouseY + "px";
		}
	}
}


function popUp( menuName, on, move )
{
if( gotlayers )
	{
	if( on )
		{
		if( move )
			moveLayers( menuName );
		if( NS )
			document.layers[menuName].visibility = "show";
		if( IE )
			document.all[menuName].style.visibility = "visible";
		if( N6 )
			document.getElementById(menuName).style.visibility = "visible";
		}
	else
		{
		if( NS )
			document.layers[menuName].visibility = "hide";
		if( IE )
			document.all[menuName].style.visibility = "hidden";
		if( N6 )
			document.getElementById(menuName).style.visibility = "hidden";
		}
	}
}

/* DHTML textbox character counter (IE4+) script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */
function taLimit()
	{
	var taObj=event.srcElement;
	if( taObj.value.length == taObj.maxLength*1 )
		return false;
	}
function taCount( visCnt )
	{
	var taObj = event.srcElement;
	if( taObj.value.length>taObj.maxLength*1 )
		taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if( visCnt )
		visCnt.innerText=taObj.maxLength-taObj.value.length;
	}

function setColorOk(field)
	{
	field.className="";
	}

function setColorHover(field)
	{
	field.className="clFormFieldHover";
	}

function setColorError(field)
	{
	field.className="clFormFieldError";
	}

