///////////////////////////////////////////////////////////////////////////////////////////////
function CheckTypes(){
	this.EMTPY = 0;
	this.EMAIL = 2;
	this.CHECKED = 1;
}
var CHK_TYPES = new CheckTypes();
///////////////////////////////////////////////////////////////////////////////////////////////
arControls = Array();
arControls.push(Array("leveringsvoorwaarden", CHK_TYPES.CHECKED, 'Om dit formulier te kunnen verzenden moet je akkoord gaan met onze leveringsvoorwaarden.'));
arControls.push(Array("achternaam", CHK_TYPES.EMPTY, ''));
arControls.push(Array("voornaam", CHK_TYPES.EMPTY, ''));
arControls.push(Array("voorletters", CHK_TYPES.EMPTY, ''));
arControls.push(Array("postadres", CHK_TYPES.EMPTY, ''));
arControls.push(Array("postcode", CHK_TYPES.EMPTY, ''));
arControls.push(Array("plaats", CHK_TYPES.EMPTY, ''));
arControls.push(Array("telefoon_werk", CHK_TYPES.EMPTY, ''));
arControls.push(Array("telefoon_mobiel", CHK_TYPES.EMPTY, ''));
arControls.push(Array("email", CHK_TYPES.EMAIL, ''));
///////////////////////////////////////////////////////////////////////////////////////////////
function HighlightField(oField){
	oField.setAttribute('sOldCssText', oField.style.cssText);
	oField.style.cssText = "background-color:#FFDDDD;border: 1px solid red;" + oField.style.cssText;
	try{
		if(oField.select) oField.select();
		if(oField.focus) oField.focus();
	}catch(e){}
}
///////////////////////////////////////////////////////////////////////////////////////////////
function ResetFieldStyle(oField){
	if(oField.hasAttribute('sOldCssText')){
		oField.style.cssText = oField.getAttribute('sOldCssText');
	}
}
/////////////////////////////////////////////////////////////////////////
function CheckSubmit(frmForm, sOnSubmit){
	var i;

	if(typeof(arControls) != 'undefined'){
		for(i = 0; i < arControls.length; i++){
			if(!CheckValue(document.getElementById(arControls[i][0]), arControls[i][1], arControls[i][2])){
				return false;
			}
		}
	}
	if(typeof(sOnSubmit) == 'undefined' || sOnSubmit == ""){
		document.getElementById(frmForm).submit();
	}else{
		if(eval(sOnSubmit) == true){					
			document.getElementById(frmForm).submit();
		}else{
			return false;
		}
	}
}
/////////////////////////////////////////////////////////////////////////
function CheckValue(oControl, nCheckType, sErr, bHideError){

	if(nCheckType == CHK_TYPES.EMPTY){
		if(oControl.value.replace(/\s+/, "") == ""){
			if(!bHideError){
				//alert(sErr);
				HighlightField(oControl);
			}
			return false;
		}else{
			return true;
		}
	}else if(nCheckType == CHK_TYPES.CHECKED){
		if (oControl.checked == false) {
			if(!bHideError){
				alert(sErr);
				HighlightField(oControl);
			}
			return false;
		} else {
			return true;
		}
	}else if(nCheckType == CHK_TYPES.EMAIL){
		sEMail = oControl.value.replace(/\s+/, "");
		var sFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(sFilter.test(sEMail)){
			return true;
		}else{
			if(!bHideError){
				//alert(sErr);
				HighlightField(oControl);
			}
			return false;
		}
	}else{
		alert('Invalid Check Type!');
		return false;
	}
}
/////////////////////////////////////////////////////////////////////////
