function responderpregunta(idpregunta,numrespuestas)
{
	i=1;
	var frase="";
	
	while(i<=numrespuestas)
	{
		resp="respuesta"+i;
		if(document.getElementById(resp).value.length<10)
		{			
			alert("La respuesta nº "+ i +" debe tener al menos 10 caracteres");
			return;
		}
		else
		{
			document.getElementById(resp).value=document.getElementById(resp).value.replace('&','~');

			frase = frase + "&respuesta"+ i + "="+document.getElementById(resp).value;
		}
		i++;
	}
	
	var selectDestino=document.getElementById("preguntas");
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=responderpregunta&idpregunta="+idpregunta+frase, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
		}
		if (ajax.readyState==4)
		{
			selectDestino.innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);
}

function acceso() { 
document.enviausuario.submit(); 
}

function divcamiseta(tipo)
{
	if(tipo==1)
	{
		document.getElementById('configcamisetas').style.display = '';
	}
	else
	{
		document.getElementById('configcamisetas').style.display='none';	
	}
}

function mostrar_regalos()
{
		document.getElementById('regalos').style.display = '';
		document.getElementById('regalos1').style.display='none';	
}

function  insertaContenidoRegalo() //Borra la relacion del proyecto con el motivo indicado
{
	var elemento=document.getElementsByName("idseleccionregalo");
	var seleccion=null;
	for (i=0;i<elemento.length;i++)
	{ 
       if (elemento[i].checked) 
	   {
          seleccion=elemento[i].value;
	   }
	}
	
	if(seleccion==null)
	{
		alert("Debes indicar el regalo");
		return;
	}
	else if(seleccion=="Pendrive")
	{
		var regalo="Pendrive";
	}
	else if(seleccion=="Camiseta")//Camiseta
	{
		/*if(document.getElementById("idioma_camiseta").value==0)
		{
			alert("Debes escoger el modelo de camiseta");
			return;		
		}*/
		if(document.getElementById("talla_camiseta").value==0)
		{
			alert("Debes escoger la talla de camiseta");
			return;		
		}
		if(document.getElementById("color_camiseta").value==0)		
		{
			alert("Debes escoger el color de camiseta");
			return;		
		}
		//var regalo="Camiseta " + document.getElementById("idioma_camiseta").value+ " - "+document.getElementById("talla_camiseta").value+ " - "+document.getElementById("color_camiseta").value;
		var regalo="Camiseta - "+document.getElementById("talla_camiseta").value+ " - "+document.getElementById("color_camiseta").value;
	}
	var cantidad=document.getElementById("cantidad").value;
	if(parseInt(cantidad)<=0 || cantidad=="")
	{
		alert("Debes indicar la cantidad de regalos");
		return;		
	}
	resto=parseInt(document.getElementById("quedan").value)+parseInt(cantidad);
	if(resto>0)
	{
		alert("Error. Limite de regalos superado con la cantidad indicada");
		return;			
	}
	var selectDestino=document.getElementById("regalos");
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=addregalo&regalo="+regalo+"&cantidad="+cantidad, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
		}
		if (ajax.readyState==4)
		{
			selectDestino.innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);
}

function  eliminaContenidoRegalo(mykey) //Borra la relacion del proyecto con el motivo indicado
{
	var selectDestino=document.getElementById("regalos");
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=eliminaregalo&mykey="+mykey, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
		}
		if (ajax.readyState==4)
		{
			selectDestino.innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);
}



function validacion_primeracceso()
{
	if(document.form_primeracceso.login.value.length<5)
	{
		alert("El campo Nombre de Usuario debe contener al menos 5 caracteres");	
		return;
	}
	
	if(document.form_primeracceso.nombre.value.length==0)
	{
		alert("El campo nombre es obligatorio");	
		return;
	}
	ok=validar_email(document.form_primeracceso.email.value)
	if(ok==false)
	{
		return;
	}
	if(document.form_primeracceso.movil.value!="")
	{
		if(document.form_primeracceso.movil.value.length!=9)
		{
			alert("El campo movil debe tener 9 números");	
			return;
		}
		else
		{
			if(document.form_primeracceso.movil.value.charAt(0)!="6")
			{
				alert("El móvil debe comenzar por un 6");	
				return;
			}
			for (i = 0; i < document.form_primeracceso.movil.value.length; i++)
			{
				if(isNaN(document.form_primeracceso.movil.value.charAt(i)))
				{
					alert("El campo movil no puede contener caracteres");	
					return;
				}
			}
		}
	}
	
	if(document.form_primeracceso.cargo.value==0)
	{
		alert("El campo cargo es obligatorio");	
		return;
	}	
	if(document.form_primeracceso.sexo.value==0)
	{
		alert("El campo Tratamiento es obligatorio");	
		return;
	}
	if(document.form_primeracceso.direccion.value!="")
	{
		if(document.form_primeracceso.idprovincia.value==0)
		{
			alert("El campo provincia es obligatorio");	
			return;
		}
		if(document.form_primeracceso.idlocalidad.value==0)
		{
			alert("El campo localidad es obligatorio");	
			return;
		}	
		if(document.form_primeracceso.cp.value.length!=5)
		{
			alert("El campo CP debe tener 5 números");	
			return;
		}
	}
	var login=document.form_primeracceso.login.value;
	var logininicial=document.form_primeracceso.logininicial.value;
	var selectDestino=document.getElementById("existe");
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=existeusuarioprimeracceso&usuario="+login+"&usuarioinicial="+logininicial, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==4)
		{
			if (selectDestino.parentNode!=null)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
				if (document.form_primeracceso.existe.value>0)
				{		

					alert("El Usuario " + document.form_primeracceso.login.value+ " ya existe, debes indicar otro");
					return;
				}
				else
				{
					document.form_primeracceso.action="./primeracceso.php";
					document.form_primeracceso.submit();		
				}
			}
		}
	}
	ajax.send(null);
}


function responderencuesta(idencuesta,idseleccion)
{
	var i,idopcion;
	
    for (i=0;i<idseleccion.length;i++)
	{ 
		if (idseleccion[i].checked) 
	   	{
			idopcion=idseleccion[i].value;
		  	break;
		}
    }
	
	if(idseleccion.checked==true) //Si solo existe un proyecto, no se crearía un indice de idseleccion
	{
			idopcion=idseleccion.value;
	}
	
	if (idopcion==undefined) 
	{
		alert("Debes seleccionar una respuesta");
	}
	else
	{
		document.form_responderencuesta.idencuesta.value = idencuesta;
		document.form_responderencuesta.idopcion.value = idopcion;
		var rutaAbsoluta = self.location.href;// http://asdas.asd/uno/dos/index.html 
		var posicionUltimaBarra = rutaAbsoluta.lastIndexOf("/"); 
		var rutaRelativa = rutaAbsoluta.substring( posicionUltimaBarra + "/".length , rutaAbsoluta.length );// index.html 
		document.form_responderencuesta.action=""+rutaRelativa+"";
		document.form_responderencuesta.submit();
	}	
	
}



function formapago(fpg1)
{
	
	var selectOrigen=document.getElementById(fpg1);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	if(opcionSeleccionada==1)
	{
		document.getElementById('divbanco').style.display = '';
		document.getElementById('divingreso').style.display='none';
	}
	else
	{		
		document.getElementById('divbanco').style.display='none';
		if(opcionSeleccionada==4 || opcionSeleccionada==6)
		{
			document.getElementById('divingreso').style.display = '';
		}
		else
		{
			document.getElementById('divingreso').style.display='none';	
		}
	}
}
function seleccionformapago()
{
	if(document.form_procesoventa4.fpg1.value=="1")
	{
		if(document.form_procesoventa4.titular.value=="")
		{
			alert("El campo Titular es obligatorio");
			return;	
		}
		if(document.form_procesoventa4.bancocontacto.value=="" || document.form_procesoventa4.sucursalcontacto.value=="" || document.form_procesoventa4.dccontacto.value=="" || document.form_procesoventa4.cuentacontacto.value=="")
		{
			alert("Los datos bancarios están incompletos");
			return;	
		}
		if(document.form_procesoventa4.bancocontacto.value=="2038" && document.form_procesoventa4.sucursalcontacto.value=="2476" && document.form_procesoventa4.dccontacto.value=="31" && document.form_procesoventa4.cuentacontacto.value=="6100009258")
		{
			alert("Los datos bancarios no pueden ser los de Recursos.");
			return;	
		}		
		
	}
	
    //Si se tiene opcion a elegir regalo, es obligatorio escoger uno...	
	if(document.getElementById("condiciones").checked==false)
	{
		alert("Debes leer y aceptar las condiciones de contratacion");
		return;
	}
	document.form_procesoventa4.action="./nuevareserva.php?accion=nuevareserva";
	document.form_procesoventa4.submit();
}

function confirmar_materiales()
{
	
	if(document.getElementById("fpg1")!=null)
	{
		if(document.form_materiales.fpg1.value=="1")
		{
			if(document.form_materiales.titular.value=="")
			{
				alert("El campo Titular es obligatorio");
				return;	
			}
			if(document.form_materiales.bancocontacto.value=="" || document.form_materiales.sucursalcontacto.value=="" || document.form_materiales.dccontacto.value=="" || document.form_materiales.cuentacontacto.value=="")
			{
				alert("Los datos bancarios están incompletos");
				return;	
			}
			if(document.form_materiales.bancocontacto.value=="2038" && document.form_materiales.sucursalcontacto.value=="2476" && document.form_materiales.dccontacto.value=="31" && document.form_materiales.cuentacontacto.value=="6100009258")
			{
				alert("Los datos bancarios no pueden ser los de Recursos.");
				return;	
			}		
			
		}
	}
	
	var elemento=document.getElementsByName("tipodireccion");
	var tipodireccion=null;
	for (i=0;i<elemento.length;i++)
	{ 
       if (elemento[i].checked) 
	   {
          tipodireccion=elemento[i].value;
	   }
	}
	//alert(tipodireccion);
	if(tipodireccion=="direccion_contacto")
	{
		//Comprobamos que todos los datos estan rellenos
		if(document.getElementById("nombrecontacto").value=="")
		{
			alert("Dirección de envío. El campo nombre es obligatorio");
			return;
		}
		if(document.getElementById("direccioncontacto").value=="")
		{
			alert("Dirección de envío. El campo dirección es obligatorio");
			return;
		}
		if(document.getElementById("provinciacontacto2").value=="Seleccione una Provincia")
		{
			alert("Dirección de envío. El campo Provincia es obligatorio");
			return;
		}
		if(document.getElementById("localidadcontacto").value=="0")
		{
			alert("Dirección de envío. El campo Localidad es obligatorio");
			return;
		}	
		if(document.getElementById("cpcontacto").value=="")
		{
			alert("Dirección de envío. El campo CP es obligatorio");
			return;
		}	
		
		
		var indiceprovincia=document.getElementById("provinciacontacto").selectedIndex;
	    document.getElementById("provinciacontacto").options[indiceprovincia].text;
	
	

		//Comprobamos que no ha modificado nada. En caso de haberlo hecho se le pide conformidad para modificar los datos de su ficha
		if(document.getElementById("nombrecontacto").value!=document.getElementById("nombre_backup").value ||
		document.getElementById("direccioncontacto").value!=document.getElementById("direccion_backup").value ||
		document.getElementById("provinciacontacto").options[indiceprovincia].text!=document.getElementById("provincia_backup").value ||
		document.getElementById("localidadcontacto").value!=document.getElementById("localidad_backup").value ||
		document.getElementById("cpcontacto").value!=document.getElementById("cp_backup").value)
		{
			if(confirm("¿Deseas guardar los datos de envío especificados como dirección de tu ficha personal?"))
			{
				document.getElementById("actualizar_datos").value="SI";
			}
			else
			{
				document.getElementById("actualizar_datos").value="NO";		
			}
		}
		else
		{
			document.getElementById("actualizar_datos").value="NO";			
		}
	}
	else if(tipodireccion=="direccion_otra")
	{
		//Comprobamos que todos los datos estan rellenos
		if(document.getElementById("nombreotra").value=="")
		{
			alert("Dirección de envío. El campo nombre es obligatorio");
			return;
		}
		if(document.getElementById("direccionotra").value=="")
		{
			alert("Dirección de envío. El campo dirección es obligatorio");
			return;
		}
		if(document.getElementById("provinciaotra2").value=="Seleccione una Provincia" || document.getElementById("provinciaotra2").value=="")
		{
			alert("Dirección de envío. El campo Provincia es obligatorio");
			return;
		}
		if(document.getElementById("localidadotra").value=="0")
		{
			alert("Dirección de envío. El campo Localidad es obligatorio");
			return;
		}	
		if(document.getElementById("cpotra").value=="")
		{
			alert("Dirección de envío. El campo CP es obligatorio");
			return;
		}	
	}
	else if(tipodireccion=="direccion_centro")
	{
		//paso	
	}
	else
	{
		alert("Error en el campo de Tipo de Dirección");
		return;
	}
	
	document.form_materiales.action="./solicitar_materiales.php?accion=finalizar";
	document.form_materiales.submit();
	
}

function recordarclave()
{
	if(document.form_recordarclave.usuario.value.length<5)
	{
		alert("El campo usuario debe contener al menos 5 caracteres");
		return;
	}
	ok=validar_email(document.form_recordarclave.email.value)
	if(ok==false)
	{
		return;
	}
	document.form_recordarclave.action="./recordarclave.php";
	document.form_recordarclave.submit();
}

function cambiarclaveusuario()
{
	if(document.form_cambiarclave.claveactual.value.length<5)
	{
		alert("El campo Clave Actual debe contener al menos 5 caracteres");
		return;
	}
	if(document.form_cambiarclave.clavenueva1.value.length<5)
	{
		alert("El campo 'Clave Nueva' es obligatorio y debe contener al menos 5 caracteres");
		return;
	}
	if(document.form_cambiarclave.clavenueva1.value!=document.form_cambiarclave.clavenueva2.value)
	{
		alert("El campo 'Repetir Clave Nueva' no coincide con la clave indicada");
		return
	}
	document.form_cambiarclave.action="./misdatos.php?accion=cambiarclave";
	document.form_cambiarclave.submit();
}


function registrarusuario()
{
	if(document.form_registrousuario.login.value.length<5)		
	{
		alert("El campo Nombre de Usuario debe contener al menos 5 caracteres");	
		return;
	}
	
	var login=document.form_registrousuario.login.value;
	var selectDestino=document.getElementById("existe");
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=existeusuario&usuario="+login, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==4)
		{
			if (selectDestino.parentNode!=null)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
				if (document.form_registrousuario.existe.value>0)
				{		

					alert("El Usuario " + document.form_registrousuario.login.value+ " ya existe, debes indicar otro");
					return;
				}
				if(document.form_registrousuario.nombre.value.length==0)
				{

					alert("El campo nombre es obligatorio");	
					return;
				}
				ok=validar_email(document.form_registrousuario.email.value)
				if(ok==false)
				{
					return;
				}
				
				if(document.form_registrousuario.movil.value!="")
				{
					if(document.form_registrousuario.movil.value.length!=9)
					{
						alert("El campo movil debe tener 9 números");	
						return;
					}
					else
					{
						if(document.form_registrousuario.movil.value.charAt(0)!="6")
						{
							alert("El móvil debe comenzar por un 6");	
							return;
						}
						for (i = 0; i < document.form_registrousuario.movil.value.length; i++)
						{
							if(isNaN(document.form_registrousuario.movil.value.charAt(i)))
							{
								alert("El campo movil no puede contener caracteres");		
								return;
							}
						}
					}
				}
				if(document.form_registrousuario.cargo.value==0)
				{
					alert("El campo cargo es obligatorio");			
					return;
				}	
				if(document.form_registrousuario.sexo.value==0)
				{
					alert("El campo tratamiento es obligatorio");			
					return;
				}

				if(document.form_registrousuario.direccion.value!="")
				{
					if(document.form_registrousuario.idprovincia.value==0)
					{
						alert("El campo provincia es obligatorio");			
						return;
					}
					if(document.form_registrousuario.idlocalidad.value==0)
					{
						alert("El campo localidad es obligatorio");			
						return;
					}	
					if(document.form_registrousuario.cp.value.length!=5)
					{
						alert("El campo CP debe tener 5 números");			
						return;
					}
				}
				document.form_registrousuario.action="./registro.php";
				document.form_registrousuario.submit();	
			}
		} 
	}
	ajax.send(null);
}

function registrarcentro()
{
	if(document.form_altacentro.nombrecontacto.value.length<5)		
	{
		alert("El campo Nombre del Contacto debe contener al menos 5 caracteres");	
		return;
	}
	if(document.form_altacentro.nombre.value.length<5)		
	{
		alert("El campo Nombre debe contener al menos 5 caracteres");	
		return;
	}
	if(document.form_altacentro.rotulo.value=="0")		
	{
		alert("Debes seleccionar un rótulo");	
		return;
	}
	if(document.form_altacentro.cif.value.length==0)
	{
		alert("El campo CIF es obligatorio");	
		return;
	}
	if(document.form_altacentro.direccion.value.length==0)
	{
		alert("El campo Dirección es obligatorio");	
		return;
	}
	if(document.form_altacentro.idprovincia.value=="0")		
	{
		alert("Debes seleccionar una provincia");	
		return;
	}
	if(document.form_altacentro.idlocalidad.value=="0")		
	{
		alert("Debes seleccionar una localidad");	
		return;
	}	
	if(document.form_altacentro.cp.value.length!=5)
	{
		alert("El campo CP debe tener 5 números");			
		return;
	}
	
	if(document.form_altacentro.telefono.value.length!=9)
	{
		alert("El campo teléfono debe tener 9 números");	
		return;
	}	
	else
	{
		for (i = 0; i < document.form_altacentro.telefono.value.length; i++)
		{
			if(isNaN(document.form_altacentro.telefono.value.charAt(i)))
			{
				alert("El campo teléfono no puede contener caracteres");		
				return;
			}
		}
	}	
	ok=validar_email(document.form_altacentro.email.value)
	if(ok==false)
	{
		return;
	}					
	document.form_altacentro.action="./altacentro.php";
	document.form_altacentro.submit();	
}
function validar_email(s)
{
	var filter=/^[A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+.[A-Za-z0-9_.-]+[A-za-z]$/; 
	if (s.length == 0 ) 
	{
		alert("El email es obligatorio");
		return false;
	}
	if (filter.test(s))
		return true;
	else
		alert("Ingrese una dirección de correo válida");
	return false;
}

function valida_cp_misdatos()
{
var texto="";
for (i = 0; i < document.form_datosusuario.cp.value.length; i++)
	{
		if(!isNaN(document.form_datosusuario.cp.value.charAt(i)))
		{
			texto=texto + document.form_datosusuario.cp.value.charAt(i);
		}
	}
	document.form_datosusuario.cp.value=texto;
}
function valida_cp()
{
	var texto="";
	for (i = 0; i < document.getElementById("cp").value.length; i++)
	{
		if(!isNaN(document.getElementById("cp").value.charAt(i)))
		{
			texto=texto + document.getElementById("cp").value.charAt(i);
		}
	}
	document.getElementById("cp").value=texto;
}

function solonumeros(numero)
{
var texto="";
	if (numero.length>0)
	{
		for (i = 0; i < numero.length; i++)
			{
				if(!isNaN(numero.charAt(i)))
				{
					texto=texto + numero.charAt(i);
				}
			}
	}
	return texto;
}


function enviar_procesoventa_2(seleccion) //Nueva reserva
{
	document.form_procesoventa2.salafechayhora.value=seleccion.value;
	document.form_procesoventa2.action="./nuevareserva.php?accion=nuevareserva";
	document.form_procesoventa2.submit();	
}

function enviar_procesoventa_3(maximo) //Nueva reserva
{
	
	continuar=0;
	if(maximo==0)
	{
		alert("No puedes continuar, no hay lineas de reserva");
		return;	
	}
	var i=0;
	while(i<=maximo)
	{
		//Fechas para libros obligatorias
		if(document.getElementById("fechaentr"+i)!=null)
		{
			if(document.getElementById("fechaentr"+i).value=="")
			{
				alert("Error, todas las fechas de entrega de libros son obligatorias");
				return;
			}
			
		}
		
		//Dudas sobre autocares???!!!
		if(document.getElementById("autocar"+i)!=null)
		{
			if(document.getElementById("autocar"+i).checked==false)
			{
				if (continuar==0)
				{
					if(!confirm("¿Seguro que NO deseas contratar el transporte con Recursos?")) 
					{
						return;
					}
					else
					{
						continuar=1;	
					}
				}
			}
			else
			{
				if(document.getElementById("movil"+i).value.length!=9)
				{
					alert("El campo movil debe tener 9 números");	
					return;
				}
				else
				{
					if(document.getElementById("movil"+i).value.charAt(0)!="6")
					{
						alert("El móvil debe comenzar por un 6");	
						return;
					}
					for (j = 0; j < document.getElementById("movil"+i).value.length; j++)
					{
						if(isNaN(document.getElementById("movil"+i).value.charAt(j)))
						{
							alert("El campo movil no puede contener caracteres");		
							return;
						}
					}
				}
			}
		}

		if(document.getElementById("transp"+i)!=null)
		{
			if(document.getElementById("transp"+i).value=="0")
			{
				alert("Error, debes indicar cual es tu forma de desplazarte al teatro");
				return;
			}
			
		}
		
		
		
		i++;
	}
	document.form_procesoventa3.action="./nuevareserva.php?accion=nuevareserva";
	document.form_procesoventa3.submit();
}
function eliminar_linea(linea) //Nueva reserva
{
	var numlinea=parseInt(linea)+1;
	if(confirm("Se va a eliminar la linea de reserva "+numlinea+"\n¿Desea continuar?")) 
	{
		var selectDestino=document.getElementById(linea);
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=eliminarlinea&opcionSeleccionada="+linea, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
					//selectDestino.parentNode.innerHTML=ajax.responseText;
					document.form_procesoventa3.action="./nuevareserva.php?accion=resumen";
					document.form_procesoventa3.submit();
				}
			} 
		}
		ajax.send(null);
	}
	
}
function enviar_procesoventa_1() //Nueva reserva
{
	if(document.form_procesoventa1.total.value<1)
	{
		alert("No puedes continuar el proceso de compra sin haber indicado ninguna plaza");
		return;
	}
	if(document.form_procesoventa1.total_pzn.value<1)
	{
		alert("Debe haber algún acompañante");
		return;
	}
	if(parseInt(document.form_procesoventa1.total.value-parseInt(document.form_procesoventa1.total_pzn.value))<20)	
	{
		if(parseInt(document.form_procesoventa1.total_pzn.value)>2)
		{
			alert("En reservas de hasta 20 niños el máximo de acompañantes son 2");
			return;	
		}
	}
	else
	{
		var porciento=(parseInt(document.form_procesoventa1.total_pzn.value)*100)/parseInt(document.form_procesoventa1.total.value-parseInt(document.form_procesoventa1.total_pzn.value));
		if(porciento>10.0)
		{
			alert("El máximo de acompañantes es el 10% sobre el total de alumnos");
			return;
		}
	}
		
	if(parseInt(document.getElementById("total").value)>parseInt(document.getElementById("maximo").value)) //no entra, enviamos a seleccion de sala
	{
		document.form_procesoventa1.paso.value="2";
		document.form_procesoventa1.action="./nuevareserva.php?accion=nuevareserva";
		document.form_procesoventa1.submit();
	}
	else //Si entra
	{
		document.form_procesoventa1.paso.value="3";
		document.form_procesoventa1.action="./nuevareserva.php?accion=nuevareserva";
		document.form_procesoventa1.submit();
	}
}
function sumaplazas() //Nueva reserva
{
	var suma=0;
	var sumapzn=0;
	if (document.getElementById("total_infantil")!=null)
	{
		suma2=solonumeros(document.getElementById("total_infantil").value);
		document.getElementById("total_infantil").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_infantil").readOnly = false;
			document.getElementById("total_acom_infantil").className="activo";
		}
		else
		{
			document.getElementById("total_acom_infantil").readOnly = true;
			document.getElementById("total_acom_infantil").value="";
			document.getElementById("total_acom_infantil").className="inactivo";	
		}
		if(document.getElementById("total_infantil_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_infantil_libros").readOnly = false;
				document.getElementById("total_infantil_libros").className="activo";
			}
			else
			{
				document.getElementById("total_infantil_libros").readOnly = true;
				document.getElementById("total_infantil_libros").value="";
				document.getElementById("total_infantil_libros").className="inactivo";
			}
		}
	}
	if (document.getElementById("total_prim")!=null)
	{
		suma2=solonumeros(document.getElementById("total_prim").value);
		document.getElementById("total_prim").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_prim").readOnly = false;
			document.getElementById("total_acom_prim").className="activo";
		}
		else
		{
			document.getElementById("total_acom_prim").readOnly = true;
			document.getElementById("total_acom_prim").value="";
			document.getElementById("total_acom_prim").className="inactivo";	
		}
		if(document.getElementById("total_prim_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_prim_libros").readOnly = false;
				document.getElementById("total_prim_libros").className="activo";
			}
			else
			{
				document.getElementById("total_prim_libros").readOnly = true;
				document.getElementById("total_prim_libros").value="";
				document.getElementById("total_prim_libros").className="inactivo";
			}
		}
	}
	if (document.getElementById("total_seg")!=null)
	{
		suma2=solonumeros(document.getElementById("total_seg").value);
		document.getElementById("total_seg").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_seg").readOnly = false;
			document.getElementById("total_acom_seg").className="activo";
		}
		else
		{
			document.getElementById("total_acom_seg").readOnly = true;
			document.getElementById("total_acom_seg").value="";
			document.getElementById("total_acom_seg").className="inactivo";	
		}
		if(document.getElementById("total_seg_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_seg_libros").readOnly = false;
				document.getElementById("total_seg_libros").className="activo";
			}
			else
			{
				document.getElementById("total_seg_libros").readOnly = true;
				document.getElementById("total_seg_libros").value="";
				document.getElementById("total_seg_libros").className="inactivo";
			}
		}
	}
	if (document.getElementById("total_ter")!=null)
	{
		suma2=solonumeros(document.getElementById("total_ter").value);
		document.getElementById("total_ter").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_ter").readOnly = false;
			document.getElementById("total_acom_ter").className="activo";
		}
		else
		{
			document.getElementById("total_acom_ter").readOnly = true;
			document.getElementById("total_acom_ter").value="";
			document.getElementById("total_acom_ter").className="inactivo";	
		}
		if(document.getElementById("total_ter_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_ter_libros").readOnly = false;
				document.getElementById("total_ter_libros").className="activo";
			}
			else
			{
				document.getElementById("total_ter_libros").readOnly = true;
				document.getElementById("total_ter_libros").value="";
				document.getElementById("total_ter_libros").className="inactivo";
			}
		}
	}
	if (document.getElementById("total_eso1")!=null)
	{
		suma2=solonumeros(document.getElementById("total_eso1").value);
		document.getElementById("total_eso1").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_eso1").readOnly = false;
			document.getElementById("total_acom_eso1").className="activo";
		}
		else
		{
			document.getElementById("total_acom_eso1").readOnly = true;
			document.getElementById("total_acom_eso1").value="";
			document.getElementById("total_acom_eso1").className="inactivo";	
		}
		if(document.getElementById("total_eso1_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_eso1_libros").readOnly = false;
				document.getElementById("total_eso1_libros").className="activo";
			}
			else
			{
				document.getElementById("total_eso1_libros").readOnly = true;
				document.getElementById("total_eso1_libros").value="";
				document.getElementById("total_eso1_libros").className="inactivo";
			}
		}
	}	
	if (document.getElementById("total_eso2")!=null)
	{
		suma2=solonumeros(document.getElementById("total_eso2").value);
		document.getElementById("total_eso2").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_eso2").readOnly = false;
			document.getElementById("total_acom_eso2").className="activo";
		}
		else
		{
			document.getElementById("total_acom_eso2").readOnly = true;
			document.getElementById("total_acom_eso2").value="";
			document.getElementById("total_acom_eso2").className="inactivo";	
		}
		if(document.getElementById("total_eso2_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_eso2_libros").readOnly = false;
				document.getElementById("total_eso2_libros").className="activo";
			}
			else
			{
				document.getElementById("total_eso2_libros").readOnly = true;
				document.getElementById("total_eso2_libros").value="";
				document.getElementById("total_eso2_libros").className="inactivo";
			}
		}
	}
	if (document.getElementById("total_bach")!=null)
	{
		suma2=solonumeros(document.getElementById("total_bach").value);
		document.getElementById("total_bach").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		if(suma2!=0)
		{
			document.getElementById("total_acom_bach").readOnly = false;
			document.getElementById("total_acom_bach").className="activo";
		}
		else
		{
			document.getElementById("total_acom_bach").readOnly = true;
			document.getElementById("total_acom_bach").value="";
			document.getElementById("total_acom_bach").className="inactivo";	
		}
		if(document.getElementById("total_bach_libros")!=null)
		{
			if(suma2!=0)
			{
				document.getElementById("total_bach_libros").readOnly = false;
				document.getElementById("total_bach_libros").className="activo";
			}
			else
			{
				document.getElementById("total_bach_libros").readOnly = true;
				document.getElementById("total_bach_libros").value="";
				document.getElementById("total_bach_libros").className="inactivo";
			}
		}
	}
	
	
	if (document.getElementById("total_acom_infantil")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_infantil").value);
		document.getElementById("total_acom_infantil").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_infantil").value);
		document.getElementById("total_acom_infantil").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
		
	}
	if (document.getElementById("total_acom_prim")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_prim").value);
		document.getElementById("total_acom_prim").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_prim").value);
		document.getElementById("total_acom_prim").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
	}
	if (document.getElementById("total_acom_seg")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_seg").value);
		document.getElementById("total_acom_seg").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_seg").value);
		document.getElementById("total_acom_seg").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
	}
	if (document.getElementById("total_acom_ter")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_ter").value);
		document.getElementById("total_acom_ter").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_ter").value);
		document.getElementById("total_acom_ter").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
	}
	if (document.getElementById("total_acom_eso1")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_eso1").value);
		document.getElementById("total_acom_eso1").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_eso1").value);
		document.getElementById("total_acom_eso1").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
	}
	if (document.getElementById("total_acom_eso2")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_eso2").value);
		document.getElementById("total_acom_eso2").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_eso2").value);
		document.getElementById("total_acom_eso2").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
	}
	if (document.getElementById("total_acom_bach")!=null)
	{
		suma2=solonumeros(document.getElementById("total_acom_bach").value);
		document.getElementById("total_acom_bach").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
		
		sumapzn2=solonumeros(document.getElementById("total_acom_bach").value);
		document.getElementById("total_acom_bach").value=sumapzn2;
		sumapzn=parseInt(sumapzn)+parseInt(Number(sumapzn2));
	}
	document.getElementById("total_pzn").value=sumapzn;
	document.getElementById("total").value=suma;
}
function sumaplazas_modif() //Nueva reserva
{
	var suma=0;
	var sumapzn=0;
	if (document.getElementById("total_infantil")!=null)
	{
		suma2=solonumeros(document.getElementById("total_infantil").value);
		document.getElementById("total_infantil").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));		
	}
	if (document.getElementById("total_prim")!=null)
	{
		suma2=solonumeros(document.getElementById("total_prim").value);
		document.getElementById("total_prim").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
	}
	if (document.getElementById("total_seg")!=null)
	{
		suma2=solonumeros(document.getElementById("total_seg").value);
		document.getElementById("total_seg").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
	}
	if (document.getElementById("total_ter")!=null)
	{
		suma2=solonumeros(document.getElementById("total_ter").value);
		document.getElementById("total_ter").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
	}
	if (document.getElementById("total_eso1")!=null)
	{
		suma2=solonumeros(document.getElementById("total_eso1").value);
		document.getElementById("total_eso1").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
	}	
	if (document.getElementById("total_eso2")!=null)
	{
		suma2=solonumeros(document.getElementById("total_eso2").value);
		document.getElementById("total_eso2").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
	}
	if (document.getElementById("total_bach")!=null)
	{
		suma2=solonumeros(document.getElementById("total_bach").value);
		document.getElementById("total_bach").value=suma2;
		suma=parseInt(suma)+parseInt(Number(suma2));
	}
	document.getElementById("total").value=suma;
}
function sumalibros() //Nueva reserva
{
	var suma=0;
	if (document.getElementById("total_infantil_libros")!=null){suma2=solonumeros(document.getElementById("total_infantil_libros").value);document.getElementById("total_infantil_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}
	if (document.getElementById("total_prim_libros")!=null){suma2=solonumeros(document.getElementById("total_prim_libros").value);document.getElementById("total_prim_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}
	if (document.getElementById("total_seg_libros")!=null){suma2=solonumeros(document.getElementById("total_seg_libros").value);document.getElementById("total_seg_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}
	if (document.getElementById("total_ter_libros")!=null){suma2=solonumeros(document.getElementById("total_ter_libros").value);document.getElementById("total_ter_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}
	if (document.getElementById("total_eso1_libros")!=null){suma2=solonumeros(document.getElementById("total_eso1_libros").value);document.getElementById("total_eso1_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}	
	if (document.getElementById("total_eso2_libros")!=null){suma2=solonumeros(document.getElementById("total_eso2_libros").value);document.getElementById("total_eso2_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}
	if (document.getElementById("total_bach_libros")!=null){suma2=solonumeros(document.getElementById("total_bach_libros").value);document.getElementById("total_bach_libros").value=suma2;suma=parseInt(suma)+parseInt(Number(suma2));}		
	
	if (document.getElementById("paso")!=null)
	{
		if(document.getElementById("paso").value!=2)
		{
			if(suma>0)
			{
				document.getElementById("fechaentr").className="activo";
				document.getElementById("lanzador1").disabled=false;
				
			}
			else
			{
				document.getElementById("fechaentr").className="inactivo";	
				document.getElementById("lanzador1").disabled="disabled";
				document.getElementById("fechaentr").value="";
			}
		}
	}
	document.getElementById("total_libros").value=suma;
}

function ver_infosala(idsala) // nueva reserva
{
	document.form_procesoventa2.setAttribute('target','_blank'); 
	//document.form_procesoventa2.idsala.value = idsala;
	document.form_procesoventa2.action="./infosalas.php?idsala=" + idsala;
	document.form_procesoventa2.submit();	
	document.form_procesoventa2.setAttribute('target',''); 
}
function ver_infosala2(idsala) // nueva reserva
{
	document.form_programacion.setAttribute('target','_blank'); 
	document.form_programacion.action="./infosalas.php?idsala=" + idsala;
	document.form_programacion.submit();
	document.form_programacion.setAttribute('target','');
}
function nuevareserva(idespectaculo) //Nueva reserva
{
	document.form_infoespectaculos.idespectaculo.value = idespectaculo;
	document.form_infoespectaculos.action="./nuevareserva.php?accion=nuevareserva";
	document.form_infoespectaculos.submit();		
}
function nuevareserva2(idespectaculo,idseleccion) //Nueva reserva
{
	document.form_programacion.idseleccion.value = idseleccion;
	document.form_programacion.idespectaculo.value = idespectaculo;
	document.form_programacion.action="./nuevareserva.php?accion=nuevareserva";
	document.form_programacion.submit();	
}
function validar_texto(e){
    tecla = (document.all) ? e.keyCode : e.which;

    //Tecla de retroceso para borrar, siempre la permite
    if (tecla==8){
        return true;
    }
        
    // Patron de entrada, en este caso solo acepta numeros
    patron =/[0-9]/;
    
    tecla_final = String.fromCharCode(tecla);
    
    return patron.test(tecla_final);
}

function CargaTablaEspectaculos(opcionSeleccionada) //Nueva reserva
{
	var selectDestino=document.getElementById("tablaespectaculos");
	var micat=document.form_infoespectaculos.micat.value;
	
	
	if (opcionSeleccionada!="0")
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarespectaculos&opcionSeleccionada="+opcionSeleccionada+"&micat="+micat, true);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
					// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
					selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
			}
			if (ajax.readyState==4)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}
}
function CargarProgramacionSalas(opcionSeleccionada) //Nueva reserva
{
	var selectDestino=document.getElementById("opcionytablasalas");
	var mirlo=document.form_procesoventa2.mirlo.value;
	var zona1=document.form_procesoventa2.zona1.value;
	var idespectaculo=document.form_procesoventa2.idespectaculo.value
	var total=document.form_procesoventa2.total.value
	if (opcionSeleccionada!="0")
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarprogramacionsalas&opcionSeleccionada="+opcionSeleccionada+"&mirlo="+mirlo+"&zona1="+zona1+"&idespectaculo="+idespectaculo+"&total="+total, true);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
					// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
					selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
			}
			if (ajax.readyState==4)
			{
				if (selectDestino!=null)
				{			
					selectDestino.innerHTML=ajax.responseText;
				}
			} 
		}
		ajax.send(null);
	}
}


function CargarProgramacionSalas2(opcionSeleccionada) // Programacion...
{
	var selectDestino=document.getElementById("tablaprogramacion");
	var mirlo=document.form_programacion.mirlo.value;
	var zona1=document.form_programacion.zona1.value;
	var idespectaculo=document.form_programacion.idespectaculo.value
	if (opcionSeleccionada!="0")
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarprogramacionsalas2&opcionSeleccionada="+opcionSeleccionada+"&mirlo="+mirlo+"&zona1="+zona1+"&idespectaculo="+idespectaculo, true);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
					// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
					selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
			}
			if (ajax.readyState==4)
			{
				if (selectDestino!=null)
				{			
					selectDestino.innerHTML=ajax.responseText;
				}
			} 
		}
		ajax.send(null);
	}
}


function buscarcentro2() //registro de usuario
{
//alert("El registro de usuarios está inactivo temporalmente");
//return
	var selectDestino=document.getElementById("idtablacentro");
	var buscarcentro=document.form_registrousuario.buscarcentro.value;
	var buscarcp=document.form_registrousuario.cp.value;
	if(buscarcentro=="" && buscarcp=="")
	{
		alert("Debes indicar el Nombre del Centro y el Codigo Postal");
		return;
	}
	else
	{
		if(buscarcentro.length<3)
		{
			alert("El nombre del centro debe contener al menos 3 caracteres");
			return;
		}
		if(buscarcp.length!=5)
		{
			alert("El Codigo postal debe contener al menos 5 numeros");
			return;
		}	
	}
	
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=mostrarbusquedacentros2&buscarcentro="+buscarcentro+"&buscarcp="+buscarcp, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
			//No es necesario hacer nada, si acaso poner "cargando"
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";	
		}
		if (ajax.readyState==4)
		{
			if (selectDestino.parentNode!=null)
			{
				selectDestino.innerHTML=ajax.responseText;
			}
		} 
	}
	ajax.send(null);
}
function seleccionarcentro(idcentro) //Registro de usuario
{
	var selectDestino=document.getElementById("iddatosregistro");
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=mostrarbusquedacentros3&idcentro="+idcentro, true);
	ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				//No es necesario hacer nada, si acaso poner "cargando"
			}
			if (ajax.readyState==4)
			{					
					selectDestino.parentNode.innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);	
}

function CargaLocalidadesRegistro(idSelectOrigen) //Registro de usuario
{
	var selectDestino=document.getElementById("idlocalidad");	
	var selectOrigen=document.getElementById(idSelectOrigen);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	if(opcionSeleccionada==0)
	{
		selectActual=document.getElementById("idlocalidad");
		selectActual.length=0;
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Selecciona Opci&oacute;n...";
		selectActual.appendChild(nuevaOpcion);	//selectActual.disabled=true;
	}
	else
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarlocalidadesregistro&opcionSeleccionada="+opcionSeleccionada, true);	
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); 
				selectDestino.appendChild(nuevaOpcion); 
				selectOrigen.disabled=true;
				selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
					selectDestino.parentNode.innerHTML=ajax.responseText;
					selectOrigen.disabled=false;
				}
			} 
		}
		ajax.send(null);
	}
}
function CargaLocalidadesCentro(idSelectOrigen) //Registro de usuario
{
	var selectDestino=document.getElementById("idlocalidad");	
	var selectOrigen=document.getElementById(idSelectOrigen);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	if(opcionSeleccionada==0)
	{
		selectActual=document.getElementById(id);
		selectActual.length=0;
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Selecciona Opci&oacute;n...";
		selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;
	}
	else
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarlocalidadescentro&opcionSeleccionada="+opcionSeleccionada, true);	
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); 
				selectDestino.appendChild(nuevaOpcion); 
				selectOrigen.disabled=true;
				selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
					selectDestino.parentNode.innerHTML=ajax.responseText;
					selectOrigen.disabled=false;
				}
			} 
		}
		ajax.send(null);
	}
}

function CargaLocalidades (idSelectOrigen) //Mis datos
{
	var selectDestino=document.getElementById("localidad");	
	var selectOrigen=document.getElementById(idSelectOrigen);
	if (selectOrigen.selectedIndex=="-1")
	{
		var opcionSeleccionada=0;	
	}
	else
	{
		var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;	
	}
	var codcliente=document.form_datosusuario.codcliente.value;	
	if(opcionSeleccionada==0)
	{
		selectOrigen.value="";
		/*selectActual=document.getElementById(idSelectOrigen);
		selectActual.length=0;
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Selecciona Opci&oacute;n...";
		selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;*/
	}
	else
	{
		var ajax=nuevoAjax();
		if(document.form_datosusuario.editar_guardar.value=="Editar")
		{
			ajax.open("GET", "procesos_ajax.php?accion=cargarlocalidades&opcionSeleccionada="+opcionSeleccionada+"&estado=inactivo&codcliente="+codcliente, true);	
		}
		else
		{
			ajax.open("GET", "procesos_ajax.php?accion=cargarlocalidades&opcionSeleccionada="+opcionSeleccionada+"&estado=activo&codcliente="+codcliente, true);	
		}
		
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				//selectOrigen.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); 
				selectDestino.appendChild(nuevaOpcion); 
				selectOrigen.disabled=true;
				selectDestino.disabled=true;
				document.getElementById("cancelar").disabled = true;
				document.getElementById("editar_guardar").disabled = true;
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
						selectDestino.parentNode.innerHTML=ajax.responseText;
						if(document.form_datosusuario.editar_guardar.value!="Editar")
						{
							selectOrigen.disabled=false;
							document.getElementById("cancelar").disabled = false;
						}
						else
						{
							document.getElementById("cancelar").disabled = true;	
						}

							document.getElementById("editar_guardar").disabled = false;
				}
			} 
		}
		ajax.send(null);
	}
}

function CargaLocalidadesMateriales (idSelectOrigen) //Mis datos
{
	var indice=document.getElementById("provinciacontacto").selectedIndex;
	document.getElementById("provinciacontacto2").value=document.getElementById("provinciacontacto").options[indice].text;
	
	var selectDestino=document.getElementById("localidadcontacto");	
	var selectOrigen=document.getElementById(idSelectOrigen);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;	
	if(opcionSeleccionada==0)
	{
		selectDestino.length=0;
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccione una provincia...";
		selectDestino.appendChild(nuevaOpcion);	selectDestino.disabled=true;
	}
	else
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarlocalidadesmateriales&opcionSeleccionada="+opcionSeleccionada, true);	
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				//selectOrigen.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); 
				selectDestino.appendChild(nuevaOpcion); 
				selectOrigen.disabled=true;
				selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
						selectOrigen.disabled=false;
						selectDestino.parentNode.innerHTML=ajax.responseText;
				}
			} 
		}
		ajax.send(null);
	}
}
function CargaLocalidadesMateriales2 (idSelectOrigen) //Mis datos
{
	var indice=document.getElementById("provinciaotra").selectedIndex;
	document.getElementById("provinciaotra2").value=document.getElementById("provinciaotra").options[indice].text;
	
	var selectDestino=document.getElementById("localidadotra");	
	var selectOrigen=document.getElementById(idSelectOrigen);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;	
	if(opcionSeleccionada==0)
	{
		selectDestino.length=0;
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccione una provincia...";
		selectDestino.appendChild(nuevaOpcion);	selectDestino.disabled=true;
	}
	else
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=cargarlocalidadesmateriales2&opcionSeleccionada="+opcionSeleccionada, true);	
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				//selectOrigen.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); 
				selectDestino.appendChild(nuevaOpcion); 
				selectOrigen.disabled=true;
				selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
						selectOrigen.disabled=false;
						selectDestino.parentNode.innerHTML=ajax.responseText;
				}
			} 
		}
		ajax.send(null);
	}
}
function CargaEspectaculos(tipo) 
{
	var selectDestino=document.getElementById("programacion");	

	var selectEspectaculo=document.getElementById("espectaculo");
	var opcionSeleccionada=selectEspectaculo.options[selectEspectaculo.selectedIndex].value;
	
	var selectProvincia=document.getElementById("idprovincia");
	var idprovincia=selectProvincia.options[selectProvincia.selectedIndex].value;
	
	var selectLocalidad=document.getElementById("idlocalidad");
	var idlocalidad=selectLocalidad.options[selectLocalidad.selectedIndex].value;
	
	var selectCiclo=document.getElementById("idciclo");
	var idciclo=selectCiclo.options[selectCiclo.selectedIndex].value;
	
	var campana=document.getElementById("campana_actual").value;
	if (tipo==1)
		opcionSeleccionada="0";
	
	if (tipo==2)
		idlocalidad="-1";
	
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=busquedaespectaculos&opcionSeleccionada="+opcionSeleccionada+"&idprovincia="+idprovincia+"&idlocalidad="+idlocalidad+"&campana="+campana+"&idciclo="+idciclo, true);	

	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{						
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";	
		}
		if (ajax.readyState==4)
		{
			if (selectDestino.parentNode!=null)
			{
					selectDestino.innerHTML=ajax.responseText;
			}
		} 
	}
	ajax.send(null);
}

function CargaProgramacion (idSelectOrigen) //Mis datos
{
	var selectDestino=document.getElementById("tablaprogramacion");
	var selectOrigen=document.getElementById(idSelectOrigen);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	
	var provincia=document.getElementById("provincia");
	var opcionSeleccionada2=provincia.options[provincia.selectedIndex].value;
	
	var idespectaculo=document.getElementById("idespectaculo").value;
	
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=cargarprogramacion&opcionSeleccionada="+opcionSeleccionada+"&opcionSeleccionada2="+opcionSeleccionada2+"&idespectaculo="+idespectaculo, true);	

	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";
		}
		if (ajax.readyState==4)
		{
			if (selectDestino.parentNode!=null)
			{
					selectDestino.innerHTML=ajax.responseText;
					//alert(ajax.responseText);
			}
		} 
	}
	ajax.send(null);
}

function guardar_gestionavisos() //Mis datos -> Gestion avisos
{
	if (document.form_gestionavisos.cambio.value == "SI")
	{
		document.form_gestionavisos.action="./misdatos.php?accion=gestionavisos";
		document.form_gestionavisos.submit();	
	}
	else
	{
		alert("No has realizado cambios");
	}
}

function cancelarcambios() //Mis datos -> Mis datos
{
	
	//Botones
	document.form_datosusuario.editar_guardar.value = "Editar";
	document.getElementById("cancelar").disabled = true;
	//Inicializamos los datos de los campos
	document.forms['form_datosusuario'].Nombre.value=document.forms['form_datosusuario'].Nombre_backup.value;
	document.forms['form_datosusuario'].emailpersonal.value=document.forms['form_datosusuario'].emailpersonal_backup.value;
	document.forms['form_datosusuario'].cargo.value=document.forms['form_datosusuario'].cargo_backup.value;
	document.forms['form_datosusuario'].sexo.value=document.forms['form_datosusuario'].sexo_backup.value;
	document.forms['form_datosusuario'].direccion.value=document.forms['form_datosusuario'].direccion_backup.value;
	document.forms['form_datosusuario'].provincia.value=document.forms['form_datosusuario'].provincia_backup.value;
	//document.forms['form_datosusuario'].localidad.value=document.forms['form_datosusuario'].localidad_backup.value;
	CargaLocalidades ("provincia");
	document.forms['form_datosusuario'].cp.value=document.forms['form_datosusuario'].cp_backup.value;
	document.forms['form_datosusuario'].movil.value=document.forms['form_datosusuario'].movil_backup.value;
	document.forms['form_datosusuario'].ididioma.value=document.forms['form_datosusuario'].ididioma_backup.value;
	
	if(document.forms['form_datosusuario'].alerta_email_backup.value=='S')
		document.forms['form_datosusuario'].alerta_email.checked=true;
	else
		document.forms['form_datosusuario'].alerta_email.checked=false;
	
	if(document.forms['form_datosusuario'].alerta_sms_backup.value=='S')
		document.forms['form_datosusuario'].alerta_sms.checked=true;
	else
		document.forms['form_datosusuario'].alerta_sms.checked=false;


	document.forms['form_datosusuario'].alerta_sms.disabled=true;	
	document.forms['form_datosusuario'].alerta_email.disabled=true;

	//Banco
	
	document.forms['form_datosusuario'].fpg1.value=document.forms['form_datosusuario'].fpg1_backup.value;
	
	document.forms['form_datosusuario'].titular.value=document.forms['form_datosusuario'].titular_backup.value;
	document.forms['form_datosusuario'].bancocontacto.value=document.forms['form_datosusuario'].bancocontacto_backup.value;
	document.forms['form_datosusuario'].sucursalcontacto.value=document.forms['form_datosusuario'].sucursalcontacto_backup.value;
	document.forms['form_datosusuario'].dccontacto.value=document.forms['form_datosusuario'].dccontacto_backup.value;
	document.forms['form_datosusuario'].cuentacontacto.value=document.forms['form_datosusuario'].cuentacontacto_backup.value;
	

	//Deshabilitamos todos los campos
	document.getElementById("Nombre").readOnly = "readonly";
	document.getElementById("emailpersonal").readOnly = "readonly";
	document.getElementById("cargo").disabled = true;
	document.getElementById("sexo").disabled = true;
	document.getElementById("direccion").readOnly = "readonly";
	document.getElementById("provincia").disabled = true;
	document.getElementById("localidad").disabled = true;
	
	document.getElementById("cp").readOnly = "readonly";
	document.getElementById("movil").readOnly = "readonly";
	document.getElementById("ididioma").disabled = true;
	

	document.getElementById("fpg1").disabled = true;
	document.getElementById("titular").readOnly = "readonly";
	document.getElementById("bancocontacto").readOnly = "readonly";
	document.getElementById("sucursalcontacto").readOnly = "readonly";
	document.getElementById("dccontacto").readOnly = "readonly";
	document.getElementById("cuentacontacto").readOnly = "readonly";
	if(document.getElementById("fpg1").options[document.getElementById("fpg1").selectedIndex].value==1)
	{
		document.getElementById('divbanco').style.display = '';
	}
	else
	{
		document.getElementById('divbanco').style.display='none';
	}	
	
	
	document.getElementById("Nombre").className="inactivo";
	document.getElementById("emailpersonal").className="inactivo";
	document.getElementById("direccion").className="inactivo";
	document.getElementById("cp").className="inactivo";
	document.getElementById("movil").className="inactivo";
	document.getElementById("titular").className="inactivo";
	document.getElementById("bancocontacto").className="inactivo";
	document.getElementById("sucursalcontacto").className="inactivo";
	document.getElementById("dccontacto").className="inactivo";
	document.getElementById("cuentacontacto").className="inactivo";


}


function editardatosusuario() //Mis datos -> Mis datos
{
	if(document.form_datosusuario.editar_guardar.value == "Guardar")
	{
		if(document.form_datosusuario.Nombre.value.length==0)
		{
			alert("El campo nombre es obligatorio");	
			return;
		}
		ok=validar_email(document.form_datosusuario.emailpersonal.value)
		if(ok==false)
		{
			return;
		}
		if(document.form_datosusuario.direccion.value!="")
		{
			if(document.forms['form_datosusuario'].provincia.value==0)
			{	
				alert("Debes indicar una provincia valida");
				return;
			}
			if(document.forms['form_datosusuario'].localidad.value==0)
			{	
				alert("Debes indicar una localidad valida");
				return;
			}
			if(document.forms['form_datosusuario'].cp.value.length<5)
			{	
				alert("Debes indicar una CP válido");
				return;
			}
		}
		if(document.form_datosusuario.movil.value!="")
		{
			if(document.form_datosusuario.movil.value.length!=9)
			{
				alert("El campo movil debe tener 9 números");	
				return;
			}
			else
			{
				if(document.form_datosusuario.movil.value.charAt(0)!="6")
				{
					alert("El móvil debe comenzar por un 6");	
					return;
				}
				for (i = 0; i < document.form_datosusuario.movil.value.length; i++)
				{
					if(isNaN(document.form_datosusuario.movil.value.charAt(i)))
					{
						alert("El campo movil no puede contener caracteres");		
						return;
					}
				}
			}
		}

		document.form_datosusuario.action="./misdatos.php";
		document.form_datosusuario.submit();	
	}
	else
	{
		document.form_datosusuario.editar_guardar.value = "Guardar";
		document.getElementById("cancelar").disabled = false;
		
		
		document.getElementById("Nombre").readOnly = "";
		document.getElementById("emailpersonal").readOnly = "";
		document.getElementById("cargo").disabled = false;
		document.getElementById("sexo").disabled = false;
		document.getElementById("direccion").readOnly = "";
		document.getElementById("provincia").disabled = false;
		document.getElementById("localidad").disabled = false;
		document.getElementById("cp").readOnly = "";
		document.getElementById("movil").readOnly = "";
		document.getElementById("ididioma").disabled = false;
		
		document.form_datosusuario.alerta_sms.disabled = false;
		document.form_datosusuario.alerta_email.disabled = false;


		document.getElementById("fpg1").disabled = false;
		//Banco
		document.getElementById("titular").readOnly = "";
		document.getElementById("bancocontacto").readOnly = "";
		document.getElementById("sucursalcontacto").readOnly = "";
		document.getElementById("dccontacto").readOnly = "";
		document.getElementById("cuentacontacto").readOnly = "";
		
		document.getElementById("Nombre").className = "activo";
		document.getElementById("emailpersonal").className = "activo";
		document.getElementById("direccion").className = "activo";
		document.getElementById("cp").className = "activo";
		document.getElementById("movil").className = "activo";
		document.getElementById("titular").className = "activo";
		document.getElementById("bancocontacto").className = "activo";
		document.getElementById("sucursalcontacto").className = "activo";
		document.getElementById("dccontacto").className = "activo";
		document.getElementById("cuentacontacto").className = "activo";
		
		

	}
}

function modificar_transporte(linea)
{
	var autocar="autocar"+linea;
	var transporte="transp"+linea;
	if(document.getElementById(autocar).checked==true)
	{
		document.getElementById(transporte).disabled = true;	
		document.getElementById(transporte).value="2";
		//Deshabilitamos el combo de transporte marcando "autocar"
	}
	else
	{
		document.getElementById(transporte).disabled = false;
		document.getElementById(transporte).value="0";
		//Habilitamos el combo de transporte y marcamos la opcion 0
	}
}

function activarcambio() //Mis datos -> Gestion Avisos
{
	document.form_gestionavisos.cambio.value = "SI";
}
function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}


function descargar_programacion(array_impresion)
{
	document.form_programacion.array_impresion.value = array_impresion;
	document.form_programacion.action="./imprimir_programacion.php";
	document.form_programacion.submit();		
}


function direccion_materiales(seleccion)
{
	if(seleccion=="direccion_centro")
	{
		document.getElementById('direccion_centro').style.display = '';
		document.getElementById('direccion_contacto').style.display='none';
		document.getElementById('direccion_otra').style.display='none';
	}
	else if(seleccion=="direccion_contacto")
	{
		document.getElementById('direccion_centro').style.display = 'none';
		document.getElementById('direccion_contacto').style.display='';
		document.getElementById('direccion_otra').style.display='none';
	}	
	else if(seleccion=="direccion_otra")
	{
		document.getElementById('direccion_centro').style.display = 'none';
		document.getElementById('direccion_contacto').style.display='none';
		document.getElementById('direccion_otra').style.display='';
	}
}


function guardar_modif_pedido(idreserva)
{
	if(document.form_reserva.total.value<1)
	{
		alert("No puedes continuar sin haber indicado ninguna plaza");
		return;
	}
	if(document.form_reserva.total_pzn.value<1)
	{
		alert("Debe haber algún acompañante");
		return;
	}
	
	if(parseInt(document.form_reserva.total.value-parseInt(document.form_reserva.total_pzn.value))<20)	
	{
		if(parseInt(document.form_reserva.total_pzn.value)>2)
		{
			alert("En reservas de hasta 20 niños el máximo de acompañantes son 2");
			return;	
		}
	}
	else
	{
		var porciento=(parseInt(document.form_reserva.total_pzn.value)*100)/parseInt(document.form_reserva.total.value);
		if(porciento>10.0)
		{
			alert("El máximo de acompañantes es el 10% sobre el total de alumnos");
			return;
		}
	}
	if(document.getElementById("fechaentr")!=null)
	{
		if(document.getElementById("fechaentr").value=="" && document.getElementById("total_libros").value>0)
		{
				alert("La fecha de entrega de los libros es obligatoria");
				return;
		}
		if(document.getElementById("total_libros_oculto2").value>0 && document.getElementById("total_libros").value==0)
		{
			alert("No se permiten anulaciones desde la web.");
			return;	
		}		
	}
	if(document.form_reserva.fpg1.value=="1")
	{
		if(document.form_reserva.titular.value=="")
		{
			alert("El campo Titular es obligatorio");
			return;	
		}
		if(document.form_reserva.bco.value.length!=4 || document.form_reserva.bag.value.length!=4 || document.form_reserva.dc.value.length!=2 || document.form_reserva.nct.value.length!=10)
		{
			alert("Los datos bancarios están incompletos");
			return;	
		}
		if(document.form_reserva.bco.value=="2038" && document.form_reserva.bag.value=="2476" && document.form_reserva.dc.value=="31" && document.form_reserva.nct.value=="6100009258")
		{
			alert("Los datos bancarios no pueden ser los de Recursos.");
			return;	
		}		
		
	}
	
	if(confirm("¿Estas seguro que deseas realizar las modificaciones indicadas?\n(Recuerda que sólo se permiten hasta 3 modificaciones por reserva diaria)")) 
	{
		cargar_ajax('form_reserva','form_reserva','modif_reserva','&tipo=modificacion');
	}
	else
	{
		return;	
	}
}

function confirmacion_reserva(idreserva,tipo)
{
	if(document.form_reserva.total.value<1)
	{
		alert("No puedes continuar sin haber indicado ninguna plaza");
		return;
	}
	if(document.form_reserva.total_pzn.value<1)
	{
		alert("Debe haber algún acompañante");
		return;
	}
	if(parseInt(document.form_reserva.total.value-parseInt(document.form_reserva.total_pzn.value))<20)	
	{
		if(parseInt(document.form_reserva.total_pzn.value)>2)
		{
			alert("En reservas de hasta 20 niños el máximo de acompañantes son 2");
			return;	
		}
	}
	else
	{
		var porciento=(parseInt(document.form_reserva.total_pzn.value)*100)/parseInt(document.form_reserva.total.value);
		if(porciento>10.0)
		{
			alert("El máximo de acompañantes es el 10% sobre el total de alumnos");
			return;
		}
	}
	if(document.getElementById("fechaentr")!=null)
	{
		if(document.getElementById("fechaentr").value=="" && document.getElementById("total_libros").value>0)
		{
				alert("La fecha de entrega de los libros es obligatoria");
				return;
		}
		if(document.getElementById("total_libros_oculto2").value>0 && document.getElementById("total_libros").value==0)
		{
			alert("No se permiten anulaciones desde la web.");
			return;	
		}
	}
	
	if(document.form_reserva.fpg1.value=="1")
	{
		if(document.form_reserva.titular.value=="")
		{
			alert("El campo Titular es obligatorio");
			return;	
		}
		if(document.form_reserva.bco.value.length!=4 || document.form_reserva.bag.value.length!=4 || document.form_reserva.dc.value.length!=2 || document.form_reserva.nct.value.length!=10)
		{
			alert("Los datos bancarios están incompletos");
			return;	
		}
		if(document.form_reserva.bco.value=="2038" && document.form_reserva.bag.value=="2476" && document.form_reserva.dc.value=="31" && document.form_reserva.nct.value=="6100009258")
		{
			alert("Los datos bancarios no pueden ser los de Recursos.");
			return;	
		}		
		
	}
	//document.form_reserva.pase.disabled = '';
	//document.form_reserva.fpg1.disabled = '';
	cargar_ajax('form_reserva','form_reserva','modif_reserva','&tipo='+tipo);
	//document.form_reserva.pase.disabled = 'disabled';
	//document.form_reserva.fpg1.disabled = 'disabled';
}

function editar_form(formulario,div,accion,pars_extra)
{
	if(document.getElementById("editar").value=="Editar")
	{
		var estado="cancelar";
	}
	else
	{
		var estado="editar";
	}
	
	var elementos = document.forms[0].elements.length;
	var num_form=0;
	if (elementos==1) //Esto ocurriría en campaña de mayo
	{
		elementos = document.forms[1].elements.length;
		num_form=1;
	}

	for(i=0; i<elementos; i++)
	{
		var oculto = document.getElementById(document.forms[num_form].elements[i].id+"_oculto");
		if (oculto!=null) // si es un campo editable, le asignamos la class de su oculto
		{	
			var clase_old=document.forms[num_form].elements[i].className;
			document.forms[num_form].elements[i].className=oculto.className;
			if(document.forms[num_form].elements[i].type=="text") // Cada input tiene su propia manera de activarse
			{	
				if(estado=="cancelar"){
					if(document.forms[num_form].elements[i].id!="fechaentr")
					{
						document.forms[num_form].elements[i].readOnly = '';
					}else{
						document.getElementById("lanzador1").disabled= '';
					}
				}else{ 
					if(document.forms[num_form].elements[i].id!="fechaentr")
					{
						document.forms[num_form].elements[i].readOnly = 'readonly';
						document.forms[num_form].elements[i].value=oculto.value;
					}
					else
					{
						document.forms[num_form].elements[i].value=oculto.value;
						document.getElementById("lanzador1").disabled= 'disabled';	
					}
				}
			}
			
			if(document.forms[num_form].elements[i].type=="select-one")
			{
				if(estado=="cancelar"){	
					document.forms[num_form].elements[i].disabled = '';
				}else {	
					document.forms[num_form].elements[i].disabled = 'disabled';
					document.forms[num_form].elements[i].value=oculto.value;
				}
				
			}
			if(document.forms[num_form].elements[i].type=="textarea")
			{
				if(estado=="cancelar"){
					document.forms[num_form].elements[i].disabled = '';
				}else{	
					document.forms[num_form].elements[i].disabled = 'disabled';
					document.forms[num_form].elements[i].value=oculto.value;
				}
			}
			if(document.forms[num_form].elements[i].type=="checkbox")
			{
				if(estado=="cancelar"){
					document.forms[num_form].elements[i].disabled = '';
				}else{	
					document.forms[num_form].elements[i].disabled = 'disabled';
					document.forms[num_form].elements[i].value=oculto.value;
					if(oculto.value=="S")
						document.forms[num_form].elements[i].checked=true;
					else
						document.forms[num_form].elements[i].checked=false;
				}
			}				
			oculto.className=clase_old;				
		}
	}
	if(estado=="cancelar")
	{
		document.getElementById("editar").value="Cancelar";
		document.getElementById("guardar").disabled = '';
		document.getElementById("guardar").className='boton';
	}
	else
	{
		document.getElementById("editar").value="Editar";
		document.getElementById("guardar").className='boton-disabled';
		document.getElementById("guardar").disabled = 'disabled';		
		if(formulario=="form_reserva")
		{
				
			formapago(document.getElementById("fpg1").id);
			sumaplazas_modif();
			if(document.getElementById("total_libros")!=null)
			{
				sumalibros();
			}
		}
	}
	return (false);
}

function cargar_ajax(formulario,div,accion,pars_extra)
{		
	var url = 'procesos_ajax.php?accion='+accion;
	var pars = Form.serialize($(formulario));
	if(pars_extra!="")
	{
		if(pars!="")
		{
			pars=pars+"&"+pars_extra;
		}
		else
		{
			pars=pars_extra;
		}
	}
	//alert(pars);
	var myAjax = new Ajax.Updater(
		div,
		url, 
		{
		onLoading: document.getElementById(div).innerHTML = "<br><img src='../img/indicator_big.gif'>",
		method: 'post', 
		parameters: pars,
		contentType: 'application/x-www-form-urlencoded; charset=ISO-8859-1',
		encoding: "iso-8859-1",
		//onFailure: '',
		evalScripts: true
		})	
	
	
}

function div_cambiar_centro()
{
	if(document.getElementById('div_cambio_centro').style.display == '')
	{
		document.getElementById('div_cambio_centro').style.display='none';
	}
	else
	{
		document.getElementById('div_cambio_centro').style.display = '';
	}
}

function buscarcentro_cambiar_centro() //registro de usuario
{
//alert("El registro de usuarios está inactivo temporalmente");
//return
	var selectDestino=document.getElementById("idbuscarcentro");
	var buscarcentro=document.form_datosusuario.buscarcentro.value;
	var buscarcp=document.form_datosusuario.cp_centro.value;
	if(buscarcentro=="" && buscarcp=="")
	{
		alert("Debes indicar el Nombre del Centro y el Codigo Postal");
		return;
	}
	else
	{
		if(buscarcentro.length<3)
		{
			alert("El nombre del centro debe contener al menos 3 caracteres");
			return;
		}
		if(buscarcp.length!=5)
		{
			alert("El Codigo postal debe contener al menos 5 numeros");
			return;
		}	
	}
	
	var ajax=nuevoAjax();
	ajax.open("GET", "procesos_ajax.php?accion=mostrar_buscarcentro_cambiar_centro&buscarcentro="+buscarcentro+"&buscarcp="+buscarcp, true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
			//No es necesario hacer nada, si acaso poner "cargando"
			selectDestino.innerHTML = "<br><img src='../img/indicator_big.gif'>";	
		}
		if (ajax.readyState==4)
		{
			if (selectDestino.parentNode!=null)
			{
				selectDestino.innerHTML=ajax.responseText;
			}
		} 
	}
	ajax.send(null);
}

function buscarcentro_cambiar_centro_seleccionarcentro(idcentro) //Registro de usuario
{
	if(confirm("Estás solicitando un cambio de centro educativo. ¿Seguro que deseas continuar?"))
	{
		var selectDestino=document.getElementById("idbuscarcentro");
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=buscarcentro_cambiar_centro_seleccionarcentro&idcentro="+idcentro, true);
		ajax.onreadystatechange=function() 
			{ 
				if (ajax.readyState==1)
				{
					// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
					//No es necesario hacer nada, si acaso poner "cargando"
				}
				if (ajax.readyState==4)
				{					
						selectDestino.parentNode.innerHTML=ajax.responseText;
				} 
			}
			ajax.send(null);	
	}
}

function CargaLocalidades_cambio_centro (idSelectOrigen) //Mis datos
{
	var selectDestino=document.getElementById("localidad");	
	var selectOrigen=document.getElementById(idSelectOrigen);
	if (selectOrigen.selectedIndex=="-1")
	{
		var opcionSeleccionada=0;	
	}
	else
	{
		var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;	
	}
	var codcliente=document.form_datosusuario.codcliente.value;	
	if(opcionSeleccionada==0)
	{
		selectOrigen.value=0;
	}
	else
	{
		var ajax=nuevoAjax();
		ajax.open("GET", "procesos_ajax.php?accion=CargaLocalidades_cambio_centro&opcionSeleccionada="+opcionSeleccionada, true);	
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				//selectOrigen.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				selectOrigen.appendChild(nuevaOpcion); 
				selectDestino.appendChild(nuevaOpcion); 
				selectOrigen.disabled=true;
				selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if (selectDestino.parentNode!=null)
				{
					selectDestino.parentNode.innerHTML=ajax.responseText;
					selectOrigen.disabled=false;
				}
			} 
		}
		ajax.send(null);
	}
}
function enviar_cambio_centro()
{
	if(document.form_datosusuario.Nombre.value.length==0)
	{
		alert("El campo nombre es obligatorio");	
		return;
	}
	ok=validar_email(document.form_datosusuario.email.value)
	if(ok==false)
	{
		return;
	}
	
	if(document.form_datosusuario.movil.value!="")
	{
		if(document.form_datosusuario.movil.value.length!=9)
		{
			alert("El campo movil debe tener 9 números");	
			return;
		}
		else
		{
			if(document.form_datosusuario.movil.value.charAt(0)!="6")
			{
				alert("El móvil debe comenzar por un 6");	
				return;
			}
			for (i = 0; i < document.form_datosusuario.movil.value.length; i++)
			{
				if(isNaN(document.form_datosusuario.movil.value.charAt(i)))
				{
					alert("El campo movil no puede contener caracteres");		
					return;
				}
			}
		}
	}
	if(document.form_datosusuario.cargo.value==0)
	{
		alert("El campo cargo es obligatorio");			
		return;
	}	
	if(document.form_datosusuario.sexo.value==0)
	{
		alert("El campo tratamiento es obligatorio");			
		return;
	}

	if(document.form_datosusuario.direccion.value!="")
	{
		if(document.form_datosusuario.provincia.value==0)
		{
			alert("El campo provincia es obligatorio");			
			return;
		}
		if(document.form_datosusuario.localidad.value==0)
		{
			alert("El campo localidad es obligatorio");			
			return;
		}	
		if(document.form_datosusuario.cp.value.length!=5)
		{
			alert("El campo CP debe tener 5 números");			
			return;
		}
	}
	//document.form_datosusuario.action="./registro.php";
	document.form_datosusuario.submit();
}

function lang_sel(idioma)
{
	document.getElementById("lang_sel").value=idioma;
	document.form_lang_sel.submit();
}


function imprimir_esp_html()
{
	document.getElementById("esp_html").value="<div align='left'><img src='../logo/logo_firma.gif'></img></div><br><div align='center'><h2>"+document.getElementById("titulo_esp").innerHTML+" "+document.getElementById("bandera_esp").innerHTML+"</div></h2><br><br>";
	
	
	
	document.getElementById("esp_html").value=document.getElementById("esp_html").value+document.getElementById("div_esp_html").innerHTML;
	
	document.form_esp_html.submit();
}
