function emptyKeyword(field, texto) {
	if (field.value == texto) {
		field.value = "";
	}
}

function emptyKeywordSubmit(form) {
	if (form.keywords.value == "Busco …") {	
		form.keywords.value = "";
	}
}

function enviaForm(f) {
	f.submit();	
}


function checkSomeField(form) {
	emptyKeywordSubmit(form);
	var empty = true;
	for (i = 0; i < form.elements.length; i++) {
		if (empty && form.elements[i].type == "text" && form.elements[i].disabled == false && form.elements[i].value != "") {
			if (form.elements[i].id == "keywords" && form.elements[i].value != "Palabra clave") {
				empty = false;
			}
		}
		if (empty && form.elements[i].type == "select-one" && form.elements[i].disabled == false && form.elements[i].value != -1) {
			empty = false;
		}
	}
	if (empty) {
		alert("Por favor, rellena algún campo para realizar una búsqueda.");
		return false;	
	} else {		
		return true;
	}
}

function checkSomeFieldAdvanced(form) {
	var empty = true;
	for (i = 0; i < form.elements.length; i++) {
		if (empty && form.elements[i].type == "select-one" && form.elements[i].value != "-1") {
			empty = false;
		}
		if (empty && form.elements[i].type == "checkbox" && form.elements[i].checked == true) {
			empty = false;
		}
	}
	if (empty) {
		alert("Por favor, rellena algún campo para realizar una búsqueda.");
		return false;	
	} else {		
		return true;
	}
}

function checkInfoRequest(form) {
	if (form.nombre_empresa.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el nombre de la empresa.");
		form.nombre_empresa.focus();
		return false;
	}
	if (form.nombre.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el nombre y los apellidos.");
		form.nombre.focus();
		return false;
	}
	if (form.telefono.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el teléfono.");
		form.telefono.focus();
		return false;
	}
	if (form.email.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el email.");
		form.email.focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) {
	} else {
		alert("Por favor, introduce una dirección de email correcta.");
		form.email.focus();
		return false;
	}
	if (form.consulta.value.replace(/ /g, '') == "") {
		alert("Por favor, indica qué necesitas.");
		form.consulta.focus();
		return false;
	}
	if (!(form.usuarioSP0.checked) && !(form.usuarioSP1.checked)) {
		alert("Por favor, marca si eres usuario/a de Secretariaplus o no.");
		return false;
	}
	if (!(form.usuarioDP0.checked) && !(form.usuarioDP1.checked)) {
		alert("Por favor, marca si eres usuario/a de Directivosplus o no.");
		return false;
	}
	return true;
}

function restaurantsServices(elemId) {
	var elem = document.getElementById(elemId);
	if (elem.style.display == "block") {
		elem.style.display = "none";
	} else {
		elem.style.display = "block";
	}
}

function showCharacters(nChar, elem, counter) {	
    var nA = elem.value.length;     
    if (nA > nChar) {
       elem.value = elem.value.substring(0, (nChar));
    } else {
        counter.innerHTML = nChar - nA;
    }
}

function checkNewFile(f) {
	var t = f.formType.value;
	if (f.razon_social.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca la razón social.");
		f.razon_social.focus();	
		return false;
	}
	if (f.nombre.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca el nombre comercial.");
		f.nombre.focus();
		return false;
	}
	if (f.categoria.value == "0") {
		alert("Por favor, introduzca la categoría.");
		f.categoria.focus();
		return false;
	}
	if (f.provincia.value == "0") {
		alert("Por favor, introduzca la provincia.");
		f.provincia.focus();
		return false;
	}			
	if (f.poblacion.value == "0") {
		alert("Por favor, introduzca la población.");
		f.poblacion.focus();
		return false;
	}			
	if (f.cp.value == "0") {
		alert("Por favor, introduzca el código postal.");
		f.cp.focus();
		return false;
	}			
	if (f.direccion.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca la dirección.");
		f.direccion.focus();
		return false;
	}			
	if (f.telefono.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca el teléfono.");
		f.telefono.focus();
		return false;
	}			
	if (f.fax.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca el fax.");
		f.fax.focus();
		return false;
	}			
	if (f.email.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca el email.");
		f.email.focus();
		return false;
	} else {
		var re  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
		if (!re.test(f.email.value.replace(/ /g, ''))) { 
			alert ("Por favor, introduzca una dirección de email correcta."); 
			return false; 
		} 					
	}
	if (t == 3 && f.cocina.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca el tipo de cocina.");
		f.cocina.focus();
		return false;
	}			
	if (t == 3 && f.capacidad.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca la información sobre la capacidad.");
		f.capacidad.focus();
		return false;
	}			
	if (f.contacto.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca la persona de contacto.");
		f.contacto.focus();
		return false;
	}			
	if (f.contactoscomerciales.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca las direcciones de los contactos comerciales.");
		f.contactoscomerciales.focus();
		return false;
	}			
	if (f.palabrasclave.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca las palabras clave.");
		f.palabrasclave.focus();
		return false;
	}				
	if (f.descripcion.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca la descripción.");
		f.descripcion.focus();
		return false;
	}				
	if (f.email_copia.value.replace(/ /g, '') == "") {
		alert("Por favor, introduzca el email donde desea recibir copia de la información introducida.");
		f.email_copia.focus();
		return false;
	} else {
		var re  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
		if (!re.test(f.email_copia.value.replace(/ /g, ''))) { 
			alert ("Por favor, introduzca una dirección de email correcta."); 
			return false; 
		} 					
	}
}

function checkPhone(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
}

function checkSuggestions(form) {
	if (form.nombre.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el nombre.");
		form.nombre.focus();
		return false;
	}
	if (form.apellidos.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena los apellidos.");
		form.apellidos.focus();
		return false;
	}
	if (form.cargo.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el cargo.");
		form.cargo.focus();
		return false;
	}
	if (form.empresa.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena la empresa.");
		form.empresa.focus();
		return false;
	}
	if (form.telefono.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el teléfono.");
		form.telefono.focus();
		return false;
	}
	if (form.email.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el email.");
		form.email.focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) {
	} else {
		alert("Por favor, introduce una dirección de email correcta.");
		form.email.focus();
		return false;
	}
	if (form.mensaje.value.replace(/ /g, '') == "") {
		alert("Por favor, indica qué necesitas.");
		form.mensaje.focus();
		return false;
	}
	return true;
}

function checkAdvertisement(form) {
	if (form.empresa.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena la empresa.");
		form.empresa.focus();
		return false;
	}
	if (form.nombre.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el nombre.");
		form.nombre.focus();
		return false;
	}
	if (form.apellidos.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena los apellidos.");
		form.apellidos.focus();
		return false;
	}
	if (form.telefono.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el teléfono.");
		form.telefono.focus();
		return false;
	}
	if (form.email.value.replace(/ /g, '') == "") {
		alert("Por favor, rellena el email.");
		form.email.focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) {
	} else {
		alert("Por favor, introduce una dirección de email correcta.");
		form.email.focus();
		return false;
	}
	if (form.categoria.value == "0") {
		alert("Por favor, elige una categoría.");
		form.categoria.focus();
		return false;
	}
	return true;
}
