// JavaScript Document


function selectTipo(tipoescapada){
	//pedir los destinos del tipo de escapada seleccionado
 // lanza_request('http://viajes.viajamus.com/hoteles/webservice/DestinosEscapadasRQ.php?tipo='+tipoescapada+'&alb='+Math.random(),'recibir_destinos_escapadas','text/html');

call2 = new ajaxObject('./webservice/DestinosEscapadasRQ.php');
call2.load('bus_sel_destinos',{tipo: tipoescapada},'GET');
call3 = new ajaxObject('./webservice/DestinosEscapadasRQ.php');
call3.load('bus_sel_zonas',{tipo: tipoescapada,zonas: '1'},'GET');

}


function selectDestino(destinoescapada){
//pide las zonas del destino seleccionado
  tipoescapada = document.getElementById('selTip').value;
  if(document.getElementById('destino_seleccionado')){
   document.getElementById('destino_seleccionado').value = destinoescapada;
   document.getElementById('zona_seleccionada').value = '';
  }
//  lanza_request('http://viajes.viajamus.com/hoteles/webservice/DestinosEscapadasRQ.php?tipo='+tipoescapada+'&destino='+destinoescapada+'&zonas=1&alb='+Math.random(),'recibir_zonas_escapadas','text/html');
  call1 = new ajaxObject('./webservice/DestinosEscapadasRQ.php');
  call1.load('bus_sel_zonas',{tipo: tipoescapada, destino: destinoescapada,zonas: '1'},'GET');
}

function selectZona(zonaescapada){
  if(document.getElementById('zona_seleccionada')){
	  document.getElementById('zona_seleccionada').value = zonaescapada;
  }
}
function destinos_tiposescapadas(){
	
call1 = new ajaxObject('./webservice/DestinosEscapadasRQ2.php');
call1.load('destinos_roman',{tipo: 'ROMAN'},'GET');
call2 = new ajaxObject('./webservice/DestinosEscapadasRQ2.php');
call2.load('destinos_relax',{tipo: 'WELLN'},'GET');
call3 = new ajaxObject('./webservice/DestinosEscapadasRQ2.php');
call3.load('destinos_fami',{tipo: 'OCIO'},'GET');
}



function verhabitaciones(numero,buscador){
	    numero = parseInt(numero,10);
		var hab = "";
		
		for(i=1;i<=numero;i++){
		  hab += '<div style="float:left;margin-top:0px"><strong>Habi. '+i+'</strong></div>'
		  hab += '<div style="display:inline; margin-left:6px ; float:left; ">';
		  hab += '<div><strong>Adultos</div>';
		  hab += '<div style="clear:both"></div>';
		  hab += '<div style="float:left; margin-right:10px">';
		  hab += '<select id="numadu_'+i+'" name="numadu_'+i+'" class="datos"  style="width: 38px;">';
		  hab += '<option value="1">1</option>';
		  hab += '<option value="2" selected="">2</option>';
		  hab += '<option value="3">3</option>';
		  hab += '<option value="4">4</option>';
		  hab += '</select>';
		  hab += '</div>';
		  hab += '</div>';
		  hab += '<div style="float:left">';
		  hab += '<div><strong>Ni&ntilde;os</div>';
		  hab += '<div style="float:left">';
		  hab += '<select id="numnin_'+i+'" name="numnin_'+i+'" class="datos"  style="width: 38px;" onchange="mostrarSelNin(\''+i+'\',this.value);">';
		  hab += '<option value="0" selected="">0</option>';
		  hab += '<option value="1">1</option>';
		  hab += '<option value="2">2</option>';
		  hab += '</select>';
		  hab += '</div>';
		  hab += '</div>';
		 // hab += '<div style="clear:both"></div>';
		  hab += '<div id="edanin'+i+'" style="float:left">';
		  hab += '<div id="txteda'+i+'"  style="display: none; margin-left: 6px;margin-top:0px">';
		  hab += '<div style="width: 70px; float: left;display:inline; margin-left:0px ">';
		  hab += '<div>Edad ni&ntilde;o</div>';
		  
		  hab += '<div style="float: left;">';
		  hab += '<div style="width: 76px;">';
		  
		  hab += '<div id="edad_'+i+'0" style="display: none; float: left;">';
		  hab += '<select id="seled_'+i+'0" name="seled_'+i+'0" class="datos"  style="width: 38px;">';
		  hab += '<option value="2" selected="">2</option>';
		  hab += '<option value="3">3</option>';
		  hab += '<option value="4">4</option>';
		  hab += '<option value="5">5</option>';
		  hab += '<option value="6">6</option>';
		  hab += '<option value="7">7</option>';
		  hab += '<option value="8">8</option>';
		  hab += '<option value="9">9</option>';
		  hab += '<option value="10">10</option>';
		  hab += '<option value="11">11</option>';
		  hab += '</select>';
		  hab += '</div>';
		  
		  hab += '<div id="edad_'+i+'1" style="display: none; float: left;">';
		  hab += '<select id="seled_'+i+'1" name="seled_'+i+'1" class="datos"  style="width: 38px;">';
		  hab += '<option value="2" selected="">2</option>';
    	  hab += '<option value="3">3</option>';
		  hab += '<option value="4">4</option>';
		  hab += '<option value="5">5</option>';
		  hab += '<option value="6">6</option>';
		  hab += '<option value="7">7</option>';
		  hab += '<option value="8">8</option>';
		  hab += '<option value="9">9</option>';
		  hab += '<option value="10">10</option>';
		  hab += '<option value="11">11</option>';
		  hab += '</select>';
		  hab += '</div>';
		  
		  hab += '</div>';
		  hab += '</div>';
		   hab += '</div>';
		  
		  hab += '</div>';
		  
		 hab += '</div>';
		 hab += '<div style="clear:both;"></div>';
		}
	
		document.getElementById('content-hab-'+buscador).innerHTML = hab;
	 }
function mostrarSelNin(id,numero){
		 numero = parseInt(numero,10);
		 objeto1 = 'edanin'+id;
		 objeto2 = 'txteda'+id;
		 objeto3 = 'edad_'+id;
		 if(numero==0){
		  document.getElementById(objeto1).style.display= 'none';
		  document.getElementById(objeto2).style.display= 'none';
		  for(i=0;i<numero;i++){
		     aux = objeto3 + i;
			 document.getElementById(aux).style.display= 'none';
		  }
		 }else{
			 document.getElementById(objeto1).style.display= 'block';
		     document.getElementById(objeto2).style.display= 'block';
			 for(i=0;i<numero;i++){
		     	aux = objeto3 + i;
			 	document.getElementById(aux).style.display= 'block';
		     } 
			 if(numero < 2){
				aux = objeto3 + "1";
				
			   if(document.getElementById(aux).style.display = 'block'){
			     document.getElementById(aux).style.display = 'none';
			   }
			 }
		 }
	 }

function mostrarSelNinF(id,numero){
		 numero = parseInt(numero,10);
		 objeto1 = 'edanin'+id+'F';
		 objeto2 = 'txteda'+id+'F';
		 objeto3 = 'edad_'+id+'F';
		 if(numero==0){
		  document.getElementById(objeto1).style.display= 'none';
		  document.getElementById(objeto2).style.display= 'none';
		  for(i=0;i<numero;i++){
		     aux = objeto3 + i+'F';
			 document.getElementById(aux).style.display= 'none';
		  }
		 }else{
			 document.getElementById(objeto1).style.display= 'block';
		     document.getElementById(objeto2).style.display= 'block';
			 for(i=0;i<numero;i++){
		     	aux = objeto3 + i+'F';
			 	document.getElementById(aux).style.display= 'block';
		     } 
			 if(numero < 2){
				aux = objeto3 + "1"+"F";
				
			   if(document.getElementById(aux).style.display = 'block'){
			     document.getElementById(aux).style.display = 'none';
			   }
			 }
		 }
	 }
function verhabitaciones2(numero,buscador){
	    numero = parseInt(numero,10);
		var hab = "";
		for(i=1;i<=numero;i++){
		  hab += '<div style="float:left; margin-right:30px"><strong>Habitaci&oacute;n '+i+'</strong></div>'
		  hab += '<div style="display:inline; margin-left:6px ; float:left; ">Adultos</div>';
		  hab += '<div style="float:left; margin-right:10px">';
		  hab += '<select id="numadu_'+i+'F" name="numadu_'+i+'F" class="datos"  style="width: 38px;">';
		  hab += '<option value="1">1</option>';
		  hab += '<option value="2" selected="">2</option>';
		  hab += '<option value="3">3</option>';
		  hab += '<option value="4">4</option>';
		  hab += '</select>';
		  hab += '</div>';
		  hab += '<div style="float:left">Ni&ntilde;os</div>';
		  hab += '<div style="float:left">';
		  hab += '<select id="numnin_'+i+'F" name="numnin_'+i+'F" class="datos"  style="width: 38px;" onchange="mostrarSelNinF(\''+i+'\',this.value);">';
		  hab += '<option value="0" selected="">0</option>';
		  hab += '<option value="1">1</option>';
		  hab += '<option value="2">2</option>';
		  hab += '</select>';
		  hab += '</div>';
		  hab += '<div style="clear:both"></div>';
		  hab += '<div id="edanin'+i+'F" style="">';
		  hab += '<div id="txteda'+i+'F"  style="display: none; margin-left: 6px;margin-top:3px">';
		  hab += '<div style="width: 70px; float: left;display:inline; margin-left:0px ">Edad ni&ntilde;o</div>';
		  hab += '<div style="float: left;">';
		  hab += '<div style="width: 76px;">';
		  hab += '<div id="edad_'+i+'0F" style="display: none; float: left;">';
		  hab += '<select id="seled_'+i+'0F" name="seled_'+i+'0F" class="datos"  style="width: 38px;">';
		  hab += '<option value="2" selected="">2</option>';
		  hab += '<option value="3">3</option>';
		  hab += '<option value="4">4</option>';
		  hab += '<option value="5">5</option>';
		  hab += '<option value="6">6</option>';
		  hab += '<option value="7">7</option>';
		  hab += '<option value="8">8</option>';
		  hab += '<option value="9">9</option>';
		  hab += '<option value="10">10</option>';
		  hab += '<option value="11">11</option>';
		  hab += '</select>';
		  hab += '</div>';
		  hab += '<div id="edad_'+i+'1F" style="display: none; float: left;">';
		  hab += '<select id="seled_'+i+'1F" name="seled_'+i+'1F" class="datos"  style="width: 38px;">';
		  hab += '<option value="2" selected="">2</option>';
    	  hab += '<option value="3">3</option>';
		  hab += '<option value="4">4</option>';
		  hab += '<option value="5">5</option>';
		  hab += '<option value="6">6</option>';
		  hab += '<option value="7">7</option>';
		  hab += '<option value="8">8</option>';
		  hab += '<option value="9">9</option>';
		  hab += '<option value="10">10</option>';
		  hab += '<option value="11">11</option>';
		  hab += '</select>';
		  hab += '</div>';
		  hab += '</div>';
		  hab += '</div>';
		  hab += '</div>';
		  
		 hab += '</div>';
		 hab += '<div style="clear:both;"></div>';
		}
		document.getElementById('content-hab-F'+buscador).innerHTML = hab;
	 }
function marcardesmarcar(nombre,ntipos,chequeado,indice){
	ntipos = parseInt(ntipos,10);
	aux = "";
	for(i=0;i<ntipos;i++){
	  obj = nombre + "_" + i;
	  if(document.getElementById(obj).checked == true){
	    valor = document.getElementById(obj).value;  
		aux +=  valor + "|";
	  }
	}
   if(aux != ''){
     aux = aux.substr(0,aux.length -1);
   }
   switch(nombre){
	 case 'cat':
	   document.getElementById('categoria').value = aux;
	 break;
	 case 'reg':
	   document.getElementById('regimen').value = aux;
	 break;
	 case 'serv':
	   document.getElementById('servicio').value = aux;
	 break;
	 case 'des':
	   document.getElementById('destino').value = aux;
	 break;
	 case 'tipo':
	   document.getElementById('tipo').value = aux;
	 break;
   }
}

function validar_busqueda(formulario){
 error = "";
   
   
   var codigo_destino = formulario.destino_seleccionado.value;
   var codigo_zona = formulario.zona_seleccionada.value;
   var fecini = formulario.fecini.value;
   var fecfin = formulario.fecfin.value;
   
   
   if(codigo_destino == "" && codigo_zona == ""){
	 error = "Debe seleccionar una costa o un destino de costa \n";
   }
   var aux_fecini = fecini.split("/");
   var dia_ent = parseInt(aux_fecini[0],10);
   var mes_ent = parseInt(aux_fecini[1],10);
   var anio_ent = parseInt(aux_fecini[2],10);

   var hoy = new Date();
   var diaHoy = hoy.getDate()+1;
   var mesHoy = hoy.getMonth()+1;
   var anioHoy = hoy.getYear();

	if(fecini == ""){
		error += "Indique la fecha de entrada.\n";
	}else{
	   if(mes_ent == mesHoy && anio_ent == anioHoy){
		   if(dia_ent < diaHoy ){
			  error+= "Fecha de entrada no v\u00E1lida \n";
		   } 
	   }
	}

	var aux_fecfin = fecfin.split("/");
	var dia_reg = parseInt(aux_fecfin[0],10);
	var mes_reg = parseInt(aux_fecfin[1],10);
	var anio_reg = parseInt(aux_fecfin[2],10);

	if(fecfin == ""){
	   error += "Indique la fecha de salida.\n";
	}else{
		if(mes_reg == mesHoy && anio_reg == anioHoy){
			 if(dia_reg < diaHoy || dia_reg == diaHoy){
			  error += "Fecha de salida no v\u00E1lida \n" ;
			 }  
		}
	}
	if(anio_ent > anio_reg){
		error += "Fechas no v\u00E1lidas.\n";
	}else{
		if(anio_ent == anio_reg){
		  if(mes_ent > mes_reg){
			  error += "Fechas no v\u00E1lidas.\n";
		  }else{
			if(mes_ent == mes_reg){
			  if(dia_ent > dia_reg){
				error += "Fechas no v\u00E1lidas.\n";  
			  }else{
				if(dia_reg <= dia_ent || dia_reg < (dia_ent + 1)){
					error += "No se permiten reservas para menos de una noche.\n"; 
				}
			  }
			}
		  }
		}
	}

   if(error != ''){
	 alert(error);
   }else{
	 formulario.submit();
   }
		 
}

function validar_busqueda_ficha2(formulario){
 error = "";
   
   
   var codigo_destino = formulario.destino_seleccionadoF.value;
   var codigo_zona = formulario.zona_seleccionadaF.value;
   var fecini = formulario.feciniF.value;
   var fecfin = formulario.fecfinF.value;
   
   
   if(codigo_destino == "" && codigo_zona == ""){
	 error = "Debe seleccionar una costa o un destino de costa \n";
   }
   var aux_fecini = fecini.split("/");
   var dia_ent = parseInt(aux_fecini[0],10);
   var mes_ent = parseInt(aux_fecini[1],10);
   var anio_ent = parseInt(aux_fecini[2],10);

   var hoy = new Date();
   var diaHoy = hoy.getDate()+1;
   var mesHoy = hoy.getMonth()+1;
   var anioHoy = hoy.getYear();

	if(fecini == ""){
		error += "Indique la fecha de entrada.\n";
	}else{
	   if(mes_ent == mesHoy && anio_ent == anioHoy){
		   if(dia_ent < diaHoy ){
			  error+= "Fecha de entrada no v\u00E1lida \n";
		   } 
	   }
	}

	var aux_fecfin = fecfin.split("/");
	var dia_reg = parseInt(aux_fecfin[0],10);
	var mes_reg = parseInt(aux_fecfin[1],10);
	var anio_reg = parseInt(aux_fecfin[2],10);

	if(fecfin == ""){
	   error += "Indique la fecha de salida.\n";
	}else{
		if(mes_reg == mesHoy && anio_reg == anioHoy){
			 if(dia_reg < diaHoy || dia_reg == diaHoy){
			  error += "Fecha de salida no v\u00E1lida \n" ;
			 }  
		}
	}
	if(anio_ent > anio_reg){
		error += "Fechas no v\u00E1lidas.\n";
	}else{
		if(anio_ent == anio_reg){
		  if(mes_ent > mes_reg){
			  error += "Fechas no v\u00E1lidas.\n";
		  }else{
			if(mes_ent == mes_reg){
			  if(dia_ent > dia_reg){
				error += "Fechas no v\u00E1lidas.\n";  
			  }else{
				if(dia_reg <= dia_ent || dia_reg < (dia_ent + 1)){
					error += "No se permiten reservas para menos de una noche.\n"; 
				}
			  }
			}
		  }
		}
	}

   if(error != ''){
	 alert(error);
   }else{
	 formulario.submit();
   }
		 
}

function validar_busqueda_ficha(formulario){
 error = "";
 
   conten = document.getElementById('disponibilidad_habitaciones').innerHTML;
   if(conten != ''){
	  
	 $("#disponibilidad_habitaciones").hide("slow"); 
   }else{
     $("#disponibilidad_habitaciones").hide();
   }
   document.getElementById('cargando').style.display = 'none';
   
   var codigo = formulario.destino_seleccionadoF.value;
   var fecini = formulario.feciniF.value;
   var fecfin = formulario.fecfinF.value;
   
   
   if(codigo == ""){
	 error = "Debe seleccionar una comunidad aut\u00F3noma o una provincia \n";
   }
   var aux_fecini = fecini.split("/");
   var dia_ent = parseInt(aux_fecini[0],10);
   var mes_ent = parseInt(aux_fecini[1],10);
   var anio_ent = parseInt(aux_fecini[2],10);

   var hoy = new Date();
   var diaHoy = hoy.getDate()+1;
   var mesHoy = hoy.getMonth()+1;
   var anioHoy = hoy.getYear();

	if(fecini == ""){
		error += "Indique la fecha de entrada.\n";
	}else{
	   if(mes_ent == mesHoy && anio_ent == anioHoy){
		   if(dia_ent < diaHoy ){
			  error+= "Fecha de entrada no v\u00E1lida \n";
		   } 
	   }
	}

	var aux_fecfin = fecfin.split("/");
	var dia_reg = parseInt(aux_fecfin[0],10);
	var mes_reg = parseInt(aux_fecfin[1],10);
	var anio_reg = parseInt(aux_fecfin[2],10);

	if(fecfin == ""){
	   error += "Indique la fecha de salida.\n";
	}else{
		if(mes_reg == mesHoy && anio_reg == anioHoy){
			 if(dia_reg < diaHoy || dia_reg == diaHoy){
			  error += "Fecha de salida no v\u00E1lida \n" ;
			 }  
		}
	}
	if(anio_ent > anio_reg){
		error += "Fechas no v\u00E1lidas.\n";
	}else{
		if(anio_ent == anio_reg){
		  if(mes_ent > mes_reg){
			  error += "Fechas no v\u00E1lidas.\n";
		  }else{
			if(mes_ent == mes_reg){
			  if(dia_ent > dia_reg){
				error += "Fechas no v\u00E1lidas.\n";  
			  }else{
				if(dia_reg <= dia_ent || dia_reg < (dia_ent + 1)){
					error += "No se permiten reservas para menos de una noche.\n"; 
				}
			  }
			}
		  }
		}
	}

   if(error != ''){
	 alert(error);
   }else{
	 //llamada a guardar datos
	    document.getElementById('disponibilidad_habitaciones').innerHTML = '';
	    document.getElementById('cargando').style.display = 'block'; 
	 
        
		
	    cal1 = new ajaxObject('./guardarbusqueda.php');
		cal1.onComplete = function (response){
			if(response != 'OK'){
			 //tratar error guardando busqueda
			   document.getElementById('cargando').style.display = 'none';
			 cadenaerror = '<div style="float:right;margin-right:26px;padding-bottom:10px" ><div style="float:left; margin-right:10px"><img src="img/warning.png" width="32px" height="32px"></div><div style="float:left;margin-top:14px"><span class="titulo_producto" style="font-size:1.2em;color:#ff0000">Lo sentinos no hay disponibilidad en estos momentos.</span></div><div style="clear: both;"></div></div>';  
			 
			 
			 var msg = mensajedispo(document.getElementById('tipo_seleccionado').value,document.getElementById('destino_seleccionado').value,document.getElementById('zona_seleccionada').value,document.getElementById('nombre_tipo_seleccionado').value,document.getElementById('nombre_destino_seleccionado').value,document.getElementById('nombre_zona_seleccionada').value,'buscadorcdF');
			
			 cadenaerror+= msg; 
			 document.getElementById('error_dispo').innerHTML = cadenaerror; 
			 
			 $("#error_dispo").show("slow");
			    
			}else{
			 buscardisponibilidad(); 	
			 
			}
		};
		
		valor_numhab = document.getElementById('numhabF').value;
		valor_buscador = document.getElementById('buscador').value;
		
		auxfecini = document.getElementById('feciniF').value.split("/");
        auxfecfin = document.getElementById('fecfinF').value.split("/");
        valor_fecini = auxfecini[2]+auxfecini[1]+auxfecini[0];
        valor_fecfin = auxfecfin[2]+auxfecfin[1]+auxfecfin[0];
		
		document.getElementById('f_entrada').innerHTML = document.getElementById('feciniF').value;
		document.getElementById('f_salida').innerHTML = document.getElementById('fecfinF').value;
		document.getElementById('n_habitaciones').innerHTML = valor_numhab;
		
		cadena_habi1 = "";
		cadena_habi2 = "";
		cadena_habi3 = "";

		habi1 = "";
		habi2 = "";
		habi3 = "";
		cadena_hab_sel ="";
		for(i=1;i<=valor_numhab;i++){	
   
		   switch(i){
			 case 1:
			    obj_adult = 'numadu_'+i+'F';
				obj_nin = 'numnin_'+i+'F';
				habi1 = document.getElementById(obj_adult).value+";"+document.getElementById(obj_nin).value;
				 ninos = parseInt(document.getElementById(obj_nin).value,10);
				 edades = "";
				 bebes = 0;
				 cadena_habi1 = document.getElementById(obj_adult).value+' adultos';
				 if(ninos> 0){
				  cadena_habi1 += ', '+ninos+' ni&ntilde;os (';
				 }
				 cad_edad_nin = "";
				 for(j=0;j<ninos;j++){
				  obj_sel = 'seled_'+i+j+'F';
				  cad_edad_nin += document.getElementById(obj_sel).value + ","; 
				   edades += document.getElementById(obj_sel).value+"~";
				   if(document.getElementById(obj_sel).value == "1"){
					 bebes++;
				   }
				 }
				 if(cad_edad_nin != ""){
				   cadena_habi1 += cad_edad_nin.substr(0,cad_edad_nin.length-1) + ')';
				 }
				 
				 if(edades != ""){
				   edades = edades.substr(0,edades.length -1);//quitamos el último ~
				 }
				 habi1 += ";"+edades;
				 habi1 += ";"+bebes;
				
			 break; 
			 case 2:
				 obj_adu2 = 'numadu_'+i+'F';
				 obj_nin2 = 'numnin_'+i+'F';
				 habi2 = document.getElementById(obj_adu2).value+";"+document.getElementById(obj_nin2).value;
				 ninos = parseInt(document.getElementById(obj_nin2).value,10);
				 edades = "";
				 bebes = 0;
				 cadena_habi2 = document.getElementById(obj_adu2).value+' adultos';
				 if(ninos> 0){
				  cadena_habi2 += ', '+ninos+' ni&ntilde;os (';
				 }
				 cad_edad_nin = "";
				 for(j=0;j<ninos;j++){
				   obj_sel = 'seled_'+i+j+'F';	 
				   cad_edad_nin += document.getElementById(obj_sel).value + ",";
				   edades += document.getElementById(obj_sel).value+"~";
				   if(document.getElementById(obj_sel).value == "1"){
					 bebes++;
				   }
				 }
				 if(cad_edad_nin != ""){
				   cadena_habi2 += cad_edad_nin.substr(0,cad_edad_nin.length-1) + ')';
				 }
				 if(edades != ""){
				   edades = edades.substr(0,edades.length -1);//quitamos el último ~
				 }
				 habi2 += ";"+edades;
				 habi2 += ";"+bebes;
			 break;
			 case 3:
			     obj_adu3 = 'numadu_'+i+'F';
				 obj_nin3 = 'numnin_'+i+'F';
				 habi3 = document.getElementById(obj_adu3).value+";"+document.getElementById(obj_nin3).value;
				 ninos = parseInt(document.getElementById(obj_nin3).value,10);
				 edades = "";
				 bebes = 0;
				 cadena_habi3 = document.getElementById(obj_adu3).value+' adultos';
				 if(ninos> 0){
				  cadena_habi3 += ', '+ninos+' ni&ntilde;os (';
				 }
				 cad_edad_nin = "";
				 for(j=0;j<ninos;j++){
				   obj_sel = 'seled_'+i+j+'F';	 
				   cad_edad_nin += document.getElementById(obj_sel).value + ",";
				   edades += document.getElementById(obj_sel).value+"~";
				   if(document.getElementById(obj_sel).value == "1"){
					 bebes++;
				   }
				 }
				 if(cad_edad_nin != ""){
				   cadena_habi3 += cad_edad_nin.substr(0,cad_edad_nin.length-1) + ')';
				 }
				 if(edades!=""){
				   edades = edades.substr(0,edades.lenght - 1);//quitamos el último ~
				 }
				 habi3 += ";"+edades;
				 habi3 += ";"+bebes;
			 break;
		   }
		  
		  
		   
		}
		if(cadena_habi1 != ""){
		    cadena_hab_sel += '<div style="float:left; margin-right:30px"><strong>Habitaci&oacute;n 1</strong></div><div style=" float:left; display:inline; margin-left:6px ">'+cadena_habi1+'</div><div style="float:left; margin-right:10px"></div><div style="clear:both"></div>';
		  }
		  if(cadena_habi2 != ""){
		    cadena_hab_sel += '<div style="float:left; margin-right:30px"><strong>Habitaci&oacute;n 2</strong></div><div style=" float:left; display:inline; margin-left:6px ">'+cadena_habi2+'</div><div style="float:left; margin-right:10px"></div><div style="clear:both"></div>';
		  }
		  if(cadena_habi3 != ""){
		    cadena_hab_sel += '<div style="float:left; margin-right:30px"><strong>Habitaci&oacute;n 3</strong></div><div style=" float:left; display:inline; margin-left:6px ">'+cadena_habi3+'</div><div style="float:left; margin-right:10px"></div><div style="clear:both"></div>';
		  }
		  document.getElementById('content-hab-costas-texto').innerHTML = cadena_hab_sel;
	    $("#buscador_disponibilidad").hide();
		$("#buscador_disponibilidad_texto").show("slow");
		
		valor_hab1 = habi1;
		valor_hab2 = habi2;
		valor_hab3 = habi3;
		valor_tipo = document.getElementById('tipo_seleccionadoF').value;
		valor_destino = document.getElementById('destino_seleccionadoF').value;
		valor_zona = document.getElementById('zona_seleccionadaF').value;
		valor_idhotel = document.getElementById('idhotel').value;
		cal1.send({numhab: valor_numhab,fecini: valor_fecini,fecfin: valor_fecfin,buscador: valor_buscador,hab1: valor_hab1,hab2: valor_hab2,hab3: valor_hab3,tipo: valor_tipo,destino: valor_destino,zona: valor_zona,idhotel: valor_idhotel},'POST');

   }
		 
}


function buscardisponibilidad(){

    var call = new ajaxObject('./webservice/DisponibilidadHotelesRQ.php');
	call.onComplete = function (response, status, responsexml){
		contenido = response;
	    if(contenido == 'OK'){
			/*d2 = new Date();
 			tiempo_restado2 = d2.getTime();
 			tiempo_restado = Math.round((tiempo_restado2 - tiempo_restado1) / 1000); */ 
			tiempo_restado = 0;
			//lanzar recuperar busqueda
			recuperar_busqueda_escapada();
			
		  }else{
			 document.getElementById('cargando').style.display = 'none';
			  cadenaerror = '<div style="float:right;margin-right:26px;padding-bottom:10px" ><div style="float:left; margin-right:10px"><img src="img/warning.png" width="32px" height="32px"></div><div style="float:left;margin-top:14px"><span class="titulo_producto" style="font-size:1.2em;color:#ff0000">Lo sentinos no hay disponibilidad en estos momentos.</span></div><div style="clear: both;"></div></div>';  
			 
			 
			 var msg = mensajedispo(document.getElementById('tipo_seleccionado').value,document.getElementById('destino_seleccionado').value,document.getElementById('zona_seleccionada').value,document.getElementById('nombre_tipo_seleccionado').value,document.getElementById('nombre_destino_seleccionado').value,document.getElementById('nombre_zona_seleccionada').value,'buscadorcdF');
			
			 cadenaerror+= msg; 
			  
			 document.getElementById('error_dispo').innerHTML = cadenaerror; 
			 $("#error_dispo").show("slow");
			
		  }
		
	};
	 
	call.send();

}

function recuperar_busqueda_escapada(){
  
    var call2 = new ajaxObject('./webservice/RecuperarHotelesRQ.php');
	call2.onComplete = function (response, status, responsexml){
		contenido = response;
		
	    if(contenido != 'KO'){
			/*d2 = new Date();
 			tiempo_restado2 = d2.getTime();
 			tiempo_restado = Math.round((tiempo_restado2 - tiempo_restado1) / 1000); */ 
			tiempo_restado = 0;
			
			//tratar los datos que vienen y pintar las habitaciones solamente;
			document.getElementById('cargando').style.display = 'none';
			document.getElementById('disponibilidad_habitaciones').innerHTML = contenido;
			$("#disponibilidad_habitaciones").show("slow");
					
			
			
			
		  }else{
			  document.getElementById('cargando').style.display = 'none';
			  cadenaerror = '<div style="float:right;margin-right:26px;padding-bottom:10px" ><div style="float:left; margin-right:10px"><img src="img/warning.png" width="32px" height="32px"></div><div style="float:left;margin-top:14px"><span class="titulo_producto" style="font-size:1.2em;color:#ff0000">Lo sentinos no hay disponibilidad en estos momentos.</span></div><div style="clear: both;"></div></div>';  
			
			
			var msg = mensajedispo(document.getElementById('tipo_seleccionado').value,document.getElementById('destino_seleccionado').value,document.getElementById('zona_seleccionada').value,document.getElementById('nombre_tipo_seleccionado').value,document.getElementById('nombre_destino_seleccionado').value,document.getElementById('nombre_zona_seleccionada').value,'buscadorcdF');
			
			cadenaerror+= msg; 
		
			document.getElementById('error_dispo').innerHTML = cadenaerror; 
			  $("#error_dispo").show("slow");
		  }
		
	};
	 
	valor_tipo = document.getElementById('tipo_seleccionado').value;
	valor_destino = document.getElementById('destino_seleccionado').value;
	valor_zona = document.getElementById('zona_seleccionada').value; 
	valor_estado = 'ficha';
	valor_idhotel = document.getElementById('idhotel').value;
	call2.send({tipo: valor_tipo,destino: valor_destino,zona: valor_zona,estado: valor_estado,idhotel: valor_idhotel},'POST');
}

function mensajedispo(valortipo,valordestino,valorzona,nombretipo,nombredestino,nombrezona,buscador){
   msg = '<div style="clear: both; float:right;margin-right:26px">';
    if(valortipo != "" && valortipo != 'ALL'){			 
	 if(valorzona != "" && valorzona != 'ALL' && nombrezona != "" && nombrezona != "undefined"){
	
		msg += '<div style="clear:both"></div><div style="margin-bottom:5px; float:right"><input type="button" value="Ver hoteles DISPONIBLES '+nombretipo+' en '+nombrezona+'"  onclick="Javascript:enviadispo(\'tipo\',\'destino\',\'zona\',\''+buscador+'\')"></div>';
		if(valordestino != "" && valordestino != 'ALL' && nombredestino!= ""){
		msg += '<div style="clear:both"></div><div style="margin-bottom:5px; float:right"><input type="button" onclick="Javascript:enviadispo(\'tipo\',\'destino\',\'\',\''+buscador+'\')" value="Ver Hoteles DISPONIBLES '+nombretipo+' en '+nombredestino+'"></div>';
		}
	 }else{
		if(valordestino != "" && valordestino != 'ALL' && nombredestino != ""){
		msg += '<div style="clear:both"></div><div style="margin-bottom:5px; float:right"><input type="button" onclick="Javascript:enviadispo(\'tipo\',\'destino\',\'\',\''+buscador+'\')" value="Ver Hoteles DISPONIBLES '+nombretipo+' en '+nombredestino+'"></div>';
		}
	 }
  }else{
	if(valordestino != "" && valordestino != 'ALL' && nombredestino != ""){
		msg += '<div style="clear:both"></div><div style="margin-bottom:5px; float:right"><input type="button" onclick="Javascript:enviadispo(\'\',\'destino\',\'\',\''+buscador+'\')" value="Ver Hoteles DISPONIBLES en '+nombredestino+'"></div>';
	 }
	 if(valorzona != "" && valorzona != 'ALL' && nombrezona != ""){
		msg += '<div style="clear:both"></div><div style="margin-bottom:5px; float:right"><input type="button" onclick="Javascript:enviadispo(\'\',\'destino\',\'zona\',\''+buscador+'\')" value="Ver Hoteles DISPONIBLES en '+nombrezona+'"></div>';
	 }
  }
  msg += '<div style="clear:both"></div></div>';
  
  return msg;

}
function actualizar_nombres(){
	if(document.getElementById('nombre_tipo_seleccionado') && cadenatipo !=""){
		 document.getElementById('nombre_tipo_seleccionado').value = cadenatipo;
		 
	 }
   if(document.getElementById('nombre_destino_seleccionado') && cadenadestino !=""){
	
	 document.getElementById('nombre_destino_seleccionado').value = cadenadestino;
   }
   if(document.getElementById('nombre_zona_seleccionada') && cadenazona !=""){
	 document.getElementById('nombre_zona_seleccionada').value = cadenazona;
   }
}
function enviadispo(tipo,destino,zona,buscador){
	
	switch(buscador){
	  case 'buscadorcd':
		 if(tipo == ""){
		   
		   document.getElementById('tipo_seleccionado').value = "";
		   document.getElementById('nombre_tipo_seleccionado').value = "";
		}
		if(destino == ""){
		   
		   document.getElementById('destino_seleccionado').value = "";
		   document.getElementById('nombre_destino_seleccionado').value = "";
		}
		if(zona == ""){
		  
		   document.getElementById('zona_seleccionada').value = "";
		   document.getElementById('nombre_zona_seleccionada').value = "";
		}
		document.buscadorcd.action = 'buscando.php';
	    validar_busqueda(document.buscadorcd);
	  break;
	  case 'buscadorcdF':
	  
	    if(tipo == ""){
	   
		   document.getElementById('tipo_seleccionadoF').value = "";
		   document.getElementById('nombre_tipo_seleccionadoF').value = "";
		}
		if(destino == ""){
		   
		   document.getElementById('destino_seleccionadoF').value = "";
		   document.getElementById('nombre_destino_seleccionadoF').value = "";
		}
		if(zona == ""){
		  
		   document.getElementById('zona_seleccionadaF').value = "";
		   document.getElementById('nombre_zona_seleccionadaF').value = "";
		}
	   document.buscadorcdF.action = 'buscando.php';
	validar_busqueda_ficha2(document.buscadorcdF);
	 break;
	  
	}
	
	//buscador.submit();
}



function validar_venta(){

error = "";

if(document.reservar.nombre.value == ""){
    error += "Nombre del titular de la reserva vac\u00EDo.\n";
}else{
  
   if(!es_cadena(document.reservar.nombre.value)){
      error += "El nombre del titular de la reserva no es v\u00E1lido.\n";
   }
}

if(document.reservar.apellido1.value == ""){
    error += "Primer apellido del titular de la reserva vac\u00EDo.\n";
}else{
 
   if(!es_cadena(document.reservar.apellido1.value)){
      error += "El primer apellido del titular de la reserva no son v\u00E1lido.\n";
   }
}
if(document.reservar.apellido2.value == ""){
    error += "Primer apellido del titular de la reserva vac\u00EDo.\n";
}else{
 
   if(!es_cadena(document.reservar.apellido2.value)){
      error += "El primer apellido del titular de la reserva no es v\u00E1lido.\n";
   }
}


if(document.reservar.telefono.value == ""){
     error += "Tel\u00E9fono del titular de la reserva vac\u00EDo.\n";
}else{
	
  if(!es_numerico(document.reservar.telefono.value)){//vemos si es numérico 
     error += "Tel\u00E9fono del titular de la reserva no v\u00E1lido.\n";
  }else{
     if(document.reservar.telefono.value.length < 9){
	   error += "Tel\u00E9fono del titular de la reserva no v\u00E1lido.\n";
	 }
  }
}
if(document.reservar.cp.value == ""){
	error += "Introduzca su c\u00F3digo postal.\n";
}else{
  if(!es_numerico(document.reservar.cp.value)){
	  error += "C\u00F3digo postal no v\u00E1lido.\n";
  }else{
    if(document.reservar.cp.value < 5){
	   error += "C\u00F3digo postal no v\u00E1lido.\n";
	}
  }
}

if(document.reservar.direccion.value == ""){
  error += "Introduzca su direcci\u00F3n postal.";
}

if(document.reservar.email.value == ""){
  error += "Campo email del titular de la reserva vac\u00EDo.\n";

}else{

	if(document.reservar.email.value.indexOf(".") == -1 || document.reservar.email.value.indexOf("@") == -1){
	   error += "Formato de email no v\u00E1lido\n";
	}
}

if(document.reservar.confirmaemail.value == ""){
  error += "Campo confirma email del titular de la reserva vac\u00EDo.\n";

}else{

	if(document.reservar.confirmaemail.value.indexOf(".") == -1 || document.reservar.confirmaemail.value.indexOf("@") == -1){
	   error += "Formato de email no v\u00E1lido\n";
	}
}


if(document.reservar.ndoc.value == ""){
	error += "Campo nº de documento del titular de la reserva vac\u00EDo.\n";
}




//forma de pago
if(forma_pago == "maxmind" && document.reservar.metodopago[0].checked ){
	//alert("entra: "+ forma_pago);
	//VALIDO EL NÚMERO DE CUENTA
	if(document.reservar.numtotal.value==""){
	  error += "Debe introducir el n\u00FAmero de su tarjeta de cr\u00E9dito.\n";
	}else{
	  if( ValidarTJ(document.reservar.numtotal.value) == false){
	    error += "Número de tarjeta no v\u00E1lido.\n";
	  }
	}
	
	 if(!es_numerico(document.reservar.numtotal.value)){//vemos si es numérico 
			error += "Número de tarjeta no v\u00E1lido.\n";
	 }
	 
	//VALIDO EL CODIGO DE SEGURIDAD CVV
	if(document.reservar.cvv.value==""){
	  error += "Debe indicar el código de seguridad de su tarjeta.\n";
	}
	var cod_cvv = document.reservar.cvv.value;
	if(cod_cvv.length < 3){
	 error +="El código de seguridad debe tener al menos 3 dígitos\n";
	} 
	if(!es_numerico(cod_cvv)){//vemos si es numérico el cvv
			error += "Código de seguridad no válido.\n";
	 }
	
	//VALIDO LA FECHA DE CADUCIDAD
	if (document.reservar.mes.value=="vacio" || document.reservar.ano.value=="vacio"){
		error += "No ha detallado la caducidad de la tarjeta\n";

	}
	
	//VALIDO EL NOMBRE QUE FIGURA EN LA TARJETA
	if(document.reservar.nombretag.value==""){
	 error += "Campo Nombre que figura en la tarjeta vacio.\n";
	}else{
	 if(!es_cadena(document.reservar.nombretag.value)){
	  error += "El nombre que aparece en la tarjeta no es válido.\n";
	 }
	}
}
	
	if(document.reservar.condiciones.checked == false){
	  error += "Debe aceptar las condiciones de reserva\n";
	}
	
	if(document.getElementById('estadobloqueo')){
	  var estado = document.getElementById('estadobloqueo').value;
	  if(estado != 'dolt_CF' && estado != 'dolt_DS'){
	     error+= "El servicio seleccionado no tiene confirmaci\u00F3n inmediata. P\u00F3ngase en contacto con nosotros para finalizar su reserva.\n";
	  }
	}
	
	if(error == ""){
		if(document.getElementById('importetotal')){
		   document.reservar.importereserva.value = document.getElementById('importetotal').value; 
		   document.reservar.submit();
		}else{
		  alert("Error inesperado. Escoja de nuevo el hotel e inténtelo de nuevo.");
		}
	    
		//alert("todo ok reservar");
	}else{
	    alert(error);
	}
}

//FUNCIÓN QUE CONTROLA QUE TODDOS LOS CARACTERES DE UNA CADENA NO SEAN NUMEROS
function es_cadena(cad){
 var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú_ ";
 var checkStr = cad;
 var allValid = true;
 for (z = 0; z < checkStr.length; z++) {
  ch = checkStr.charAt(z);
 
  for (j = 0; j < checkOK.length; j++){
	// alert(ch+"-->"+checkOK.charAt(j));
	if (ch == checkOK.charAt(j))
	 break;

	//alert(j)
	if (j == (checkOK.length - 1)) {
	 allValid = false;
	 
	}
  }
 }
   return (allValid);
 
}//FIN FUNCIÓN ES_CADENA


//función que controla que todos los caracteres de una cadena son números
function es_numerico(cadena){
var numeros = "0123456789";
var todo_valido = true;

for (i = 0; i < cadena.length; i++) 
{
 ch = cadena.charAt(i);

 for (j = 0; j < numeros.length; j++){
	
	if (ch == numeros.charAt(j))
	  break;
	  
	if (j == (numeros.length - 1) ) {
	 todo_valido = false;
	}
  }		
}


return todo_valido;
}//fin funcion es_numerico

function ValidarTJ(numero_tarjeta) {
 var cadena = numero_tarjeta.toString();
 var longitud = cadena.length;
 var cifra = null;
 var cifra_cad=null;
 var suma=0;
 for (var i=0; i < longitud; i+=2){
   cifra = parseInt(cadena.charAt(i))*2;
   if (cifra > 9){ 
     cifra_cad = cifra.toString();
     cifra = parseInt(cifra_cad.charAt(0)) + 
parseInt(cifra_cad.charAt(1));
   }
   suma+=cifra;
 }
 for (var i=1; i < longitud; i+=2){
   suma += parseInt(cadena.charAt(i));
 }
	
 if ((suma % 10) == 0){ 
  return true;
 } else {
  return false;
 }
}
 function isCreditCard( CC ) 
     {                         
          if (CC.length > 19)
               return (false);

          sum = 0; mul = 1; l = CC.length;
          for (i = 0; i < l; i++) 
          {
               digit = CC.substring(l-i-1,l-i);
               tproduct = parseInt(digit ,10)*mul;
               if (tproduct >= 10)
                    sum += (tproduct % 10) + 1;
               else
                    sum += tproduct;
               if (mul == 1)
                    mul++;
               else
                    mul--;
          }
          if ((sum % 10) == 0)
               return (true);
          else
               return (false);
     }
//función no espacios
function no_espacios(cadena){
//pasamos a liminar primero el primer espacio en blanco introducido y el último
var primerBlanco = /^ /
var ultimoBlanco = / $/

cadena = cadena.replace (primerBlanco,"");
cadena = cadena.replace (ultimoBlanco,"");

return (cadena);
}

function validar_buscador_sindispo(){
	var tip = document.getElementById('selTip').value;
	var des = document.getElementById('selDes').value;
	var zon = document.getElementById('selZona').value;
	var busca = 0;
	if(tip == "" && des =="" && zon == ""){
	   alert('Debe elegir al menos una Costa o destino');
	}else{
	  //ver si hay destinos con qty 0 y obligar a pedir fechas
	  if(des != ""){
	     nombredestino = document.getElementById('selDes').options[document.getElementById('selDes').selectedIndex].text;
		  if(validatedes(nombredestino)===false){
		    alert('Para este destino debe indicar fechas y pasajeros.');
		  }else{
		    busca = 1;
		  }
	  }else{
		  if(tip != ""){
			 nombretipo = document.getElementById('selTip').options[document.getElementById('selTip').selectedIndex].text;
			  if(validatedes(nombretipo)===false){
				alert('Para este destino debe indicar fechas y pasajeros.');
			  }else{
			    busca = 1;
			  }
		  }else{
			  if(zon != ""){
				 nombrezona = document.getElementById('selZona').options[document.getElementById('selZona').selectedIndex].text;
				  if(validatedes(nombrezona)===false){
					alert('Para este destino debe indicar fechas y pasajeros.');
				  }else{
				    busca = 1;
				  }
			  }
		  }
	  }
	  if(busca==1){
	  document.buscador_sd.submit();
	  }
		
	  
	}
}

function validatedes(campo) {   
    var RegExPattern = /[(][0-9]*[)]$/;   
    if ((campo.match(RegExPattern)) && (campo!='')) {   
       return true;
    } else {   
       return false;   
        //campo.focus();   
    }    
}   

/*******costas***********/
function selectPais(pais){
call2 = new ajaxObject('./webservice/DestinosHotelesRQ.php');
call2.load('bus_sel_destinos',{tipo: pais},'GET');
call3 = new ajaxObject('./webservice/DestinosHotelesRQ.php');
call3.load('bus_sel_zonas',{tipo: pais,zonas: '1'},'GET');

}

function selectDestinoCostas(destinocosta){
//pide las zonas del destino seleccionado
  pais = document.getElementById('selTip').value;
  if(document.getElementById('destino_seleccionado')){
   document.getElementById('destino_seleccionado').value = destinocosta;
   document.getElementById('zona_seleccionada').value = '';
  }
  call1 = new ajaxObject('./webservice/DestinosHotelesRQ.php');
  call1.load('bus_sel_zonas',{tipo: pais, destino: destinocosta,zonas: '1'},'GET');
}

function selectZonaCostas(zonacosta){
  if(document.getElementById('zona_seleccionada')){
	  document.getElementById('zona_seleccionada').value = zonacosta;
  }
}

//rellena los 3 select de la portada
function destinos_tiposcostas(){
	
call1 = new ajaxObject('./webservice/DestinosHotelesRQ2.php');
call1.load('destinos_roman',{tipo: 'UK', destino:'1021', zonas: '1'},'GET');
call2 = new ajaxObject('./webservice/DestinosHotelesRQ2.php');
call2.load('destinos_relax',{tipo: 'FR', destino:'1333', zonas: '1'},'GET');
call3 = new ajaxObject('./webservice/DestinosHotelesRQ2.php');
call3.load('destinos_fami',{tipo: 'IT', destino:'1504', zonas: '1'},'GET');
}

function hoteles_costas_sugerencias(){
	call1 = new ajaxObject('./webservice/ListadoHotelesRQ_sugerencias.php');
	call1.onComplete = function(response){
		if(response != 'KO'){
		  document.getElementById('reco1').innerHTML = response;
		}
		call2 = new ajaxObject('./webservice/ListadoHotelesRQ_sugerencias.php');
		call2.onComplete = function(response){
			if(response != 'KO'){
			  document.getElementById('reco2').innerHTML = response;
			}
			call3 = new ajaxObject('./webservice/ListadoHotelesRQ_sugerencias.php');
			call3.onComplete = function(response){
				if(response != 'KO'){
				  document.getElementById('reco3').innerHTML = response;
				}
				call4 = new ajaxObject('./webservice/ListadoHotelesRQ_sugerencias.php');
				call4.onComplete = function(response){
					if(response != 'KO'){
					  document.getElementById('reco4').innerHTML = response;
					}
					destinos_tiposcostas();
				};
				call4.send({tipo:'ES',destino:'13',zona:'ALL',mostrar:'3',classname: 'titulo_cblanca',pintar:'1'});
			};
			call3.send({tipo:'ES',destino:'16',zona:'ALL',mostrar:'3',classname: 'titulo_cdorada',pintar:'1'});
		};
		call2.send({tipo:'ES',destino:'14',zona:'ALL',mostrar:'3',classname: 'titulo_cbrava',pintar:'1'});
	};
	
	call1.send({tipo:'ES',destino:'22',zona:'ALL',mostrar:'3',classname: 'titulo_csol',pintar:'1'});

}

function aux_hoteles_costas_sugerencias(){
 call1 = new ajaxObject('./webservice/auxl_ListadoHotelesRQ_sugerencias.php'); 
 call1.onComplete = function(response){
	 var aux = response.split("#~#");
	 document.getElementById('reco1').innerHTML = aux[0];
	 document.getElementById('reco2').innerHTML = aux[1];
	 document.getElementById('reco3').innerHTML = aux[2];
	
	 hoteles_costas_resto();
	// destinos_tiposcostas();
 };
 call1.send();
}

function hoteles_costas_resto(){
	 call1 = new ajaxObject('./webservice/aux2_ListadoHotelesRQ_sugerencias.php'); 
 call1.onComplete = function(response){
	 var aux = response.split("#~#");
	 document.getElementById('resto1').innerHTML = aux[0];
	 document.getElementById('resto2').innerHTML = aux[1];
	 document.getElementById('resto3').innerHTML = aux[2];
     destinos_tiposcostas();
 };
 call1.send();
}


function selecciona_destinocosta(iddestino,idpais){
  if(document.getElementById('destino_seleccionado')){
   document.getElementById('destino_seleccionado').value = iddestino;
   document.getElementById('zona_seleccionada').value = '';
  }
  call = new ajaxObject('./webservice/PaisesRQ.php');
  call.onComplete = function(response){
      document.getElementById('bus_sel_tipos').innerHTML = response;
	  var elepais = document.getElementById('selTip').options.length;
	  for(i=0;i<elepais;i++){
		 if(document.getElementById('selTip').options[i].value == idpais){
			document.getElementById('selTip').options[i].selected = true;
			break;
		 }
	  }
	   
  };
  call.send();
  call1 = new ajaxObject('./webservice/DestinosHotelesRQ.php');
  call1.onComplete = function(response){
	  document.getElementById('bus_sel_zonas').innerHTML = response;
	  
	 
	  
	  var ele = document.getElementById('selDes').options.length;
	  for(i=0;i<ele;i++){
		 if(document.getElementById('selDes').options[i].value == iddestino){
			document.getElementById('selDes').options[i].selected = true;
			break;
		 }
	  }
	  document.getElementById('caja_mapas').style.display = 'none';
	  document.getElementById('exposeMask').style.display = 'none';
  };
  call1.send({tipo: idpais, destino: iddestino,zonas: '1'},'GET');
   
}


function selecciona_zonacosta(idzona,idpais,iddestino){

  call = new ajaxObject('./webservice/PaisesRQ.php');
  call.onComplete = function(response){
      document.getElementById('bus_sel_tipos').innerHTML = response;
	  var elepais = document.getElementById('selTip').options.length;
	  for(i=0;i<elepais;i++){
		 if(document.getElementById('selTip').options[i].value == idpais){
			document.getElementById('selTip').options[i].selected = true;
			break;
		 }
	  }
	   
  };
  call.send();

  call2 = new ajaxObject('./webservice/DestinosHotelesRQ.php');
  call2.onComplete = function(response){
     document.getElementById('bus_sel_destinos').innerHTML = response;
	 
	  var eledes = document.getElementById('selDes').options.length;
	  for(i=0;i<eledes;i++){
	   if(document.getElementById('selDes').options[i].value == iddestino){
		   document.getElementById('selDes').options[i].selected = true;
		   break;
	   }
	  }
  };
  call2.send({tipo: idpais},'GET');

  
  call3 = new ajaxObject('./webservice/DestinosHotelesRQ.php');
  call3.onComplete=function(response){
    document.getElementById('bus_sel_zonas').innerHTML = response;
	
	 if(document.getElementById('zona_seleccionada')){
	  document.getElementById('zona_seleccionada').value = idzona;
	  }
	  var ele = document.getElementById('selZona').options.length;
	  for(i=0;i<ele;i++){
	   if(document.getElementById('selZona').options[i].value == idzona){
		   document.getElementById('selZona').options[i].selected = true;
		   break;
	   }
	  }
	  document.getElementById('caja_mapas').style.display = 'none';
	   document.getElementById('exposeMask').style.display = 'none';
  };
  call3.send({tipo: idpais,zonas: '1'},'GET');
//  call3.load('bus_sel_zonas',{tipo: pais,zonas: '1'},'GET');

  //selectPais(pais);	
 
  
  
  
}


function ver_lanzar_busqueda(){
	if(document.getElementById('fecini').value != '' && document.getElementById('fecfin').value != ''){
	  validar_busqueda(document.buscadorcd);  
	}else{
	  validar_buscador_sindispo();
	}
}
function calcular_importe_total(gastos_gestion){
  var importe = parseFloat(document.getElementById('importetotal').value);
  
  var total = importe + parseFloat(gastos_gestion);
  document.getElementById('importetotal').value = total;
  document.getElementById('texto_importetotal').innerHTML = "<strong>"+total + "&euro;</strong>";
}


function verdispoenlace(objeto){
	var aux = document.getElementById(objeto).value;
	var datos = aux.split('#~#');
	//$hoteles_asia[$i]['id_destino'].'#~#'.$hoteles_asia[$i]['nombre_destino'].'#~#'.$hoteles_asia[$i]['finicio'].'#~#'.$hoteles_asia[$i]['ffin'];
	document.getElementById('destino_seleccionado').value = datos[0];
	document.getElementById('vdestino_hotel').value = datos[1];
	document.getElementById('nombre_destino_seleccionado').value = datos[1];
	document.getElementById('fecini').value = datos[2];
	document.getElementById('fecfin').value = datos[3];
	
	//validar_busqueda(document.buscadorcd);
	var urldestino = 'listado_sd.php?destino='+datos[0]+'&ndestino='+escape(datos[1]);
	document.location.href = urldestino;
	
}

