// Acá el javascript que usemos a lo largo del todo el sitio

// Valida Newsletter
function validarNewsletter(theForm){
	
	if (theForm.email.value == "") {
		alert("Falta tu email!");
		theForm.email.focus();
		return (false);
	}
	
	var checkEmail = "@.";
	var checkStr = theForm.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkEmail.length;  j++) {
			if (ch == checkEmail.charAt(j) && ch == "@")
				EmailAt = true;
			if (ch == checkEmail.charAt(j) && ch == ".")
				EmailPeriod = true;
		  	if (EmailAt && EmailPeriod)
				break;
		  	if (j == checkEmail.length)
				break;
			}
		// if both the @ and . were in the string
		if (EmailAt && EmailPeriod) {
			EmailValid = true
			break;
		}
	}
	
	if (!EmailValid) {
		alert("El email esta mal!");
		theForm.email.focus();
		return (false);
	}
	
}

// Valida Email
function validarConsulta(theForm){
	
	if (theForm.nombre.value == "") {
		alert("Falta tu Nombre");
		theForm.nombre.focus();
		return (false);
	}
	
	if (theForm.mensaje.value == "") {
		alert("Falta tu Mensaje!");
		theForm.mensaje.focus();
		return (false);
	}
	
	if (theForm.email.value == "") {
		alert("Falta tu email!");
		theForm.email.focus();
		return (false);
	}
	
	var checkEmail = "@.";
	var checkStr = theForm.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkEmail.length;  j++) {
			if (ch == checkEmail.charAt(j) && ch == "@")
				EmailAt = true;
			if (ch == checkEmail.charAt(j) && ch == ".")
				EmailPeriod = true;
		  	if (EmailAt && EmailPeriod)
				break;
		  	if (j == checkEmail.length)
				break;
			}
		// if both the @ and . were in the string
		if (EmailAt && EmailPeriod) {
			EmailValid = true
			break;
		}
	}
	
	if (!EmailValid) {
		alert("El email esta mal!");
		theForm.email.focus();
		return (false);
	}
	
}

// Confirm
function confirmarBorrarProducto() {
	if(!confirm("Borrar producto?")) {
		return false;
	} else {
		return true;
	}
}
