function seleccionarElementoCitaWeb(elemento, valorSeleccionado)
{
	
	document.getElementById("itemCitaMedica").className="itemCitasWeb";
	document.getElementById("itemPedirCita").className="itemCitasWeb";
	document.getElementById("itemCambioAnulacion").className="itemCitasWeb";
	document.getElementById("itemSolicitaInformacion").className="itemCitasWeb";
	elemento.className="itemCitasWebSeleccionado";
	document.getElementById("tipoSolicitudWeb").value = valorSeleccionado;
	
}

function deseleccionarElementosCitaWeb()
{
	
	document.getElementById("itemCitaMedica").className="itemCitasWeb";
	document.getElementById("itemPedirCita").className="itemCitasWeb";
	document.getElementById("itemCambioAnulacion").className="itemCitasWeb";
	document.getElementById("itemSolicitaInformacion").className="itemCitasWeb";
	document.getElementById("opcionCambio").checked=false;
	document.getElementById("opcionAnulacion").checked=false;
	document.getElementById("tipoSolicitudWeb").value = -1;
	
}

function mostrarOpcionesCambioCita()
{
	
	document.getElementById("opcionesCambioCitaWeb").style.display="block";	
	
}

function ocultarOpcionesCambioCita()
{
	
	document.getElementById("opcionesCambioCitaWeb").style.display="none";	
	
}

function mostrarOpcionesSolicitudInfo()
{
	
	document.getElementById("opcionesSolicitudInfo").style.display="block";	
	
}

function ocultarOpcionesSolicitudInfo()
{
	
	document.getElementById("opcionesSolicitudInfo").style.display="none";	
	
}

function revisarContenido(elemento, contenido)
{
	
	if(elemento.value == contenido)
		elemento.value = '';
	
}

function revisarContenidoDefecto(elemento, contenido)
{
	
	if(elemento.value == '')
		elemento.value = contenido;
	
}

function mostrarFormularioAmigo()
{
	
	document.getElementById('datosEnviarAmigo').style.display="block";	
	
}

function ocultarFormularioWeb()
{
	
	document.getElementById('datosSolicitudWeb').style.display="none";	
	
}

function ocultarFormularioAmigo()
{
	
	document.getElementById('datosEnviarAmigo').style.display="none";	
	
}

function mostrarFormularioWeb()
{
	
	document.getElementById('datosSolicitudWeb').style.display="block";	
	
}
function cargarContenido(documentoPasarela, accion, seccion, parametrosAdicionales)
{
	
	loader = new XmlHttp();
	loader.cargarResultado(documentoPasarela + "?accion=" + accion + "&seccion=" + seccion + parametrosAdicionales, document.getElementById('contenido'), "");
	
}
function cargarClinicasPoblacionDondeEstamos(idPoblacion)
{

	llamarasincrono("cargadorClinicas.php?idPoblacion=" + idPoblacion, "contenedorCiudadesDondeEstamos");

}

function cargarClinicasPoblacionCitaWeb(idPoblacion)
{

	llamarasincrono("cargadorClinicasCitaWeb.php?idPoblacion=" + idPoblacion, "contenedorClinicasCitaWeb");

}
function cargarClinicasPoblacionRRHH(idPoblacion)
{

	llamarasincrono("cargadorClinicasRRHH.php?idPoblacion=" + idPoblacion, "contenedorClinicasRRHH");

}
function cargarClinicasPoblacionSugerencia(idPoblacion)
{

	llamarasincrono("cargadorClinicasSugerencia.php?idPoblacion=" + idPoblacion, "contenedorClinicasSugerencia");

}
function cargarTarifaClinica(clinica)
{

	llamarasincrono("cargadorTarifas.php?clinica=" + clinica, "imagenClinica");
	document.getElementById("imagenClinica").style.backgroundImage="";

}
function validarFormularioSugerencia()
{

	var valido = true;

	var mensaje = "El formulario está incompleto.\r\n\r\n";

	var valor = document.getElementById('datoNombreSugerencia').value;
	
	if(valor == '' || valor == 'Nombre')
	{
		mensaje += "-Debe indicar su nombre.\r\n";
		valido = false;
		
	}	
	
	valor = document.getElementById('datoApellidosSugerencia').value;
		
	if(valor == '' || valor == 'Apellidos')
	{
		mensaje += "-Debe indicar sus apellidos.\r\n";
		valido = false;
			
	}
	
	valor = document.getElementById('datoMovilSugerencia').value;
			
	if(valor == '' || valor == 'Móvil' || !telefonoValido(valor))
	{
		mensaje += "-Debe indicar su teléfono móvil.\r\n";
		valido = false;
				
	}
	
	valor = document.getElementById('datoEmailSugerencia').value;
				
	if(valor == '' || valor == 'E-mail' || !mailValido(valor))
	{
		mensaje += "-Debe indicar su E-mail.\r\n";
		valido = false;
					
	}
	
	valor = document.getElementById('clinicaSugerencia').value;
				
	if(valor < 1)
	{
		mensaje += "-Debe seleccionar una clínica.\r\n";
		valido = false;
						
	}
	
	valor = document.getElementById('horarioContacto').value;
		
	if(valor < 1)
	{
		mensaje += "-Debe especificar un horario de contacto.\r\n";
		valido = false;

	}
	
	valor = document.getElementById('textoSugerencia').value;
							
	if(valor == '' || valor == 'Indique aquí su sugerencia')
	{
		mensaje += "-No ha indicado ninguna sugerencia.\r\n";
		valido = false;

	}
	
	valor = document.getElementById('politicaSugerencia').checked;
								
	if(!valor)
	{
		mensaje += "-Debe aceptar la política de privacidad.\r\n";
		valido = false;
	
	}
	
	if(!valido)
		alert(mensaje);
	
	return valido;

}

function validarFormularioCitaWeb()
{

	var valido = true;

	var mensaje = "El formulario de solicitud de cita está incompleto.\r\n\r\n";

	var valor = document.getElementById('tipoSolicitudWeb').value;
		
	if(valor == '' || valor == '-1')
	{
		mensaje += "-Debe indicar la solicitud a realizar.\r\n";
		valido = false;

	}

	valor = document.getElementById('datoNombreWeb').value;
	
	if(valor == '' || valor == 'Nombre')
	{
		mensaje += "-Debe indicar su nombre.\r\n";
		valido = false;
		
	}	
	
	valor = document.getElementById('datoApellidosWeb').value;
		
	if(valor == '' || valor == 'Apellidos')
	{
		mensaje += "-Debe indicar sus apellidos.\r\n";
		valido = false;
			
	}
	
	valor = document.getElementById('datoMovilWeb').value;
			
	if(valor == '' || valor == 'Móvil' || !telefonoValido(valor))
	{
		mensaje += "-Debe indicar su teléfono móvil.\r\n";
		valido = false;
				
	}
	
	valor = document.getElementById('datoEmailWeb').value;
				
	if(valor == '' || valor == 'E-mail' || !mailValido(valor))
	{
		mensaje += "-Debe indicar su E-mail.\r\n";
		valido = false;
					
	}
	
	valor = document.getElementById('datoClinicaWeb').value;
				
	if(valor < 1)
	{
		mensaje += "-Debe seleccionar una clínica.\r\n";
		valido = false;
						
	}
	
	if(document.getElementById('tipoSolicitudWeb').value < 5)
	{
	
		valor = document.getElementById('datoFechaCitaWeb').value;

		if(valor == '' || valor == 'Fecha de la cita')
		{
			mensaje += "-Debe especificar una fecha para la cita.\r\n";
			valido = false;

		}

	}

	valor = document.getElementById('datoPoliticaWeb').checked;
								
	if(!valor)
	{
		mensaje += "-Debe aceptar la política de privacidad.\r\n";
		valido = false;
	
	}
	
	if(!valido)
		alert(mensaje);
	else
		document.getElementById('datoNombreTuyo').value = '';
		
	if(valido && document.getElementById('tipoSolicitudWeb').value > 4)
	{
	
		var date = new Date();
		document.getElementById('datoFechaCitaWeb').value = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
		
	
	}
		
	return valido;

}

function validarFormularioEnviarAmigo()
{

	var valido = true;

	var mensaje = "El formulario de envío a un amigo está incompleto.\r\n\r\n";

	var valor = document.getElementById('datoNombreTuyo').value;
	
	if(valor == '' || valor == 'Tu nombre')
	{
	
		mensaje += "-Debes indicar tu nombre.\r\n";
		valido = false;
	
	}
	
	valor = document.getElementById('datoMailTuyo').value;
	
	if(valor == '' || valor == 'Tu e-mail' || !mailValido(valor))
	{
	
		mensaje += "-Debes indicar tu e-mail.\r\n";
		valido = false;
	
	}
	
	valor = document.getElementById('datoNombreSuyo').value;

	if(valor == '' || valor == 'Su nombre')
	{

		mensaje += "-Debes indicar el nombre de tu amigo.\r\n";
		valido = false;

	}

	valor = document.getElementById('datoMailSuyo').value;

	if(valor == '' || valor == 'Su e-mail' || !mailValido(valor))
	{

		mensaje += "-Debes indicar el e-mail de tu amigo.\r\n";
		valido = false;
		
	}
	
	if(!valido)
		alert(mensaje);
	else
		document.getElementById('tipoSolicitudWeb').value = '-1';

	return valido;
	
}

function telefonoValido(sText)
{

   if(sText.length != 9)
   	return false;

   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
   {
      Char = sText.charAt(i);

      if (ValidChars.indexOf(Char) == -1)
      	IsNumber = false;

   }

   return IsNumber;

}

function mailValido(str)
{

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1)
		return false;

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		return false;


	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false;

	 if (str.indexOf(at,(lat+1))!=-1)
		return false;


	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false;


	 if (str.indexOf(dot,(lat+2))==-1)
		return false;


	 if (str.indexOf(" ")!=-1)
		return false;

	 return true
}

function validarFormularioFranquicia()
{

	var valido = true;

	var mensaje = "El formulario está incompleto.\r\n\r\n";

	var valor = document.getElementById('datoNombreFranquicia').value;
	
	if(valor == '' || valor == 'Nombre')
	{
		mensaje += "-Debe indicar su nombre.\r\n";
		valido = false;
		
	}	
	
	valor = document.getElementById('datoApellidosFranquicia').value;
		
	if(valor == '' || valor == 'Apellidos')
	{
		mensaje += "-Debe indicar sus apellidos.\r\n";
		valido = false;
			
	}
	
	
	valor = document.getElementById('datoCiudadFranquicia').value;

	if(valor == '' || valor == 'Ciudad')
	{
		mensaje += "-Debe indicar su ciudad.\r\n";
		valido = false;
	
	}
	
	valor = document.getElementById('datoTelefonoFranquicia').value;
			
	if(valor == '' || valor == 'Teléfono de contacto')
	{
		mensaje += "-Debe indicar el teléfono de contacto.\r\n";
		valido = false;
				
	}
	
	valor = document.getElementById('datoMailFranquicia').value;
				
	if(valor == '' || valor == 'E-mail' || !mailValido(valor))
	{
		mensaje += "-Debe indicar su E-mail.\r\n";
		valido = false;
					
	}

	valor = document.getElementById('datoLugarFranquicia').value;
				
	if(valor == '' || valor == 'Lugar en el que está interesado montar una clínica')
	{
		mensaje += "-Debe indicar el lugar donde quiere montar una franquicia.\r\n";
		valido = false;
					
	}

	valor = document.getElementById('politicaWebFranquicia').checked;
									
	if(!valor)
	{
		mensaje += "-Debe aceptar la política de privacidad.\r\n";
		valido = false;
		
	}
	
	if(!valido)
		alert(mensaje);
	
	return valido;

}
