
function get(id){
	var obj = document.getElementById(id);
	return obj;
}

function borra() {
	get('formu_contacto').reset();
}

function enviar() {
	for (var i=0; i<campos.length; i++) {
		if ( (get(campos[i]).value == '')||(get(campos[i]).value == ' ') ) {
			alert ('Debes rellenar todos los campos.\n"' + nombres[i] + '" no puede quedar en blanco.');
			get(campos[i]).focus();
			return false;
		}
	}
	if (!es_email(get('email').value)) {
		alert('El email no parece válido.');
		get('email').focus();
		return false;
	}
	if (!get('clausula').checked) {
		alert ( 'Debes leer y aceptar la cláusula de consentimiento para continuar.');
		muestra_clausula();
		return false;
	}
	return true;
}

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])+)*))$")
}

var clau = false;
function muestra_clausula() {
	if (!clau) {
		get('div_clausula').style.visibility = 'visible';
		get('div_clausula').style.display = 'block';
		if (get('tipocontacto')) get('tipocontacto').style.visibility = 'hidden';
		clau = true;
	}
}

function cierra_clausula() {
	get('div_clausula').style.visibility = 'hidden';
	get('div_clausula').style.display = 'none';
	if (get('tipocontacto')) get('tipocontacto').style.visibility = 'visible';
	get('clausula').checked = true;
	clau = true;
}

function inicio(){
	get('formu_contacto').onsubmit = enviar;
}

window.onload =  inicio;


