// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function irA(elemID) {
  var offsetTrail = document.getElementById(elemID);
  var offsetLeft = 0;
  var offsetTop = 0;
  while (offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
  }
  if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined" && navigator.appName=="Microsoft Internet Explorer" ) {
    offsetLeft += parseInt(document.body.leftMargin);
    offsetTop += parseInt(document.body.topMargin);
  }
  window.scrollTo(offsetLeft,offsetTop)
}

function desplegar_reservar(idioma){
	//Mostramos la capa oculta
	document.getElementById("capa_reserva").style.display="block";
}
function mostrar_reserva_2(idioma,codigo){
	//Mostramos la capa oculta
	if(codigo){
	  document.getElementById("capa_reserva_2").style.display="block";
	  document.getElementById("botonReservar").style.display="none";
	  irA('anclaFormularioReserva');
	}
} 
function desplegar_reservarOLD(idioma)
{
	//Obtenemos los valores de los campos ocultos
	var clave_piso = document.getElementById('apa_id').value;
	var numero_ocupantes_base = document.getElementById('numero_ocupantes_base').value;
	var alquiler_diario_minimo = document.getElementById('alquiler_diario_minimo').value;
	var alquiler_diario_ocupante_adicional = document.getElementById('alquiler_diario_ocupante_adicional').value;
	var tarifa_limpieza = document.getElementById('tarifa_limpieza').value;
	var fianza = document.getElementById('fianza').value;
	var estancia_minima = document.getElementById('estancia_minima').value;
	var reserva_personas = document.getElementById('reserva_personas').value;
	var reserva_menores = document.getElementById('reserva_menores').value;
	
	var reserva_entrada_mes = document.getElementById('reserva_entrada_mes').value;
	var reserva_entrada_dia = document.getElementById('reserva_entrada_dia').value;
	reserva_entrada_dia = (reserva_entrada_dia.length==1)?'0'+reserva_entrada_dia:reserva_entrada_dia;
	var reserva_salida_mes = document.getElementById('reserva_salida_mes').value;
	var reserva_salida_dia = document.getElementById('reserva_salida_dia').value;
	reserva_salida_dia = (reserva_salida_dia.length==1)?'0'+reserva_salida_dia:reserva_salida_dia;
	//Descomponemos las fechas de entrada y salida mes en meses y anos
	var reserva_entrada_mes_suelto = reserva_entrada_mes.substr(5);
	reserva_entrada_mes_suelto = (reserva_entrada_mes_suelto.length==1)?'0'+reserva_entrada_mes_suelto:reserva_entrada_mes_suelto;
	var reserva_entrada_ano_suelto = reserva_entrada_mes.substr(0,4);
	var reserva_salida_mes_suelto = reserva_salida_mes.substr(5);
	reserva_salida_mes_suelto = (reserva_salida_mes_suelto.length==1)?'0'+reserva_salida_mes_suelto:reserva_salida_mes_suelto;
	var reserva_salida_ano_suelto = reserva_salida_mes.substr(0,4);
	
	//Vaciamos la capa
	var contenedor = document.getElementById('calculo_precio');
	while(contenedor.childNodes[0]){  
		contenedor.removeChild(contenedor.childNodes[0]);  
	}  
	
	//Generamos el html
	var noches = calcula_dias(reserva_entrada_dia,reserva_entrada_mes_suelto,reserva_entrada_ano_suelto,reserva_salida_dia,reserva_salida_mes_suelto,reserva_salida_ano_suelto,estancia_minima,idioma);
	if(noches==-1){
		return;
	}
	if(parseInt(reserva_menores!=0)){
		texto4+=" y "+reserva_menores+" menores de 4 aÃ±os";
	}
	//Calculamos el precio base
	var precio_base_diario=parseInt(alquiler_diario_minimo);
	if(parseInt(reserva_personas)-parseInt(numero_ocupantes_base)>0){
		precio_base_diario+=(parseInt(reserva_personas)-parseInt(numero_ocupantes_base))*parseInt(alquiler_diario_ocupante_adicional);
	}
	var total = (parseInt(precio_base_diario*noches) + parseInt(tarifa_limpieza));
	var reserva = Math.floor((parseInt(precio_base_diario*noches))*25/100);
	
	//Espanol
	if(idioma==1){
		var texto1 = " Entrada: "+reserva_entrada_dia+"/"+reserva_entrada_mes_suelto+"/"+reserva_entrada_ano_suelto;
		var texto2 = " Salida: "+reserva_salida_dia+"/"+reserva_salida_mes_suelto+"/"+reserva_salida_ano_suelto;
		var texto3 = " Noches: "+ noches;
		var texto4 = " Personas: "+reserva_personas+" Adultos";
		
		var texto5 = " Precio base: "+formatearEuros(precio_base_diario*noches)+String.fromCharCode(8364);
		var texto6 = " Tarifa limpieza: "+formatearEuros(tarifa_limpieza)+String.fromCharCode(8364);
		var texto7 = " Total: "+ formatearEuros(total)+String.fromCharCode(8364);
		var texto8 = " Reserva: "+ formatearEuros(reserva)+String.fromCharCode(8364);
		var texto9 = " Fianza: "+ formatearEuros(fianza)+String.fromCharCode(8364);
	
		var texto10 = " Total estancia: "+ formatearEuros(total)+String.fromCharCode(8364);
		var texto11 = " Reserva: "+ formatearEuros(reserva)+String.fromCharCode(8364);
		var texto12 = " A pagar en efectivo a la entrada: "+formatearEuros(total-reserva)+String.fromCharCode(8364)+" + "+formatearEuros(fianza)+String.fromCharCode(8364)+" Fianza";
	
		var texto13 = "ConfirmaciÃ³n y reserva";
		var texto14 = "Le enviaremos un e-mail confirmando la disponibilidad de la reserva e indicÃ¡ndole cÃ³mo proceder para pago del 25%";
		var texto15 = "del importe de la estancia, como seÃ±al para la reserva. El 75% restante y la fianza serÃ¡n entregados en efectivo";
		var texto16 = "a la entrada en el apartamento.";	

		var acepto = "He leÃ­do y acepto las ";
		var condiciones = "condiciones";	
		var reservar = "Reservar"
		var documento_condiciones = "condiciones_castellano.pdf"
	//Ingles
	}else if(idioma==2){
		var texto1 = " Arrival date: "+reserva_entrada_dia+"/"+reserva_entrada_mes_suelto+"/"+reserva_entrada_ano_suelto;
		var texto2 = " Departure date: "+reserva_salida_dia+"/"+reserva_salida_mes_suelto+"/"+reserva_salida_ano_suelto;
		var texto3 = " Nights: "+ noches;
		var texto4 = " People: "+reserva_personas+" Adults";
		
		var texto5 = " Basic price: "+formatearEuros(precio_base_diario*noches)+String.fromCharCode(8364);
		var texto6 = " Cleaning rate: "+formatearEuros(tarifa_limpieza)+String.fromCharCode(8364);
		var texto7 = " Total: "+ formatearEuros(total)+String.fromCharCode(8364);
		var texto8 = " Reservation: "+ formatearEuros(reserva)+String.fromCharCode(8364);
		var texto9 = " Caution money: "+ formatearEuros(fianza)+String.fromCharCode(8364);
	
		var texto10 = " Total stay: "+ formatearEuros(total)+String.fromCharCode(8364);
		var texto11 = " Reservation: "+ formatearEuros(reserva)+String.fromCharCode(8364);
		var texto12 = " To be paid in cash on arrival: "+formatearEuros(total-reserva)+String.fromCharCode(8364)+" + "+formatearEuros(fianza)+String.fromCharCode(8364)+" Caution money";
	
		var texto13 = "Confirmation and booking";
		var texto14 = "In short, we will send you an e-mail to confirm the availability.";
		var texto15 = "You will also be informed of how to proceed for the payment of the 25% to make the reservation.";
		var texto16 = "The remaining 75% and the caution money will be given in cash on arrival.";	

		var acepto = "I've read and I agree to the ";
		var condiciones = "terms and conditions";	
		var reservar = "Reserve"
		var documento_condiciones = "condiciones_ingles.pdf"
	}
	var condicionesespacio = " ";	
	
	flecha1 = document.createElement("img");
	flecha1.setAttribute("id","imagen_flecha");
	flecha1.setAttribute("src","images/flecha_gris.gif");
	flecha2 = document.createElement("img");
	flecha2.setAttribute("id","imagen_flecha");
	flecha2.setAttribute("src","images/flecha_gris.gif");
	flecha3 = document.createElement("img");
	flecha3.setAttribute("id","imagen_flecha");
	flecha3.setAttribute("src","images/flecha_gris.gif");
	flecha4 = document.createElement("img");
	flecha4.setAttribute("id","imagen_flecha");
	flecha4.setAttribute("src","images/flecha_gris.gif");
	flecha5 = document.createElement("img");
	flecha5.setAttribute("id","imagen_flecha");
	flecha5.setAttribute("src","images/flecha_gris.gif");
	flecha6 = document.createElement("img");
	flecha6.setAttribute("id","imagen_flecha");
	flecha6.setAttribute("src","images/flecha_gris.gif");
	flecha7 = document.createElement("img");
	flecha7.setAttribute("id","imagen_flecha");
	flecha7.setAttribute("src","images/flecha_gris.gif");
	flecha8 = document.createElement("img");
	flecha8.setAttribute("id","imagen_flecha");
	flecha8.setAttribute("src","images/flecha_gris.gif");
	flecha9 = document.createElement("img");
	flecha9.setAttribute("id","imagen_flecha");
	flecha9.setAttribute("src","images/flecha_gris.gif");
	flecha10 = document.createElement("img");
	flecha10.setAttribute("id","imagen_flecha");
	flecha10.setAttribute("src","images/flecha_gris.gif");
	flecha11 = document.createElement("img");
	flecha11.setAttribute("id","imagen_flecha");
	flecha11.setAttribute("src","images/flecha_gris.gif");
	flecha12 = document.createElement("img");
	flecha12.setAttribute("id","imagen_flecha");
	flecha12.setAttribute("src","images/flecha_gris.gif");
	
	span1 = document.createElement("span");
	span1.appendChild(document.createTextNode(texto1));
	span2 = document.createElement("span");
	span2.appendChild(document.createTextNode(texto2));
	span3 = document.createElement("span");
	span3.appendChild(document.createTextNode(texto3));
	span4 = document.createElement("span");
	span4.appendChild(document.createTextNode(texto4));
	span5 = document.createElement("span");
	span5.appendChild(document.createTextNode(texto5));
	span6 = document.createElement("span");
	span6.appendChild(document.createTextNode(texto6));
	span7 = document.createElement("span");
	span7.appendChild(document.createTextNode(texto7));
	span8 = document.createElement("span");
	span8.appendChild(document.createTextNode(texto8));
	span9 = document.createElement("span");
	span9.appendChild(document.createTextNode(texto9));
	span10 = document.createElement("span");
	span10.setAttribute("id","negrita");
	span10.appendChild(document.createTextNode(texto10));
	span11 = document.createElement("span");
	span11.setAttribute("id","negrita");
	span11.appendChild(document.createTextNode(texto11));
	span12 = document.createElement("span");
	span12.setAttribute("id","negrita");
	span12.appendChild(document.createTextNode(texto12));
	span13 = document.createElement("span");
	span13.setAttribute("id","negrita");
	span13.appendChild(document.createTextNode(texto13));
	
	reservaform = document.createElement("form");
	reservaform.setAttribute("id", "reservaform");
	reservaform.setAttribute("action", "realizar_reserva.php");
	reservaform.setAttribute("method", "post");
	reservaform.onsubmit = function(){return validarFormulario(idioma)};
	
	reservaform.appendChild(flecha1);
	reservaform.appendChild(span1);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha2);
	reservaform.appendChild(span2);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha3);
	reservaform.appendChild(span3);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha4);
	reservaform.appendChild(span4);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha5);
	reservaform.appendChild(span5);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha6);
	reservaform.appendChild(span6);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha7);
	reservaform.appendChild(span7);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha8);
	reservaform.appendChild(span8);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha9);
	reservaform.appendChild(span9);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha10);
	reservaform.appendChild(span10);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha11);
	reservaform.appendChild(span11);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(flecha12);
	reservaform.appendChild(span12);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createTextNode(acepto));
	
	//Link a las condiciones
	var condicioneslink = document.createElement('a');
	condicioneslink.setAttribute('href', 'apartamento_files/'+documento_condiciones);
	condicioneslink.setAttribute('target', '_blank');
	condicioneslink.style.textDecoration='underline';
	condicioneslink.setAttribute("id", "condiciones");
	condicioneslink.appendChild(document.createTextNode(condiciones));
	reservaform.appendChild(condicioneslink);
	reservaform.appendChild(document.createTextNode(condicionesespacio));	
		
	//Check condiciones
	var checkbox = document.createElement("input");
	checkbox.setAttribute("type", "checkbox");
	checkbox.setAttribute("name", "aceptacondiciones");
	checkbox.setAttribute("id", "aceptacondiciones");
	addEvent(checkbox,'click',function(){document.getElementById("submitcondiciones").disabled=(document.getElementById("submitcondiciones").disabled==true)?false:true;},false);
	reservaform.appendChild(checkbox);
	
	reservaform.appendChild(document.createElement("br"));
	//Submit
	var condicionessubmit = document.createElement("input");
	condicionessubmit.setAttribute('type', 'button');
	condicionessubmit.setAttribute('name', 'submitcondiciones');
	condicionessubmit.setAttribute('id', 'submitcondiciones');
	condicionessubmit.setAttribute('value', reservar);
	condicionessubmit.disabled=true;
	addEvent(condicionessubmit,'click',function(){mostrar_form_reserva(reserva_entrada_dia,reserva_entrada_mes_suelto,reserva_entrada_ano_suelto,reserva_salida_dia,reserva_salida_mes_suelto,reserva_salida_ano_suelto,idioma);},false);
	reservaform.appendChild(condicionessubmit);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(span13);
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createTextNode(texto14));
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createTextNode(texto15));
	reservaform.appendChild(document.createElement("br"));
	reservaform.appendChild(document.createTextNode(texto16));
	
	//Mostramos la capa oculta
	document.getElementById("calculo_precio").style.display="block";
	
	//Creamos el formulario de envio de datos adicionales para la reserva, que permanecerÃ¡ oculto hasta que se pulse el boton de "reservar"
	//Espanol
	if(idioma==1){
		var formulario0 = "* Campo obligatorio ";
		var formulario1 = "Nombre *  ";
		var formulario12 = "Apellidos *  ";
		var formulario2 = "DNI / Pasaporte *  ";
		var formulario3 = "DirecciÃ³n *  ";
		var formulario301 = "Ciudad *  ";
		var formulario31 = "CÃ³digo postal *  ";
		var formulario32 = "PaÃ­s *  ";
		var formulario4 = "E-mail *  ";
		var formulario5 = "TelÃ©fono *  ";
		var formulario6 = "Comentarios: (hora de entrada, cuna para bebes...)  ";
		var formulario7 = "Â¿CÃ³mo nos ha conocido?  ";
		var formularioaceptar = "Enviar";
	//Ingles
	}else if(idioma==2){
		var formulario0 = "* Required information ";
		var formulario1 = "Name *  ";
		var formulario12 = "Surname *  ";
		var formulario2 = "National Identity Card / Passport *  ";
		var formulario3 = "Address *  ";
		var formulario301 = "City *  ";
		var formulario31 = "P.O. Box *  ";
		var formulario32 = "Country *  ";
		var formulario4 = "E-mail *  ";
		var formulario5 = "Phone number *  ";
		var formulario6 = "Comments: (entry hour, baby cradle...)  ";
		var formulario7 = "How did you hear about us?  ";
		var formularioaceptar = "Send";
	}
	
	//Creamos el div que contendra el formulario
	var capaformulario = document.createElement("div");
	capaformulario.setAttribute("id", "capaformulario");
	
	//Creamos los campos
	var nombre = document.createElement("input");
	nombre.setAttribute('type', 'text');
	nombre.setAttribute('name', 'nombre');
	nombre.setAttribute('id', 'nombre');
	nombre.setAttribute('size', '32');
	nombre.setAttribute('maxlength', '32');
	var apellidos = document.createElement("input");
	apellidos.setAttribute('type', 'text');
	apellidos.setAttribute('name', 'apellidos');
	apellidos.setAttribute('id', 'apellidos');
	apellidos.setAttribute('size', '64');
	apellidos.setAttribute('maxlength', '64');
	var pasaporte = document.createElement("input");
	pasaporte.setAttribute('type', 'text');
	pasaporte.setAttribute('name', 'pasaporte');
	pasaporte.setAttribute('id', 'pasaporte');
	pasaporte.setAttribute('size', '14');
	pasaporte.setAttribute('maxlength', '14');
	var direccionPostal = document.createElement("input");
	direccionPostal.setAttribute('type', 'text');
	direccionPostal.setAttribute('name', 'direccionPostal');
	direccionPostal.setAttribute('id', 'direccionPostal');
	direccionPostal.setAttribute('size', '50');
	direccionPostal.setAttribute('maxlength', '128');
	var ciudadPais = document.createElement("input");
	ciudadPais.setAttribute('type', 'text');
	ciudadPais.setAttribute('name', 'ciudadPais');
	ciudadPais.setAttribute('id', 'ciudadPais');
	ciudadPais.setAttribute('size', '50');
	ciudadPais.setAttribute('maxlength', '128');
	var codigoPostal = document.createElement("input");
	codigoPostal.setAttribute('type', 'text');
	codigoPostal.setAttribute('name', 'codigoPostal');
	codigoPostal.setAttribute('id', 'codigoPostal');
	codigoPostal.setAttribute('size', '10');
	codigoPostal.setAttribute('maxlength', '10');
	var pais = document.createElement("input");
	pais.setAttribute('type', 'text');
	pais.setAttribute('name', 'pais');
	pais.setAttribute('id', 'pais');
	pais.setAttribute('size', '50');
	pais.setAttribute('maxlength', '64');
	var email = document.createElement("input");
	email.setAttribute('type', 'text');
	email.setAttribute('name', 'email');
	email.setAttribute('id', 'email');
	email.setAttribute('size', '50');
	email.setAttribute('maxlength', '64');
	var telefono = document.createElement("input");
	telefono.setAttribute('type', 'text');
	telefono.setAttribute('name', 'telefono');
	telefono.setAttribute('id', 'telefono');
	telefono.setAttribute('size', '20');
	telefono.setAttribute('maxlength', '20');
	var llegada = document.createElement("textarea");
	llegada.setAttribute('name', 'llegada');
	llegada.setAttribute('id', 'llegada');
	llegada.setAttribute('rows', '5');
	llegada.setAttribute('cols', '50');
	llegada.setAttribute('maxlength', '1024');
	var informacion = document.createElement("textarea");
	informacion.setAttribute('name', 'informacion');
	informacion.setAttribute('id', 'informacion');
	informacion.setAttribute('rows', '5');
	informacion.setAttribute('cols', '50');
	informacion.setAttribute('maxlength', '128');

	//Campos ocultos
	var entrada_oculto = document.createElement("input");
	entrada_oculto.setAttribute('type', 'hidden');
	entrada_oculto.setAttribute('name', 'entrada');
	entrada_oculto.setAttribute('value', reserva_entrada_ano_suelto+reserva_entrada_mes_suelto+reserva_entrada_dia);
	var salida_oculto = document.createElement("input");
	salida_oculto.setAttribute('type', 'hidden');
	salida_oculto.setAttribute('name', 'salida');
	salida_oculto.setAttribute('value', reserva_salida_ano_suelto+reserva_salida_mes_suelto+reserva_salida_dia);
	var personas_oculto = document.createElement("input");
	personas_oculto.setAttribute('type', 'hidden');
	personas_oculto.setAttribute('name', 'personas');
	personas_oculto.setAttribute('value', reserva_personas);
	var menores_oculto = document.createElement("input");
	menores_oculto.setAttribute('type', 'hidden');
	menores_oculto.setAttribute('name', 'menores');
	menores_oculto.setAttribute('value', reserva_menores);
	var reserva_oculto = document.createElement("input");
	reserva_oculto.setAttribute('type', 'hidden');
	reserva_oculto.setAttribute('name', 'reserva');
	reserva_oculto.setAttribute('value', reserva);
	var total_estancia_oculto = document.createElement("input");
	total_estancia_oculto.setAttribute('type', 'hidden');
	total_estancia_oculto.setAttribute('name', 'total_estancia');
	total_estancia_oculto.setAttribute('value', total);
	var fianza_oculto = document.createElement("input");
	fianza_oculto.setAttribute('type', 'hidden');
	fianza_oculto.setAttribute('name', 'fianza');
	fianza_oculto.setAttribute('value', fianza);
	var clave_piso_oculto = document.createElement("input");
	clave_piso_oculto.setAttribute('type', 'hidden');
	clave_piso_oculto.setAttribute('name', 'clave_piso');
	clave_piso_oculto.setAttribute('value', clave_piso);
	
	//Anadimos los campos a la capa
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario0));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario1));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(nombre);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario12));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(apellidos);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario2));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(pasaporte);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario3));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(direccionPostal);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario301));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(ciudadPais);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario31));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(codigoPostal);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario32));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(pais);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario4));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(email);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario5));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(telefono);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario6));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(llegada);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createTextNode(formulario7));
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(informacion);
	capaformulario.appendChild(document.createElement("br"));
	capaformulario.appendChild(document.createElement("br"));
	
	//Anadimos campos ocultos
	capaformulario.appendChild(entrada_oculto);
	capaformulario.appendChild(salida_oculto);
	capaformulario.appendChild(personas_oculto);
	capaformulario.appendChild(menores_oculto);
	capaformulario.appendChild(reserva_oculto);
	capaformulario.appendChild(total_estancia_oculto);
	capaformulario.appendChild(fianza_oculto);
	capaformulario.appendChild(clave_piso_oculto);
	
	//Boton de envio final para la reserva
	var reservafinalsubmit = document.createElement("input");
	reservafinalsubmit.setAttribute('type', 'submit');
	reservafinalsubmit.setAttribute('id', 'reservafinalsubmit');
	reservafinalsubmit.setAttribute('value', formularioaceptar);
	capaformulario.appendChild(reservafinalsubmit);
	
	//Anadimos el div al formulario
	reservaform.appendChild(capaformulario);

	contenedor.appendChild(reservaform);
}

function avisarSexo(sexo){
	//Mostramos alerta
	if(sexo=='0'){
	  document.getElementById('sexo1').checked=true;
	  alert('El piso que ha seleccionado est\u00e1 destinado a hombres. Por favor, elija uno de mujeres');
	}else{
	  document.getElementById('sexo2').checked=true;
	  alert('El piso que ha seleccionado est\u00e1 destinado a mujeres. Por favor, elija uno de hombres');
	}
}

//Validamos el formulario con los datos del cliente
function validarFormularioContacto() {
	document.getElementById("boton_envio").disabled = true;
	
	idioma=1;
	var alertaNombre = "";
	var alertaApellidos = "";
	var alertaDni = "";
	var alertaDireccion = "";
	var alertaCiudad = "";
	var alertaCodigoPostal = "";
	var alertaPais = "";
	var alertaEmail = "";
	var alertaEmailIncorrecto = "";
	var alertaTelefono = "";
	if (idioma==1) {
		alertaNombre = "El campo nombre es obligatorio";
		alertaApellidos = "El campo apellidos es obligatorio";
		alertaDni = "El campo dni/pasaporte es obligatorio";
		alertaDireccion = "El campo direccion es obligatorio";
		alertaCiudad = "El campo ciudad es obligatorio";
		alertaCodigoPostal = "El campo codigo postal es obligatorio y debe ser numerico";
		alertaPais = "El campo pais es obligatorio";
		alertaEmail = "El campo email es obligatorio";
		alertaEmailIncorrecto = "La direcci¨®n de email no es v¨¢lida";
		alertaTelefono = "El campo telefono es obligatorio";
	}else{
		alertaNombre = "You are required to complete the 'Name' field";
		alertaEmail = "You are required to complete the 'Email' field";
		alertaEmailIncorrecto = "Provide a correct email address";
		alertaComentario = "You are required to complete the 'Comments' field";	
	}
	//valido el nombre
	var campoNombre = document.getElementById("nombre");
    if (campoNombre.value.length==0){
       alert(alertaNombre);
       campoNombre.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido apellidos
	var campoApellidos = document.getElementById("apellidos");
    if (campoApellidos.value.length==0){
       alert(alertaApellidos);
       campoApellidos.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido el dni
	var campoDni = document.getElementById("dni");
    if (campoDni.value.length==0){
       alert(alertaDni);
       campoDni.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido la direccion
	var campoDireccion = document.getElementById("direccion");
    if (campoDireccion.value.length==0){
       alert(alertaDireccion);
       campoDireccion.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido la ciudad
	var campoCiudad = document.getElementById("ciudad");
    if (campoCiudad.value.length==0){
       alert(alertaCiudad);
       campoCiudad.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido el codigo postal
	var campoCodigoPostal = document.getElementById("codigo_postal");
    if (campoCodigoPostal.value.length==0 || isNaN(campoCodigoPostal.value)){
       alert(alertaCodigoPostal);
       campoCodigoPostal.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido el pais
	var campoPais = document.getElementById("pais");
    if (campoPais.value.length==0){
       alert(alertaPais);
       campoPais.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	//valido el email
	var campoEmail = document.getElementById("email");
    var formato  = /^([\w-\.])+@([\w-]+\.)+([a-z]){2,4}$/;
    if (campoEmail.value.length==0){
       alert(alertaEmail);
       campoEmail.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    }else if (!(formato.test(campoEmail.value))){
	    alert (alertaEmailIncorrecto);    
	    document.getElementById("boton_envio").disabled = false;
    	return false;
	}    
	//valido el telefono
	var campoTelefono = document.getElementById("telefono");
    if (campoTelefono.value.length==0){
       alert(alertaTelefono);
       campoTelefono.focus();
       document.getElementById("boton_envio").disabled = false;
       return false;
    } 
	return true;
}

//Validamos el formulario con los datos del cliente
function validarFormularioLocalizador() {
	idioma=1;
	var alertaNombre = "";
	var alertaApellidos = "";
	var alertaEmail = "";
	var alertaEmailIncorrecto = "";
	if (idioma==1) {
		alertaNombre = "El campo nombre es obligatorio";
		alertaApellidos = "El campo apellidos es obligatorio";
		alertaEmail = "El campo email es obligatorio";
		alertaEmailIncorrecto = "La direcci¨®n de email no es v¨¢lida";
	}else{
		alertaNombre = "You are required to complete the 'Name' field";
		alertaEmail = "You are required to complete the 'Email' field";
		alertaEmailIncorrecto = "Provide a correct email address";
		alertaComentario = "You are required to complete the 'Comments' field";	
	}
	//valido el nombre
	var campoNombre = document.getElementById("nombre");
    if (campoNombre.value.length==0){
       alert(alertaNombre);
       campoNombre.focus();
       return false;
    } 
	//valido apellidos
	var campoApellidos = document.getElementById("apellidos");
    if (campoApellidos.value.length==0){
       alert(alertaApellidos);
       campoApellidos.focus();
       return false;
    } 
	//valido el email
	var campoEmail = document.getElementById("email");
    var formato  = /^([\w-\.])+@([\w-]+\.)+([a-z]){2,4}$/;
    if (campoEmail.value.length==0){
       alert(alertaEmail);
       campoEmail.focus();
       return false;
    }else if (!(formato.test(campoEmail.value))){
	    alert (alertaEmailIncorrecto);    
    	return false;
	}    
	return true;
}

