
﻿function heltal(falt,txtut) {
	var oldstring = document.all(falt).value;
	var newstring = parseInt(oldstring).toString();
	if (oldstring.length == newstring.length && newstring != 'NaN') {
		null;
	}
	else {
		alert('Du må angi ett heltall (ikke desimaler) i feltet for ' + txtut + '.');
		InpValid=0;
		document.all(falt).value = "0";
	}
}

function heltalpositiv(falt,txtut) {
	var oldstring = document.all(falt).value;
	var newstring = parseInt(oldstring).toString();
	if (oldstring.length == newstring.length && newstring != 'NaN' && newstring >= 0) {
		null;
	}
	else {
		alert('Du maste ange ett POSITIVT HELTAL (ej decimaler) i faltet for ' + txtut + '.');
		InpValid=0;
		document.all(falt).value = "0";
	}
}


function kommatal(falt,txtut) {
	var oldstring = document.all(falt).value;
	var newstring = parseFloat(oldstring).toString();
	if (newstring != 'NaN') {
		var ffalt = document.all(falt).value;
		newffalt = ffalt.replace(/\,/, '.');
		document.all(falt).value = newffalt;
		null;
	}
	else {
		alert('Du maste ange ett TAL (heltal eller decimaltal) i faltet far ' + txtut + '.');
		InpValid=0;
		document.all(falt).value = "0.00";
	}
}



function ejnull(falt,txtut) {
	var ffalt = document.all(falt).value;
	if (ffalt.length != 0) {
		null;
	}
	else {
		alert('Du maste ange nagot i faltet for ' + txtut + '.');
		InpValid=0;
	}
}


function ntn(falt) {
	var ffalt = document.all(falt).value;
	if (ffalt.length == 0) {
		document.all(falt).value = '0';
	}
}

function anmodan(falt,txtut) {
	var ffalt = document.all(falt).value;
	if (ffalt.length != 0) {
		null;
	}
	else {
		if (confirm('Det rekomenderas att faltet for ' + txtut + ' fylls i med ratt data.' + String.fromCharCode(13) + 'Du kan enda valja att spara utan att fylla i detta falt.' + String.fromCharCode(13) + ' ' + String.fromCharCode(13) + 'Tryck OK for att spara.' + String.fromCharCode(13) + 'Tryck Avbryt for att aterga.')) 
		{null;}
		else
		{InpValid=0;}
	}
}

function ddatum(falt,txtut) {
	indatum=document.all(falt).value;
	tmpDag=indatum.substr(8,2);
	tmpManad=indatum.substr(5,2);
	tmpAr=indatum.substr(0,4);
	if ((tmpAr*1) > 2999 || (tmpAr*1) < 1999) {InpValid=0;}
	if ((tmpManad*1) > 12 || (tmpManad*1) < 1) {InpValid=0;}
	if (((tmpManad*1) == 1 || (tmpManad*1) == 3 || (tmpManad*1) == 5 || (tmpManad*1) == 7 || (tmpManad*1) == 8 || (tmpManad*1) == 10 || (tmpManad*1) == 12) && ((tmpDag*1) < 1 || (tmpDag*1) > 31 )) {InpValid=0;}
	if (((tmpManad*1) == 4 || (tmpManad*1) == 6 || (tmpManad*1) == 9 || (tmpManad*1) == 11) && ((tmpDag*1) < 1 || (tmpDag*1) > 30 )) {InpValid=0;}
	if (((tmpManad*1) == 2) && ((tmpDag*1) < 1 || (tmpDag*1) > 29 )) {InpValid=0;}
	if (InpValid == 0) {alert('Felaktigt datum. Datum maste vara i formatet AAAA-MM-DD'); document.all(falt).value='AAAA-MM-DD';}
	
	}
	
	function komma(falt) {
	var ffalt = document.all(falt).value;
	newffalt = ffalt.replace(/\,/, '.');
	document.all(falt).value = newffalt;
}
