//-----------------------
// Rutinas varias para los formularios Contacto y Registro OnLine
// Copyright: eniker
// Fecha: 28/12/2005
//-----------------------

// Rutina para posicionarme en el primer campo del formulario cto con SetFocus
function sf() {

	document.cto.elements["nombre"].focus();
}

// Lee la variable pasada por GET id=X, y seleccciona la linea con el valor X
function ss() {

	document.cto.elements["servicio"].focus();			
	if (location.search.length > 0) {
		eval('var ' + location.search.substring(1));
		if (eval(id) > 0) {
			document.cto.elements["servicio"].value = eval(id)
			document.cto.elements["nombre"].focus();		
		}
	}
}

// Rutina para chequear el formulario de reserva o contacto
function vf(f) {

	if (f.elements["nombre"].value.length == 0) {
		alert("Por favor, Rellene el campo con su Nombre");
		f.elements["nombre"].focus();
		return false;
	}
	if (!isValidEmail(f.elements["email"].value)) {
		alert("Por favor, Introduzca una direccion de correo válida");
		f.elements["email"].focus();
		return false;
	}
	if (f.elements["servicio"].value == 0) {
		alert("Por favor, Seleccione un Servicio o Ruta");
		f.elements["servicio"].focus();
		return false;
	}
	f.elements["descrip"].value = f.elements["servicio"].options[f.elements["servicio"].selectedIndex].text;
	return true;
}

// Chequea formato de email válido (Sencillo)
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

