

var total_filas = 0;


function graphicsb_data0()
{
    /*---------------------------------------------
    Scroll Bar Images
    ---------------------------------------------*/
	this.up_button = "img/sample2_up.gif";                                          //image path and name only
	this.up_button_roll = "img/sample2_up_roll.gif";                                //image path and name only
	this.down_button = "img/sample2_down.gif";                                      //image path and name only
	this.down_button_roll = "img/sample2_down_roll.gif";                            //image path and name only

	this.slider_tile_bg_style = "background-image:url(img/sample2_slider_bg.gif);"  //image defined as CSS style

	this.bubble_top_cap = "img/sample2_bubble_topcap.gif,2";                        //image path and name, height - (width is automatically set to scroll bar width)
	this.bubble_bottom_cap = "img/sample2_bubble_bottomcap.gif,2";                  //image path and name, height - ""
	this.bubble_center = "img/sample2_bubble_center.gif,7";                         //image path and name, height - ""
	this.bubble_tile_bg_style = "img/sample2_bubble_bg.gif";                        //image path and name only

    /*---------------------------------------------
    Scroll Bar Container and Content
    ---------------------------------------------*/

	this.container_width = 240
	this.container_height = 85


	this.container_bg_color = "";

	this.content_padding = 7;
	this.content_styles = "font-family:Arial;font-weight:normal;font-size:11px; color:##5F5D5C; ";
	this.content_class_name = "texto_scroll";

    /*---------------------------------------------
    Scroll Bar Behaviour and Width
    ---------------------------------------------*/

	this.scroll_bar_width = 9                     //The width of the bar in pixels.
	this.scroll_increment = 10                     //The distance to scroll when clicking the up or down buttons.


	this.allow_hover_scroll = true;                //Auto scroll while hovering over top and bottom buttons.
	this.hover_scroll_delay = 70;                   //Milliseconds (1/1000 second)


	this.use_hand_cursor = true;

}


function graphicsb_data1()
{
    /*---------------------------------------------
    Scroll Bar Images
    ---------------------------------------------*/
	this.up_button = "img/sample2_up.gif";                                          //image path and name only
	this.up_button_roll = "img/sample2_up_roll.gif";                                //image path and name only
	this.down_button = "img/sample2_down.gif";                                      //image path and name only
	this.down_button_roll = "img/sample2_down_roll.gif";                            //image path and name only

	this.slider_tile_bg_style = "background-image:url(img/sample2_slider_bg.gif);"  //image defined as CSS style

	this.bubble_top_cap = "img/sample2_bubble_topcap.gif,2";                        //image path and name, height - (width is automatically set to scroll bar width)
	this.bubble_bottom_cap = "img/sample2_bubble_bottomcap.gif,2";                  //image path and name, height - ""
	this.bubble_center = "img/sample2_bubble_center.gif,7";                         //image path and name, height - ""
	this.bubble_tile_bg_style = "img/sample2_bubble_bg.gif";                        //image path and name only

    /*---------------------------------------------
    Scroll Bar Container and Content
    ---------------------------------------------*/

	this.container_width = 450
	this.container_height = 270


	this.container_bg_color = "";

	this.content_padding = 7;
	this.content_styles = "font-family:Arial;font-weight:normal;font-size:11px; color:##5F5D5C; ";
	this.content_class_name = "texto_scroll";

    /*---------------------------------------------
    Scroll Bar Behaviour and Width
    ---------------------------------------------*/

	this.scroll_bar_width = 9                     //The width of the bar in pixels.
	this.scroll_increment = 10                     //The distance to scroll when clicking the up or down buttons.


	this.allow_hover_scroll = true;                //Auto scroll while hovering over top and bottom buttons.
	this.hover_scroll_delay = 70;                   //Milliseconds (1/1000 second)


	this.use_hand_cursor = true;

}

function graphicsb_data2()
{
    /*---------------------------------------------
    Scroll Bar Images
    ---------------------------------------------*/
	this.up_button = "img/sample2_up.gif";                                          //image path and name only
	this.up_button_roll = "img/sample2_up_roll.gif";                                //image path and name only
	this.down_button = "img/sample2_down.gif";                                      //image path and name only
	this.down_button_roll = "img/sample2_down_roll.gif";                            //image path and name only

	this.slider_tile_bg_style = "background-image:url(img/sample2_slider_bg.gif);"  //image defined as CSS style

	this.bubble_top_cap = "img/sample2_bubble_topcap.gif,2";                        //image path and name, height - (width is automatically set to scroll bar width)
	this.bubble_bottom_cap = "img/sample2_bubble_bottomcap.gif,2";                  //image path and name, height - ""
	this.bubble_center = "img/sample2_bubble_center.gif,7";                         //image path and name, height - ""
	this.bubble_tile_bg_style = "img/sample2_bubble_bg.gif";                        //image path and name only

    /*---------------------------------------------
    Scroll Bar Container and Content
    ---------------------------------------------*/

	this.container_width = 450
	this.container_height = 90


	this.container_bg_color = "";

	this.content_padding = 7;
	this.content_styles = "font-family:Arial;font-weight:normal;font-size:11px; color:##5F5D5C; ";
	this.content_class_name = "texto_scroll";

    /*---------------------------------------------
    Scroll Bar Behaviour and Width
    ---------------------------------------------*/

	this.scroll_bar_width = 9                     //The width of the bar in pixels.
	this.scroll_increment = 10                     //The distance to scroll when clicking the up or down buttons.


	this.allow_hover_scroll = true;                //Auto scroll while hovering over top and bottom buttons.
	this.hover_scroll_delay = 70;                   //Milliseconds (1/1000 second)


	this.use_hand_cursor = true;

}


function anyadirFilas(){
		total_filas++;	
		tabla = document.getElementById("select_frecuencia");
		fila = tabla.insertRow(total_filas);		

		fila.setAttribute("className","frecuencias");	
	  fila.setAttribute("id","frecuencias");	
		
		celda1 = fila.insertCell(0);		
		
		
		label = document.createTextNode("Día: ");
		celda1.appendChild(label);
		
		 nodoSelect = document.createElement('select');
		 nodoSelect.setAttribute("className","inputText_select");	
		 nodoSelect.setAttribute("id","inputText_select");				 		 
		 nodoSelect.setAttribute("name","dia_"+total_filas);		
		 
		 array_dias = new Array("Lunes","Martes","Miércoles","Jueves","Viernes");
		 
		 for(i=0;i<5;i++){
			var op1 = document.createElement('option');
			op1.value = (i+1);
			var txt1 = document.createTextNode(array_dias[i]);
			op1.appendChild(txt1);
			
			nodoSelect.appendChild(op1);
			}		 
	
			celda1.appendChild(nodoSelect);	
			
			/**segunda celda**/
			celda1 = fila.insertCell(1);	
			
			label = document.createTextNode(" ");
			celda1.appendChild(label);			
			label = document.createTextNode("   Hora Inicio: ");
			celda1.appendChild(label);
			
			 nodoSelect = document.createElement('select');
			 nodoSelect.setAttribute("className","inputText_select");	
			 nodoSelect.setAttribute("id","inputText_select");				 
			 nodoSelect.setAttribute("name","hora_inicio_"+total_filas);		
			 

			 
		 for(i=8;i<=21;i++){
			var op1 = document.createElement('option');
			op1.value = (i);
			var txt1 = document.createTextNode(i+':00h');
			op1.appendChild(txt1);
			
			nodoSelect.appendChild(op1);
			}		 
	
			celda1.appendChild(nodoSelect);			
				
			/**segunda celda**/
			celda1 = fila.insertCell(2);				
				
			label = document.createTextNode(" ");
			celda1.appendChild(label);			
			label = document.createTextNode("   Hora Fin: ");
			celda1.appendChild(label);
			
			 nodoSelect = document.createElement('select');
			 nodoSelect.setAttribute("className","inputText_select");	
			 nodoSelect.setAttribute("id","inputText_select");				 			 
			 nodoSelect.setAttribute("name","hora_fin_"+total_filas);		
			 

			 
			 for(i=8;i<=21;i++){
				var op1 = document.createElement('option');
				op1.value = (i);
				var txt1 = document.createTextNode(i+':00h');
				op1.appendChild(txt1);
				
				nodoSelect.appendChild(op1);
				}		 
		
				celda1.appendChild(nodoSelect);					
		}
		
		
		function borrarFila() {
			

		 if(total_filas>0){

			 tbody = document.getElementById('select_frecuencia');	 
			 filas = tbody.getElementsByTagName("tr");
			 if (total_filas+1>filas.length)
					alert("Solo hay " + filas.length + " filas");
			 else {
					tbody.deleteRow(total_filas);
					total_filas--;			
			 }
	 
		}		
		

		}

	
	
	
	function comprobar_fecha(fecha){
		var RegExPattern = /^\d{2}\/\d{2}\/\d{4}$/;
		var RegExPattern2 = /^\d{2}-\d{2}-\d{4}$/;
		var dia=0;
		var mes=0;
		var anyo=0;
		
		if ( ((fecha.match(RegExPattern)) && fecha!="") || ((fecha.match(RegExPattern2)) && fecha!="") ) {
			dia=(fecha.substring(0,2))*1;
			mes=(fecha.substring(3,5))*1;
			anyo=(fecha.substring(6,10))*1;
			
			if (dia>=1 && dia<=31 && mes>=1 && mes<=12 && anyo>=2006 && anyo<=2020)
				return(true);
		}
		
		return(false);
		
	}
	
	function comprobar_hora(hora){
		var RegExPattern = /^\d{2}:\d{2}$/;
		var horas=0;
		var minutos=0;
		
		if ( ((hora.match(RegExPattern)) && hora!="")) {
			horas=(hora.substring(0,2))*1;
			minutos=(hora.substring(3,5))*1;
			
			if (horas>=0 && horas<=23 && minutos>=0 && minutos<=59)
				return(true);
		}
		
		return(false);
		
	}
	
	function comprobar_correo(correo){
		var cadena1="abcdefghijklmnñopqrstuvwxyz._-ABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789";
		var cadena2="abcdefghijklmnñopqrstuvwxyz._-ABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789";
			
			
			if (correo.indexOf("@")!=correo.lastIndexOf("@")) //solo una arroba
				return (false);
			if (correo.indexOf("@")==-1 || correo.indexOf(".")==-1) //que haya al menos un punto y una arroba
				return (false);
			
			var nombre=correo.substring(0,correo.indexOf("@"));
			var dominio=correo.substring(correo.indexOf("@")+1,correo.length);
			
			if (nombre.length<1 || dominio.length<3 )
				return (false);
			
			if (dominio.substring(dominio.lastIndexOf(".")+1,dominio.length).length>3 || dominio.substring(dominio.lastIndexOf(".")+1,dominio.length).length==1) //para que el dominio no tenga mas de 3 letras
				return (false);
			
			
			for (cont=0;cont<nombre.length;cont++){
				if (cadena1.indexOf(nombre.charAt(cont))==-1) {
					return (false);
				}
			}
			
			for (cont=0;cont<dominio.length;cont++){
			
				if (cont==0 || cont==dominio.length-1) //que no haya . en primera o ultima parete del dominio
					if ( dominio.charAt(cont) == "." )
						return (false);
			
				if (cadena2.indexOf(dominio.charAt(cont))==-1)
					return (false);		
			}
			
			return (true);
		}

	
	function validarInstalacion() {
		numero=document.edita_instalacion.numero.value;
		kwpico=document.edita_instalacion.kwpico.value;
		kw=document.edita_instalacion.kw.value;
		num_ejes=document.edita_instalacion.num_ejes.value;
		num_modulos=document.edita_instalacion.num_modulos.value;
		produccion_inicial=document.edita_instalacion.produccion_inicial.value;
		
		enero=document.edita_instalacion.enero.value;
		febrero=document.edita_instalacion.febrero.value;
		marzo=document.edita_instalacion.marzo.value;
		abril=document.edita_instalacion.abril.value;
		mayo=document.edita_instalacion.mayo.value;
		junio=document.edita_instalacion.junio.value;
		julio=document.edita_instalacion.julio.value;
		agosto=document.edita_instalacion.agosto.value;
		septiembre=document.edita_instalacion.septiembre.value;
		octubre=document.edita_instalacion.octubre.value;
		noviembre=document.edita_instalacion.noviembre.value;
		diciembre=document.edita_instalacion.diciembre.value;
		anyo=document.edita_instalacion.anyo.value;
		
		if (isNaN(numero) || numero<=0) {
			alert("El campo número debe contener un valor numérico mayor que 0.");
			return(false);
		}
		if (isNaN(kwpico)) {
			alert("El campo potencia pico debe contener un valor numérico.");
			return(false);
		}
		if (isNaN(kw)) {
			alert("El campo potencia debe contener un valor numérico.");
			return(false);
		}
		if (isNaN(num_ejes)) {
			alert("El campo número de ejes debe contener un valor numérico.");
			return(false);
		}
		if (isNaN(num_modulos)) {
			alert("El campo número de módulos debe contener un valor numérico.");
			return(false);
		}
		if (isNaN(produccion_inicial)) {
			alert("El campo producción inicial debe contener un valor númerico (indique 0 si fuera necesario).");
			return(false);
		}
		if (isNaN(enero) || isNaN(febrero) || isNaN(marzo) || isNaN(abril) || isNaN(mayo) || isNaN(junio) || isNaN(julio) || isNaN(agosto) || isNaN(septiembre) || isNaN(octubre) || isNaN(noviembre) || isNaN(diciembre)) {
			alert("Las estimaciones deben contener un valor numérico (indique 0 si fuera necesario).");
			return(false);
		}
		if (enero=="" || febrero=="" || marzo=="" || abril=="" || mayo=="" || junio=="" || julio=="" || agosto=="" || septiembre=="" || octubre=="" || noviembre=="" || diciembre=="") {
			alert("Las estimaciones deben contener un valor numérico (indique 0 si fuera necesario).");
			return(false);
		}
		if (isNaN(anyo) || anyo=="") {
			alert("El campo año de compra debe contener un valor numérico.");
			return(false);
		}
		
		return(true);
	}
	
	function validarCliente() {
		nombre=document.edita_cliente.nombre.value;
		usuario=document.edita_cliente.usuario.value;
		pass=document.edita_cliente.pass.value;
		if (nombre=="" || usuario=="" || pass=="") {
			alert("Los campos nombre, usuario y contraseña son de cumplimentación obligatoria.");
			return(false);
		}
		return(true);
	}
	

	function validarReseteo() {	
		instalacion=document.edita_reseteo.instalacion.value;
		lectura_anterior=document.edita_reseteo.lectura_anterior.value;
		lectura_nueva=document.edita_reseteo.lectura_nueva.value;
		fecha=document.edita_reseteo.fecha.value;
		hora=document.edita_reseteo.hora.value;
		if (instalacion=="-1" || lectura_anterior=="" || lectura_nueva=="" || fecha=="" || hora=="") {
			alert("Todos los campos son de cumplimentación obligatoria.");
			return(false);
		}
		if (isNaN(lectura_anterior) || lectura_anterior<0 || isNaN(lectura_nueva) || lectura_nueva<0) {
			alert("Los campos de lectura debe contener un valor numérico positivo.");
			return(false);
		}
		if(!(comprobar_fecha(fecha))) {
			alert("Formato de fecha incorrecto");
			document.getElementById("fecha").style.color="#f00";
			return(false);
		}		
		if(!(comprobar_hora(hora))) {
			alert("Formato de hora incorrecto");
			document.getElementById("hora").style.color="#f00";
			return(false);
		}
		return(true);
	}
	
	
	function validarParque() {
		nombre=document.edita_parque.nombre.value;
		inicio=document.edita_parque.inicio.value;
		fin=document.edita_parque.fin.value;
		
		if (nombre=="") {
			alert("El campo nombre es de cumplimentación obligatoria.");
			return(false);
		}
		
		if ((correo=document.edita_parque.correo1.value)!="")
			if(!(comprobar_correo(correo))) {
				alert("La dirección de correo electrónica no es válida");
				document.getElementById("correo1").style.color="#f00";
				return(false);
			}
		
		if ((correo=document.edita_parque.correo2.value)!="")
			if(!(comprobar_correo(correo))) {
				alert("La dirección de correo electrónica no es válida");
				document.getElementById("correo2").style.color="#f00";
				return(false);
			}
			
		if(!(comprobar_hora(inicio))) {
			alert("Formato de hora incorrecto");
			document.getElementById("inicio").style.color="#f00";
			return(false);
		}
		if(!(comprobar_hora(fin))) {
			alert("Formato de hora incorrecto");
			document.getElementById("fin").style.color="#f00";
			return(false);
		}
		if (inicio>fin) {
			alert("La hora de inicio ha de ser inferior a la de fin");
			document.getElementById("inicio").style.color="#f00";
			document.getElementById("fin").style.color="#f00";
			return(false);
		}
		
		return(true);
	}
	
	function validarListados(){
		numero_items=document.form_lista.numItems.value;
		for (i=0;i<numero_items;i++) {
			eval("aux=document.form_lista.inp"+i+".checked;");
			if (aux===true) return(true);
		}
		
		alert("Debe seleccionar algún elemento para eliminar.");
		return(false);
	}
	
	
	function validarNoticia(){
		fecha=document.edita_noticia.fecha.value;
		if(!(comprobar_fecha(fecha))) {
			alert("Formato de fecha incorrecto");
			document.getElementById("e_fecha").style.color="#f00";
			return(false);
		}
		if(document.edita_noticia.titular.value=="" || document.edita_noticia.desarrollo.value=="") {
			alert("Todos los campos del formulario son obligatorios.");
			return(false);
		}
	}
	
	function validarCalculos(){
		fecha=document.configura_calculos.fecha.value;
		if(!(comprobar_fecha(fecha))) {
			alert("Formato de fecha incorrecto");
			document.getElementById("fecha").style.color="#f00";
			return(false);
		}
		
		hora=document.configura_calculos.hora.value;
		if(!(comprobar_hora(hora))) {
			alert("Formato de hora incorrecto");
			document.getElementById("hora").style.color="#f00";
			return(false);
		}

		return true;
	}
	
	
	function validarAlarmas(){
		if ((correo=document.configura_alarmas.correo1.value)!="")
			if(!(comprobar_correo(correo))) {
				alert("La dirección de correo electrónica no es válida");
				document.getElementById("correo1").style.color="#f00";
				return(false);
			}
		
		if ((correo=document.configura_alarmas.correo2.value)!="")
			if(!(comprobar_correo(correo))) {
				alert("La dirección de correo electrónica no es válida");
				document.getElementById("correo2").style.color="#f00";
				return(false);
			}
				
		return true;
	}
	
	function validarConstantes(){
		if (isNaN(document.configura_constantes.ratio_alarma_leve.value) || document.configura_constantes.ratio_alarma_leve.value<=0) {
			alert("Las constantes deben ser un valor numérico superior a 0");
			document.getElementById("ratio_alarma_leve").style.color="#f00";
			return(false);
		}
		if (isNaN(document.configura_constantes.ratio_alarma_grave.value) || document.configura_constantes.ratio_alarma_grave.value<=0) {
			alert("Las constantes deben ser un valor numérico superior a 0");
			document.getElementById("ratio_alarma_grave").style.color="#f00";
			document.getElementById("ratio_alarma_grave").focus();
			return(false);
		}
		if (isNaN(document.configura_constantes.factor_rechazo.value) || document.configura_constantes.factor_rechazo.value<=0) {
			alert("Las constantes deben ser un valor numérico superior a 0");
			document.getElementById("factor_rechazo").style.color="#f00";
			document.getElementById("factor_rechazo").focus();
			return(false);
		}
		if (isNaN(document.configura_constantes.cuota_desgaste.value) || document.configura_constantes.cuota_desgaste.value<=0) {
			alert("Las constantes deben ser un valor numérico superior a 0");
			document.getElementById("cuota_desgaste").style.color="#f00";
			return(false);
		}
		if (isNaN(document.configura_constantes.constante_CO2.value) || document.configura_constantes.constante_CO2.value<=0) {
			alert("Las constantes deben ser un valor numérico superior a 0");
			document.getElementById("constante_CO2").style.color="#f00";
			return(false);
		}
		
		return true;
	}
	
	
	
	function abrirVentanaFestivos(fecha,pag){
		window.open("establecerFestivo.php?fecha="+fecha+"&pag="+pag,"Festivos","width=250,height=200,scrollbars=yes, top=0, left=0");
	}
	
	function abrirVentanaModFestivos(fecha,pag){
		window.open("modificarFestivo.php?fecha="+fecha+"&pag="+pag,"Festivos","width=250,height=200,scrollbars=yes, top=0, left=0");
	}	
	
	function abrirVentanaBorrarPaciente(num){
		window.open("borrarPaciente.php?num="+num,"Borrar","width=280,height=250,scrollbars=yes, top=0, left=0");
	}	
	
	function abrirVentanaDarCita(ident,i){
		eval("index = document.listas_"+i+".anyadir_lista.selectedIndex");
		eval("valor = document.listas_"+i+".anyadir_lista.options[index].value");		
		

		window.open("darCita.php?ident="+ident+"&tipo="+valor,"Cita","width=750,height=620,scrollbars=yes, top=0, left=0");
	}		
	
	function abrirVentanaModDarCita(ident,i){
		window.open("darCita.php?ident="+ident+"&tipo="+i,"Cita","width=750,height=620,scrollbars=yes, top=0, left=0");
	}		
	
	
	function abrirVentanaDarAlta(id){
		window.open("darAltaPaciente.php?num="+id,"Alta","width=280,height=250,scrollbars=yes, top=0, left=0");
	}
	
	
	function abrirDetalleCita(fecha,hora){
		window.open("detalleCita.php?fecha="+fecha+"&hora="+hora,"Detalle","width=244,height=300,scrollbars=no, top=0, left=0");
	}
	
	
	function abrirVentanaBorrarCita(id){
		window.open("borrarCita.php?id="+id,"Detalle","width=244,height=200,scrollbars=yes, top=0, left=0");
	}	
	
	function abrirVentanaAsignarCita(idFecha,idCliente){
		window.open("asignarCitaPaciente.php?idFecha="+idFecha+"&idPaciente="+idCliente,"Detalle","width=730,height=396,scrollbars=yes, top=0, left=0");
	}		
	
	function deshabilitar(semana){
			
			form = document.horario;

			if(semana != "todos"){
				eval("activado = form.todo_"+semana+".checked");

				if(activado == true){ //desactivamos los inputs de ese día
					 eval("form.hora1_ini_"+semana+".className = 'inputText inputHorario tachado'") ;
					 eval("form.hora1_fin_"+semana+".className = 'inputText inputHorario tachado'") ;				 
					 eval("form.hora2_ini_"+semana+".className = 'inputText inputHorario tachado'") ;
					 eval("form.hora2_fin_"+semana+".className = 'inputText inputHorario tachado'") ;				 
					 eval("form.hora3_ini_"+semana+".className = 'inputText inputHorario tachado'") ;				 				 
					 eval("form.hora3_fin_"+semana+".className = 'inputText inputHorario tachado'") ;		
					 
					 eval("form.hora1_ini_"+semana+".disabled = true") ;
					 eval("form.hora1_fin_"+semana+".disabled = true") ;				 
					 eval("form.hora2_ini_"+semana+".disabled = true") ;
					 eval("form.hora2_fin_"+semana+".disabled = true") ;				 
					 eval("form.hora3_ini_"+semana+".disabled = true") ;				 				 
					 eval("form.hora3_fin_"+semana+".disabled = true") ;						 

					document.getElementById("todo_"+semana+"").checked = true					 

				}
				else{
					 eval("form.hora1_ini_"+semana+".className = 'inputText inputHorario'") ;
					 eval("form.hora1_fin_"+semana+".className = 'inputText inputHorario'") ;				 
					 eval("form.hora2_ini_"+semana+".className = 'inputText inputHorario'") ;
					 eval("form.hora2_fin_"+semana+".className = 'inputText inputHorario'") ;				 
					 eval("form.hora3_ini_"+semana+".className = 'inputText inputHorario'") ;				 				 
					 eval("form.hora3_fin_"+semana+".className = 'inputText inputHorario'") ;			
					 
					 eval("form.hora1_ini_"+semana+".disabled = false") ;
					 eval("form.hora1_fin_"+semana+".disabled = false") ;				 
					 eval("form.hora2_ini_"+semana+".disabled = false") ;
					 eval("form.hora2_fin_"+semana+".disabled = false") ;				 
					 eval("form.hora3_ini_"+semana+".disabled = false") ;				 				 
					 eval("form.hora3_fin_"+semana+".disabled = false") ;					
					 
					 document.getElementById("todo_"+semana+"").checked = false;
				}
		}
		else{
			diasSemana = new Array("lunes","martes","miercoles","jueves","viernes");
			eval("activado = form.todos_dias.checked");
			for(i=0;i<5;i++){
				semana = diasSemana[i];
				if(activado == true){ //desactivamos los inputs de ese día
					 eval("form.hora1_ini_"+semana+".className = 'inputText inputHorario tachado'") ;
					 eval("form.hora1_fin_"+semana+".className = 'inputText inputHorario tachado'") ;				 
					 eval("form.hora2_ini_"+semana+".className = 'inputText inputHorario tachado'") ;
					 eval("form.hora2_fin_"+semana+".className = 'inputText inputHorario tachado'") ;				 
					 eval("form.hora3_ini_"+semana+".className = 'inputText inputHorario tachado'") ;				 				 
					 eval("form.hora3_fin_"+semana+".className = 'inputText inputHorario tachado'") ;		
					 
					 eval("form.hora1_ini_"+semana+".disabled = true") ;
					 eval("form.hora1_fin_"+semana+".disabled = true") ;				 
					 eval("form.hora2_ini_"+semana+".disabled = true") ;
					 eval("form.hora2_fin_"+semana+".disabled = true") ;				 
					 eval("form.hora3_ini_"+semana+".disabled = true") ;				 				 
					 eval("form.hora3_fin_"+semana+".disabled = true") ;					
				}
				else{
					 eval("form.hora1_ini_"+semana+".className = 'inputText inputHorario'") ;
					 eval("form.hora1_fin_"+semana+".className = 'inputText inputHorario'") ;				 
					 eval("form.hora2_ini_"+semana+".className = 'inputText inputHorario'") ;
					 eval("form.hora2_fin_"+semana+".className = 'inputText inputHorario'") ;				 
					 eval("form.hora3_ini_"+semana+".className = 'inputText inputHorario'") ;				 				 
					 eval("form.hora3_fin_"+semana+".className = 'inputText inputHorario'") ;			
					 
					 eval("form.hora1_ini_"+semana+".disabled = false") ;
					 eval("form.hora1_fin_"+semana+".disabled = false") ;				 
					 eval("form.hora2_ini_"+semana+".disabled = false") ;
					 eval("form.hora2_fin_"+semana+".disabled = false") ;				 
					 eval("form.hora3_ini_"+semana+".disabled = false") ;				 				 
					 eval("form.hora3_fin_"+semana+".disabled = false") ;		
				}				
				
			}
			if(activado == true){
				form.todos_dias.checked = true;
				form.todo_lunes.disabled = "disabled";
				form.todo_martes.disabled = "disabled";				
				form.todo_miercoles.disabled = "disabled";				
				form.todo_jueves.disabled = "disabled";				
				form.todo_viernes.disabled = "disabled";
				
				form.todo_lunes.checked = false;
				form.todo_martes.checked = false;				
				form.todo_miercoles.checked = false;				
				form.todo_jueves.checked = false;				
				form.todo_viernes.checked = false;
			}
			else{
			  form.todos_dias.checked = false;			 					 
				form.todo_lunes.disabled = "";
				form.todo_martes.disabled = "";				
				form.todo_miercoles.disabled = "";				
				form.todo_jueves.disabled = "";				
				form.todo_viernes.disabled = "";					
			}
		}
		
	}
	
	
	function validarDato(name){
		 valor = document.horario.hora1_ini_lunes.value;
		 eval("valor = document.horario."+name+".value") ;
 		 var hora = /^(\d){1,2}(:00)?$/;		
		 var hora_peq = /^(\d){1,2}$/;		;
		 
		if(hora.test(valor) == false && valor != ""){		 
			alert("El formato de la hora introducida no es válido.\nLa hora debe ser del tipo HH:00 (horas enteras)");
		  eval("document.horario."+name+".focus()");
		  eval("document.horario."+name+".blur()");
		  eval("document.horario."+name+".select()");		
			return false;
		}
		else if(hora_peq.test(valor)==true && valor != ""){
			if(valor>22 || valor<8){
				alert("La hora debe estar comprendida entre las 8:00 y las 21:00");
				eval("document.horario."+name+".focus()");
				eval("document.horario."+name+".blur()");
				eval("document.horario."+name+".select()");						
			}
			else{
				aux = valor + ":00";
			  eval("valor = document.horario."+name+".value = aux") ;				
			}
		}
		else if(valor != ""){
				aux = valor.split(':00');
				if(aux[0]>22 || aux[0]<8){
					alert("La hora debe estar comprendida entre las 8:00 y las 21:00");
					eval("document.horario."+name+".focus()");
					eval("document.horario."+name+".blur()");
					eval("document.horario."+name+".select()");							
					return false;
				}
		}
	}
	
	
	
	function validarHorario(){
			form = document.horario;
			diasSemana = new Array("lunes","martes","miercoles","jueves","viernes");
 		  var hora = /^(\d){1,2}(:00)?$/;		
		  var hora_peq = /^(\d){1,2}$/;					
			var algoSel = false;
			
			
			for(i=0;i<5;i++){
				semana = diasSemana[i];
				 //comprobamos los datos
				 eval("activado = form.todo_"+semana+".checked");
				 if(activado == true)
				 	algoSel = true;
					
				 if(activado == false){
					 for(j=1;j<4;j++){
						 eval("indice1 = form.hora"+j+"_ini_"+semana+".selectedIndex");
						 eval("indice2 = form.hora"+j+"_fin_"+semana+".selectedIndex");						 

						 
						 eval("valor = form.hora"+j+"_ini_"+semana+".options[indice1].value");
						 eval("valor_fin = form.hora"+j+"_fin_"+semana+".options[indice2].value");						 


							if(indice1 !=0 || indice2 !=0)
								algoSel = true;

								if(valor !="" && valor_fin !="" && indice1!= 0 && indice2!= 0){
									auxIni = valor.split(':');
									auxFin = valor_fin.split(':');

									if(parseInt(auxIni[0]) > parseInt(auxFin[0]) ){
											alert("La hora de INICIO no puede ser mayor que la hora de FIN.\nPor favor revise estos datos");
											return false;
									}
								}
									
						 }
				 }
			}		
			todoActivado = form.todos_dias.checked;
			if(todoActivado == true)
				algoSel = true;
			
			if(algoSel==false){
					alert("Debe tener algo campo seleccionado, bien un rango de horario o marcar alguna de las casillas de la derecha");
					return false;				
			}
			

			var Digital=new Date();
			dia_actual = Digital.getDate();
			mes_actual = Digital.getMonth();
			anyo_actual = Digital.getYear();

			var fechaActual = new Date(anyo_actual, mes_actual, dia_actual);
			marcaActual = fechaActual.getTime();		

			
			form = document.horario;
			anyo  = parseInt(form.anyo.options[form.anyo.selectedIndex].value);
			mes   = parseInt(form.mes.options[form.mes.selectedIndex].value);
			dia   = parseInt(form.dia.options[form.dia.selectedIndex].value);	

			var fechaAux2 = new Date(anyo	, mes-1, dia);
			marcaElegida = fechaAux2.getTime();
			diferencia = (marcaElegida - marcaActual)			
			

			diferencia /= 86400000;			
			
			if(diferencia<0){
					alert("La fecha para grabar el aviso tiene que ser superior a la fecha de hoy");
					return false;
			}				

			

	}
	
	
	function validarFechaAlta(){
		var em2 =/^(\d){2}(\/){1}(\d){2}(\/){1}(\d\d)$/;	
		var em4 =/^(\d){2}(\/){1}(\d){2}(\/){1}(\d){2,4}$/;			
		form = document.altaPaciente;

		if(em2.test(form.fecha1.value)==false && em4.test(form.fecha1.value) == false ) {
				alert('El formato de la fecha no es correcto. Debe introducir un formato válido. dd/mm/aa ó dd/mm/aaaa');
				return false;
		}
		else{
				mensaje = "Esta seguro de querer dar ALTA a este paciente?";
				valor = confirm(mensaje);
				if(valor == false)
					return false;
		}
	}
	
	function confirmarAsignar(num){
			if(num>0)
				mensaje = "Al asignar esta fecha se producirán "+num+" solapamientos con otros pacientes\n ¿Está seguro que desea asignar esta Cita?";
		 else 
		 	  mensaje = "¿Está seguro que desea asignar esta Cita?";
				
			valor = confirm(mensaje);
			
			if(valor==true)
				return true;
			
			return false;
	}
	
	
	function validarCamposCita(){
			form = document.dia_hora;
			form1 = document.frecuencias;
			
			var Digital=new Date();
			dia_actual = Digital.getDate();
			mes_actual = Digital.getMonth();
			anyo_actual = Digital.getYear();
			hora = Digital.getHours();

			var fechaActual = new Date(anyo_actual, mes_actual, dia_actual,hora);
			marcaActual = fechaActual.getTime();

			

			
			if(form1.frecuencia.selectedIndex == 0){
					alert("Debe establecer una FRECUENCIA para poder realizar el calculo de la Cita");
					return false;
			}	else{
					indice = form1.frecuencia.selectedIndex;
					valor = form1.frecuencia.options[indice].value;
					form.frecuencia.value = valor;
			}
			
			if(form.anyo.selectedIndex == 0){
					alert("Debe establecer un año para poder asignar la Cita");
					return false;
			}
			
			if(form.mes.selectedIndex == 0){
					alert("Debe establecer un mes para poder asignar la Cita");
					return false;
			}			
			
			if(form.dia.selectedIndex == 0){
					alert("Debe establecer un dia para poder asignar la Cita");
					return false;
			}			
			
			if(form.hora.selectedIndex == 0){
					alert("Debe establecer un hora para poder asignar la Cita");
					return false;
			}		
			
			anyo  = parseInt(form.anyo.options[form.anyo.selectedIndex].value);
			mes   = parseInt(form.mes.options[form.mes.selectedIndex].value);
			dia   = parseInt(form.dia.options[form.dia.selectedIndex].value);	
			hora  = form.hora.options[form.hora.selectedIndex].value;				
			vHora = hora.split(":");
			

			var fechaAux2 = new Date(anyo	, mes-1, dia,vHora[0]);
			marcaElegida = fechaAux2.getTime();
			diferencia = (marcaElegida - marcaActual)			
			

			diferencia /= 86400000;			
			
			if(diferencia<0){
					alert("La fecha de la cita tiene que ser superior a la fecha de hoy");
					return false;
			}

	
	}


	function venantaComentario(idFecha){
		window.open("anyadirComentario.php?idFecha="+idFecha,"Comentario","width=270,height=350,scrollbars=yes, top=0, left=0");
	}	
	
	function ventanaImprimirDia(idFecha){
		window.open("imprimirDia.php?idFecha="+idFecha,"Imprimir","width=370,height=650,scrollbars=yes, top=0, left=0");
	}	


	function ventanaImprimirCitasPaciente(){
		window.open("imprimirCitasPaciente.php","Imprimir","width=730,height=396,scrollbars=yes, top=0, left=0");
	}	


	function ventanaSemanaCancel(){
		window.open("marcarSemanaCancel.php","Imprimir","width=300,height=290,scrollbars=yes, top=0, left=0");
	}	


	function validarFechaSem(){
		form = document.semana;
		if(form.anyo.value==-1){
				alert("Debes elegir un AÑO para poder establecer la semana de cancelación de citas");
				return false;
		}
		if(form.mes.value==-1){
				alert("Debes elegir un MES para poder establecer la semana de cancelación de citas");
				return false;
		}
		if(form.dia.value==-1){
				alert("Debes elegir un DÍA para poder establecer la semana de cancelación de citas");
				return false;
		}
		return true;
	}
	
	function ventanaImprimirCitasPacienteActual(paciente,anyo){
		window.open("imprimirCitasPaciente.php?idPaciente="+paciente+"&anyo="+anyo+"&anyo_elegido=1","Imprimir","width=730,height=396,scrollbars=yes, top=0, left=0");
	}		
	
	function registrarNuevaIncidencia(paciente, incidencia){
		window.open("registrarNuevaIncidencia.php?idPaciente="+paciente+"&incidencia="+incidencia,"Nueva_incidencia","width=300,height=290,scrollbars=yes, top=0, left=0");
	}		
	
	
	function validarCamposIncidencia(){
			form = document.nueva_incidencia;

		
			if(form.anyo.selectedIndex == 0){
					alert("Debe establecer un año para poder registrar la Incidencia");
					return false;
			}
			
			if(form.mes.selectedIndex == 0){
					alert("Debe establecer un mes para poder registrar la Incidencia");
					return false;
			}			
			
			if(form.dia.selectedIndex == 0){
					alert("Debe establecer un dia para poder registrar la Incidencia");
					return false;
			}			
			
			if(form.hora.selectedIndex == 0){
					alert("Debe establecer un hora para poder registrar la Incidencia");
					return false;
			}		
			
			
			if(form.coment_incidencia.value == "" ){
					alert("Debe establecer un comentario a la incidencia");
					return false;				
			}
	}	
	
	
	function confirmarBorradoIncidencia(){
		mensaje = "Esta seguro de que quiere borrar esta incidencia?";
		valor = confirm(mensaje);
		return valor;
	}
	
	
	function abrirDetalleCitaAjuste(fecha,hora){
		window.open("detalleCitaAjuste.php?fecha="+fecha+"&hora="+hora,"Detalle","width=244,height=300,scrollbars=no, top=0, left=0");
	}

	function abrirVentanaBorrarCitaAjuste(id){
		window.open("borrarCitaAjuste.php?id="+id,"Detalle","width=244,height=200,scrollbars=yes, top=0, left=0");
	}	

	function venantaComentarioAjuste(idFecha){
		window.open("anyadirComentarioAjuste.php?idFecha="+idFecha,"Comentario","width=270,height=350,scrollbars=yes, top=0, left=0");
	}	

	function abrirVentantaCargar(){
		window.open("cargarDatosSemana.php","Comentario","width=300,height=250,scrollbars=yes, top=0, left=0");
	}	

	function imprimirSemanaAjuste(){
		window.open("agenda_semana_imprimir.php","Comentario","width=720,height=550,scrollbars=yes, top=0, left=0");
	}	


	function imprimirSemana(fecha){
		window.open("agenda_imprimir.php?fecha_actual="+fecha+"&noCambio=1","Agenda","width=720,height=550,scrollbars=yes, top=0, left=0");
	}	




	function confirmarVolcado(){
		
		form = document.altaPaciente;
			
		if(form.anyo.selectedIndex==0){
				alert("Debe de elegir un AÑO para indicar la fecha.");
				return false;
		}
		
		if(form.mes.selectedIndex==0){
				alert("Debe de elegir un MES para indicar la fecha.");
				return false;
		}		


		if(form.dia.selectedIndex==0){
				alert("Debe de elegir un Día para indicar la fecha.");
				return false;
		}		

		
		mensaje = "Esta seguro de que quiere volcar los datos de la semana de ajuste al calendario?";
		valor = confirm(mensaje);
		return valor;		
	}
	
	
	function mostrarFechaPosponer(id,color){
		ident = "fecha_"+id;
		clase = document.getElementById(ident).className;
		if(clase=="noMostrar")
			document.getElementById(ident).className = color;
	 else
		 document.getElementById(ident).className = "noMostrar";
	}
	
	
	function validarborradoAviso(){
			valor = confirm("¿Está seguro de querer eliminar este aviso?");
			if(valor==true)
				return true;
			else
				return false;
	}
	
	function abrirObservaciones(ident){
		window.open("modificarObservacionesAviso.php?idAviso="+ident,"Observaciones","width=264,height=370,scrollbars=yes, top=0, left=0");		
	}
	
	function borraAviso(){
			valor = validarborradoAviso();
			if(valor == true){
					document.horario.borrarAviso.value = 1;
					document.horario.submit();
			}
	}
	
	
	function validarFechaPosponer(num){
		
			var Digital=new Date();
			dia_actual = Digital.getDate();
			mes_actual = Digital.getMonth();
			anyo_actual = Digital.getYear();

			var fechaActual = new Date(anyo_actual, mes_actual, dia_actual);
			marcaActual = fechaActual.getTime();		

			
			eval("form = document.posponer_"+num);
			anyo  = parseInt(form.anyo.options[form.anyo.selectedIndex].value);
			mes   = parseInt(form.mes.options[form.mes.selectedIndex].value);
			dia   = parseInt(form.dia.options[form.dia.selectedIndex].value);	

			var fechaAux2 = new Date(anyo	, mes-1, dia);
			marcaElegida = fechaAux2.getTime();
			diferencia = (marcaElegida - marcaActual)			
			

			diferencia /= 86400000;			
			
			if(diferencia<0){
					alert("La fecha para posponer el aviso tiene que ser superior a la fecha de hoy");
					return false;
			}			
		
	}