// JavaScript Document


function checkmail(e) {
	var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	var returnval = emailfilter.test(e.value);
	return returnval;
}


function validateForm() {
	var cotizacion = document.form1a1;
	if (cotizacion.nombre.value == "") {
		alert("Debe de escribir al menos un nombre.");
		cotizacion.nombre.focus();
		return 0;
	}
	if (cotizacion.apellido.value == "") {
		alert("Debe de escribir al menos un apellido.");
		cotizacion.apellido.focus();
		return 0;
	}
	if (checkmail(document.form1a1.email) == false) {
		alert("Debe de escribir un email válido.");
		cotizacion.email.focus();
		return 0;
	}
	if ((cotizacion.telefono.value == "") & (cotizacion.celular.value == "")) {
		alert("Debe de escribir al menos un numero telefonico.");
		cotizacion.telefono.focus();
		return 0;
	}
	if (cotizacion.modelo.value == "-1") {
		alert("Debe de escoger un modelo de vivienda.");
		cotizacion.modelo.focus();
		return 0;
	}
	if (cotizacion.enganche.value != "") {
		if ((cotizacion.enganche.value <= cotizacion.xvalx.value)) {
			alert("El valor del enganche debe de ser mayor al 5% del valor total de la casa.");
			cotizacion.enganche.focus(); 
			return 0;
		}
	}	
	cotizacion.submit();
}

function validateForm2() {
	var cotizacion = document.form2a1;
	if (cotizacion.nombre.value == "") {
		alert("Debe de escribir al menos un nombre.");
		cotizacion.nombre.focus();
		return 0;
	}
	if (cotizacion.apellido.value == "") {
		alert("Debe de escribir al menos un apellido.");
		cotizacion.apellido.focus();
		return 0;
	}
	if (checkmail(document.form2a1.email) == false) {
		alert("Debe de escribir un email válido.");
		cotizacion.email.focus();
		return 0;
	}
	if ((cotizacion.telefono.value == "") & (cotizacion.celular.value == "")) {
		alert("Debe de escribir al menos un numero telefonico.");
		cotizacion.telefono.focus();
		return 0;
	}
	if (cotizacion.modelo2.value == "-1") {
		alert("Debe de escoger un modelo de vivienda.");
		cotizacion.modelo.focus();
		return 0;
	}
	if (cotizacion.enganche.value != "") {
		if ((cotizacion.enganche.value <= cotizacion.xvalx.value)) {
			alert("El valor del enganche debe de ser mayor al 5% del valor total de la casa.");
			cotizacion.enganche2.focus(); 
			return 0;
		}
	}	
	cotizacion.submit();
}

function validateForm3() {
	var cotizacion = document.form3a1;
	if (cotizacion.nombre.value == "") {
		alert("Debe de escribir al menos un nombre.");
		cotizacion.nombre.focus();
		return 0;
	}
	if (cotizacion.apellido.value == "") {
		alert("Debe de escribir al menos un apellido.");
		cotizacion.apellido.focus();
		return 0;
	}
	if (checkmail(document.form3a1.email) == false) {
		alert("Debe de escribir un email válido.");
		cotizacion.email.focus();
		return 0;
	}
	if ((cotizacion.telefono.value == "") & (cotizacion.celular.value == "")) {
		alert("Debe de escribir al menos un numero telefonico.");
		cotizacion.telefono.focus();
		return 0;
	}
	if (cotizacion.modelo.value == "-1") {
		alert("Debe de escoger un modelo de vivienda.");
		cotizacion.modelo.focus();
		return 0;
	}
	if (cotizacion.enganche.value != "") {
		if ((cotizacion.enganche.value <= cotizacion.xvalx.value)) {
			alert("El valor del enganche debe de ser mayor al 20% del valor total de la casa.");
			cotizacion.enganche.focus(); 
			return 0;
		}
	}	
	cotizacion.submit();
}

function validateForm4() {
	var cotizacion = document.formport;
	if (cotizacion.nombre.value == "") {
		alert("Debe de escribir al menos un nombre.");
		cotizacion.nombre.focus();
		return 0;
	}
	if (cotizacion.apellido.value == "") {
		alert("Debe de escribir al menos un apellido.");
		cotizacion.apellido.focus();
		return 0;
	}
	if (checkmail(document.formport.email) == false) {
		alert("Debe de escribir un email válido.");
		cotizacion.email.focus();
		return 0;
	}
	if ((cotizacion.telefono.value == "") & (cotizacion.celular.value == "")) {
		alert("Debe de escribir al menos un numero telefonico.");
		cotizacion.telefono.focus();
		return 0;
	}
	if (cotizacion.modeloSelectPortada.value == "-1") {
		alert("Debe de escoger un modelo de vivienda.");
		cotizacion.modeloSelectPortada.focus();
		return 0;
	}
	if (cotizacion.enganche.value != "") {
		if ((cotizacion.enganche.value <= cotizacion.xvalPortadax.value)) {
			alert("El valor del enganche debe de ser mayor al 20% del valor total de la casa.");
			cotizacion.enganche.focus(); 
			return 0;
		}
	}	
	cotizacion.submit();
}

