﻿function isValidEmailAddress(str) {
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

// as convenient a place as any to store this...
var STD_ERROR_PREFIX = "Por favor verifique los valores de los siguientes campos y vuelva a intentarlo:\n\n"

// push is a quite useful method of arrays in newer 
// javascript implementations, but not in ie5-
Array.prototype.push = function(v) {
	this[this.length] = v
	return v
}

function validate() {
	
	var f = document.getElementById("contacto");
	var errors = [];
	
	if (f.empresa.value == "") {	
		errors.push("Debe ingresar el nombre de su empresa.");
	}
	
	if (f.personaContacto.value == "") {	
		errors.push("Debe ingresar el nombre de la persona de contacto.");
	}
	
	if (f.telefono.value == "") {	
		errors.push("Debe ingresar su número de teléfono.");
	}
	
	if (!isValidEmailAddress(f.email.value)) {
		errors.push("Debe ingresar una dirección de email correcta.");
	}
	
	if (f.provincia.value == "0") {	
		errors.push("Debe seleccionar su provincia.");
	}
	
	if (f.poblacion.value == "") {	
		errors.push("Debe ingresar su población.");
	}
	
	if (f.operadorActual.value == "0") {
		errors.push("Debe seleccionar su operador actual.");
	}
	
	if (errors.length > 0) {
		alert(STD_ERROR_PREFIX + errors.join("\n"))
		return false;
	}
	
	return true;
}