var gotlayers = 0;

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";
		}
	}
}

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

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 highlight( field )
	{
	field.focus();
	field.select();
	}
	
function setColorOk(field)
	{
	field.className="";
	}

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

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

function showDiv( divName )
{
var element = document.getElementById(divName);
element.style.visibility = "visible";
}

function hideDiv( divName )
{
var element = document.getElementById(divName);
element.style.visibility = "hidden";
}

function toggleDiv( divName )
{
var element = document.getElementById(divName);
if( element.style.visibility == "visible" )
	hideDiv(divName);
else
	showDiv(divName);
}

/* 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.ledigalokaler.com/main_lediga.php?cmd=view_object&id=" + id.value;
	else
		alert("Felaktig objektnummer!");
	}

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

/* CHARACTER COUNTER */

/**
 * 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 errorHandler()
{
return 0;
}

window.onerror = errorHandler;
