function VF(form)
{
	var ok = true;
	
	for (ctrl_name in FC) {
		// clear control invalid status
		CCI(ctrl_name);

		// get the value of the control
		var values = GCV(ctrl_name);
		var value = '';
		for (var i=0; i<values.length; i++) {
			if (values[i].length > 0) {
				value = values[i];
				break;
			}
		}
		
		// see all validations for this control and perform them
		var validations = FC[ctrl_name].split("_");		
		for (var i=0; i<validations.length; i++) {
			switch (validations[i]) {
				case 'required':
					if (value.length <= 0) {
						ok = false;
						SCI(ctrl_name, 'This field is required');
					}
					break;
				case 'number':
					if (value.length > 0 && !/^\-?\d+(\.\d*)?$/.test(value)) {
						ok = false;
						SCI(ctrl_name, 'This field must contain a valid number');
					}
					break;
				case 'phone':
					if (value.length > 0 && !/^[\d \.\+\-\#\(\)]+$/.test(value)) {
						ok = false;
						SCI(ctrl_name, 'This field must contain a valid phone number');
					}
					break;
				case 'website':
					if (value.length > 0 && !/^(https?:\/\/)?(([\w\-_\d]+\.)*([\w\-_\d]+)\.(\w){2,4}(\.(\w){2,3})?)(:\d*)?(\/.*)?$/.test(value)) {
						ok = false;
						SCI(ctrl_name, 'This field must contain a valid website address');
					}
					break;
				case 'email':
					if (value.length > 0 && !/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)) {
						ok = false;
						SCI(ctrl_name, 'This field must contain a valid email');
					}
					break;
				default:
					break;
			}
		}
	}

	return ok;
}

function CCI(ctrl_name)
{
	var el = document.getElementsByName(ctrl_name)[0];
	if (el) {
		el.style.backgroundColor="";
		el.setAttribute("alt", "");
		el.setAttribute("title", "");
	}
}

function SCI(ctrl_name, error)
{
	var el = document.getElementsByName(ctrl_name)[0];
	if (el) {
		el.style.backgroundColor="#ffc8c8";
		el.setAttribute("alt", error);
		el.setAttribute("title", error);
	}
}

function SCV(ctrl_name, values)
{
	var elems = document.getElementsByName(ctrl_name);

	if (values.length == 0) {
		if (elems[0]) {
			elems[0].value = '';
		}
	}
	else if (values.length == 1) {
		if (elems[0]) {
			elems[0].value = values[0];
		}
	}
	else {
		// multiple elements of the same type (checkboxes / radios)
		for (var i=0; i<elems.length; i++) {
			for (var j=0; j<values.length; j++) {
				if (elems[i].value == values[j]) {
					elems[i].checked = "checked";
					break;
				}
			}
		}
	}
}

function GCV(ctrl_name)
{
	var arr = document.getElementsByName(ctrl_name);
	var values = new Array();

	for (var i=0; i<arr.length; i++) {
		values[values.length] = arr[i].value;
	}

	return values;
}