﻿ 
function isVal(strng){
	if(!strng.match(/\!|\£|\$|\%|\^|\&|\*|\_/)) {
			return true;
		}
	else {
			return false;
		}			
}
function isBlank(strng){
	if (!strng){
		return true;
	}
	else{
		return false;
	}
}

function isGT(strng,length){
	strng = strng.replace(/\s/g,'');
	if (strng.length > length){
		return true;
	}
	else{
		return false;
	}
}

function isLT(strng,length){
	strng = strng.replace(/\s/g,'');
	if (strng.length < length){
		return true;
	}
	else{
		return false;
	}
}


function valEmail(strng){
	if(!strng.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)) {
			return true;
		}
	else {
			return false;
		}			
}

function valNumChars(strng){
	if(strng.match(/^[\/\d\-+,() ]{5,24}$/i)) {
			return true;
		}
	else {
			return false;
		}			
}

function valRegistration(){
	var RegistrationError =''; 
	
	if (!isVal(document.getElementById('forename').value)||isBlank(document.getElementById('forename').value)||!isGT(document.getElementById('forename').value,'1')||document.getElementById('forename').value=='Etunimi')
	{
		RegistrationError += '- Virheellinen etunimi \n';
	}
	if (!isVal(document.getElementById('surname').value)||isBlank(document.getElementById('surname').value)||!isGT(document.getElementById('surname').value,'1')||document.getElementById('forename').value=='Sukunimi')
	{
		RegistrationError += '- Virheellinen sukunimi \n';
	}
	if(valEmail(document.getElementById('email').value)){
		RegistrationError += '- Virheellinen shk\366postiosoite. Anna s\346hk\366postiosoite muodossa nimi@verkko-osoite.fi \n';
	}
	if (RegistrationError !=''){
		alert(RegistrationError);
		return false;
	}
	else{
		return true;
	}			
}

var popup = null;

function openInfo(url, event) {
			 mm_openWindow(url, 'popupwindow', 650, 550, 1, 0, event);
			}

			
			function mm_openWindow(URL, name, width, height, scrollbars, resizable, event) {
			if(popup != null) {
			    popup.close();
			}
			 var x = 100;
			 var y = 125;
			 var xmod = width / 2;
			 var ymod = height / 2;
			 if(event != null) {
			 x = event.screenX - xmod;
			 y = event.screenY - ymod;
			 if(x < 0)
			 x = 0;
			 if(y < 0)
			 y = 0;
			 var maxW = screen.availWidth;
			 var maxH = screen.availHeight;
			 if(!maxW) {
			 var overScreenX = screen.availWidth - (x + xmod);
			 if(overScreenX > 0)
			 x = x - overScreenX;
			 var overScreenY = screen.availHeight - (y + ymod);
			 if(overScreenY > 0)
			 y = y - overScreenY;
			 }
			 }
			 popup = window.open(URL, name, 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizable+',width='+width+',height='+height+',left = '+x+',top = '+y);
			 popup.focus();
			}

function openComp(url, event) {
			 mm_openWindow(url, 'popup', 800, 520, 1, 0, event);
			}

			var popup;
			function mm_openWindow(URL, name, width, height, scrollbars, resizable, event) {
			if(popup != null)
			 popup.close();
			 var x = 100;
			 var y = 125;
			 var xmod = width / 2;
			 var ymod = height / 2;
			 if(event != null) {
			 x = event.screenX - xmod;
			 y = event.screenY - ymod;
			 if(x < 0)
			 x = 0;
			 if(y < 0)
			 y = 0;
			 var maxW = screen.availWidth;
			 var maxH = screen.availHeight;
			 if(!maxW) {
			 var overScreenX = screen.availWidth - (x + xmod);
			 if(overScreenX > 0)
			 x = x - overScreenX;
			 var overScreenY = screen.availHeight - (y + ymod);
			 if(overScreenY > 0)
			 y = y - overScreenY;
			 }
			 }
			 popup = window.open(URL, name, 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height+',left = '+x+',top = '+y);
			 popup.focus();
			}

var checkdigits = "0123456789ABCDEFHJKLMNPRSTUVWXY";
var dss_matcher = new RegExp("^\\d{6}[-+A]\\d{3}[" + checkdigits + "]$");

function fi_dss_validate(inputtext) {
	inputtext = inputtext.toUpperCase();
        if (inputtext == null) return false;

        var working = inputtext.replace(/ /g,'');
        if (working.length != 11) return false;

        if (!dss_matcher.test(working))
          return false;

        var ccString = parseFloat(working.substring(0,6) + "" + working.substring(7,10));
        var check = (ccString) % 31;

        window.status=check;

        if (working.charAt(10) != checkdigits.charAt(check)) return false;
        return true;
      }