function checkStatus(element) {
	if(element.className == 'inputError') {
		element.className = 'campos';
	}
}

window.onload = function () {
	if(!document.getElementsByTagName('input')) return false;
	var inputs = document.getElementsByTagName('input');
	for(var i = 0; i < inputs.length; i++) {
		if(inputs[i].className == 'campos') {
			inputs[i].onfocus = function () {
				checkStatus(this);
			}
		}
	}	
}

function validateForm() {
	var msgError = 'Los siguientes campos son obligatorios \n';
	var error = 0;	
	var nombre = document.getElementById('nombre');
	var apellido = document.getElementById('apellido');
	var email = document.getElementById('email');
	var telefono = document.getElementById('telefono');


	//Valido nombre y apellido
	if(!(/\w{2}/.exec(nombre.value))) {
	msgError += '- Nombre \n';
	nombre.className = 'inputError';	
	error = 1;
	}
	if(!(/\w+/.exec(apellido.value))) {
	msgError += '- Apellido \n';
	apellido.className = 'inputError';	
	error = 1;
	}

	//Si ingreso email, chequeo que sea valido
	if(email.value != '') {
		if(!(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.exec(email.value))) {
		alert('La dirección de e-mail no es valida');
		email.className = 'inputError';	
		error = 1;
		}
	}
	
	//Chequeo que se haya ingresado telefono particular
	if(telefono.value != '') {
		if(/[a-zA-Z_]+/.exec(telefono.value)) {
			msgError += '- Teléfono (Debe contener solamente números) \n';
			telefono.className = 'inputError';	
			error = 1;
		}
	} else {
		msgError += '- Teléfono \n';
		telefono.className = 'inputError';	
		error = 1;
	}	
	
	// Si no hay error envio el formulario
	if(error) {
		alert(msgError);
		return false;
	} else {
		document.formmail.submit();
	}
}
