function guarda_news()
{
c = document.getElementById('correon');
if(idioma=='en'){
	var msj1= "You have not entered a valid email address.\n";
}
else{
	var msj1= "El email introducido es incorrecto.\n";
}
if(!validarEmail(c.value)) alert(msj1);
else {	
    respuesta = document.getElementById('news');
    envia('ajax/guarda_news.php',
	'&correo='+c.value);
	}
}
function guarda_news2()
{
c = document.getElementById('correo2');
if(idioma=='en'){
	var msj1= "You have not entered a valid email address.\n";
}
else{
	var msj1= "El email introducido es incorrecto.\n";
}
if(!validarEmail(c.value)) alert(msj1);
else {	
    respuesta = document.getElementById('news2');
    envia('ajax/guarda_news.php',
	'&correo='+c.value+
	'&tipo=2');
	}
}
function contacto()
{
f = document.getElementById('form1');
if((f.nombre.value.length <3) || (f.asunto.value.length <3) || (f.mensaje.value.length <3) || !validarEmail(f.correo.value)) alert("Rellene correctamente los campos para enviar el formulario.");
else {	
    respuesta = document.getElementById('res');
    envia('ajax/envio_contacto.php',
	'&nombre='+parsea(f.nombre.value)+
	'&asunto='+parsea(f.asunto.value)+
	'&mensaje='+parsea(f.mensaje.value)+
	'&correo='+parsea(f.correo.value));
	}
}
function habitaciones(ver)
{
	try{
		document.getElementById("habit1").style.display = "none";
		document.getElementById("habit2").style.display = "none";
		document.getElementById("habit3").style.display = "none";
		document.getElementById("habit4").style.display = "none";
		document.getElementById("habit5").style.display = "none";
		document.getElementById("habit"+ver).style.display = "block";
	} catch(err){}
    respuesta = document.getElementById('res');
    envia('galeria.php',
	'&zona='+ver);
}
function opinion()
{
	f = document.getElementById('form1');
	var com="";
	if(idioma=='en'){
		var msj1= "You can not leave the comment field empty.\n";
		var msj2= "Enter your reservation number.\n";
	}
	else{
		var msj1= "No puede dejar el campo de comentarios vacio.\n";
		var msj2= "Introduzca su numero de reserva.\n";
	}
	try{ com=f.comentarios.value; }catch(err){};
	
	if(!f.n_res.value) alert(msj2);
	else{
		if(!com){
			// Introduce el número de reserva
			document.getElementById('compres').style.display='none';
			respuesta = document.getElementById('formu2');
			envia('ajax/guarda_opinion.php',
			'&n_res='+f.n_res.value	);
		} else {
			if(com.length<100){
				alert("Intente realizar un comentario mas exhaustivo.")
			}
			else{
				respuesta = document.getElementById('res');
				envia('ajax/guarda_opinion.php',
				'&n_res='+f.n_res.value	+
				'&nombre='+f.nombre.value+
				'&email='+f.email.value+
				'&dni='+f.dni.value+
				'&telefono='+f.telefono.value+
				'&comentarios='+f.comentarios.value	);
			}
		}
	}
}
function ventajas()
{
	f = document.getElementById('form1');
	respuesta = document.getElementById('res');
	var cadena="";
	cadena +="&element_1="+parsea(f.element_1.value);		cadena +="&element_2="+parsea(f.element_2.value);
	cadena +="&element_3="+parsea(f.element_3.value);		cadena +="&element_4="+parsea(f.element_4.value);
	cadena +="&element_5="+parsea(f.element_5.value);		cadena +="&element_6="+parsea(f.element_6.value);
	cadena +="&element_7="+parsea(f.element_7.value);		cadena +="&element_8="+parsea(f.element_8.value);
															cadena +="&element_8b="+parsea(f.element_8b.value);
	cadena +="&element_9="+parsea(f.element_9.value);		cadena +="&element_10="+parsea(f.element_10.value);
	cadena +="&element_11="+parsea(f.element_11.value);		cadena +="&element_12="+parsea(f.element_12.value);
	cadena +="&element_13="+parsea(f.element_13.value);		cadena +="&element_14="+parsea(f.element_14.value);
	if(f.element_14b_1.checked) cadena +="&element_14b="+parsea(f.element_14b_1.value);
	if(f.element_14b_2.checked) cadena +="&element_14b="+parsea(f.element_14b_2.value);
	cadena +="&element_15="+parsea(f.element_15.value);		cadena +="&element_15b="+parsea(f.element_15b.value);
	cadena +="&element_15c="+parsea(f.element_15c.value);	cadena +="&element_16="+parsea(f.element_16.value);
	cadena +="&element_17="+parsea(f.element_17.value);		cadena +="&element_18="+parsea(f.element_18.value);
	if(f.element_19_1.checked) cadena +="&element_19="+parsea(f.element_19_1.value);
	if(f.element_19_2.checked) cadena +="&element_19="+parsea(f.element_19_2.value);
	if(f.element_20_1.checked) cadena +="&element_20="+parsea(f.element_20_1.value);
	if(f.element_20_2.checked) cadena +="&element_20="+parsea(f.element_20_2.value);
	if(f.element_21_1.checked) cadena +="&element_21="+parsea(f.element_21_1.value);
	if(f.element_21_2.checked) cadena +="&element_21="+parsea(f.element_21_2.value);
	cadena +="&element_22="+parsea(f.element_22.value);		cadena +="&element_23="+parsea(f.element_23.value);
	cadena +="&element_24="+parsea(f.element_24.value);		cadena +="&element_25="+parsea(f.element_25.value);
	cadena +="&element_26="+parsea(f.element_26.value);		cadena +="&element_27="+parsea(f.element_27.value);
	cadena +="&element_28="+parsea(f.element_28.value);		cadena +="&element_29="+parsea(f.element_29.value);
	cadena +="&element_30="+parsea(f.element_30.value);		cadena +="&element_31="+parsea(f.element_31.value);
	cadena +="&element_32="+parsea(f.element_32.value);		cadena +="&element_33="+parsea(f.element_33.value);
	envia('ajax/envia_ventajas.php',cadena);
}

// Funciones ajax admin //

//cabeceras.php
function ver_cabeceras()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_cabeceras.php','');
}
function borra_cabecera(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_cabeceras.php','borra='+borra);}
}
function edita_cabecera(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_cabeceras.php','form='+edita);
}
function muestra_cabecera(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_cabeceras.php','muestra='+id);
}
function oculta_cabecera(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_cabeceras.php','oculta='+id);
}
function guarda_cabecera(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_cabeceras.php',
	'guarda='+edita+
	'&imagen='+f.imagen.value+
	'&link='+f.link.value+
	'&fecha_ver_ini='+f.fecha_ver_ini.value+
	'&fecha_ver_fin='+f.fecha_ver_fin.value+
	'&texto1='+parsea(f.texto1.value)+
	'&texto2='+parsea(f.texto2.value)+
	'&texto3='+parsea(f.texto3.value)+
	'&texto1en='+parsea(f.texto1en.value)+
	'&texto2en='+parsea(f.texto2en.value)+
	'&texto3en='+parsea(f.texto3en.value));
}

//ofertas.php
function ver_ofertas()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_ofertas.php','');
}
function borra_oferta(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_ofertas.php','borra='+borra);}
}
function edita_oferta(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_ofertas.php','form='+edita);
}
function muestra_oferta(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_ofertas.php','muestra='+id);
}
function oculta_oferta(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_ofertas.php','oculta='+id);
}
function guarda_oferta(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
	var desc,cond,descen,conden;
	
	var inst,contents=new Array();
	for(inst in tinyMCE.editors){
	contents[contents.length]= tinyMCE.editors[inst].getContent();
	tinyMCE.editors
	}
	//elimino instancias
	var i, t = tinyMCE.editors;
	for (i in t){
		if (t.hasOwnProperty(i)){
			t[i].remove();
		}
	}
	tinyMCE.execCommand('mceRemoveControl', false, 'idOfElement');
	tinyMCE.execCommand('mceAddControl', false, 'idOfElement');
	//
	desc=contents[0];
	cond=contents[1];
	inc=contents[2];
	descen=contents[3];
	conden=contents[4]; 
	incen=contents[5];
    envia('../ajax/cargar_ofertas.php',
	'guarda='+edita+
	'&fecha_res_ini='+f.fecha_res_ini.value+
	'&fecha_res_fin='+f.fecha_res_fin.value+
	'&fecha_ver_ini='+f.fecha_ver_ini.value+
	'&fecha_ver_fin='+f.fecha_ver_fin.value+
	'&titulo='+parsea(f.titulo.value)+
	'&subtitulo='+parsea(f.subtitulo.value)+
	'&descripcion='+parsea(desc)+
	'&condiciones='+parsea(cond)+
	'&incluidos='+parsea(inc)+
	'&tituloen='+parsea(f.tituloen.value)+
	'&subtituloen='+parsea(f.subtituloen.value)+
	'&descripcionen='+parsea(descen)+
	'&condicionesen='+parsea(conden)+
	'&incluidosen='+parsea(incen)+
	'&imagen='+f.imagen.value+
	'&oferta='+f.oferta.value+
	'&precio1='+f.precio1.value.replace(/,/g,'.')+
	'&precio2='+f.precio2.value.replace(/,/g,'.')+
	'&precio3='+f.precio3.value.replace(/,/g,'.')+
	'&si='+f.si.value.replace(/,/g,'.')+
	'&sj='+f.sj.value.replace(/,/g,'.')+
	'&ss='+f.ss.value.replace(/,/g,'.')+
	'&ofertables='+f.ofertables.value+
	'&personas='+f.personas.value+
	'&noches='+f.noches.value);
}

//acceso.php
function ver_accesos()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_accesos.php','');
}
function borra_acceso(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_accesos.php','borra='+borra);}
}
function edita_acceso(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_accesos.php','form='+edita);
}
function guarda_acceso(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_accesos.php',
	'guarda='+edita+
	'&usuario='+f.usuario.value+
	'&pass='+f.pass.value+
	'&passpro='+f.passpro.value+
	'&passn='+f.passn.value);
}

//eventos.php
function ver_eventos()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_eventos.php','');
}
function borra_evento(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_eventos.php','borra='+borra);}
}
function edita_evento(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_eventos.php','form='+edita);
}
function guarda_evento(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
	var texto;
	
	var inst,contents=new Array();
	for(inst in tinyMCE.editors){
	contents[contents.length]= tinyMCE.editors[inst].getContent();
	tinyMCE.editors
	}
	//elimino instancias
	var i, t = tinyMCE.editors;
	for (i in t){
		if (t.hasOwnProperty(i)){
			t[i].remove();
		}
	}
	tinyMCE.execCommand('mceRemoveControl', false, 'idOfElement');
	tinyMCE.execCommand('mceAddControl', false, 'idOfElement');
	//
	texto=contents[0];
	if(edita != 99999){
	    envia('../ajax/cargar_eventos.php',
		'guarda='+edita+
		'&repetir='+f.repetir.checked+
		'&fecha='+f.fecha.value+
		'&titulo='+parsea(f.titulo.value)+
		'&texto='+parsea(texto));
	} else {
	    envia('../ajax/cargar_eventos.php',
	    		'guarda='+edita+
	    		'&texto='+parsea(texto));
	}
}

//fotos.php
function ver_fotos(zona)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_fotos.php','zona='+zona);
}
function borra_foto(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_fotos.php','borra='+borra);}
}
function edita_foto(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_fotos.php','form='+edita);
}
function guarda_foto(edita)
{
	f = document.getElementById('form1');
if(f.zona.value>0 && f.zona.value<900){	
    respuesta = document.getElementById('res');
	var texto,textoen;
	
	var inst,contents=new Array();
	for(inst in tinyMCE.editors){
	contents[contents.length]= tinyMCE.editors[inst].getContent();
	tinyMCE.editors
	}
	//elimino instancias
	var i, t = tinyMCE.editors;
	for (i in t){
		if (t.hasOwnProperty(i)){
			t[i].remove();
		}
	}
	tinyMCE.execCommand('mceRemoveControl', false, 'idOfElement');
	tinyMCE.execCommand('mceAddControl', false, 'idOfElement');
	//
	texto=contents[0];
	textoen=contents[1];
    envia('../ajax/cargar_fotos.php',
	'guarda='+edita+
	'&imagen='+f.imagen.value+
	'&zona='+f.zona.value+
	'&titulo='+parsea(f.titulo.value)+
	'&tituloen='+parsea(f.tituloen.value)+
	'&pie='+parsea(texto)+
	'&pieen='+parsea(textoen));
}
else alert("Error: No ha seleccionado zona.");
}

//boletines.php
function ver_boletines()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_boletines.php',''); 
}
function borra_boletin(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_boletines.php','borra='+borra);}
}
function edita_boletin(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_boletines.php','form='+edita);
}
function guarda_boletin(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    var temp=""; 
    if(f.tipo.value==1) temp = '&nombre='+parsea(f.nombre1.value)+'&enviado='+f.enviado1.value+'&imagen_destacado='+f.imagen_destacado.value+'&link_destacado='+parsealink(f.link_destacado.value)+
	'&imagen1='+f.imagen1.value+'&link1='+parsealink(f.link1.value)+
	'&titulo1='+parsea(f.titulo1.value)+'&texto1='+parsea(f.texto1.value)+
'&imagen2='+f.imagen2.value+'&link2='+parsealink(f.link2.value)+
	'&titulo2='+parsea(f.titulo2.value)+'&texto2='+parsea(f.texto2.value)+
'&imagen3='+f.imagen3.value+'&link3='+parsealink(f.link3.value)+
	'&titulo3='+parsea(f.titulo3.value)+'&texto3='+parsea(f.texto3.value)+
	'&link_u1='+parsealink(f.link_u1.value)+'&titulo_u1='+parsea(f.titulo_u1.value)+
	'&link_u2='+parsealink(f.link_u2.value)+'&titulo_u2='+parsea(f.titulo_u2.value)+
	'&link_u3='+parsealink(f.link_u3.value)+'&titulo_u3='+parsea(f.titulo_u3.value)+
	'&link_u4='+parsealink(f.link_u4.value)+'&titulo_u4='+parsea(f.titulo_u4.value)+
	'&link_u5='+parsealink(f.link_u5.value)+'&titulo_u5='+parsea(f.titulo_u5.value)+
	'&link_i1='+parsealink(f.link_i1.value)+'&titulo_i1='+parsea(f.titulo_i1.value)+
	'&link_i2='+parsealink(f.link_i2.value)+'&titulo_i2='+parsea(f.titulo_i2.value)+
	'&link_i3='+parsealink(f.link_i3.value)+'&titulo_i3='+parsea(f.titulo_i3.value)+
	'&link_i4='+parsealink(f.link_i4.value)+'&titulo_i4='+parsea(f.titulo_i4.value)+
	'&link_i5='+parsealink(f.link_i5.value)+'&titulo_i5='+parsea(f.titulo_i5.value)+
	'&imagen_c='+f.imagen_c.value+'&titulo_c='+parsea(f.titulo_c.value)+'&edicion='+parsea(f.edicion1.value);
    
    if(f.tipo.value==2) temp = '&nombre='+parsea(f.nombre2.value)+'&enviado='+f.enviado2.value+'&imagen_full='+f.imagen_full.value+'&link_full='+parsealink(f.link_full.value)+
	'&texto_full='+parsea(f.texto_full.value)+'&edicion='+parsea(f.edicion2.value);
	    envia('../ajax/cargar_boletines.php',	'guarda='+edita+'&tipo='+f.tipo.value+temp );  
}
function envia_boletin(edita)
{
	if(confirm ('Esta acción enviará el boletín a todos los correos activados ¿Está seguro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_boletines.php','envio='+edita);}
}
function editando(id){
	if(id==0) {
		document.getElementById("tipo1").style.display = "none";
		document.getElementById("tipo2").style.display = "none";
		document.getElementById("guarda").style.display = "none";
	}
	if(id==1) {
		document.getElementById("tipo1").style.display = "block";
		document.getElementById("tipo2").style.display = "none";
		document.getElementById("guarda").style.display = "block";
	}
	if(id==2) {
		document.getElementById("tipo1").style.display = "none";
		document.getElementById("tipo2").style.display = "block";
		document.getElementById("guarda").style.display = "block";
	}
}

//mails.php
function ver_mails()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_mails.php','');
}
function borra_mail(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_mails.php','borra='+borra);}
}

// opiniones.php
function ver_opiniones(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_opiniones.php','');
}
function borra_opinion(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_opiniones.php','borra='+borra);}
}
function carga_opinion(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_opiniones.php','form='+edita);
}
function muestra_opinion(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_opiniones.php','muestra='+id);
}
function oculta_opinion(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_opiniones.php','oculta='+id);
}

//// Sistema de RESERVAS ////

function ver_habitaciones()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_habs.php','');
}
function borra_habitacion(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_habs.php','borra='+borra);}
}
function edita_habitacion(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_habs.php','form='+edita);
}
function guarda_habitacion(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    
var texto,textoen;
	var inst,contents=new Array();
	for(inst in tinyMCE.editors){
	contents[contents.length]= tinyMCE.editors[inst].getContent();
	tinyMCE.editors
	}
	//elimino instancias
	var i, t = tinyMCE.editors;
	for (i in t){
		if (t.hasOwnProperty(i)){
			t[i].remove();
		}
	}
	tinyMCE.execCommand('mceRemoveControl', false, 'idOfElement');
	tinyMCE.execCommand('mceAddControl', false, 'idOfElement');
	//
	texto=contents[0];
	textoen=contents[1];
	
    var serv="";
    for(var a=1;a<50;a++){
	try { if(document.getElementById("s"+a).checked) serv+=document.getElementById("s"+a).value+"_"; }catch(err){}
	}
	if(serv!="") serv=serv.substr(0,serv.length-1);
    if(f.tipo.value && f.nombre.value){
	    envia('../ajax/cargar_habs.php',
		'guarda='+edita+
		'&nombre='+parsea(f.nombre.value)+
		'&nombreen='+parsea(f.nombreen.value)+
		'&fumador='+f.fumador.value+
		'&tipo='+f.tipo.value+
		'&imagen='+f.imagen.value+
		'&descripcion='+parsea(texto)+
		'&descripcionen='+parsea(textoen)+
		'&serv='+serv);
    }
    else alert("Error: Los campos nombre y tipo han de rellenarse.");
}
// tipo de habitacion
function ver_thabitaciones()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_thabs.php','');
}
function borra_thabitacion(borra)
{
	if(confirm ('Es posible que existan habitaciones usando este "Tipo de habitación".\n\n¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_thabs.php','borra='+borra);}
}
function edita_thabitacion(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_thabs.php','form='+edita);
}
function guarda_thabitacion(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    if(f.tipo.value && f.personas.value){
	    envia('../ajax/cargar_thabs.php',
		'guarda='+edita+
		'&tipo='+parsea(f.tipo.value)+
		'&tipoen='+parsea(f.tipoen.value)+
		'&personas='+f.personas.value);
    }
    else alert("Error: Algun campo se encuentra vacio.");
}
// servicios de habitaciones
function ver_servicios()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios.php','');
}
function borra_servicio(borra)
{
	if((borra==1) || (borra==3) || (borra==19))
		alert("Este servicio tiene condiciones especiales y no puede ser borrado.");
	else{
	if(confirm ('Es posible que existan habitaciones usando este "Servicio".\n\n¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios.php','borra='+borra);}
	}
}
function edita_servicio(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios.php','form='+edita);
}
function muestra_servicio(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios.php','muestra='+id);
}
function oculta_servicio(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios.php','oculta='+id);
}
function guarda_servicio(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    if(f.servicio.value && f.servicioen.value && f.cantidad.value){
	    envia('../ajax/cargar_servicios.php',
		'guarda='+edita+
		'&servicio='+parsea(f.servicio.value)+
		'&servicioen='+parsea(f.servicioen.value)+
		'&cantidad='+f.cantidad.value+
		'&precio='+f.precio.value.replace(/,/g,'.')+
		'&alerta='+parsea(f.alerta.value)+
		'&alertaen='+parsea(f.alertaen.value));
    }
    else alert("Error: Algun campo se encuentra vacio.");
}
//servicios de ofertas
function ver_servicios2()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios2.php','');
}
function borra_servicio2(borra)
{
	if(confirm ('Es posible que existan habitaciones usando este "Servicio".\n\n¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios2.php','borra='+borra);}
}
function edita_servicio2(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios2.php','form='+edita);
}
function muestra_servicio2(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios2.php','muestra='+id);
}
function oculta_servicio2(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_servicios2.php','oculta='+id);
}
function guarda_servicio2(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    if(f.servicio.value && f.servicioen.value && f.cantidad.value){
	    envia('../ajax/cargar_servicios2.php',
		'guarda='+edita+
		'&servicio='+parsea(f.servicio.value)+
		'&servicioen='+parsea(f.servicioen.value)+
		'&cantidad='+f.cantidad.value+
		'&precio='+f.precio.value.replace(/,/g,'.')+
		'&alerta='+parsea(f.alerta.value)+
		'&alertaen='+parsea(f.alertaen.value));
    }
    else alert("Error: Algun campo se encuentra vacio.");
}
//clientes
function ver_clientes()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_clientes.php','');
}
function borra_clientes(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_clientes.php','borra='+borra);}
}
function edita_cliente(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_clientes.php','form='+edita);
}
function guarda_cliente(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    	var n=0; if(f.news.checked) n=1;
    	if(f.numero.value.substr(0,4)!="****" && (!validarTJ(f.numero.value) || f.numero.value.length<16))
    			alert("La tarjeta de crédito es incorrecta\n");
    	else{
    	
	    envia('../ajax/cargar_clientes.php',
		'guarda='+edita+
		'&nombre='+parsea(f.nombre.value)+
		'&apellidos='+parsea(f.apellidos.value)+
		'&documento='+f.documento.value+
		'&pais='+parsea(f.pais.value)+
		'&email='+f.email.value+
		'&telefono='+f.telefono.value+
		'&tarjeta='+f.tarjeta.value+
		'&numero='+f.numero.value+
		'&cadm='+f.cadm.value+
		'&cada='+f.cada.value+
		'&cvc='+f.cvc.value+
		'&news='+n+
		'&usuario='+f.usuario.value+
		'&password='+f.password.value);
    	}
}
//temporadas
function ver_temporadas()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_temporadas.php','');
}
function borra_temporada(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_temporadas.php','borra='+borra);}
}
function edita_temporada(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_temporadas.php','form='+edita);
}
function guarda_temporada(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');

	    envia('../ajax/cargar_temporadas.php',
		'guarda='+edita+
		'&fecha_ini='+f.fecha_ini.value+
		'&fecha_fin='+f.fecha_fin.value+
		'&temporada='+f.temporada.value);

}
//tarifas
function ver_tarifas()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_tarifas.php','');
}
function borra_tarifa(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_tarifas.php','borra='+borra);}
}
function edita_tarifa(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_tarifas.php','form='+edita);
}
function guarda_tarifa(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    var datos="";
	for (var i=0; i<document.getElementById("form1").elements.length; i++) {
		objeto = document.getElementById("form1").elements[i] ;
	    datos+="&"+objeto.id+"="+objeto.value.replace(/,/g,'.');
	} // for
    envia('../ajax/cargar_tarifas.php',
	'guarda='+edita+datos);

}

//promos.php
function ver_promos()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_promociones.php','');
}
function borra_promo(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_promociones.php','borra='+borra);}
}
function edita_promo(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_promociones.php','form='+edita);
}
function muestra_promo(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_promociones.php','muestra='+id);
}
function oculta_promo(id)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_promociones.php','oculta='+id);
}
function guarda_promo(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
	var cond;
	var conden;
	
	var inst,contents=new Array();
	for(inst in tinyMCE.editors){
	contents[contents.length]= tinyMCE.editors[inst].getContent();
	tinyMCE.editors
	}
	//elimino instancias
	var i, t = tinyMCE.editors;
	for (i in t){
		if (t.hasOwnProperty(i)){
			t[i].remove();
		}
	}
	tinyMCE.execCommand('mceRemoveControl', false, 'idOfElement');
	tinyMCE.execCommand('mceAddControl', false, 'idOfElement');
	//
	cond=contents[0];
	conden=contents[1];
    envia('../ajax/cargar_promociones.php',
	'guarda='+edita+
	'&nombre='+parsea(f.nombre.value)+
	'&nombreen='+parsea(f.nombreen.value)+
	'&tipo='+f.tipo.value+
	'&condiciones='+parsea(cond)+
	'&condicionesen='+parsea(conden)+
	'&parametro1='+f.parametro1.value+
	'&parametro2='+f.parametro2.value+
	'&parametro3='+f.parametro3.value
	);
}

function promotipo(tipo){
	if(tipo==1 || tipo==3 || tipo==9 || tipo==11 || tipo==13){
	document.getElementById("p1").innerHTML="Descuento:";
	document.getElementById("p2").innerHTML="Antelación mínima:";
	document.getElementById("p3").innerHTML="Estancia mínima:";
	document.getElementById("p1b").innerHTML="%";
	document.getElementById("p2b").innerHTML="días";
	document.getElementById("p3b").innerHTML="noches";
	document.getElementById("parametro1").type="text";
	document.getElementById("parametro2").type="text";
	document.getElementById("parametro3").type="text";
	}
	if(tipo==2 || tipo==4){
		document.getElementById("p1").innerHTML="&nbsp;";
		document.getElementById("p2").innerHTML="Antelación mínima:";
		document.getElementById("p3").innerHTML="&nbsp;";
		document.getElementById("p1b").innerHTML="&nbsp;";
		document.getElementById("p2b").innerHTML="días";
		document.getElementById("p3b").innerHTML="&nbsp;";
		document.getElementById("parametro1").type="hidden";
		document.getElementById("parametro2").type="text";
		document.getElementById("parametro3").type="hidden";
	}
	if(tipo==15){
		document.getElementById("p1").innerHTML="&nbsp;";
		document.getElementById("p2").innerHTML="Antelación mínima:";
		document.getElementById("p3").innerHTML="Estancia mínima:";
		document.getElementById("p1b").innerHTML="&nbsp;";
		document.getElementById("p2b").innerHTML="días";
		document.getElementById("p3b").innerHTML="noches";
		document.getElementById("parametro1").type="hidden";
		document.getElementById("parametro2").type="text";
		document.getElementById("parametro3").type="text";
	}

}

//fechas
function ver_fechas()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_fechas.php','');
}
function borra_fecha(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_fechas.php','borra='+borra);}
}
function cambia_fecha()
{
    if(!document.getElementById('visual').checked) alert("No está trabajando en este formulario.");
    else{
	f = document.getElementById('formf');
	if(confirm ('Si ha realizado cambios y no los ha guardado, éstos se perderán. ¿Continuar?')){
	    respuesta = document.getElementById('res');
	    envia('../ajax/cargar_fechas.php',
	    'fecha_ini='+f.fecha_ini.value+
	    '&fecha_fin='+f.fecha_fin.value);
	}
    }
}
function guarda_fechas(edita)
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    if(!document.getElementById('visual').checked) alert("No está trabajando en este formulario.");
    else{
	    var datos="";
		for (var i=0; i<document.getElementById("form1").elements.length; i++) {
			objeto = document.getElementById("form1").elements[i] ;
			if(objeto.value!='>') datos+="&"+objeto.id+"="+objeto.value;
		} // for
	    envia('../ajax/cargar_fechas.php',
		'guarda=1'+datos);
    }
}
function guarda_fechas2(edita)
{
	f = document.getElementById('form2');
    respuesta = document.getElementById('res');
    if(!document.getElementById('visual0').checked) alert("No está trabajando en este formulario.");
    else{
	    var datos="";
		for (var i=0; i<document.getElementById("form2").elements.length; i++) {
			objeto = document.getElementById("form2").elements[i] ;
			if(objeto.checked) datos+="&"+objeto.id+"=1";
			else datos+="&"+objeto.id+"="+objeto.value;
		} // for
		if(!(f.accion[0].checked || f.accion[1].checked || f.accion[2].checked || f.accion[3].checked))
			alert('No ha seleccionado acción a realizar.');
		else
			envia('../ajax/cargar_fechas.php','guarda=2'+datos);
    }
		
}
//Funciones dentro de fecha
function cerrar(fecha){
	var valor=document.getElementById('cerrado['+fecha+']').value;
	if(valor==1) {
		document.getElementById('c['+fecha+']').style.background="#99DD88";
		document.getElementById('cerrado['+fecha+']').value='0';
	} else {
		document.getElementById('c['+fecha+']').style.background="#FF6969";
		document.getElementById('cerrado['+fecha+']').value='1';
	}
}
var colort=new Array(); 
colort[1]= '#FF99CC';
colort[2]= '#FF9900';
colort[3]= '#00FF00';
colort[4]= '#FFFF00';
colort[5]= '#CC99FF';
colort[6]= '#CCFFFF';
colort[7]= '#969696';
colort[8]= '#3366FF';
colort[9]= '#CCFFCC';

colort[101]= '#FF99CC';
colort[102]= '#FF9900';
colort[103]= '#00FF00';
colort[104]= '#FFFF00';
colort[105]= '#CC99FF';
colort[106]= '#CCFFFF';
colort[107]= '#969696';
colort[108]= '#3366FF';
colort[109]= '#CCFFCC';
colort[110]= '#800080';
colort[111]= '#99CC00';
colort[112]= '#FF00FF';
colort[113]= '#0000FF';
colort[114]= '#008000';
colort[115]= '#99CCFF';

function colorearall(){
try{
	for (var i=0; i<document.getElementById("form1").elements.length; i++) {
		objeto = document.getElementById("form1").elements[i];
   	 if( objeto.id.lastIndexOf("tarifa[")>=0) {
		var objId=objeto.id.split("tarifa[");
		var fecha = objId[1].substr(0,objId[1].length-1);
		coloreart(fecha);
   	 	}
	}
	coloreart('all');
} catch(err){};
}

function coloreart(fecha){
	var valor=document.getElementById('tarifa['+fecha+']').value;
	document.getElementById('tarifatd['+fecha+']').style.background=colort[valor];
}

function avisaresall(){
	try{
		for (var i=0; i<document.getElementById("form1").elements.length; i++) {
			objeto = document.getElementById("form1").elements[i];
	   	 if( objeto.id.lastIndexOf("disponibilidad[")>=0) {
			var objId=objeto.id.split("disponibilidad[");
			var args = objId[1].substr(0,objId[1].length-1);
			var o=args.split("][");
			var fecha=o[0];
			var subid=o[1];
			avisares(fecha,subid);
	   	 	}
		}
	} catch(err){};
	}

function avisares(fecha,subid){
	var disp=0;
	var res=0;
	disp=document.getElementById('disponibilidad['+fecha+']['+subid+']').value;
	try{
		res=document.getElementById('reservadas['+fecha+']['+subid+']').value;
	} catch(err){};
	if(disp-res<2) try{
		document.getElementById('campo['+fecha+']['+subid+']').style.border="2px solid #ffd666";
		document.all.campo[fecha][subid].style.border = "2px solid #ffd666";
	} catch(err){};
	if(disp-res<1) try{
		document.getElementById('campo['+fecha+']['+subid+']').style.border="2px solid #FF6969";
		document.all.campo[fecha][subid].style.border = "2px solid #FF6969";
	} catch(err){};
	if(disp-res>1) try{
		document.getElementById('campo['+fecha+']['+subid+']').style.border="0px solid #FF6969";
		document.all.campo[fecha][subid].style.border = "0px solid #FF6969";
	} catch(err){};
}

function acero(id){
	var valor=document.getElementById(id).value;
	var parseado=parseInt(valor);
	if (parseado) document.getElementById(id).value=parseado;
	else document.getElementById(id).value=0;
}
function lanza(hab){
	if(document.getElementById('marca['+hab+']').value){
	for (var i=0; i<document.getElementById("form1").elements.length; i++) {
		objeto = document.getElementById("form1").elements[i];
		// Si activo supletoria aumento en uno los campos pers/estancia
	   	 if( objeto.id.lastIndexOf("disponibilidad[")>=0) {
			var objId=objeto.id.split("][");
			var id_hab = objId[1].substr(0,objId[1].length-1);
			if(hab==id_hab) 
				document.getElementById(objeto.id).value=document.getElementById('marca['+hab+']').value;
   	 	}
	}
	avisaresall();
	document.getElementById('marca['+hab+']').value="";
	alert('El cambio automático ha sido generado. Pulse guardar si desea confirmar los cambios.');
	}
}

function vefecha(id){

	var str = document.getElementById(id).value;
	var er = /(\d+)\/(\d+)\/(\d+)/;

	var a = str.replace(er,"$3");
	var m = str.replace(er,"$2")-1;
	var d = str.replace(er,"$1");
	
	var now = new Date();
	
	//lo necesito en MM/dd/aaaa
	
	var f = new Date( m+1 + "/" +  d + "/" + a );
	var h = new Date( parseInt(now.getMonth()+1) + "/" +  now.getDate() + "/" + now.getFullYear() );
	if(f<h){	document.getElementById(id).value= now.getDate() + "/" + parseInt(now.getMonth()+1) + "/" + now.getFullYear()
		alert("La fecha de inicio introducida ha pasado.");
	}
}

function cambiavisual(){
	if(document.getElementById('visual').checked){
		document.getElementById('dvisual').style.border='1px solid #275FAA';
		document.getElementById('dvisual').style.background='#FFFFCC';
		document.getElementById('dvisual0').style.border='1px solid #FFFFFF';
		document.getElementById('dvisual0').style.background='#FFFFFF';
	}
	if(document.getElementById('visual0').checked){
		document.getElementById('dvisual0').style.border='1px solid #275FAA';
		document.getElementById('dvisual0').style.background='#FFFFCC';
		document.getElementById('dvisual').style.border='1px solid #FFFFFF';
		document.getElementById('dvisual').style.background='#FFFFFF';
	}
}
//Fin funciones de fecha

//reservas
function ver_reservas()
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_reservas.php','');
}
function borra_reserva(borra)
{
	if(confirm ('¿Está seguro de borrar el registro?')){
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_reservas.php','borra='+borra);}
}
function muestra_reserva(edita)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_reservas.php','form='+edita);
}

// Vales
function ver_vale()
{
	f = document.getElementById('form1');
    respuesta = document.getElementById('res');
    
    envia('../ajax/cargar_vale.php',
    	    'numero='+f.numero.value+
    	    '&codigo='+f.codigo.value);
}
function guarda_vale()
{
	f = document.getElementById('form2');
    respuesta = document.getElementById('res');
    
    envia('../ajax/cargar_vale.php',
    	    'id='+f.id.value+
    	    '&nombre='+f.nombre.value+
    	    '&dni='+f.dni.value+
    	    '&fecha='+f.fecha.value
    	    );
}


//Estadisticas
function ver_visitas(fecha)
{
    respuesta = document.getElementById('res');
    envia('../ajax/cargar_visitas.php',
    		'fecha='+fecha);
}

// Informe reservas
function ver_informe(){
	location.href='informe.php?mes='+document.getElementById('ano').value+'-'+document.getElementById('mes').value;
}
