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 at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    return false;
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }
	
	 return true;				
}


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;
}