// JavaScript Document

function formValidator(){
	// Make quick references to our fields
	var nombre = document.getElementById('nombre');
	//var paterno = document.getElementById('paterno');
	//var materno = document.getElementById('materno');
	var email = document.getElementById('email');
	//var boleto = document.getElementById('boleto');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(nombre, "Por favor, escribe tu nombre.")){
		//if(isAlphabet(paterno, "Escribe tu apellido paterno.")){
		//	if(isAlphabet(materno, "Escribe tu apellido materno")){
					if(emailValidator(email, "Por favor, escribe una dirección de correo válida.")){
						//if(notEmpty(asunto, "Escribe un asunto.")){
						//if(notEmpty(mensaje, "Escribe el mensaje.")){
							return true;
						}
						}
					//}
			//}
		//}
	//}
	
	
	return false;
	
}

function notEmpty(elem, helperMsg){
	if(elem.value.length <= 2){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z áéíóúñÁÉÍÓÚÑ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Código incorrecto. Por favor, verifica el No. de tu boleto (código de barras)");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
