// JavaScript Document
//These functions provide input masks eg for numeric form fields, to ensure correct and consistent treatment and/or conversion 
//when entereing data
//+ standard functions often used when checking forms

function doNumberInput(fld) {
	//make sure that numbers use "," for decimal separators!
	//firsts convert any "." numbers to ","
	fld.value = fld.value.replace('.',',')
	//Now replace back, because javascripts only works with english decimal conventions
	var val = fld.value.replace(',','.');
	if (isNaN(val)) {
		alert("Vul hier een geldig getal in aub.");
		fld.style.color = 'red';
		this.focus();
		return false; }
	else {
		fld.style.color = 'black';
		return true; }
}

function isEmpty() {
	//test if any of a series of values (in the args) is empty and return true if so.
	for (var i=0; i<isEmpty.arguments.length; i++) {
		if (isEmpty.arguments[i] == '')
			return true;
	}
	return false;
}

function isEmail(str) {
	//returns true if str is a valid e-mail adress OR if str is empty
	if (str != '')  {
		if (str.indexOf('@') == -1)
			return false;
		for (i = 0; i < str.length; i++) {
			if (  ( str.charAt(i) < 'a' || str.charAt(i) > 'z' ) && isNaN(str.charAt(i)) )
				if (str.charAt(i) < 'A' || str.charAt(i) > 'Z')
					if (str.charAt(i) != '.' && str.charAt(i) != '-' && str.charAt(i) != '_' && str.charAt(i) != '@')
						return false;
			}
		}
	return true;
}

function noSelection(fld) {
	//tests if the value of a SELECT selection = empty string and returns true if it is
	if(fld[fld.selectedIndex].value == '')
		return true;
	else
		return false;
}

function noRadioChecked(fld) {
	//test if none of the radio buttons in a radio button have been checked and if so, return true, otherwise, return false
	for (var i = 0; i < fld.length ; i++) {
		if(fld[i].checked) {
			return false; }
	}
	return true;
}

function getCheckedRadioValue(radioObj) {
	//get the value of the checked radio button in a group.
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


