<!--

	var OnTop = true;       
			
	function ChangeOnTop() {
		if (OnTop) OnTop = false;       
		
		else if (!OnTop) {       
			OnTop = true; 
//			self.focus();
		}
	}         
                              
	function FocusMe() {
		if (OnTop) self.focus();     
	}

	function doLogout() {
		window.top.location.href = "default.asp";
	}

	function BeforeSubmit() {
		document.frmName.Save.value = "Save";
		document.frmName.submit();
	}
	
	function checkEmail(myForm,myCtrl)  {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.forms[myForm][myCtrl].value)) {
			return (true)
		}
	}

	function NewWindow(mypage, myname, w, h, scroll)  {
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
		win = window.open(mypage, myname, winprops)
		if (parseInt(navigator.appVersion) >= 4) { 
			win.window.focus(); 
		}
	}

// Properties to "Kappale" 

	function CheckDate( value ) {
		var localVal;
		localYear = new Date();
		localDate = new Date();

		// delimiter in datestring
		avals = value.split(".");
		if (avals.length == 1 )
			// false, value without delimiter
			return false;
		if (avals.length == 2 ) {
			localDate.setYear(localYear.getYear());				// year value from system
			localDate.setMonth(parseInt(avals[1])-1);			// month value from datestring
			localDate.setDate(parseInt(avals[0]));				// day value from datestring
		}
		else {
			if (avals.length == 3 ) {
				localDate.setYear(parseInt(avals[2]));			// year value from datestring
				localDate.setMonth(parseInt(avals[1])-1);		// month value from datestring
				localDate.setDate(parseInt(avals[0]));			// day value from datestring
			}
			else {
				return false;
			}
		}
		if (isNaN(localDate)) {
			// localDate does not represent a specific instant of time
			return false;
		}
		else {
			if (avals.length == 2) {
				//old, used to check if month was 2
				//if ( parseInt(avals[1]) == 2 )
				//{
				//	if (localDate.getMonth() != parseInt(avals[1]))
				//	{
				//		return false;
				//	}
				//}
				//else
				//{
					//  defined month from datestring (-1)
					if (localDate.getMonth()+1 != parseInt(avals[1])) {
						return false;
					}
				//}
				if (localDate.getDate() != parseInt(avals[0])) {
					return false;
				}
			}
			else {
				//if ( parseInt(avals[1]) == 2 )
				//{
				//	if (localDate.getMonth() != parseInt(avals[1]))
				//	{
				//		return false;
				//	}
				//}
				//else
				//{
					//  defined month from datestring (-1)
					if (localDate.getMonth()+1 != parseInt(avals[1])) {
						return false;
					}
				//}
				if (localDate.getDate() != parseInt(avals[0])) {
					return false;
				}
				if (localDate.getYear() != parseInt(avals[2])) {
					if (parseInt("19" + localDate.getYear()) != parseInt(avals[2]))
						return false;
				}
				// year value length > 4
				if (avals[2].length > 4) {
					return false;
				}
			}
		}
		return true;
	}

	function BeforeSubmitIndex( form, ctrl )
	{
		this.form = form;
		this.ctrl = ctrl;
		//if ( document.forms[this.form][this.ctrl].value != 0 )
		//{
			document.forms[this.form].submit();
		//}
		//else
		//{
		//	return false;
		//}
	}

	function BeforeSubmitIndex1( form, ctrl )
	{
		this.form = form;
		this.ctrl = ctrl;
		//if ( document.forms[this.form][this.ctrl].value != 0 )
		//{
			document.forms[this.form].cmd1.value = 1;
			document.forms[this.form].submit();
		//}
		//else
		//{
		//	return false;
		//}
	}

	function BeforeSubmitIndex2( form, ctrl )
	{
		this.form = form;
		this.ctrl = ctrl;
		//if ( document.forms[this.form][this.ctrl].value != 0 )
		//{
			document.forms[this.form].cmd2.value = 2;
			document.forms[this.form].submit();
		//}
		//else
		//{
		//	return false;
		//}
	}
		
	function CheckDayMonthDate( value )
	{
		var localVal;
		localYear = new Date();
		localDate = new Date();

		avals = value.split(".");
		if (avals.length == 1 )
			return false;
		if (avals.length == 2 ) {
			//localDate.setYear(localYear.getYear());
			localDate.setMonth(parseInt(avals[1])-1);
			localDate.setDate(parseInt(avals[0]));
		}
		else {
			return false;
		}
		if (isNaN(localDate)) {
			return false;
		}
		else {
			if (avals.length == 2) {
				if (localDate.getMonth()+1 != parseInt(avals[1])) {
					return false;
				}
				if (localDate.getDate() != parseInt(avals[0])) {
					return false;
				}
			}
		}
		return true;
	}
		
	function CheckHenkHaku() {
//		if ( !BeforeSubmitHenkHaku() )
//		{
//			alert("Haettava ryhmä on liian suuri! Tarkenna valintaa.");
//			return false;
//		}
		
		if ( document.frmHenkHaku.hakStart.value.length != 0 ) {
			if ( !CheckDayMonthDate( document.frmHenkHaku.hakStart.value )) {
				alert("Alkupäivämäärä väärässä muodossa! esim. \"1.1\"");
				document.frmHenkHaku.hakStart.focus();
				return false;
			}
		}
		if ( document.frmHenkHaku.hakStop.value.length != 0 ) {
			if ( !CheckDayMonthDate( document.frmHenkHaku.hakStop.value )) {
				alert("Loppupäivämäärä väärässä muodossa! esim. \"31.1\"");
				document.frmHenkHaku.hakStop.focus();
				return false;
			}
		}
		if ( document.frmHenkHaku.hakVStart.value.length != 0 && document.frmHenkHaku.hakVStop.value.length == 0 || 
					document.frmHenkHaku.hakVStart.value.length == 0 && document.frmHenkHaku.hakVStop.value.length != 0 ) {
			alert("Molemmat ikävuodet pitää antaa!"); return false;
		}
		else if (document.frmHenkHaku.hakVStart.value.length != 0 && document.frmHenkHaku.hakVStop.value.length != 0 ) {
			if ( document.frmHenkHaku.hakStart.value.length == 0 && document.frmHenkHaku.hakStop.value.length == 0 || 
						document.frmHenkHaku.hakStart.value.length != 0 && document.frmHenkHaku.hakStop.value.length == 0 || 
						document.frmHenkHaku.hakStart.value.length == 0 && document.frmHenkHaku.hakStop.value.length != 0 ) {
				alert("Syntymäaikavälille pitää antaa!"); return false;		
			}
		}
		else if ( document.frmHenkHaku.hakStart.value.length != 0 && document.frmHenkHaku.hakStop.value.length == 0 || 
							document.frmHenkHaku.hakStart.value.length == 0 && document.frmHenkHaku.hakStop.value.length != 0 ) {
			alert("Molemmat syntymäajat pitää antaa!"); return false;
		}
		else if (document.frmHenkHaku.hakStart.value.length != 0 && document.frmHenkHaku.hakStop.value.length != 0 ) {
			if ( document.frmHenkHaku.hakVStart.value.length == 0 && document.frmHenkHaku.hakVStop.value.length == 0 || 
						document.frmHenkHaku.hakVStart.value.length != 0 && document.frmHenkHaku.hakVStop.value.length == 0 || 
						document.frmHenkHaku.hakVStart.value.length == 0 && document.frmHenkHaku.hakVStop.value.length != 0 ) {
				alert("Ikävuodet pitää antaa!");
				return false;		
			}
		}
	}
	
	function BeforeSubmitHenkHaku()
	{
		var bolSubmit = false;
	
		if ( !bolSubmit ) {
			for (i=0;i<document.frmHenkHaku.hakHV.length;i++) {
				// 4 - yksityishenkilö
				if ( document.frmHenkHaku.hakHV(i).checked ) {
					if ( document.frmHenkHaku.hakHV(i).value == 6 ) {
						bolSubmit = false; break;
					}
					else {
						bolSubmit = true; break;
					}
				}
			}
		}

		if ( !bolSubmit ) {
			for (i=0;i<document.frmHenkHaku.hakPiirteet.length;i++) {
				//28 - lehti-asiakas
				//29 - kortti-asiakas
				if ( document.frmHenkHaku.hakPiirteet.selectedIndex == i ) {
					if ( parseInt(document.frmHenkHaku.hakPiirteet.options(i).value) == 24 )// || parseInt(document.frmHenkHaku.hakPiirteet.options(i).value) == 29 )
					{
						bolSubmit = false; break;
					}
					else {
						bolSubmit = true; break;
					}
				}
			}
		}

		if ( !bolSubmit ) {
			//for (i=0;i<document.frmHenkHaku.hakValtiot.length;i++)
			//{
				//186 - Suomi
				if ( document.frmHenkHaku.hakValtiot.value != 186 &&
							document.frmHenkHaku.hakValtiot.value != 227 &&  
							document.frmHenkHaku.hakValtiot.value != 0) {
					bolSubmit = true;
					//break;
				}	
			//}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakPaikkakunnat.value != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakPostinro.value.length != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakTittelit.value != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakKielet.value != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakYritykset.value != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakVStart.value.length != 0 &&
						document.frmHenkHaku.hakVStop.value.length != 0 &&
						document.frmHenkHaku.hakStart.value.length != 0 &&
						document.frmHenkHaku.hakStop.value.length != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakNimihaku.value.length != 0 ) {
				bolSubmit = true;
			}
		}
		if ( !bolSubmit ) {
			if ( document.frmHenkHaku.hakHID.value.length != 0 ) {
				bolSubmit = true;
			}
		}
		return bolSubmit;
	}

// Tuote functions	
	function CheckCurrency( reqcurVal )
	{
		var curH = reqcurVal;
		
		if ( curH.indexOf(',') == -1 )
		{
			//alert(curH);
			if ( isNaN(parseInt(curH)) ) {
				return false;					
			}
		}
		else if ( curH.indexOf(',') != -1 ) {
			avals = curH.split(",");
			if (avals.length == 1) {
				if ( isNaN(avals[0]) ) {
					return false;
				}
			}
			if (avals.length == 2) {
				if ( isNaN(avals[0]) ) {
					return false;
				}
				if ( isNaN(avals[1]) ) {
					return false;
				}				
			}
		}
		else {
			return true;
		}
	}
// Kaaviot

	function BeforeViewChart( intReqT, strURL )
	{
		// TutkimusID ...
		var tid = intReqT;
		// Referens to page ...
		var ref = strURL + "&tid=" + tid;
		
		// Vertailu ...
		for (i=0;i<document.frmName.optVertailu.length;i++) {
			if ( document.frmName.optVertailu(i).checked ) {
				var v = document.frmName.optVertailu(i).value;
				ref += "&v=" + v; break;
			}
		}
		if ( !v ) {
			alert("Valitse vertailu!"); return false;
		}
		// Tietotyyppi ...
		for (i=0;i<document.frmName.optTulokset.length;i++) {
			if ( document.frmName.optTulokset(i).checked ) {
				var t = document.frmName.optTulokset(i).value;
				ref += "&t=" + t; break;
			}
		}
		if ( !t ) {
			alert("Valitse tietotyyppi!"); return false;
		}		
		// Kaaviolaji ...
		if ( t == 2 || t == 3) {
			if ( document.frmName.cmbKaaviot.value == 0 ) {
				alert("Valitse kaaviolaji!"); return false;
			}
			else {
				for (i=0;i<document.frmName.cmbKaaviot.length;i++) {
					if ( document.frmName.cmbKaaviot.selectedIndex == i ) {
						var k = document.frmName.cmbKaaviot.options[i].value;
						ref += "&k=" + k; break;
					}
				}
			}	
		}
				
		NewWindow( ref, "name", "800","600", "yes");
	}

	function EnableKaaviotControl() {
		for ( i=0; i<document.frmName.optTulokset.length; i++ ) {
			if ( document.frmName.optTulokset(i).checked ) {
				if (document.frmName.optTulokset(i).value == 2 || document.frmName.optTulokset(i).value == 3) {
					document.frmName.cmbKaaviot.disabled = "";
					break;
				}
				else {
					document.frmName.cmbKaaviot.value = 0;
					document.frmName.cmbKaaviot.disabled = "true";
					break;
				}
			}
		}
	}

// Sanalliset

	function BeforeSubmitSanalliset( intT, strHref ) {
		var Href = strHref;
		if ( intT != "" ) {
			Href += "&tid=" + intT;
		}
		if ( document.frmName.cmbY.value != 0 ) {
			Href += "&yritysid=" + document.frmName.cmbY.value;
		}
		if ( document.frmName.cmbKR.value != 0 ) {
			Href += "&krid=" + document.frmName.cmbKR.value;
		}
		NewWindow(Href, "name", "800","600", "yes");
	}

// Lomakkeet

	function GetDate() {
		var d, s = "";
		d = new Date();
		s += d.getDate() + ".";
		s += (d.getMonth() + 1) + ".";
		s += d.getYear();
		document.frmName.txtDate.value = s;
	}

	function BeforeSubmitLomake() {
		if ( document.frmName.txtDate.value.length == 0 ) {
			alert("Päivämäärä puuttuu!");
			document.frmName.txtDate.focus();
			return false;
		}
		if ( document.frmName.txtDate.value.length != 0 ) {
			if (!CheckDate(document.frmName.txtDate.value)) {
				alert("Palautteen päivämäärä väärässä muodossa! esim \"12.5.2002\"");
				document.frmName.txtDate.focus();
				return false;
			}
		}
	}

// Error handling ...
	function error_onpage( errNumber ) {
		if ( !isNaN( errNumber ) ) {
			NewWindow( "popup/errorhandler.asp?err=" + errNumber, "ErrorWindow", "400", "400", "yes" );
			return false;
		}
	}
	
	function BeforeChangeTutkimus( myRef ) {
		for (i=0; i<=document.frmName.cmbTutkimukset.length; i++) {
			if ( document.frmName.cmbTutkimukset.selectedIndex == i || document.frmName.cmbTutkimukset.selectedIndex != 0 ) {
				location.href = myRef + "&tid=" + document.frmName.cmbTutkimukset.options(i).value;
			}
			else {
				return false;
			}
		}
	}
			
	// NOTE: Modul at the moment for SLY
	function BeforeSaveLehti( intL )
	{
		if ( intL == 1 ) {
			if ( document.frmKorttitilaus.txtEnimi.value.length == 0 ) {
				alert("Etunimesi puuttuu!"); document.frmKorttitilaus.txtEnimi.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtSnimi.value.length == 0 ) {
				alert("Sukunimesi puuttuu!"); document.frmKorttitilaus.txtSnimi.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtKatuosoite.value.length == 0 ) {
				alert("Kotiosoitteesi puuttuu!"); document.frmKorttitilaus.txtKatuosoite.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtPostinro.value.length == 0 ) {
				alert("Postinumero puuttuu!"); document.frmKorttitilaus.txtPostinro.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtPaikkakunta.value.length == 0 ) {
				alert("Paikkakunta puuttuu!"); document.frmKorttitilaus.txtPaikkakunta.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtBirth.value.length == 0 ) {
				alert("Syntymäaika puuttuu!"); document.frmKorttitilaus.txtBirth.focus(); return false;
			}
			if ( document.frmKorttitilaus.txtBirth.value.length != 0 ) {
				if (!CheckDate( document.frmKorttitilaus.txtBirth.value )) {
					alert("Syntymäaika väärässä muodossa! \"(esim. 12.5.2002)\""); document.frmKorttitilaus.txtBirth.focus(); return false;
				}
			}
			if ( document.frmKorttitilaus.cmbValtiot.value == 227 || document.frmKorttitilaus.cmbValtiot.value == 0 ) {
				alert("Valitse valtio!"); document.frmKorttitilaus.cmbValtiot.focus(); return false;
			}
		}
		else if ( intL == 2 )
		{
			if ( document.frmKorttitilaus.txtEnimi.value.length == 0 ) {
				alert("Fyll i ert förnamn!"); document.frmKorttitilaus.txtEnimi.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtSnimi.value.length == 0 ) {
				alert("Fyll i ert efternamn!"); document.frmKorttitilaus.txtSnimi.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtKatuosoite.value.length == 0 ) {
				alert("Fyll i er näradress!"); document.frmKorttitilaus.txtKatuosoite.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtPostinro.value.length == 0 ) {
				alert("Fyll i postnumret! "); document.frmKorttitilaus.txtPostinro.focus(); return false;
			}		
			else if ( document.frmKorttitilaus.txtPaikkakunta.value.length == 0 ) {
				alert("Fyll i stad!"); document.frmKorttitilaus.txtPaikkakunta.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtBirth.value.length == 0 ) {
				alert("Fyll i ert födelsedatum!"); document.frmKorttitilaus.txtBirth.focus(); return false;
			}
			if ( document.frmKorttitilaus.txtBirth.value.length != 0 ) {
				if (!CheckDate( document.frmKorttitilaus.txtBirth.value )) {
					alert("Datum har fel format! \"(ex. 12.5.2002)\""); document.frmKorttitilaus.txtBirth.focus(); return false;
				}
			}
			if ( document.frmKorttitilaus.cmbValtiot.value == 227 || document.frmKorttitilaus.cmbValtiot.value == 0 ) {
				alert("Välj vilket land!"); document.frmKorttitilaus.cmbValtiot.focus(); return false;
			}
		}
		else
		{
			if ( document.frmKorttitilaus.txtEnimi.value.length == 0 ) {
				alert("Fill in your first name!"); document.frmKorttitilaus.txtEnimi.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtSnimi.value.length == 0 ) {
				alert("Fill in your surname!"); document.frmKorttitilaus.txtSnimi.focus(); return false; 
			}
			else if ( document.frmKorttitilaus.txtKatuosoite.value.length == 0 ) {
				alert("Fill in your adress!"); document.frmKorttitilaus.txtKatuosoite.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtPostinro.value.length == 0 ) {
				alert("Fill in your zip code!"); document.frmKorttitilaus.txtPostinro.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtPaikkakunta.value.length == 0 ) {
				alert("Fill in your city!"); document.frmKorttitilaus.txtPaikkakunta.focus(); return false;
			}
			else if ( document.frmKorttitilaus.txtBirth.value.length == 0 ) {
				alert("Fill in your birth date!"); document.frmKorttitilaus.txtBirth.focus(); return false;
			}
			if ( document.frmKorttitilaus.txtBirth.value.length != 0 ) {
				if (!CheckDate( document.frmKorttitilaus.txtBirth.value )) {
					alert("Wrong format in Birthdate! \"(e.g 12.5.2002)\""); document.frmKorttitilaus.txtBirth.focus(); return false;
				}
			}
			if ( document.frmKorttitilaus.cmbValtiot.value == 227 || document.frmKorttitilaus.cmbValtiot.value == 0 ) {
				alert("Choose country!"); document.frmKorttitilaus.cmbValtiot.focus(); return false;
			}
		}
	}

//-->
