function ValidateRequiredFields(formId, RequiredFields, RequiredNames)
{
	var FieldList = RequiredFields.split(",");
	var NameList = RequiredNames.split(",");
	var BadList = new Array();
	for (var i = 0; i < FieldList.length; i++)
	{
		var s = eval('document.getElementById(\'' + FieldList[i] + '\').value');
		if(s.length < 1)
		{
			BadList.push(NameList[i]);
		}
		else {
			if (FieldList[i] == "email") {
				if (echeck(document.getElementById('email').value) == false) {
					BadList.push('E-mailadres heeft niet het goede formaat.');
				}
			}
			if (FieldList[i] == "agb") 
			{
				var value = document.getElementById(FieldList[i]).value;
				if (!isNumeric(value))
				{
					BadList.push('De AGB code dient 8 cijfers te bevatten.');
				}
				else if (!checkStrLength(value, 8, 8))
				{
					BadList.push('De AGB code dient 8 cijfers te bevatten.');
				}
			}
		}
	}
	
	if(BadList.length < 1)
	{
		return true;
	}
	
	var message = new String('De volgende velden zijn verplicht:');
	for(var i = 0; i < BadList.length; i++)
	{
		message += '\n- ' + value2name(BadList[i]);
	}
	
	alert (message);
	return false;
}

function value2name(value)
{
 value = value.replace("_sl_", " / ");
 value = value.replace("_st_", "-");
 value = value.replace("_", " ");
 value = ucfirst(value);


 return value;
}

function ucfirst(str)
{
 var f = str.charAt(0).toUpperCase();
 return f + str.substr(1, str.length-1);
}

function echeck(str){
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
    {
        testresults=true
    }
    else{
        testresults=false
    }
    return (testresults)
}

function isNumeric(strString)	
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function checkStrLength(string, minLength, maxLength)
{
	var blnResult = true;
	if ((string.length < minLength) || (string.length > maxLength)) {
    	blnResult = false;
	}
	return blnResult;
}
