function cleanForm(event)
{
	Event.stop(event);
	
	$('nombre').value = '';
	$('poblacion').value = '';
	$('direccion').value = '';	
	$('empresa').value = '';
	$('telefono').value = '';
	$('email').value = '';
	$('consulta').value = '';
}

function validateForm(event)
{	
	var nombre = $('nombre').value;
	var direccion = $('direccion').value;
	var poblacion = $('poblacion').value;	
	var empresa = $('empresa').value;
	var telefono = $('telefono').value;
	var email = $('email').value;
	var consulta = $('consulta').value;
	
	var error = false;
	var errorText = '';
	
	if ('' == nombre)
	{	
		error = true;
		errorText = errorText + '\nEl campo nombre es obligatorio.';
	}
	/*
	if ('' == apellidos)
	{	
		error = true;
		errorText = errorText + '\nEl campo apellidos es obligatorio.';
	}	
	*/
	
	if ('' == empresa)
	{	
		error = true;
		errorText = errorText + '\nEl campo empresa es obligatorio.';
	}		
	
	if ('' == telefono)
	{	
		error = true;
		errorText = errorText + '\nEl campo teléfono es obligatorio.';
	}
	
	if ('' == email)
	{	
		error = true;
		errorText = errorText + '\nEl campo email es obligatorio.';
	}
		
	if (!isValidEmailAddress(email))
	{	
		error = true;
		errorText = errorText + '\nLa dirección de email debe ser correcta.';
	}

	if ('' == consulta)
	{	
		error = true;
		errorText = errorText + '\nEl campo consulta es obligatorio.';
	}		

	if (error)
	{
		alert('Debe rellenar todos los campos del formulario.' + errorText);
		Event.stop(event);
		return false;
	}
	else	
	{
		return true;
	}
}

function isValidEmailAddress(email) 
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
    {
	return true;
    }
    else
    {
	return false;
    }
}	

Event.observe(window, 'load', function() {
	Event.observe('borrarButton', 'click', cleanForm);	
	Event.observe('contactoForm', 'submit', validateForm);
});