function fieldNotEmpty (fieldname) {

	if (fieldname.value == "") {
		//  alert(fieldname.name);
		fieldname.focus();
		return false;
	}
	return true;
}

function validInteger (fieldname, minlength, minvalue, maxlength, maxvalue) {

//alert (fieldname.value + "/" + minlength + "/" + minvalue + "/" + maxlength + "/" + maxvalue);

	// intNumber = parseInt (fieldname.value);
	intNumber = fieldname.value * 1;
	if (isNaN (intNumber)) {
		fieldname.focus();
		// alert (fieldname.name + " " + NaN);
		return false;
	}

	if (fieldname.value.length < minlength || fieldname.value.length > maxlength) {
		fieldname.focus();
		// alert (fieldname.name + " length " + fieldname.value.length);
		return false;
	}
	if (intNumber < minvalue || intNumber > maxvalue) {
		fieldname.focus();
		// alert (fieldname.name + " value " + fieldname.value);
		return false;
	}

	return true;
}

function validEmail (email) {

	validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWXYZ1234567890_-.@";
	emailv = email.value;

	if (emailv == "") {return true};

	// scan all characters and check they are allowed
	// alert ("scan all characters and check they are allowed");

	for (i=0; i < emailv.length; i++) {
		nextChar = emailv.charAt(i);
		if (validChars.indexOf(nextChar,0) == -1) {
			alert ("Din e-postadress innehåller minst ett ej godkänt tecken: '" + nextChar + "'");
			email.focus();
			return false
		};
	}

	// check that one and only one at-sign is given
	// alert ("check that one and only one at-sign is given");

	atPos = emailv.indexOf("@",0);

	if (atPos == -1 ||
	emailv.indexOf("@",atPos+1) != -1) {
		alert ("Din e-postadress måste innehålla ett och enbart ett @ (At-sign)");
		email.focus();
		return false
	};

	// check that the at-sign is not the first or the last character
	//  alert ("check that the at-sign is not the first or the last character");

	atPos = emailv.indexOf("@",0);

	if (atPos == 0  ||
	atPos == emailv.length - 1) {
		alert ("Din e-postadress får ej innehålla ett @ (At-sign) som första eller sista tecken");
		email.focus();
		return false
	};

	// check that the at-sign is flanked by a non-period
	//  alert ("check that the at-sign is flanked by a non-period");

	prevChar = emailv.charAt(atPos-1);
	nextChar = emailv.charAt(atPos+1);

	if (prevChar == "." ||
	nextChar == ".") {
		alert ("Din e-postadress innehåller en punkt som står direkt bredvid  @ (At-sign)");
		email.focus();
		return false
	};


	// check that a period is not the first or the last character
	// alert ("check that a period is not the first or the last character");

	firstChar = emailv.charAt(0);
	lastChar  = emailv.charAt(emailv.length - 1);

	if (firstChar == "." ||
      lastChar  == ".") {
		alert ("Din e-postadress får ej ha en punkt som först eller sista tecken");
		email.focus();
		return false
	};


	// check that all period-signs not are flanked by a period
	// alert ("check that all period-signs not are flanked by a period");

	if (emailv.indexOf("..",0) != -1) {
		alert ("Din e-postadress får ej ha två punkter bredvid varandra");
		email.focus();
		return false
	};


	// check that a domain region is at least 2 characters
	// alert ("check that a domain region is at least 2 characters");

	periodPos = emailv.lastIndexOf(".");

	if (periodPos == -1 ||
	periodPos+3 > emailv.length) {
		alert ("Din e-postadress måste innehålla minst 2 tecken efter sista punkten");
		email.focus();
		return false
	};

	return true;
}



function Radio_Checked (buttongroup) {


	checkedOption = -1;

	for (i=0; i<buttongroup.length; i++) {
		if (buttongroup[i].checked) {checkedOption = i}
	}

	if (checkedOption == -1) {
		buttongroup[0].focus();
		alert ("Du måste ange ett svarsalternativ");
		return false;
	}

	return true;
}