function get(id){
	var obj = document.getElementById(id);
	return obj;
}
function validarNumero(c_numero) { 
   return c_numero.match("^[0-9]+([0-9]*)?$");
} 
function es_email(email){
	return email.match("^([a-zA-Z0-9_\\-])+(\\.([a-zA-Z0-9_\\-])+)*@((\\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\\]))|((([a-zA-Z0-9])+(([\\-])+([a-zA-Z0-9])+)*\\.)+([a-zA-Z])+(([\\-])+([a-zA-Z0-9])+)*))$")
}

String.prototype.ltrim = function() { return this.replace(/^\s+/, ""); }
String.prototype.rtrim = function() { return this.replace(/\s+$/, ""); }
String.prototype.trim = function() { return this.rtrim().ltrim(); }

function comprobarcamposcontacto(){
	for (var i=0; i<campos.length; i++) {
		if (get(campos[i]) && get(campos[i]).value.trim() == '') {
			alert ('Debes rellenar todos los campos.\n"' + nombres[i] + '" no puede quedar en blanco.');
			get(campos[i]).focus();
			return false;
		}
	}
	
	if (get('telefono') && !validarNumero(get('telefono').value)) {
		alert('El campo Teléfono ha de ser numérico, y no ha de contener ni espacios ni guiones.');
		get('telefono').focus();
		return false;
	}
	
	if (get('email') && !es_email(get('email').value)) {
		alert('El campo Email no parece válido.');
		get('email').focus();
		return false;
	}
	
	if (get('clausula') && get('clausula').checked==false) {
		alert('Debe leer y aceptar la Claúsula de protección de datos');
		return false;
	}
	
	return true;
}

var clau = false;
function muestra_clausula() {
	if (!clau) {
		get('div_clausula').style.display = 'block';
		clau = true;
	}
}

function cierra_clausula() {
	get('div_clausula').style.display = 'none';
	get('enviar').style.display = 'block';
	get('clausula').checked = true;
	clau = true;
}

function enviarcontacto(id) {
	if (comprobarcamposcontacto())
		get(id).submit();
}