if (top.frames.length!=0)
{
	top.location=self.document.location;
}

function lahetaPalaute(lomake){

   if(lomake.PalauteTeksti.value.length < 5){
    alert("Palautteesi on liian lyhyt!")
   }
   else{
   lomake.submit();
   }
}

function kisailitJo(){
    alert("Voit osallistua äänestykseen vain kerran!");
}

function avaaPalaute(url){
    window.open(url,"PalauteIkkuna","WIDTH=496,HEIGHT=470,SCROLLBARS=no,toolbars=no");
}

function avaaFGMA(url){
    window.open(url,"FGMA","WIDTH=525,HEIGHT=525,SCROLLBARS=YES,toolbars=no");
}

function avaaIkkuna(url){
    window.open(url,"Esitetilaus","WIDTH=415,HEIGHT=410,scrollbars=yes,toolbars=no");
}

function avaaIkkuna2(url,size1,size2){
    window.open(url,"UusiIkkuna","WIDTH="+ size1 +",HEIGHT="+ size2 +",scrollbars=yes,toolbars=no");
}

function avaaIkkuna3(url,size1,size2){
    window.open(url,"UusiIkkuna","WIDTH="+ size1 +",HEIGHT="+ size2 +",scrollbars=no,toolbars=no");
}

function fieldLength(fieldname, resultfield, fieldlength) {
	if (fieldname.value.length > fieldlength)
		fieldname.value = fieldname.value.substring(0, fieldlength);
	else 
		resultfield.value = fieldlength - fieldname.value.length;
}

function startValues() {
	document.ilmoitus.ilmoitusteksti.value = 255 - document.ilmoitus.ilmoitusteksti.value.length;
}

function checkIt2() {
	var msg = "";

	if (document.ilmoitus.nimi.value.length < 3) {
		msg = msg + "\n- Nimi puuttuu";
	}
	
	if (document.ilmoitus.osoite.value.length < 4) {
		msg = msg + "\n- Osoite puuttuu";
	}

	if (document.ilmoitus.postinumero.value.length < 5) {
		msg = msg + "\n- Postinumero puuttuu";
	}

	if (document.ilmoitus.postitmp.value.length < 5) {
		msg = msg + "\n- Postitoimipaikka puuttuu";
	}

	if (document.ilmoitus.puhelin.value.length < 5) {
		msg = msg + "\n- Puhelinnumero puuttuu";
	}

	if (document.ilmoitus.otsikko.value.length < 5) {
		msg = msg + "\n- Otsikko puuttuu";
	}

	if (document.ilmoitus.ilmoitusteksti.value.length < 5) {
		msg = msg + "\n- Ilmoitusteksti puuttuu";
	}

	re = /^[0-9]{1,6}$/;		//0-99999mk eli1-5merkkiä 
	OK = re.exec(document.ilmoitus.hinta.value)
	if (!OK) {
		msg = msg + "\n- Hinnan täytyy olla numeerinen";
	}

	if (msg != "") {
		window.alert("Virheitä lomakkeessa! "+ msg +"");
		msg = "";
		return false;
	}

	return true;
}

function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
   var search = Name + "=";
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search);
      if (offset != -1) { // if cookie exists
         offset += search.length;
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset);
         // set index of end of cookie value
         if (end == -1)
            end = document.cookie.length;
         return unescape(document.cookie.substring(offset, end));
      }
   }
   return "";
}

function doResearch() {
        if(getCookie("iro4593gp") == "true")
               return;
		  else if((Math.floor(Math.random()* 5) + 1) == 5) {
                setCookie("iro4593gp", "true", new Date(2010,1,1));
                research = window.open('http://ironet.iro.fi/surveys/4593','researcher','width=600,height=500,resizable=yes,scrollbars=yes');
        }
        return;
}

function openNiitvalja(){
	var cookieValue = readCookie('niitvalja');
	if (cookieValue != '1') {
		window.open('/niitvalja.asp','Niitvalja','WIDTH=300,HEIGHT=345,TOOLBARS=no,SCROLLBARS=no');
	}
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


// Karttapalvelu alkaa

var where = ""; // which link
var place = "";

//function checkwhere(thiss) {
//	if (document.layers){
//		xCoord = e.x;
//		yCoord = e.y;
//	}
//	else if (document.all){
//		xCoord = event.clientX;
//		yCoord = event.clientY;
//	}
//	else if (document.getElementById){
//		xCoord = e.clientX;
//		yCoord = e.clientY;
//	}
//	
//	document.form2.X1.value = "X="+ xCoord + "  Y=" + yCoord;
//	self.status = "X="+ xCoord + "  Y=" + yCoord;
//	place = xCoord + ", " + yCoord;
//}

//function setX2() {
//	if (document.form2.X2.value == "") {
//		document.form2.X2.value = place;
//	}
//	if (document.form2.X2.value != "") {
//		document.form2.X3.value = place;
//	}
//}
//document.onmousemove = checkwhere;
//document.onclick = setX2;

//if(document.captureEvents) {
	//document.captureEvents(Event.MOUSEMOVE);
//}



function locateObject(n, d) {
  	var p,i,x;
   if(!d)
   	d=document; 
   	if((p=n.indexOf("?")) > 0 && parent.frames.length) {
    		d=parent.frames[n.substring(p+1)].document;
    		n=n.substring(0,p);
    	}
  		if(!(x=d[n])&&d.all)
  			x=d.all[n];
  			for (i=0;!x&&i<d.forms.length;i++)
  				x=d.forms[i][n];
  			for(i=0;!x&&d.layers&&i<d.layers.length;i++)
  				x=locateObject(n,d.layers[i].document);
  			return x;
}

function hideTooltip(object)
{
if (document.all)
{
	locateObject(object).style.visibility="hidden"
	locateObject(object).style.left = 1;
	locateObject(object).style.top = 1;
	return false
}
else if (document.layers)
{
	locateObject(object).visibility="hide"
	locateObject(object).left = 1;
	locateObject(object).top = 1;
	return false
}
else if (document.getElementById && !document.all)
{
	document.getElementById(object).style.visibility="hidden"
	document.getElementById(object).style.left = 1;
	document.getElementById(object).style.top = 1;
	return false
}
else
	return true
}


function showTooltip(object,e, tipContent, backcolor, bordercolor, textcolor, displaytime)
{
	
	if (document.all)
		{
			locateObject(object).style.top=document.body.scrollTop+event.clientY+20
			
			locateObject(object).innerHTML='<table style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; border: '+bordercolor+'; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: '+backcolor+'" width="10" border="0" cellspacing="1" cellpadding="1"><tr><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table> '

			if ((e.x + locateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft))
				{	
					locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - locateObject(object).clientWidth-10;
				}
			else
			{
			locateObject(object).style.left=document.body.scrollLeft+event.clientX+20;
			}
		locateObject(object).style.visibility="visible"
		//window.setTimeout("hideTooltip('"+object+"')", displaytime);
		}
		
	else if (document.layers)
		{
		locateObject(object).document.write('<table width="10" border="0" cellspacing="1" cellpadding="1"><tr bgcolor="'+bordercolor+'"><td><table width="10" border="0" cellspacing="0" cellpadding="2"><tr bgcolor="'+backcolor+'"><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table><td></tr></table>')
		locateObject(object).document.close()
		locateObject(object).top=e.y+10

		if ((e.x + locateObject(object).clip.width) > (window.pageXOffset + window.innerWidth))
			{
				locateObject(object).left = window.innerWidth - locateObject(object).clip.width-10;
			}
		else
			{
			locateObject(object).left=e.x+20;
			}
		locateObject(object).visibility="show"
		//window.setTimeout("hideTooltip('"+object+"')", displaytime);
		}
		
	else if (document.getElementById && !document.all)
		{
		document.getElementById(object).innerHTML='<table style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; border: '+bordercolor+'; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: '+backcolor+'" width="10" border="0" cellspacing="1" cellpadding="1"><tr><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table> '
		document.getElementById(object).style.top=e.clientY+5
		
		if ((e.clientX + document.getElementById(object).style.clip.width) > (window.pageXOffset + window.innerWidth))

			{
				document.getElementById(object).style.left = window.innerWidth - document.getElementById(object).style.clip.width-10;
			}
		else
			{
			document.getElementById(object).style.left=e.clientX+20;
			}

		document.getElementById(object).style.visibility="show";
		document.getElementById(object).document.close();
		//window.ClearTimeout("hideTooltip('"+ object +"')", displaytime);
	}
	else
	{
		return true
	}
}


function toggleVisibility(id, NNtype, IEtype, WC3type) {
    if (document.getElementById) {
        eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
    } else {
        if (document.layers) {
            document.layers[id].visibility = NNtype;
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
            }
        }
    }
}

function sendLoginForm(formi){
	var msg = "";
	var founderror = false;
	if(formi.login.value == ""){
		msg += "Käyttäjätunnus on tyhjä!\n";
		founderror = true;
	}	
	if(formi.password.value == ""){
		msg += "Salasana on tyhjä!\n";
		founderror = true;
	}

	// IF CLUB CHECKBOX EXISTS
	if(formi.loginSystem){
		if(formi.loginSystem.checked){
			formi.username.value = formi.login.value;
			formi.action = "http://193.66.59.134/cgi-bin/sqwebmail";
		}
	}
	
	if(founderror){
		alert("Tarkista tiedot.\n\n" + msg);		
	}else{
		formi.submit();
	}

}
function checkLoginForm(formi){
	var msg = "";
	var founderror = false;
	if(formi.login.value == ""){
		msg += "Käyttäjätunnus on tyhjä!\n";
		founderror = true;
	}	
	if(formi.password.value == ""){
		msg += "Salasana on tyhjä!\n";
		founderror = true;
	}
	
	if(founderror){
		alert("Tarkista tiedot.\n\n" + msg);		
		return false;
	}else{
		return true;
	}

}

//var preloadFlag = false;
var preloadFlag = true;
function preloadImages() {
	if (document.images) {
		navi_arrow_over = newImage("/kentat/images/navi_arrow.gif");
		preloadFlag = true;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


function init() { 
	if (document.layers) { 
		layerRef="document.layers"; 
		styleSwitch=""; 
		visibleVar="show"; 
		screenSize = window.innerWidth; 
		what ="ns4"; 
	} else if (document.all) { 
		layerRef="document.all"; 
		styleSwitch=".style"; 
		visibleVar="visible"; 
		screenSize = document.body.clientWidth + 18; 
		what ="ie4"; 
	} else if (document.getElementById) { 
		layerRef="document.getElementByID"; 
		styleSwitch=".style"; 
		visibleVar="visible"; 
		what="dom1"; 
	} else { 
		what="none"; 
		newbrowser = false; 
	} 
	check = true; 
} 

// Toggles the layer visibility on 
function showLayer(layerName) { 
	init();
	if(check) { 
		if (what =="none") { 
			return; 
		} else if (what == "dom1") { 
			document.getElementById(layerName).style.visibility="visible"; 
		} else { 
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"'); 
		} 
	} else {
		return; 
	} 
} 

// Toggles the layer visibility off 
function hideLayer(layerName) { 
	if(check) { 
		if (what =="none") { 
			return; 
		} else if (what == "dom1") { 
			document.getElementById(layerName).style.visibility="hidden"; 
		} else { 
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"'); 
		} 
	} else { 
		return; 
	} 
} 

// IE only
function changeText(input, startChar, endChar){ 
	strSelection = document.selection.createRange().text
	if (strSelection == ""){ 
		return false;
	}else{
		document.selection.createRange().text = startChar + strSelection + endChar;
		return true;
	}
}

function addText(myField, startChar, endChar) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange().text;
		document.selection.createRange().text = startChar + sel + endChar;
		
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionEnd && (myField.selectionEnd - myField.selectionStart > 0)) {
		startPos = myField.selectionStart;
		endPos = myField.selectionEnd;
		lenSel = endPos - startPos;
		myField.value = myField.value.substring(0, startPos)
			+ startChar
			+ myField.value.substring(startPos, startPos+lenSel)
			+ endChar
			+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.focus();
		myField.value += startChar + endChar;
	}
}

function sendIt(formi,urli,method){
	document.forms[formi].method = method;
	document.forms[formi].action = urli;
	document.forms[formi].submit();
}

function resizeCaller() {
	var iframeids=["kysymysframe"]
	var iframehide="yes"
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById)
			resizeIframe(iframeids[i])
		//reveal iframe for lower end browsers? (see var above):
		if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display="block"
		}
	}
}

function resizeIframe(frameid){
	var currentfr=document.getElementById(frameid)
	if (currentfr){
		currentfr.style.display="block";
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6+7 + FF + Opera7 syntax
			if(currentfr.contentDocument.body.scrollHeight)
				currentfr.style.height = currentfr.contentDocument.body.scrollHeight;
			else
				currentfr.style.height = currentfr.contentDocument.body.offsetHeight;
		}
		else {
			if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
				currentfr.style.height = currentfr.Document.body.scrollHeight;
			else {
				if (window.frames[frameid] && window.frames[frameid].document && window.frames[frameid].document.body.scrollHeight) { //Opera 8.5 syntax
					currentfr.style.height = window.frames[frameid].document.body.scrollHeight;
				}
			}
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
	window.attachEvent("onload", resizeCaller)
else
	window.onload=resizeCaller


// Changes the backgroundcolor of an input field, normally triggered by onfocus and onblur events
function changeInputBgColor(inputField, focus, bgColor) {
	if(bgColor==''){
		if(focus==1) {
			bgColor = '#FFDF5E';
		}
		else {
			bgColor = '#EFEFEF';
		}
	}
	inputField.style.backgroundColor = bgColor;
}

// Invert all checkboxes at once by clicking a single checkbox.
function invertAll(headerfield, checkform, mask)
{
	for (var i = 0; i < checkform.length; i++)
	{
		if (typeof(mask) != "undefined" && checkform[i].name.substr(0, mask.length) != mask)
			continue;

		if (!checkform[i].disabled)
			checkform[i].checked = headerfield.checked;
	}
}

function addQuote(toForm, fromField, toField){
	document.forms[toForm].elements[toField].value += document.forms[toForm].elements[fromField].value;
	document.forms[toForm].elements[toField].focus();
}

// Remember the current position.
function storeCaret(text)
{
	// Only bother if it will be useful.
	if (typeof(text.createTextRange) != 'undefined')
		text.caretPos = document.selection.createRange().duplicate();
}

// Replaces the currently selected text with the passed text.
function replaceText(text, textarea)
{
	// Attempt to create a text range (IE).
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		caretPos.select();
	}
	// Mozilla text range replace.
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);

		textarea.value = begin + text + end;

		if (textarea.setSelectionRange)
		{
			textarea.focus();
			textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
		}
	}
	// Just put it on the end.
	else
	{
		textarea.value += text;
		textarea.focus(textarea.value.length - 1);
	}
}

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, textarea)
{
	// Can a text range be created?
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
		caretPos.select();
	}
	// Mozilla text range wrap.
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);

		textarea.value = begin + text1 + selection + text2 + end;

		if (textarea.setSelectionRange)
		{
			var newCursorPos = textarea.selectionEnd + text1.length + text2.length;
			textarea.focus();
			textarea.setSelectionRange(newCursorPos, newCursorPos);
		}
	}
	// Just put them on the end, then.
	else
	{
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}

// Checks if the passed input's value is nothing.
function isEmptyText(theField)
{
	// Copy the value so changes can be made..
	var theValue = theField.value;

	// Strip whitespace off the left side.
	while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
		theValue = theValue.substring(1, theValue.length);
	// Strip whitespace off the right side.
	while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
		theValue = theValue.substring(0, theValue.length - 1);

	if (theValue == '')
		return true;
	else
		return false;
}

function toggle_checkbox(checkbox)
{
	checkbox . checked = ! checkbox . checked;
}

function switchElement(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

var xmlHttp;

function getCaptchaImage(CaptchaId, CaptchaMode) {

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Varmistunumero päivitys ei onnistu.");
		return;
	}
	
	var sid = Math.random()*100000000000000000;
	var url = "/captcha/index.asp";
	url = url + "?cmode=" + CaptchaMode;
	url = url + "&sid=" + sid;
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			document.getElementById("captcha").src = url;
		}
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function textLength(fieldname, resultfield, fieldlength) {
	if (fieldname.value.length > fieldlength)
		fieldname.value = fieldname.value.substring(0, fieldlength);
	else 
		resultfield.value = fieldlength - fieldname.value.length;
}


function toggleLivescoring(obj) {
	var el = document.getElementById(obj);
	if (el.style.display != "none") {
		el.style.display = 'none';
		el.style.visibility = "hidden";
		document.getElementById('livescoring_open').innerHTML = '» AVAA LIVE SCORING';
	} else {
		el.style.display = '';
		el.style.visibility = 'visible';
		document.getElementById('livescoring_open').innerHTML = '» SULJE LIVE SCORING';
	}
}