function cambiaFechaSalida()
{
	var d=document.form;
	var fechafin="";
	if (d.noches.options[d.noches.selectedIndex].value!="")
	{
	
	var fechaini=d.fechaini.value;
	fechaini=fechaini.substring(3,5)+"/"+fechaini.substring(0,2)+"/"+fechaini.substring(6,10);
	f1=new Date(fechaini);
	var dd=parseInt(d.noches.options[d.noches.selectedIndex].value);
	//var newDate   = f1.getDate();// + (d.noches.options[d.noches.selectedIndex].value*24*60*60*1000);
   	f1.setDate(f1.getDate() + dd);
	var dia=new String(f1.getDate());
	if (dia.length==1) dia="0"+dia;
	var mes=new String(f1.getMonth()+1);
	if (mes.length==1) mes="0"+mes;
	fechafin=dia+"/"+mes+"/"+f1.getFullYear();
	}
	d.fechafin.value=fechafin;
}

function cambiaNoches()
{
	if (document.form) {
		if (document.form.fechaini) {	//para las reservas de grupos y eventos
			var d=document.form;
			var fechaini=d.fechaini.value;
			fechaini=fechaini.substring(3,5)+"/"+fechaini.substring(0,2)+"/"+fechaini.substring(6,10);
			var fechafin=d.fechafin.value;
			fechafin=fechafin.substring(3,5)+"/"+fechafin.substring(0,2)+"/"+fechafin.substring(6,10);
			f1=new Date(fechaini);
			f2=new Date(fechafin);
			var noches=(f2.getTime()-f1.getTime())/24/60/60/1000;
			if (noches>15) {
				alert("Sólo se admite un máximo de 15 noches");
				d.fechafin.value="";
			}
			else if (noches<1) {
				alert("Asegúrese que la fecha de salida es posterior a la de entrada");
				d.fechafin.value="";
			}
			else d.noches.value=noches;
		}
	}
}

function envia(texto1,texto2,motivo,idioma,html) {

	hoy = new Date();
	mes= hoy.getMonth() + 1;
	if (mes<10)	mes = "0"+mes;
	fecha=hoy.getYear()+mes+hoy.getDate();
	aux=document.form.fechaini.value;
	fechainicial= new String(document.form.fechaini.value);
	fechainicial=fechainicial.substring(6,10)+fechainicial.substring(3,5)+fechainicial.substring(0,2);
	fecha=parseInt(fecha);
	fechainicial=parseInt(fechainicial);
	if (fechainicial < fecha) {
		alert("La fecha de entrada no puede ser anterior al día actual");
		document.form.fechaini.value=aux;
		document.form.fechafin.value="";
		
	}
	else {
	
		if (document.form.fechaini.value=="")	alert(texto1);
		else	{
			if (document.form.fechafin.value=="")	alert(texto2);
			else {
					if (html=="0")	NewWindowScroll("content/comun/reservas.php?fechaini="+document.form.fechaini.value+"&fechafin="+document.form.fechafin.value+"&noches="+document.form.noches.value+"&NHab="+document.form.nhab.value+"&motivo="+motivo+"&idioma="+idioma,520,700);
					else	NewWindowScroll("../content/comun/reservas.php?fechaini="+document.form.fechaini.value+"&fechafin="+document.form.fechafin.value+"&noches="+document.form.noches.value+"&NHab="+document.form.nhab.value+"&motivo="+motivo+"&idioma="+idioma,520,700);
			}
		}
	}
}

